"MichaÅ BieliÅski" <michal@xxxxxxxxxxx> writes: > Dnia 15 PaÅdziernika 2010, 00:22, Pt, Ian Lance Taylor napisaÅ: >> "MichaÅ BieliÅski" <michal@xxxxxxxxxxx> writes: >> >>> Dnia 14 PaÄÅdziernika 2010, 22:42, Cz, Ian Lance Taylor napisaÅ: >>>> "MichaÅ BieliÅski" <michal@xxxxxxxxxxx> writes: >>>> >>>>> I am linking C object files which rely on functions with constructor >>>>> attribute with my program. Ordinarily gcc generates code calling all >>>>> such >>>>> routines before main gets control. However, my program is not written >>>>> in >>>>> C and such code is not included. Resulting executable works but linked >>>>> objects refuse to cooperate because their initializing constructors >>>>> were not called. Is there a way to manually run these functions? >>>> >>>> In general, yes. However, the precise details depend greatly on your >>>> target. So tell us more. >>> > [snip] >>> Is any other information needed? >> >> Sorry, I should have said. What matters here is your operating system >> and your libc. > > Linux 2.6.35-ARCH i686 GNU/Linux > libc-2.12.1.so The key is going to be to somehow get the address of the .init section. If you can do that, I think you can call it as though it were a function. If you are using a linker script, you can add a symbol assignment. If not, you may have to dig into the dynamic tags, perhaps via /proc/self/exe, to find the DT_INIT tag and call that. Ideally you just want to call the function __do_global_ctors_aux, but that is a local function which is normally called because the startup code calls the start of the .init section. > Does the solution you have on mind break code portability? The concept of portability does not apply to the question of how to get global constructors to run. None of it is portable. Ian