This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/46770] Replace .ctors/.dtors with .init_array/.fini_array on targets supporting them
- From: "hjl.tools at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 12 Dec 2010 00:08:40 +0000
- Subject: [Bug target/46770] Replace .ctors/.dtors with .init_array/.fini_array on targets supporting them
- Auto-submitted: auto-generated
- References: <bug-46770-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46770
--- Comment #39 from H.J. Lu <hjl.tools at gmail dot com> 2010-12-12 00:08:29 UTC ---
(In reply to comment #38)
> On 12/11/2010 4:00 PM, hjl.tools at gmail dot com wrote:
>
> > Really? Here is a testcase. Do you think goo's constructor
> > will be called before another constructor in another file
> > with priority 1005?
>
> Yes.
Here it is
[hjl@gnu-6 pr46770-2]$ cat bar.C
class Two {
private:
int i, j, k;
public:
static int count;
Two( int ii, int jj ) { i = ii; j = jj; k = count++; };
Two( void ) { i = 0; j = 0; k = count++; };
int eye( void ) { return i; };
int jay( void ) { return j; };
int kay( void ) { return k; };
};
extern Two xoo;
extern Two bar;
Two xoo __attribute__((init_priority(1005))) ( 5, 6 );
Two bar __attribute__((init_priority(1007))) = Two( 7, 8 );
[hjl@gnu-6 pr46770-2]$ gcc -m32 -c bar.C
[hjl@gnu-6 pr46770-2]$ readelf -S --wide bar.o | grep ctor
[ 8] .ctors.64530 PROGBITS 00000000 0000f8 000004 00 WA 0 0
4
[ 9] .rel.ctors.64530 REL 00000000 000778 000008 08 17 8
4
[10] .ctors.64528 PROGBITS 00000000 0000fc 000004 00 WA 0 0
4
[11] .rel.ctors.64528 REL 00000000 000780 000008 08 17 10
4
[hjl@gnu-6 pr46770-2]$
When bar and foo.o are linked together, can you tell me what
the constructor order is?
> (Or after, I don't remember if smaller numbers indicate higher priority.
> In either case, there is a deterministic order based on the priority
> number.)
>
> This is the point of the feature. If that were not the case, there
> would be no need to have .ctors.NNNN sections; everything would just go
> in .ctors.
We only support constructor priority in single source file:
---
Note that the particular values of PRIORITY do not matter; only
their relative ordering.
---
may be the clue.