A simple linker script question

Nick Clifton nickc@redhat.com
Mon Jun 21 14:33:00 GMT 2004


Hi Tao,

> I am new to linker script. I just want to write one to place all system
> library code before the user code. Could anybody give me some hint on
> that?

First of all - why do you need to do this ?

Secondly do you mean that you want to put the contents of the sections 
in the system libraries before similarly named sections in the user 
code, or do you want to put the entire contents of the system libraries 
before the user code ?

For example given a system library sys.a containing a .text section and 
a .data section and a user file user.o also containing a .text and a 
.data section, how do you want the final executable to appear ?  Should 
it have one .text section containing the contents of the .text section 
from sys.a and then the contents of the .text section from user.o, and 
followed by a single .data section containing the contents of the .data 
sections from sys.a and user.o.  Or, should the output file have two 
.text sections, one from sys.a and one from user.o, with the one from 
sys.a occurring first in the memory map, and similarly two .data sections ?

Assuming you want a single .text section and a single .data section then 
you can do something like this in your linker script:

   SECTIONS {
      .text : { *(EXCLUDE_FILE (user.o).text)
                *(.text) }
      .data : { *(EXCLUDE_FILE (user.o).data)
                *(.data) }
   }

Cheers
   Nick




More information about the Binutils mailing list