You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
5.9 KiB
HTML
124 lines
5.9 KiB
HTML
<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.13">
|
|
<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">
|
|
<!--
|
|
This file documents the GNU linker LD
|
|
(GNU Binutils)
|
|
version 2.26.
|
|
|
|
Copyright (C) 1991-2015 Free Software Foundation, Inc.
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3
|
|
or any later version published by the Free Software Foundation;
|
|
with no Invariant Sections, with no Front-Cover Texts, and with no
|
|
Back-Cover Texts. A copy of the license is included in the
|
|
section entitled ``GNU Free Documentation License''.-->
|
|
<meta http-equiv="Content-Style-Type" content="text/css">
|
|
<style type="text/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">
|
|
<a name="Output-Section-LMA"></a>
|
|
<p>
|
|
Next: <a rel="next" accesskey="n" href="Forced-Output-Alignment.html#Forced-Output-Alignment">Forced Output Alignment</a>,
|
|
Previous: <a rel="previous" accesskey="p" href="Output-Section-Type.html#Output-Section-Type">Output Section Type</a>,
|
|
Up: <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-472"></a><a name="index-AT_0028_0040var_007blma_007d_0029-473"></a><a name="index-load-address-474"></a><a name="index-section-load-address-475"></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 virtual address is specified by the
|
|
see <a href="Output-Section-Address.html#Output-Section-Address">Output Section Address</a> described earlier. The load address is
|
|
specified by the <code>AT</code> or <code>AT></code> keywords. Specifying a load
|
|
address is optional.
|
|
|
|
<p>The <code>AT</code> keyword takes an expression as an argument. This
|
|
specifies the exact load address of the section. The <code>AT></code> keyword
|
|
takes the name of a memory region as an argument. See <a href="MEMORY.html#MEMORY">MEMORY</a>. The
|
|
load address of the section is set to the next free address in the
|
|
region, aligned to the section's alignment requirements.
|
|
|
|
<p>If neither <code>AT</code> nor <code>AT></code> is specified for an allocatable
|
|
section, the linker will use the following heuristic to determine the
|
|
load address:
|
|
|
|
<ul>
|
|
<li>If the section has a specific VMA address, then this is used as
|
|
the LMA address as well.
|
|
|
|
<li>If the section is not allocatable then its LMA is set to its VMA.
|
|
|
|
<li>Otherwise if a memory region can be found that is compatible
|
|
with the current 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.
|
|
|
|
<li>If no memory regions have been declared then a default region
|
|
that covers the entire address space is used in the previous step.
|
|
|
|
<li>If no suitable region could be found, or there was no previous
|
|
section then the LMA is set equal to the VMA.
|
|
</ul>
|
|
|
|
<p><a name="index-ROM-initialized-data-476"></a><a name="index-initialized-data-in-ROM-477"></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 = &_etext;
|
|
char *dst = &_data;
|
|
|
|
/* ROM has data at end of text; copy it. */
|
|
while (dst < &_edata)
|
|
*dst++ = *src++;
|
|
|
|
/* Zero bss. */
|
|
for (dst = &_bstart; dst< &_bend; dst++)
|
|
*dst = 0;
|
|
</pre>
|
|
</body></html>
|
|
|