From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22993 invoked by alias); 6 Nov 2012 16:23:15 -0000 Received: (qmail 22700 invoked by uid 48); 6 Nov 2012 16:22:40 -0000 From: "adivilceanu at yahoo dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/54791] AIX-only: Constructors are not called in main program. Date: Tue, 06 Nov 2012 16:23:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: adivilceanu at yahoo dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg00496.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54791 --- Comment #14 from Adi 2012-11-06 16:22:37 UTC --- Regarding the __attribute__ ((init_priority (NNNN))). Are you sure this works on AIX at namespace level. I think it might work on linux. But on AIX I see no way of that ever working. Here is my understanding on how collect2 works on AIX(correct me if I am wrong): - g++ front end creates one _GLOBAL__I_65535_0_ per object file. Here it is putting all the static constructors that should be called from that object file. - collect2 links (via ld) the whole exe(+libs). Then it is scanning all the _GLOBAL__ and is putting them into the ctors array and generates a functions named _GLOBAL__FI_ that will call each _GLOBAL__* entry fro the array in reverse order. So as I see it this whole mechanism can at maximum support priority ordering on a object file basis. (I mean it could sort the _GLOBAL__* entries according to some criteria). Question: How can you influence this criteria? I did a hack and altered the ctors array generated by collect2(in that /tmp//ccGVUVzP.c) and reordered all those _GLOBAL__* entries based on my project needs. Then I recompiled the ccGVUVzP.c file and manually called ld (like g++ is doing the second time). So somehow I simulate the #pragma priority from xlC on a file basis. And the hack worked. Now if you use init_priority for a single global variable in an object file, and use it again on another global in a different object file I do not see how this could work? How would bypass the _GLOBAL__* entries in the ctors array which is already sorted? So my big assumption here is(correct me if I am wrong): On gcc for AIX, all globals from an object file are initialized before globals from another object file are. So you can not have initialization of one global1 from object1.o and then global2 from object2 and then global3 from object1 again. Is my assuption correct? If so a __attribute__ ((init_priority is not ok for what I need. Now regarding the fPIC. I just started using it now. That has changed a lot of stuff. First the _GLOABL__* names are now based on file name rather than name of first object. I am just starting to test this. I will follow up with the results. Thanks for your support.