9.5.5.9.2 Output Section LMA

Every section has a virtual address (VMA) and a load address (LMA). The address expression that may appear in an output section description sets the VMA.

The linker will normally set the LMA equal to the VMA. This can be changed by using the AT keyword. The expression lma that follows the AT keyword specifies the load address of the section. Alternatively, with AT>lma_region expression, a memory region may be specified for the section’s load address. See 9.5.4 Memory Command.

This feature is designed to make it easy to build a ROM image. For example, the following linker script creates three output sections: one called .text, which starts at 0xBFC00000, one called .mdata, which is loaded at the end of the .text section even though its VMA is 0xA0000000, and one called .bss to hold uninitialized data at address 0xA0001000. The symbol _data is defined with the value 0xA0000000, which shows that the location counter holds the VMA value, not the LMA value.

SECTIONS
  {
  .text 0xBFC00000: { *(.text) _etext = . ; }
  .mdata 0xA0000000:
    AT ( ADDR (.text) + SIZEOF (.text) )
    { _data = . ; *(.data); _edata = . ;  }
  .bss 0xA0001000:
    { _bstart = . ;  *(.bss) *(COMMON) ; _bend = . ;}
}

The run-time initialization code for use with a program generated with this linker script would include a function to copy the initialized data from the ROM image to its run-time address. The initialization function could take advantage of the symbols defined by the linker script.

Writing such a function would rarely be necessary, however. These functions are provided by the C compiler's startup and initialization code. See the C compiler user's guide relevant for your target device for more information on the startup code provided with the compiler.