Bug 34587 - gcc.dg/initpri1.c fails on *-apple-darwin
Summary: gcc.dg/initpri1.c fails on *-apple-darwin
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 38441 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-12-25 16:44 UTC by Jack Howarth
Modified: 2009-02-18 02:49 UTC (History)
6 users (show)

See Also:
Host: *-apple-darwin9
Target: powerpc-apple-darwin9
Build: powerpc-apple-darwin9
Known to work:
Known to fail:
Last reconfirmed: 2008-02-29 21:28:54


Attachments
assembly file for gcc.dg/initpri1.c at -m32 on i686-apple-darwin9 (793 bytes, text/plain)
2008-11-18 04:08 UTC, Jack Howarth
Details
assembly file for gcc.dg/initpri1.c at -m32 with -fno-PIC on i686-apple-darwin9 (414 bytes, text/plain)
2008-11-18 04:09 UTC, Jack Howarth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jack Howarth 2007-12-25 16:44:35 UTC
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
Comment 1 Dominique d'Humieres 2008-01-24 15:55:11 UTC
Confirmed on i686-apple-darwin9 on both 32 and 64 bit modes.

Comment 2 Dominique d'Humieres 2008-01-24 23:00:19 UTC
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.

Comment 3 İsmail Dönmez 2008-02-29 21:28:54 UTC
This also fails on i686-apple-darwin9 so its not powerpc specific.
Comment 4 Jack Howarth 2008-11-18 04:05:12 UTC
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.
Comment 5 Jack Howarth 2008-11-18 04:08:35 UTC
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
Comment 6 Jack Howarth 2008-11-18 04:09:39 UTC
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
Comment 7 Jack Howarth 2008-11-18 04:19:30 UTC
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.
Comment 8 Jack Howarth 2008-11-23 04:43:31 UTC
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) 
Comment 9 Jack Howarth 2008-11-23 04:47:35 UTC
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.
Comment 10 John David Anglin 2008-12-07 21:18:06 UTC
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 ()
Comment 11 John David Anglin 2009-02-17 01:37:07 UTC
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.
Comment 12 Jack Howarth 2009-02-17 17:36:19 UTC
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?
Comment 13 Mike Stump 2009-02-17 19:18:11 UTC
Ok to add that to darwin.h.
Comment 14 dave 2009-02-17 19:49:58 UTC
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
Comment 15 John David Anglin 2009-02-17 23:43:00 UTC
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

Comment 16 John David Anglin 2009-02-17 23:50:07 UTC
Fixed on trunk.
Comment 17 John David Anglin 2009-02-18 00:31:28 UTC
*** Bug 38441 has been marked as a duplicate of this bug. ***
Comment 18 Jack Howarth 2009-02-18 02:49:04 UTC
Fixed in current gcc trunk.