This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: A simple linker script question


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]