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.

212 Zeilen
9.5KB

  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>MEMORY (LD)</title>
  17. <meta name="description" content="MEMORY (LD)">
  18. <meta name="keywords" content="MEMORY (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="Scripts.html#Scripts" rel="up" title="Scripts">
  26. <link href="PHDRS.html#PHDRS" rel="next" title="PHDRS">
  27. <link href="Overlay-Description.html#Overlay-Description" rel="prev" title="Overlay Description">
  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="MEMORY"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="PHDRS.html#PHDRS" accesskey="n" rel="next">PHDRS</a>, Previous: <a href="SECTIONS.html#SECTIONS" accesskey="p" rel="prev">SECTIONS</a>, Up: <a href="Scripts.html#Scripts" accesskey="u" rel="up">Scripts</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="MEMORY-Command"></a>
  64. <h3 class="section">3.7 MEMORY Command</h3>
  65. <a name="index-MEMORY"></a>
  66. <a name="index-memory-regions"></a>
  67. <a name="index-regions-of-memory"></a>
  68. <a name="index-allocating-memory"></a>
  69. <a name="index-discontinuous-memory"></a>
  70. <p>The linker&rsquo;s default configuration permits allocation of all available
  71. memory. You can override this by using the <code>MEMORY</code> command.
  72. </p>
  73. <p>The <code>MEMORY</code> command describes the location and size of blocks of
  74. memory in the target. You can use it to describe which memory regions
  75. may be used by the linker, and which memory regions it must avoid. You
  76. can then assign sections to particular memory regions. The linker will
  77. set section addresses based on the memory regions, and will warn about
  78. regions that become too full. The linker will not shuffle sections
  79. around to fit into the available regions.
  80. </p>
  81. <p>A linker script may contain many uses of the <code>MEMORY</code> command,
  82. however, all memory blocks defined are treated as if they were
  83. specified inside a single <code>MEMORY</code> command. The syntax for
  84. <code>MEMORY</code> is:
  85. </p><div class="smallexample">
  86. <pre class="smallexample">MEMORY
  87. {
  88. <var>name</var> [(<var>attr</var>)] : ORIGIN = <var>origin</var>, LENGTH = <var>len</var>
  89. &hellip;
  90. }
  91. </pre></div>
  92. <p>The <var>name</var> is a name used in the linker script to refer to the
  93. region. The region name has no meaning outside of the linker script.
  94. Region names are stored in a separate name space, and will not conflict
  95. with symbol names, file names, or section names. Each memory region
  96. must have a distinct name within the <code>MEMORY</code> command. However you can
  97. add later alias names to existing memory regions with the <a href="REGION_005fALIAS.html#REGION_005fALIAS">REGION_ALIAS</a>
  98. command.
  99. </p>
  100. <a name="index-memory-region-attributes"></a>
  101. <p>The <var>attr</var> string is an optional list of attributes that specify
  102. whether to use a particular memory region for an input section which is
  103. not explicitly mapped in the linker script. As described in
  104. <a href="SECTIONS.html#SECTIONS">SECTIONS</a>, if you do not specify an output section for some input
  105. section, the linker will create an output section with the same name as
  106. the input section. If you define region attributes, the linker will use
  107. them to select the memory region for the output section that it creates.
  108. </p>
  109. <p>The <var>attr</var> string must consist only of the following characters:
  110. </p><dl compact="compact">
  111. <dt>&lsquo;<samp>R</samp>&rsquo;</dt>
  112. <dd><p>Read-only section
  113. </p></dd>
  114. <dt>&lsquo;<samp>W</samp>&rsquo;</dt>
  115. <dd><p>Read/write section
  116. </p></dd>
  117. <dt>&lsquo;<samp>X</samp>&rsquo;</dt>
  118. <dd><p>Executable section
  119. </p></dd>
  120. <dt>&lsquo;<samp>A</samp>&rsquo;</dt>
  121. <dd><p>Allocatable section
  122. </p></dd>
  123. <dt>&lsquo;<samp>I</samp>&rsquo;</dt>
  124. <dd><p>Initialized section
  125. </p></dd>
  126. <dt>&lsquo;<samp>L</samp>&rsquo;</dt>
  127. <dd><p>Same as &lsquo;<samp>I</samp>&rsquo;
  128. </p></dd>
  129. <dt>&lsquo;<samp>!</samp>&rsquo;</dt>
  130. <dd><p>Invert the sense of any of the attributes that follow
  131. </p></dd>
  132. </dl>
  133. <p>If an unmapped section matches any of the listed attributes other than
  134. &lsquo;<samp>!</samp>&rsquo;, it will be placed in the memory region. The &lsquo;<samp>!</samp>&rsquo;
  135. attribute reverses the test for the characters that follow, so that an
  136. unmapped section will be placed in the memory region only if it does
  137. not match any of the attributes listed afterwards. Thus an attribute
  138. string of &lsquo;<samp>RW!X</samp>&rsquo; will match any unmapped section that has either
  139. or both of the &lsquo;<samp>R</samp>&rsquo; and &lsquo;<samp>W</samp>&rsquo; attributes, but only as long as
  140. the section does not also have the &lsquo;<samp>X</samp>&rsquo; attribute.
  141. </p>
  142. <a name="index-ORIGIN-_003d"></a>
  143. <a name="index-o-_003d"></a>
  144. <a name="index-org-_003d"></a>
  145. <p>The <var>origin</var> is an numerical expression for the start address of
  146. the memory region. The expression must evaluate to a constant and it
  147. cannot involve any symbols. The keyword <code>ORIGIN</code> may be
  148. abbreviated to <code>org</code> or <code>o</code> (but not, for example,
  149. <code>ORG</code>).
  150. </p>
  151. <a name="index-LENGTH-_003d"></a>
  152. <a name="index-len-_003d"></a>
  153. <a name="index-l-_003d"></a>
  154. <p>The <var>len</var> is an expression for the size in bytes of the memory
  155. region. As with the <var>origin</var> expression, the expression must
  156. be numerical only and must evaluate to a constant. The keyword
  157. <code>LENGTH</code> may be abbreviated to <code>len</code> or <code>l</code>.
  158. </p>
  159. <p>In the following example, we specify that there are two memory regions
  160. available for allocation: one starting at &lsquo;<samp>0</samp>&rsquo; for 256 kilobytes,
  161. and the other starting at &lsquo;<samp>0x40000000</samp>&rsquo; for four megabytes. The
  162. linker will place into the &lsquo;<samp>rom</samp>&rsquo; memory region every section which
  163. is not explicitly mapped into a memory region, and is either read-only
  164. or executable. The linker will place other sections which are not
  165. explicitly mapped into a memory region into the &lsquo;<samp>ram</samp>&rsquo; memory
  166. region.
  167. </p>
  168. <div class="smallexample">
  169. <pre class="smallexample">MEMORY
  170. {
  171. rom (rx) : ORIGIN = 0, LENGTH = 256K
  172. ram (!rx) : org = 0x40000000, l = 4M
  173. }
  174. </pre></div>
  175. <p>Once you define a memory region, you can direct the linker to place
  176. specific output sections into that memory region by using the
  177. &lsquo;<samp>&gt;<var>region</var></samp>&rsquo; output section attribute. For example, if you have
  178. a memory region named &lsquo;<samp>mem</samp>&rsquo;, you would use &lsquo;<samp>&gt;mem</samp>&rsquo; in the
  179. output section definition. See <a href="Output-Section-Region.html#Output-Section-Region">Output Section Region</a>. If no address
  180. was specified for the output section, the linker will set the address to
  181. the next available address within the memory region. If the combined
  182. output sections directed to a memory region are too large for the
  183. region, the linker will issue an error message.
  184. </p>
  185. <p>It is possible to access the origin and length of a memory in an
  186. expression via the <code>ORIGIN(<var>memory</var>)</code> and
  187. <code>LENGTH(<var>memory</var>)</code> functions:
  188. </p>
  189. <div class="smallexample">
  190. <pre class="smallexample"> _fstack = ORIGIN(ram) + LENGTH(ram) - 4;
  191. </pre></div>
  192. <hr>
  193. <div class="header">
  194. <p>
  195. Next: <a href="PHDRS.html#PHDRS" accesskey="n" rel="next">PHDRS</a>, Previous: <a href="SECTIONS.html#SECTIONS" accesskey="p" rel="prev">SECTIONS</a>, Up: <a href="Scripts.html#Scripts" accesskey="u" rel="up">Scripts</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>
  196. </div>
  197. </body>
  198. </html>