From: Dave Hart Date: Mon, 21 Mar 2011 06:28:29 +0000 (+0000) Subject: [Bug 1844] ntpd 4.2.7p131 NetBSD, ld --gc-sections links bad executable. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=916145ce1e1a9cbe364df4d4f75d33e13a2bc09d;p=thirdparty%2Fntp.git [Bug 1844] ntpd 4.2.7p131 NetBSD, ld --gc-sections links bad executable. bk: 4d86f00dAtMyI33ZKd3tHN7HS672CQ --- diff --git a/ChangeLog b/ChangeLog index a778cc4882..ed402c8d9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +* [Bug 1844] ntpd 4.2.7p131 NetBSD, --gc-sections links bad executable. +* Fix "make distcheck" break in libevent/sample caused by typo. (4.2.7p141) 2011/03/20 Released by Harlan Stenn * Add "ntpq -c iostats" similar to "ntpdc -c iostats". * Compare entire timestamp to reject duplicates in refclock_pps(). diff --git a/sntp/libevent/Makefile.am b/sntp/libevent/Makefile.am index 5eb2ed820c..9b048179b5 100644 --- a/sntp/libevent/Makefile.am +++ b/sntp/libevent/Makefile.am @@ -217,7 +217,7 @@ noinst_HEADERS = util-internal.h mm-internal.h ipv6-internal.h \ WIN32-Code/tree.h \ compat/sys/queue.h -EVENT1_HDRs = event.h evhttp.h evdns.h evrpc.h evutil.h +EVENT1_HDRS = event.h evhttp.h evdns.h evrpc.h evutil.h if INSTALL_LIBEVENT include_HEADERS = $(EVENT1_HDRS) diff --git a/sntp/libevent/configure.in b/sntp/libevent/configure.in index d856f0514f..cd8711e505 100644 --- a/sntp/libevent/configure.in +++ b/sntp/libevent/configure.in @@ -677,26 +677,64 @@ LIBEVENT_GC_SECTIONS= if test "$GCC" = yes ; then AC_CACHE_CHECK( [if linker supports omitting unused code and data], - [libevent_cv_gc_sections_works], + [libevent_cv_gc_sections_runs], [ + dnl NetBSD will link but likely not run with --gc-sections + dnl http://bugs.ntp.org/1844 + dnl http://gnats.netbsd.org/40401 + dnl --gc-sections causes attempt to load as linux elf, with + dnl wrong syscalls in place. Test a little gauntlet of + dnl simple stdio read code checking for errors, expecting + dnl enough syscall differences that the NetBSD code will + dnl fail even with Linux emulation working as designed. + dnl A shorter test could be refined by someone with access + dnl to a NetBSD host with Linux emulation working. origCFLAGS="$CFLAGS" CFLAGS="$CFLAGS -Wl,--gc-sections" AC_LINK_IFELSE( - [AC_LANG_PROGRAM([[]], [[]])], + [AC_LANG_PROGRAM( + [[ + #include + #include + ]], + [[ + FILE * fpC; + char buf[32]; + size_t cch; + int read_success_once; + + fpC = fopen("conftest.c", "r"); + if (NULL == fpC) + exit(1); + do { + cch = fread(buf, sizeof(buf), 1, fpC); + read_success_once |= (0 != cch); + } while (0 != cch); + if (!read_success_once) + exit(2); + if (!feof(fpC)) + exit(3); + if (0 != fclose(fpC)) + exit(4); + + exit(EXIT_SUCCESS); + ]] + )], [ - if grep gc-sections conftest.err ; then - libevent_cv_gc_sections_works=no + if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then + libevent_cv_gc_sections_runs=no else - libevent_cv_gc_sections_works=yes + libevent_cv_gc_sections_runs=no + ./conftest >/dev/null 2>&1 && libevent_cv_gc_sections_runs=yes fi ], - [libevent_cv_gc_sections_works=no] + [libevent_cv_gc_sections_runs=no] ) CFLAGS="$origCFLAGS" AS_UNSET([origCFLAGS]) ] ) - case "$libevent_cv_gc_sections_works" in + case "$libevent_cv_gc_sections_runs" in yes) CFLAGS="-ffunction-sections -fdata-sections $CFLAGS" LIBEVENT_GC_SECTIONS="-Wl,--gc-sections" diff --git a/sntp/m4/ntp_compiler.m4 b/sntp/m4/ntp_compiler.m4 index 7727d3f561..c69b2b0ee4 100644 --- a/sntp/m4/ntp_compiler.m4 +++ b/sntp/m4/ntp_compiler.m4 @@ -67,26 +67,64 @@ case "$GCC" in # AC_CACHE_CHECK( [if linker supports omitting unused code and data], - [ntp_cv_gc_sections_works], + [ntp_cv_gc_sections_runs], [ + dnl NetBSD will link but likely not run with --gc-sections + dnl http://bugs.ntp.org/1844 + dnl http://gnats.netbsd.org/40401 + dnl --gc-sections causes attempt to load as linux elf, with + dnl wrong syscalls in place. Test a little gauntlet of + dnl simple stdio read code checking for errors, expecting + dnl enough syscall differences that the NetBSD code will + dnl fail even with Linux emulation working as designed. + dnl A shorter test could be refined by someone with access + dnl to a NetBSD host with Linux emulation working. origCFLAGS="$CFLAGS" CFLAGS="$CFLAGS -Wl,--gc-sections" AC_LINK_IFELSE( - [AC_LANG_PROGRAM([[]], [[]])], + [AC_LANG_PROGRAM( + [[ + #include + #include + ]], + [[ + FILE * fpC; + char buf[32]; + size_t cch; + int read_success_once; + + fpC = fopen("conftest.c", "r"); + if (NULL == fpC) + exit(1); + do { + cch = fread(buf, sizeof(buf), 1, fpC); + read_success_once |= (0 != cch); + } while (0 != cch); + if (!read_success_once) + exit(2); + if (!feof(fpC)) + exit(3); + if (0 != fclose(fpC)) + exit(4); + + exit(EXIT_SUCCESS); + ]] + )], [ - if grep gc-sections conftest.err ; then - ntp_cv_gc_sections_works=no + if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then + ntp_cv_gc_sections_runs=no else - ntp_cv_gc_sections_works=yes + ntp_cv_gc_sections_runs=no + ./conftest >/dev/null 2>&1 && ntp_cv_gc_sections_runs=yes fi ], - [ntp_cv_gc_sections_works=no] + [ntp_cv_gc_sections_runs=no] ) CFLAGS="$origCFLAGS" AS_UNSET([origCFLAGS]) ] ) - case "$ntp_cv_gc_sections_works" in + case "$ntp_cv_gc_sections_runs" in yes) LDADD_LIBNTP="-Wl,--gc-sections" CFLAGS_NTP="$CFLAGS_NTP -ffunction-sections -fdata-sections"