<html lang="en">
<head>
<title>Output Section LMA - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.8">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Output-Section-Attributes.html#Output-Section-Attributes" title="Output Section Attributes">
<link rel="prev" href="Output-Section-Type.html#Output-Section-Type" title="Output Section Type">
<link rel="next" href="Forced-Output-Alignment.html#Forced-Output-Alignment" title="Forced Output Alignment">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
@import url("../raisonance.css");
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Output-Section-LMA"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="Forced-Output-Alignment.html#Forced-Output-Alignment">Forced Output Alignment</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Output-Section-Type.html#Output-Section-Type">Output Section Type</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Output-Section-Attributes.html#Output-Section-Attributes">Output Section Attributes</a>
<hr>
</div>

<h5 class="subsubsection">3.6.8.2 Output Section LMA</h5>

<p><a name="index-AT_003e_0040var_007blma_005fregion_007d-389"></a><a name="index-AT_0028_0040var_007blma_007d_0029-390"></a><a name="index-load-address-391"></a><a name="index-section-load-address-392"></a>Every section has a virtual address (VMA) and a load address (LMA); see
<a href="Basic-Script-Concepts.html#Basic-Script-Concepts">Basic Script Concepts</a>.  The address expression which may appear in
an output section description sets the VMA (see <a href="Output-Section-Address.html#Output-Section-Address">Output Section Address</a>).

   <p>The linker will normally set the LMA equal to the VMA.  You can change
that by using the <code>AT</code> keyword.  The expression <var>lma</var> that
follows the <code>AT</code> keyword specifies the load address of the
section.

   <p>Alternatively, with `<samp><span class="samp">AT&gt;</span><var>lma_region</var></samp>' expression, you may
specify a memory region for the section's load address. See <a href="MEMORY.html#MEMORY">MEMORY</a>. 
Note that if the section has not had a VMA assigned to it then the
linker will use the <var>lma_region</var> as the VMA region as well. 
See <a href="Output-Section-Region.html#Output-Section-Region">Output Section Region</a>.

   <p><a name="index-ROM-initialized-data-393"></a><a name="index-initialized-data-in-ROM-394"></a>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 `<samp><span class="samp">.text</span></samp>', which starts at <code>0x1000</code>, one called
`<samp><span class="samp">.mdata</span></samp>', which is loaded at the end of the `<samp><span class="samp">.text</span></samp>' section
even though its VMA is <code>0x2000</code>, and one called `<samp><span class="samp">.bss</span></samp>' to hold
uninitialized data at address <code>0x3000</code>.  The symbol <code>_data</code> is
defined with the value <code>0x2000</code>, which shows that the location
counter holds the VMA value, not the LMA value.

<pre class="smallexample">     SECTIONS
       {
       .text 0x1000 : { *(.text) _etext = . ; }
       .mdata 0x2000 :
         AT ( ADDR (.text) + SIZEOF (.text) )
         { _data = . ; *(.data); _edata = . ;  }
       .bss 0x3000 :
         { _bstart = . ;  *(.bss) *(COMMON) ; _bend = . ;}
     }
</pre>
   <p>The run-time initialization code for use with a program generated with
this linker script would include something like the following, to copy
the initialized data from the ROM image to its runtime address.  Notice
how this code takes advantage of the symbols defined by the linker
script.

<pre class="smallexample">     extern char _etext, _data, _edata, _bstart, _bend;
     char *src = &amp;_etext;
     char *dst = &amp;_data;
     
     /* ROM has data at end of text; copy it. */
     while (dst &lt; &amp;_edata) {
       *dst++ = *src++;
     }
     
     /* Zero bss */
     for (dst = &amp;_bstart; dst&lt; &amp;_bend; dst++)
       *dst = 0;
</pre>
   </body></html>

