The gcc.dg/initpri1.c testcase aborts on powerpc-apple-darwin9 in the following sections... void c2() { if (i++ != 2) abort (); <=== } [....] void c3() { if (i++ != 1) abort (); <=== } [...] void d2() { if (--i != 2) abort (); <=== } [...] void d3() { if (j != 2) abort (); if (--i != 1) abort (); <==== } I assume this should have been reported before but can't find any PR for it. The order of the aborts are... in c2 in c3 in d3 i in d2
Confirmed on i686-apple-darwin9 on both 32 and 64 bit modes.
This test case appeared in revision 122315 and failed on powerpc-apple-darwin from revision 122323 (see http://gcc.gnu.org/ml/gcc-testresults/2007-02/msg01022.html) up to now.
This also fails on i686-apple-darwin9 so its not powerpc specific.
This test case appears to only fail for the default -fPIC on darwin. If compiled with -fno-PIC, the test case passes on i686-apple-darwin9.
Created attachment 16714 [details] assembly file for gcc.dg/initpri1.c at -m32 on i686-apple-darwin9 created with... /sw/src/fink.build/gcc44-4.3.999-20081117/darwin_objdir/gcc/xgcc -B/sw/src/fink.build/gcc44-4.3.999-20081117/darwin_objdir/gcc/ /sw/src/fink.build/gcc44-4.3.999-20081117/gcc-4.4-20081117/gcc/testsuite/gcc.dg/initpri1.c -ansi -pedantic-errors -lm -m32 --save-temps -o ./initpri1.exe
Created attachment 16715 [details] assembly file for gcc.dg/initpri1.c at -m32 with -fno-PIC on i686-apple-darwin9 created with... /sw/src/fink.build/gcc44-4.3.999-20081117/darwin_objdir/gcc/xgcc -B/sw/src/fink.build/gcc44-4.3.999-20081117/darwin_objdir/gcc/ /sw/src/fink.build/gcc44-4.3.999-20081117/gcc-4.4-20081117/gcc/testsuite/gcc.dg/initpri1.c -ansi -pedantic-errors -lm -m32 -fno-PIC --save-temps -o ./initpri1.exe
Can confirm the same behavior with gcc 4.3.2 on powerpc-apple-darwin9. With... gcc-4 -ansi -pedantic-errors -lm -m32 initpri1.c the testcase aborts. With... gcc-4 -ansi -pedantic-errors -lm -m32 -fno-PIC initpri1.c it executes fine.
This backtraces on i686 darwin as... jack-howarths-macbook-pro-17:temp6 howarth$ gcc-4 -g -ansi -pedantic-errors -lm -m32 initpri1.c jack-howarths-macbook-pro-17:temp6 howarth$ gdb ./a.out GNU gdb 6.3.50-20050815 (Apple version gdb-1309) (Fri Oct 10 03:38:53 UTC 2008) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ... done (gdb) r Starting program: /Users/howarth/temp6/a.out Reading symbols for shared libraries ++. done Program received signal SIGABRT, Aborted. 0x981d8ffe in __kill () (gdb) bt #0 0x981d8ffe in __kill () #1 0x981d8ff1 in kill$UNIX2003 () #2 0x9824d39f in raise () #3 0x9825f190 in abort () #4 0x00001dc1 in c2 () at initpri1.c:19 #5 0x8fe146d8 in __dyld__ZN16ImageLoaderMachO16doInitializationERKN11ImageLoader11LinkContextE () #6 0x8fe0ec6d in __dyld__ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextEj () #7 0x8fe0ed59 in __dyld__ZN11ImageLoader15runInitializersERKNS_11LinkContextE () #8 0x8fe052e2 in __dyld__ZN4dyld24initializeMainExecutableEv () #9 0x8fe083e9 in __dyld__ZN4dyld5_mainEPK11mach_headermiPPKcS5_S5_ () #10 0x8fe01960 in __dyld__ZN13dyldbootstrap5startEPK11mach_headeriPPKcl () #11 0x8fe01057 in __dyld__dyld_start () (gdb)
I am mainly trying to determine if this is a flaw in darwin linker or assembler rather than a bug in gcc. If the former, we can at least file a radar bug report with Apple.
g++.dg/special/initpri1.C also aborts in the same way: Starting program: /Users/dave/gnu/gcc/objdir/gcc/testsuite/g++/initpri1.xg Reading symbols for shared libraries +++. done Program received signal SIGABRT, Aborted. 0x90b74b9e in __kill () (gdb) bt #0 0x90b74b9e in __kill () #1 0x90b74b91 in kill$UNIX2003 () #2 0x90bebec2 in raise () #3 0x90bfb47f in abort () #4 0x00001d07 in c2 () #5 0x8fe12e76 in __dyld__ZN16ImageLoaderMachO18doModInitFunctionsERKN11ImageLoader11LinkContextE () #6 0x8fe0e723 in __dyld__ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextEj () #7 0x8fe0e809 in __dyld__ZN11ImageLoader15runInitializersERKNS_11LinkContextE () #8 0x8fe04102 in __dyld__ZN4dyld24initializeMainExecutableEv () #9 0x8fe07b5f in __dyld__ZN4dyld5_mainEPK11mach_headermiPPKcS5_S5_ () #10 0x8fe01872 in __dyld__ZN13dyldbootstrap5startEPK11mach_headeriPPKcl () #11 0x8fe01037 in __dyld__dyld_start ()
It is a limitation of the Apple assembler and linker. From the Apple assembler manual: .mod_init_func This is equivalent to .section __DATA, __mod_init_func, mod_init_funcs This section is of type mod_init_funcs and has no attributes. The C++ compiler places a pointer to a function in this section for each function it creates to call the constructors (if the module has them). .mod_term_func This is equivalent to .section __DATA, __mod_term_func, mod_term_funcs This section is of type mod_term_funcs and has no attributes. The C++ compiler places a pointer to a function in this section for each function it creates to call the destructors (if the module has them). These directives don't allow for a priority. It might be possible to sort constructors/destructors with collect2, but for now it as if something like the following /* The Apple linker does not support constructor priorities. */ #undef SUPPORTS_INIT_PRIORITY #define SUPPORTS_INIT_PRIORITY 0 should be added to darwin.h.
John, Doesn't this also fix g++.dg/special/conpr-3.C as well? Are you planning to submit this to gcc-patches so we can get it into gcc 4.4 before the branch?
Ok to add that to darwin.h.
Subject: Re: gcc.dg/initpri1.c fails on *-apple-darwin > John, > Doesn't this also fix g++.dg/special/conpr-3.C as well? Are you planning to > submit this to gcc-patches so we can get it into gcc 4.4 before the branch? I'll know when I get home. Ran a full build and check with the change last night. There might be some testsuite issues. Dave
Subject: Bug 34587 Author: danglin Date: Tue Feb 17 23:42:44 2009 New Revision: 144251 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144251 Log: PR target/34587 * config/darwin.h (SUPPORTS_INIT_PRIORITY): Define. Modified: trunk/gcc/ChangeLog trunk/gcc/config/darwin.h
Fixed on trunk.
*** Bug 38441 has been marked as a duplicate of this bug. ***
Fixed in current gcc trunk.