Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Output-Section-LMA.html 7.4KB

vor 3 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the GNU linker LD
  4. (GNU Arm Embedded Toolchain 10-2020-q4-major)
  5. version 2.35.1.
  6. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  7. Permission is granted to copy, distribute and/or modify this document
  8. under the terms of the GNU Free Documentation License, Version 1.3
  9. or any later version published by the Free Software Foundation;
  10. with no Invariant Sections, with no Front-Cover Texts, and with no
  11. Back-Cover Texts. A copy of the license is included in the
  12. section entitled "GNU Free Documentation License". -->
  13. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Output Section LMA (LD)</title>
  17. <meta name="description" content="Output Section LMA (LD)">
  18. <meta name="keywords" content="Output Section LMA (LD)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="LD-Index.html#LD-Index" rel="index" title="LD Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Output-Section-Attributes.html#Output-Section-Attributes" rel="up" title="Output Section Attributes">
  26. <link href="Forced-Output-Alignment.html#Forced-Output-Alignment" rel="next" title="Forced Output Alignment">
  27. <link href="Output-Section-Type.html#Output-Section-Type" rel="prev" title="Output Section Type">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style: oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Output-Section-LMA"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Forced-Output-Alignment.html#Forced-Output-Alignment" accesskey="n" rel="next">Forced Output Alignment</a>, Previous: <a href="Output-Section-Type.html#Output-Section-Type" accesskey="p" rel="prev">Output Section Type</a>, Up: <a href="Output-Section-Attributes.html#Output-Section-Attributes" accesskey="u" rel="up">Output Section Attributes</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  61. </div>
  62. <hr>
  63. <a name="Output-Section-LMA-1"></a>
  64. <h4 class="subsubsection">3.6.8.2 Output Section LMA</h4>
  65. <a name="index-AT_003elma_005fregion"></a>
  66. <a name="index-AT_0028lma_0029"></a>
  67. <a name="index-load-address"></a>
  68. <a name="index-section-load-address"></a>
  69. <p>Every section has a virtual address (VMA) and a load address (LMA); see
  70. <a href="Basic-Script-Concepts.html#Basic-Script-Concepts">Basic Script Concepts</a>. The virtual address is specified by the
  71. see <a href="Output-Section-Address.html#Output-Section-Address">Output Section Address</a> described earlier. The load address is
  72. specified by the <code>AT</code> or <code>AT&gt;</code> keywords. Specifying a load
  73. address is optional.
  74. </p>
  75. <p>The <code>AT</code> keyword takes an expression as an argument. This
  76. specifies the exact load address of the section. The <code>AT&gt;</code> keyword
  77. takes the name of a memory region as an argument. See <a href="MEMORY.html#MEMORY">MEMORY</a>. The
  78. load address of the section is set to the next free address in the
  79. region, aligned to the section&rsquo;s alignment requirements.
  80. </p>
  81. <p>If neither <code>AT</code> nor <code>AT&gt;</code> is specified for an allocatable
  82. section, the linker will use the following heuristic to determine the
  83. load address:
  84. </p>
  85. <ul>
  86. <li> If the section has a specific VMA address, then this is used as
  87. the LMA address as well.
  88. </li><li> If the section is not allocatable then its LMA is set to its VMA.
  89. </li><li> Otherwise if a memory region can be found that is compatible
  90. with the current section, and this region contains at least one
  91. section, then the LMA is set so the difference between the
  92. VMA and LMA is the same as the difference between the VMA and LMA of
  93. the last section in the located region.
  94. </li><li> If no memory regions have been declared then a default region
  95. that covers the entire address space is used in the previous step.
  96. </li><li> If no suitable region could be found, or there was no previous
  97. section then the LMA is set equal to the VMA.
  98. </li></ul>
  99. <a name="index-ROM-initialized-data"></a>
  100. <a name="index-initialized-data-in-ROM"></a>
  101. <p>This feature is designed to make it easy to build a ROM image. For
  102. example, the following linker script creates three output sections: one
  103. called &lsquo;<samp>.text</samp>&rsquo;, which starts at <code>0x1000</code>, one called
  104. &lsquo;<samp>.mdata</samp>&rsquo;, which is loaded at the end of the &lsquo;<samp>.text</samp>&rsquo; section
  105. even though its VMA is <code>0x2000</code>, and one called &lsquo;<samp>.bss</samp>&rsquo; to hold
  106. uninitialized data at address <code>0x3000</code>. The symbol <code>_data</code> is
  107. defined with the value <code>0x2000</code>, which shows that the location
  108. counter holds the VMA value, not the LMA value.
  109. </p>
  110. <div class="smallexample">
  111. <pre class="smallexample">SECTIONS
  112. {
  113. .text 0x1000 : { *(.text) _etext = . ; }
  114. .mdata 0x2000 :
  115. AT ( ADDR (.text) + SIZEOF (.text) )
  116. { _data = . ; *(.data); _edata = . ; }
  117. .bss 0x3000 :
  118. { _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;}
  119. }
  120. </pre></div>
  121. <p>The run-time initialization code for use with a program generated with
  122. this linker script would include something like the following, to copy
  123. the initialized data from the ROM image to its runtime address. Notice
  124. how this code takes advantage of the symbols defined by the linker
  125. script.
  126. </p>
  127. <div class="smallexample">
  128. <pre class="smallexample">extern char _etext, _data, _edata, _bstart, _bend;
  129. char *src = &amp;_etext;
  130. char *dst = &amp;_data;
  131. /* ROM has data at end of text; copy it. */
  132. while (dst &lt; &amp;_edata)
  133. *dst++ = *src++;
  134. /* Zero bss. */
  135. for (dst = &amp;_bstart; dst&lt; &amp;_bend; dst++)
  136. *dst = 0;
  137. </pre></div>
  138. <hr>
  139. <div class="header">
  140. <p>
  141. Next: <a href="Forced-Output-Alignment.html#Forced-Output-Alignment" accesskey="n" rel="next">Forced Output Alignment</a>, Previous: <a href="Output-Section-Type.html#Output-Section-Type" accesskey="p" rel="prev">Output Section Type</a>, Up: <a href="Output-Section-Attributes.html#Output-Section-Attributes" accesskey="u" rel="up">Output Section Attributes</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  142. </div>
  143. </body>
  144. </html>