GNU Linker Scripts
Linker scripts use the .ld file extension.
Entry Point
The entry point of a program can be specified in a few different ways1:
- Using the 
ENTRYcommand. - The value to the 
startsymbol. - The address of the first byte of the 
.textsection. - The address 
0. 
For example, if we were to use the ENTRY() command:
ENTRY(reset_handler)Memory Layout
You can use the MEMORY command to describe the size and location of memory “blocks” in the target system. Based on this information, the linker will place requested sections into the correct memory blocks and also raise errors if any block overflows.
A .ld file can contain only one MEMORY command. Inside the command, you can define as many blocks of memory as you want. The syntax is1:
MEMORY{  name1 (attr) : ORIGIN = origin1, LENGTH = length1  ...}name1is the name of the memory block, used internally by the linker to refer to that region.attris a list of attributes for the memory block. The supported attributes are:rfor read-only.wfor read/write sections.xfor executable sections.afor allocatable sections.ifor initialized sections.lsame asi.
origin1is the starting address of the memory block.length1is the size (in bytes) of the memory block.
Sections
The following example creates an output file with three sections: .text, .data, and .bss. It takes all input files and takes the corresponding sections from them (.text goes to .text) and places them in the output file:
SECTIONS {  .text : { *(.text) }  .data : { *(.data) }  .bss :  { *(.bss)  *(COMMON) }}Footnotes
- 
GNU. Manuals > ld v2.9.1. > Command Language. Retrieved 2024-09-17, from https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_3.html. ↩ ↩2