http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54791



--- Comment #18 from Adi <adivilceanu at yahoo dot com> 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_<name of my exe> is calling the _GLOBAL__FI_<name_of_my_shaderlib>:

void _GLOBAL__FI_<name of my exe>() {

        _GLOBAL__FI_<name_of_my_shaderlib>;

    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.

Reply via email to