From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9523 invoked by alias); 7 Nov 2012 15:25:50 -0000 Received: (qmail 9439 invoked by uid 48); 7 Nov 2012 15:25:29 -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: Wed, 07 Nov 2012 15:25: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/msg00614.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54791 --- Comment #18 from Adi 2012-11-07 15:25:27 UTC --- Follow up on comment 17: 1) I did try to set the priority on the shared lib (via -binitfini) and it does not work. I mean the priority is set but the exe is still the one that is getting initialized first. 2) I did manage to make my project work with shared libs by doing the following hack: I rewrite the generated file(the one collect2 generates) from /tmp so that the _GLOBAL__FI_ is calling the _GLOBAL__FI_: void _GLOBAL__FI_() { _GLOBAL__FI_; static entry_pt *ctors[] = { x11, reg_frame, }; entry_pt **p; if (count++ != 0) return; p = ctors + 2; while (p > ctors) (*--p)(); } Then I recompiled this file and relink it with ld and it works. So basically I got the lib to get initialized before the exe is initialized. It is true though that my whole lib will be initialized and only after that my exe will be. So if I set init_priority on 2 objects(one in exe and on in the shared lib) it will not work. I mean always all the objects from the lib will get initialized first regardless of the init_priority on the exe. Right ? Can you tell me a more elegant solution to this ?(if there is). If not at least how can I do this more automatically? Now I do some steps manually(like going to /tmp and modify that file and recompile it and relink). I wander how this has worked with xlC. There we used the -p flag when linking the shared libraries with makeCCSharedLibs, and I think (not 100% sure )the library got first initialized.