⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 output-section-lma.html

📁 gcc手册
💻 HTML
字号:
<html lang="en">

<head>

<title>Untitled</title>

<meta http-equiv="Content-Type" content="text/html">

<meta name="description" content="Untitled">

<meta name="generator" content="makeinfo 4.3">

<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">

</head>

<body>

<div class="node">

<p>

Node:<a name="Output%20Section%20LMA">Output Section LMA</a>,

Next:<a rel="next" accesskey="n" href="Output-Section-Region.html#Output%20Section%20Region">Output Section Region</a>,

Previous:<a rel="previous" accesskey="p" href="Output-Section-Type.html#Output%20Section%20Type">Output Section Type</a>,

Up:<a rel="up" accesskey="u" href="Output-Section-Attributes.html#Output%20Section%20Attributes">Output Section Attributes</a>

<hr><br>

</div>



<h5 class="subsubsection">Output section LMA</h5>



   <p>Every section has a virtual address (VMA) and a load address (LMA); see

<a href="Basic-Script-Concepts.html#Basic%20Script%20Concepts">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%20Section%20Address">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.  Alternatively, with <code>AT&gt;</code><var>lma_region</var><code></code> expression,

you may specify a memory region for the section's load address. See <a href="MEMORY.html#MEMORY">MEMORY</a>.



   <p>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 <code>.text</code>, which starts at <code>0x1000</code>, one called

<code>.mdata</code>, which is loaded at the end of the <code>.text</code> section

even though its VMA is <code>0x2000</code>, and one called <code>.bss</code> 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>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -