[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

arm gcc 4.1.3 -O2 dead code removal breaks configure test

From: Dave Hart
Subject: arm gcc 4.1.3 -O2 dead code removal breaks configure test
Date: Tue, 29 Mar 2011 09:58:53 +0000

The NTP package has long had a configure test for in6addr_any
availability, forked from BIND 9's configure script, which provides a
bunch of IPv6-related gap-filling in portability library libisc.  In
the recent ntp-dev tarballs (4.2.7p142 is the latest) it lives in
sntp/m4/ntp_ipv6.m4 [1].

Stefan ollson recently reported NTP failing to compile on his
ARM-based Linux NAS using gcc 4.1.3 [2].  NTP's configure script
mistakenly was finding his system provided "struct in6_addr
in6addr_any;" at configure time, then failed to link ntpd with
unresolved external in6addr_any.  With a little help along the way, he
discovered the problem went away if compiler optimization was dialed
back using -O0.  I had predicted it would not make a difference, which
he thankfully did not put too much faith in.  The test is basically

                struct in6_addr in6;
                in6 = in6addr_any;

and the optimizer (quite rightly) noticed the value of in6 goes out of
scope without being referenced again and eliminated the assignment,
thereby eliminating all references to in6addr_any, undermining the
intent of the test.

What surprises me is why this didn't come up sooner.  The NTP
reference implementation package is routinely built on a wide variety
of gcc versions and on quite a few older systems lacking IPv6.
Similarly BIND 9.  I searched the autoconf mailing list archives for a
variety of keywords like "-O2 breaks test" but didn't manage to find
any similar reports of configure tests being broken by optimization.

Have you hit a similar problem in the past?  Please share what you
recall or can dig up!

We have a solution, changing the test to assign the address of
in6addr_any to a global variable preserves the reference:

#include <...>

struct in6_addr * pin6addr_any = &in6addr_any;

int main() {
    return 0;

But as I commented in the NTP bug report, I find this a bit scary, and
in his position, I'd be tempted to use -O1 or -O0 routinely with that
compiler to avoid triggering similar configure test failures in other
software.  Shooting from the hip, I expect there are a lot of
similarly simple, apparently dead references lurking in other
configure tests in the wild.  Apparently most gcc version/arch
combinations in the wild do _not_ optimize away the external reference
to in6addr_any at -O2, as evidenced by NTP and BIND 9 relying on
similar tests for years.

Is our fix the best you can imagine?  Is this particular gcc version
an outlier, or have we just been lucky or had less coverage than I

Thanks for your time,
Dave Hart

    [for in6addr_any],
                #include <sys/types.h>
                #include <sys/socket.h>
                #include <netinet/in.h>

case "$isc_cv_have_in6addr_any" in
    AC_DEFINE([ISC_PLATFORM_NEEDIN6ADDRANY], [1], [missing in6addr_any?])

                             0000644 0000000 0003717 00000011163
11544200132 012244  0
                                                  ustar   root

                     Using built-in specs.
Target: arm-unknown-linux-uclibc
Configured with:
--enable-languages=c,c++ --enable-__cxa_atexit
--with-local-prefix=/ffp --disable-multilib --disable-libssp
--disable-libgomp --disable-libmudflap --disable-tls --with-float=soft
Thread model: posix
gcc version 4.1.3 20080414 (prerelease)
%{mbig-endian:-EB} %{mlittle-endian:-EL} %{mcpu=*:-mcpu=%*}
%{march=*:-march=%*} %{mapcs-*:-mapcs-%*} %(subtarget_asm_float_spec)
%{mthumb-interwork:-mthumb-interwork} %{msoft-float:-mfloat-abi=soft}
%{mhard-float:-mfloat-abi=hard} %{mfloat-abi=*} %{mfpu=*}



%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}

%{!S:-o %|.s |
 as %(asm_options) %m.s %A }

and -mhard_float may not be used
together}}      %{mbig-endian:%{mlittle-endian:                                 
                %e-mbig-endian and
-mlittle-endian may not be used together}}

%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*}
%{w} %{f*} %{g*:%{!g0:%{!fno-working-directory:-fworking-directory}}}
%{O*} %{undef} %{save-temps:-fpch-preprocess}


%{C|CC:%{!E:%eGCC does not support -C or -CC without -E}} %{!Q:-quiet}
%{nostdinc*} %{C} %{CC} %{v} %{I*&F*} %{P} %I %{MD:-MD
%{!o:%b.d}%{o*:%.d%*}} %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}} %{M} %{MM}
%{MF*} %{MG} %{MP} %{MQ*} %{MT*} %{!E:%{!M:%{!MM:%{MD|MMD:%{o*:-MQ
%*}}}}} %{remap} %{g3:-dD} %{H} %C %{D*&U*&A*} %{i*} %Z %i
%{fmudflap:-D_MUDFLAP -include mf-runtime.h} %{fmudflapth:-D_MUDFLAP
-D_MUDFLAPTH -include mf-runtime.h} %{E|M|MM:%W{o*}}

cc1 -E %{traditional|ftraditional|traditional-cpp:-traditional-cpp}


%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are
incompatible}} %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}
%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}%{!c:%{!S:-auxbase
%b}} %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}
%{v:-version} %{pg:-p} %{p} %{f*} %{undef} %{Qn:-fno-ident}
%{--help:--help} %{--target-help:--target-help}
%{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}} %{fsyntax-only:-o %j}
%{-param*} %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}
%{coverage:-fprofile-arcs -ftest-coverage}


%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}

%{fstack-protector|fstack-protector-all:-lssp_nonshared -lssp}

%{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s

%{!static:--eh-frame-hdr} %{h*} %{version:-v}    %{b}
%{static:-Bstatic}    %{shared:-shared}    %{symbolic:-Bsymbolic}
%{rdynamic:-export-dynamic}    %{!dynamic-linker:-dynamic-linker
/ffp/lib/}    -X    %{mbig-endian:-EB}
%{mlittle-endian:-EL} -m armelf_linux -p

%{pthread:-lpthread}    %{shared:-lc}

 %{static: %{fmudflap|fmudflapth:  --wrap=malloc --wrap=free
--wrap=calloc --wrap=realloc --wrap=mmap --wrap=munmap --wrap=alloca}
%{fmudflapth: --wrap=pthread_create}} %{fmudflap|fmudflapth:

%{fmudflap|fmudflapth: -export-dynamic}

-lgcc_eh}%{!static:%{!static-libgcc:%{!shared-libgcc:-lgcc --as-needed
-lgcc_s --no-as-needed}%{shared-libgcc:-lgcc_s%{!shared: -lgcc}}}}

%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}}
crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}




. ;

marm mlittle-endian mhard-float mno-thumb-interwork














%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}



%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:    %(linker) %l %{pie:-pie}
%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}    %{s} %{t} %{u*} %{x}
%{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}    %{static:} %{L*}
%(mfwrap) %(link_libgcc) %o %(mflib)
%{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}
%{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]