1<html lang="en"> 2<head> 3<title>Output Section LMA - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Output-Section-Attributes.html#Output-Section-Attributes" title="Output Section Attributes"> 9<link rel="prev" href="Output-Section-Type.html#Output-Section-Type" title="Output Section Type"> 10<link rel="next" href="Forced-Output-Alignment.html#Forced-Output-Alignment" title="Forced Output Alignment"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13This file documents the GNU linker LD 14(Sourcery CodeBench Lite 2011.09-69) 15version 2.21.53. 16 17Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 182001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. 19 20Permission is granted to copy, distribute and/or modify this document 21under the terms of the GNU Free Documentation License, Version 1.3 22or any later version published by the Free Software Foundation; 23with no Invariant Sections, with no Front-Cover Texts, and with no 24Back-Cover Texts. A copy of the license is included in the 25section entitled ``GNU Free Documentation License''.--> 26<meta http-equiv="Content-Style-Type" content="text/css"> 27<style type="text/css"><!-- 28 pre.display { font-family:inherit } 29 pre.format { font-family:inherit } 30 pre.smalldisplay { font-family:inherit; font-size:smaller } 31 pre.smallformat { font-family:inherit; font-size:smaller } 32 pre.smallexample { font-size:smaller } 33 pre.smalllisp { font-size:smaller } 34 span.sc { font-variant:small-caps } 35 span.roman { font-family:serif; font-weight:normal; } 36 span.sansserif { font-family:sans-serif; font-weight:normal; } 37--></style> 38<link rel="stylesheet" type="text/css" href="../cs.css"> 39</head> 40<body> 41<div class="node"> 42<a name="Output-Section-LMA"></a> 43<p> 44Next: <a rel="next" accesskey="n" href="Forced-Output-Alignment.html#Forced-Output-Alignment">Forced Output Alignment</a>, 45Previous: <a rel="previous" accesskey="p" href="Output-Section-Type.html#Output-Section-Type">Output Section Type</a>, 46Up: <a rel="up" accesskey="u" href="Output-Section-Attributes.html#Output-Section-Attributes">Output Section Attributes</a> 47<hr> 48</div> 49 50<h5 class="subsubsection">3.6.8.2 Output Section LMA</h5> 51 52<p><a name="index-AT_003e_0040var_007blma_005fregion_007d-448"></a><a name="index-AT_0028_0040var_007blma_007d_0029-449"></a><a name="index-load-address-450"></a><a name="index-section-load-address-451"></a>Every section has a virtual address (VMA) and a load address (LMA); see 53<a href="Basic-Script-Concepts.html#Basic-Script-Concepts">Basic Script Concepts</a>. The virtual address is specified by the 54see <a href="Output-Section-Address.html#Output-Section-Address">Output Section Address</a> described earlier. The load address is 55specified by the <code>AT</code> or <code>AT></code> keywords. Specifying a load 56address is optional. 57 58 <p>The <code>AT</code> keyword takes an expression as an argument. This 59specifies the exact load address of the section. The <code>AT></code> keyword 60takes the name of a memory region as an argument. See <a href="MEMORY.html#MEMORY">MEMORY</a>. The 61load address of the section is set to the next free address in the 62region, aligned to the section's alignment requirements. 63 64 <p>If neither <code>AT</code> nor <code>AT></code> is specified for an allocatable 65section, the linker will use the following heuristic to determine the 66load address: 67 68 <ul> 69<li>If the section has a specific VMA address, then this is used as 70the LMA address as well. 71 72 <li>If the section is not allocatable then its LMA is set to its VMA. 73 74 <li>Otherwise if a memory region can be found that is compatible 75with the current section, and this region contains at least one 76section, then the LMA is set so the difference between the 77VMA and LMA is the same as the difference between the VMA and LMA of 78the last section in the located region. 79 80 <li>If no memory regions have been declared then a default region 81that covers the entire address space is used in the previous step. 82 83 <li>If no suitable region could be found, or there was no previous 84section then the LMA is set equal to the VMA. 85</ul> 86 87 <p><a name="index-ROM-initialized-data-452"></a><a name="index-initialized-data-in-ROM-453"></a>This feature is designed to make it easy to build a ROM image. For 88example, the following linker script creates three output sections: one 89called ‘<samp><span class="samp">.text</span></samp>’, which starts at <code>0x1000</code>, one called 90‘<samp><span class="samp">.mdata</span></samp>’, which is loaded at the end of the ‘<samp><span class="samp">.text</span></samp>’ section 91even though its VMA is <code>0x2000</code>, and one called ‘<samp><span class="samp">.bss</span></samp>’ to hold 92uninitialized data at address <code>0x3000</code>. The symbol <code>_data</code> is 93defined with the value <code>0x2000</code>, which shows that the location 94counter holds the VMA value, not the LMA value. 95 96<pre class="smallexample"> SECTIONS 97 { 98 .text 0x1000 : { *(.text) _etext = . ; } 99 .mdata 0x2000 : 100 AT ( ADDR (.text) + SIZEOF (.text) ) 101 { _data = . ; *(.data); _edata = . ; } 102 .bss 0x3000 : 103 { _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;} 104 } 105</pre> 106 <p>The run-time initialization code for use with a program generated with 107this linker script would include something like the following, to copy 108the initialized data from the ROM image to its runtime address. Notice 109how this code takes advantage of the symbols defined by the linker 110script. 111 112<pre class="smallexample"> extern char _etext, _data, _edata, _bstart, _bend; 113 char *src = &_etext; 114 char *dst = &_data; 115 116 /* ROM has data at end of text; copy it. */ 117 while (dst < &_edata) 118 *dst++ = *src++; 119 120 /* Zero bss. */ 121 for (dst = &_bstart; dst< &_bend; dst++) 122 *dst = 0; 123</pre> 124 </body></html> 125 126