Linker Scripts

Reference

Output Section description:

section [address] [(type)] :
       [AT(lma)]
       [ALIGN(section_align) | ALIGN_WITH_INPUT]
       [SUBALIGN(subsection_align)]
       [constraint]
       {
         output-section-command
         output-section-command
         ...
       } [>region] [AT>lma_region] [:phdr :phdr ...] [=fillexp] [,]

VMA and LMA

Every section has a virtual memory address (VMA) and a load memory address (LMA), see baseic script concepts.

  • The address in a linker script is virtual address (VMA). This address is optional, but if it is provided then the output address will be set exactly as specified. If the output address is not specified, a virtual address will be choosen. The heuristic below will be used to choose the VMA:
    • If an output memory region is set for the section then it is added to this region and its address will be the next free address in that region.
    • If the MEMORY command has been used to create a list of memory regions then the first region which has attributes compatible with the section is selected to contain it. The section’s output address will be the next free address in that region;
    • If no memory regions were specified, or none match the section then the output address will be based on the current value of the location counter.
  • The load address (LMA) is specified by the AT or AT> keywords. Specifying a load address is optional.
    • This feature is designed to make it easy to build a ROM image. LMA can point to a ROM address, and when the program is loaded and running, the system will first load the contents from LMA to VMA and starting execution.
    • Heuristic to choose the LMA without AT or AT>:
    • If the section has a specific VMA address, then this is used as the LMA address as well.
    • If the section is not allocatable then its LMA is sect to its VMA.
    • Otherwise, if a memory region can be found that is compatible with the curent section, and this region contains at least one section, then the LMA is set so the difference between the VMA and LMA is the same as the difference between the VMA and LMA of the last section in the located region.
    • If no memory regions have been declared then a default region that covers the entire address space is used in the previous step.
    • If no suitable region could be found, or there was no previous section then the LMA is set equal to the VMA.
Created Aug 3, 2020 // Last Updated Aug 3, 2020

If you could revise
the fundmental principles of
computer system design
to improve security...

... what would you change?