ld: Output Section LMA
1
1 3.6.8.2 Output Section LMA
1 ..........................
1
1 Every section has a virtual address (VMA) and a load address (LMA); see
1 ⇒Basic Script Concepts. The virtual address is specified by the
1 ⇒Output Section Address described earlier. The load address is
1 specified by the 'AT' or 'AT>' keywords. Specifying a load address is
1 optional.
1
1 The 'AT' keyword takes an expression as an argument. This specifies
1 the exact load address of the section. The 'AT>' keyword takes the name
1 of a memory region as an argument. ⇒MEMORY. The load address of
1 the section is set to the next free address in the region, aligned to
1 the section's alignment requirements.
1
1 If neither 'AT' nor 'AT>' is specified for an allocatable section,
1 the linker will use the following heuristic to determine the load
1 address:
1
1 * If the section has a specific VMA address, then this is used as the
1 LMA address as well.
1
1 * If the section is not allocatable then its LMA is set to its VMA.
1
1 * Otherwise if a memory region can be found that is compatible with
1 the current section, and this region contains at least one section,
1 then the LMA is set so the difference between the VMA and LMA is
1 the same as the difference between the VMA and LMA of the last
1 section in the located region.
1
1 * If no memory regions have been declared then a default region that
1 covers the entire address space is used in the previous step.
1
1 * If no suitable region could be found, or there was no previous
1 section then the LMA is set equal to the VMA.
1
1 This feature is designed to make it easy to build a ROM image. For
1 example, the following linker script creates three output sections: one
1 called '.text', which starts at '0x1000', one called '.mdata', which is
1 loaded at the end of the '.text' section even though its VMA is
1 '0x2000', and one called '.bss' to hold uninitialized data at address
1 '0x3000'. The symbol '_data' is defined with the value '0x2000', which
1 shows that the location counter holds the VMA value, not the LMA value.
1
1 SECTIONS
1 {
1 .text 0x1000 : { *(.text) _etext = . ; }
1 .mdata 0x2000 :
1 AT ( ADDR (.text) + SIZEOF (.text) )
1 { _data = . ; *(.data); _edata = . ; }
1 .bss 0x3000 :
1 { _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;}
1 }
1
1 The run-time initialization code for use with a program generated
1 with this linker script would include something like the following, to
1 copy the initialized data from the ROM image to its runtime address.
1 Notice how this code takes advantage of the symbols defined by the
1 linker script.
1
1 extern char _etext, _data, _edata, _bstart, _bend;
1 char *src = &_etext;
1 char *dst = &_data;
1
1 /* ROM has data at end of text; copy it. */
1 while (dst < &_edata)
1 *dst++ = *src++;
1
1 /* Zero bss. */
1 for (dst = &_bstart; dst< &_bend; dst++)
1 *dst = 0;
1