Fixup futimens issues.
## not, see <http://www.gnu.org/licenses/>.
##
+WEXTRA = @WEXTRA@
+LD_AS_NEEDED = @LD_AS_NEEDED@
+
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"${localedir}"'
AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_srcdir)/lib -I..
-AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \
+
+ # Warn about stack usage of more than 256K = 262144 bytes.
+ if ADD_STACK_USAGE_WARNING
+ STACK_USAGE_WARNING=-Wstack-usage=262144
+ else
+ STACK_USAGE_WARNING=
+ endif
+AM_CFLAGS = -std=gnu99 -Wall -Wshadow \
$(if $($(*F)_no_Werror),,-Werror) \
- $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \
+ $(if $($(*F)_no_Wunused),,-Wunused $(WEXTRA)) \
+ $(if $($(*F)_no_Wformat),-Wno-format,-Wformat=2) \
+ $(if $($(*F)_no_Wstack_usage),,$(STACK_USAGE_WARNING)) \
$($(*F)_CFLAGS)
+if BUILD_WERROR
+AM_CFLAGS += $(if $($(*F)_no_Werror),,-Werror)
+endif
+
COMPILE.os = $(filter-out -fprofile-arcs -ftest-coverage, $(COMPILE))
+ DEFS.os = -DPIC -DSHARED
+ if SYMBOL_VERSIONING
+ DEFS.os += -DSYMBOL_VERSIONING
+ else
+ endif
+
%.os: %.c %.o
if AMDEP
- if $(COMPILE.os) -c -o $@ -fpic -DPIC -DSHARED -MT $@ -MD -MP \
+ if $(COMPILE.os) -c -o $@ -fpic $(DEFS.os) -MT $@ -MD -MP \
-MF "$(DEPDIR)/$*.Tpo" `test -f '$<' || echo '$(srcdir)/'`$<; \
then cat "$(DEPDIR)/$*.Tpo" >> "$(DEPDIR)/$*.Po"; \
rm -f "$(DEPDIR)/$*.Tpo"; \
AC_CHECK_TOOL([READELF], [readelf])
AC_CHECK_TOOL([NM], [nm])
- AC_CACHE_CHECK([for gcc with C99 support], ac_cv_c99, [dnl
++AC_CHECK_FUNCS([futimens])
++
+ # We use -std=gnu99 but have explicit checks for some language constructs
+ # and GNU extensions since some compilers claim GNU99 support, but don't
+ # really support all language extensions. In particular we need
+ # Mixed Declarations and Code
+ # https://gcc.gnu.org/onlinedocs/gcc/Mixed-Declarations.html
+ # Nested Functions
+ # https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html
+ # Arrays of Variable Length
+ # https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html
+ AC_CACHE_CHECK([for gcc with GNU99 support], ac_cv_c99, [dnl
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -std=gnu99"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
ac_cv_c99=yes, ac_cv_c99=no)
CFLAGS="$old_CFLAGS"])
AS_IF([test "x$ac_cv_c99" != xyes],
- AC_MSG_ERROR([gcc with C99 support required]))
+ AC_MSG_ERROR([gcc with GNU99 support required]))
+AC_CACHE_CHECK([for -Wextra option to $CC], ac_cv_cc_wextra, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Wextra"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([void foo (void) { }])],
+ ac_cv_cc_wextra=yes, ac_cv_cc_wextra=no)
+CFLAGS="$old_CFLAGS"])
+AC_SUBST(WEXTRA)
+AS_IF([test "x$ac_cv_cc_wextra" = xyes], [WEXTRA=-Wextra], [WEXTRA=-W])
+
+AC_CACHE_CHECK([for -fgnu89-inline option to $CC], ac_cv_cc_gnu89_inline, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -fgnu89-inline -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([
+void foo (void)
+{
+ inline void bar (void) {}
+ bar ();
+}
+extern inline void baz (void) {}
+])], ac_cv_cc_gnu89_inline=yes, ac_cv_cc_gnu89_inline=no)
+CFLAGS="$old_CFLAGS"])
+AS_IF([test "x$ac_cv_cc_gnu89_inline" = xyes],
+ [WEXTRA="${WEXTRA:+$WEXTRA }-fgnu89-inline"])
+
+AC_CACHE_CHECK([for --as-needed linker option],
+ ac_cv_as_needed, [dnl
+cat > conftest.c <<EOF
+int main (void) { return 0; }
+EOF
+if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
+ -fPIC -shared -o conftest.so conftest.c
+ -Wl,--as-needed 1>&AS_MESSAGE_LOG_FD])
+then
+ ac_cv_as_needed=yes
+else
+ ac_cv_as_needed=no
+fi
+rm -f conftest*])
+AS_IF([test "x$ac_cv_as_needed" = xyes],
+ [LD_AS_NEEDED=-Wl,--as-needed], [LD_AS_NEEDED=])
+AC_SUBST(LD_AS_NEEDED)
+
+AC_CACHE_CHECK([for __builtin_popcount], ac_cv_popcount, [dnl
+AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[exit (__builtin_popcount (127));]])],
+ ac_cv_popcount=yes, ac_cv_popcount=no)])
+AS_IF([test "x$ac_cv_popcount" = xyes],
+ [AC_DEFINE([HAVE_BUILTIN_POPCOUNT], [1], [Have __builtin_popcount.])])
+
AC_CACHE_CHECK([for __thread support], ac_cv_tls, [dnl
# Use the same flags that we use for our DSOs, so the test is representative.
# Some old compiler/linker/libc combinations fail some ways and not others.
esac
# Round up to the next release API (x.y) version.
-eu_version=$(( (eu_version + 999) / 1000 ))
+eu_version=`expr \( $eu_version + 999 \) / 1000`
+ dnl Unique ID for this build.
+ MODVERSION="Build for ${LIBEBL_SUBDIR} ${eu_version} ${ac_cv_build}"
+ AC_SUBST([MODVERSION])
+ AC_DEFINE_UNQUOTED(MODVERSION, "$MODVERSION")
+ AH_TEMPLATE([MODVERSION], [Identifier for modules in the build.])
+
AC_CHECK_SIZEOF(long)
# On aarch64 before glibc 2.20 we would get the kernel user_pt_regs instead
/* This macro is used by the tests conditionalize for standalone building. */
#define ELFUTILS_HEADER(name) <lib##name.h>
+#ifndef HAVE_BUILTIN_POPCOUNT
+# define __builtin_popcount hakmem_popcount
+static inline unsigned int __attribute__ ((unused))
+hakmem_popcount (unsigned int x)
+{
+ /* HAKMEM 169 */
+ unsigned int n = x - ((x >> 1) & 033333333333) - ((x >> 2) & 011111111111);
+ return ((n + (n >> 3)) & 030707070707) % 63;
+}
+#endif /* HAVE_BUILTIN_POPCOUNT */
+
- #ifdef SHARED
+ #ifdef SYMBOL_VERSIONING
# define OLD_VERSION(name, version) \
asm (".globl _compat." #version "." #name "\n" \
"_compat." #version "." #name " = " #name "\n" \
# XXX While the file is not finished, don't warn about this
ldgeneric_no_Wunused = yes
+ ldgeneric_no_Wstack_usage = yes
- readelf_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) -ldl
- nm_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) -ldl \
+# Buggy old compilers or libc headers.
+readelf_no_Werror = yes
+strings_no_Werror = yes
+addr2line_no_Wformat = yes
+
+ # Bad, bad stack usage...
+ readelf_no_Wstack_usage = yes
+ nm_no_Wstack_usage = yes
+ size_no_Wstack_usage = yes
+ strip_no_Wstack_usage = yes
+ elflint_no_Wstack_usage = yes
+ findtextrel_no_Wstack_usage = yes
+ elfcmp_no_Wstack_usage = yes
+ objdump_no_Wstack_usage = yes
+ ranlib_no_Wstack_usage = yes
+ ar_no_Wstack_usage = yes
+ unstrip_no_Wstack_usage = yes
+
+ readelf_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl
+ nm_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl \
$(demanglelib)
- size_LDADD = $(libelf) $(libeu)
- strip_LDADD = $(libebl) $(libelf) $(libeu) -ldl
- ld_LDADD = $(libebl) $(libelf) $(libeu) -ldl
+ size_LDADD = $(libelf) $(libeu) $(argp_LDADD)
+ strip_LDADD = $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl
+ ld_LDADD = $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl
if NATIVE_LD
# -ldl is always needed for libebl.
ld_LDADD += libld_elf.a
if (preserve_dates)
{
- struct timeval tv[2];
+ struct timespec tv[2];
tv[0].tv_sec = arhdr->ar_date;
- tv[0].tv_usec = 0;
+ tv[0].tv_nsec = 0;
tv[1].tv_sec = arhdr->ar_date;
- tv[1].tv_usec = 0;
-
- if (unlikely (futimes (xfd, tv) != 0))
+ tv[1].tv_nsec = 0;
+
++#ifdef HAVE_FUTIMENS
+ if (unlikely (futimens (xfd, tv) != 0))
++#else
++ struct timeval times[2];
++ TIMESPEC_TO_TIMEVAL (×[0], &tv[0]);
++ TIMESPEC_TO_TIMEVAL (×[1], &tv[1]);
++ if (unlikely (futimes (xfd, times) != 0))
++#endif
{
error (0, errno,
gettext ("cannot change modification time of %s"),
/* If requested, preserve the timestamp. */
if (tvp != NULL)
{
- if (FUTIMES (fd, output_fname, tvp) != 0)
++#ifdef HAVE_FUTIMENS
+ if (futimens (fd, tvp) != 0)
++#else
++ struct timeval times[2];
++ TIMESPEC_TO_TIMEVAL (×[0], &tvp[0]);
++ TIMESPEC_TO_TIMEVAL (×[1], &tvp[1]);
++ if (futimes (fd, times) != 0)
++#endif
{
error (0, errno, gettext ("\
cannot set access and modification date of '%s'"),
if (tvp != NULL)
{
- if (unlikely (FUTIMES (fd, fname, tvp) != 0))
++#ifdef HAVE_FUTIMENS
+ if (unlikely (futimens (fd, tvp) != 0))
++#else
++ struct timeval times[2];
++ TIMESPEC_TO_TIMEVAL (×[0], &tvp[0]);
++ TIMESPEC_TO_TIMEVAL (×[1], &tvp[1]);
++ if (unlikely (futimes (fd, times) != 0))
++#endif
{
error (0, errno, gettext ("\
cannot set access and modification date of '%s'"), fname);
get_files_LDADD = $(libdw) $(libelf)
get_aranges_LDADD = $(libdw) $(libelf)
allfcts_LDADD = $(libdw) $(libelf)
- line2addr_LDADD = $(libdw)
- addrscopes_LDADD = $(libdw)
- funcscopes_LDADD = $(libdw)
- funcretval_LDADD = $(libdw)
- allregs_LDADD = $(libdw)
- find_prologues_LDADD = $(libdw)
+line2addr_no_Wformat = yes
+ line2addr_LDADD = $(libdw) $(argp_LDADD)
+ addrscopes_LDADD = $(libdw) $(argp_LDADD)
+ funcscopes_LDADD = $(libdw) $(argp_LDADD)
+ funcretval_LDADD = $(libdw) $(argp_LDADD)
+ allregs_LDADD = $(libdw) $(argp_LDADD)
+ find_prologues_LDADD = $(libdw) $(argp_LDADD)
#show_ciefde_LDADD = ../libdwarf/libdwarf.so $(libelf)
asm_tst1_LDADD = $(libasm) $(libebl) $(libelf) -ldl
asm_tst2_LDADD = $(libasm) $(libebl) $(libelf) -ldl