gcc/ld init section and libraries

John Donoghue john.donoghue@ieee.org
Fri Aug 11 13:01:00 GMT 2006


Im not sure if this question belong in this list but ... 

I have a cross compiling suite for m68k-elf I am using for a small 68332 
board and want to add some code that will be run (initialize some stuff for 
me) when the program runs.
I can do this be adding to the .init section like: 

void some_init_function()
asm(" .section .init, \"ax\"");
 asm(" bsr.l fd_init");
asm(" .text"); 

When this gets compiled, it inserts the init code in the init section which 
is run from crt0.S, and I can do an object dump and see the inserted code.

The problem happens though when I have some code I want to have inserted in 
the init section that is is a archive file.
ie: the above code is compiled and put in a archive of  say libinit.a. When 
I link that in with the main code, the init section in the archibe file is 
not added!.
Why? Or better yet, how can I make it add it? I want it to add it so that 
any initialization required by the functions in the archive is done 
automatically without the programmer needing to do anything except link in 
the archive. 




More information about the Gcc-help mailing list