You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 line
8.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>Overlay Description (LD)</title>
  17. <meta name="description" content="Overlay Description (LD)">
  18. <meta name="keywords" content="Overlay Description (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="SECTIONS.html#SECTIONS" rel="up" title="SECTIONS">
  26. <link href="MEMORY.html#MEMORY" rel="next" title="MEMORY">
  27. <link href="Output-Section-Fill.html#Output-Section-Fill" rel="prev" title="Output Section Fill">
  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="Overlay-Description"></a>
  58. <div class="header">
  59. <p>
  60. Previous: <a href="Output-Section-Attributes.html#Output-Section-Attributes" accesskey="p" rel="prev">Output Section Attributes</a>, Up: <a href="SECTIONS.html#SECTIONS" accesskey="u" rel="up">SECTIONS</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="Overlay-Description-1"></a>
  64. <h4 class="subsection">3.6.9 Overlay Description</h4>
  65. <a name="index-OVERLAY"></a>
  66. <a name="index-overlays"></a>
  67. <p>An overlay description provides an easy way to describe sections which
  68. are to be loaded as part of a single memory image but are to be run at
  69. the same memory address. At run time, some sort of overlay manager will
  70. copy the overlaid sections in and out of the runtime memory address as
  71. required, perhaps by simply manipulating addressing bits. This approach
  72. can be useful, for example, when a certain region of memory is faster
  73. than another.
  74. </p>
  75. <p>Overlays are described using the <code>OVERLAY</code> command. The
  76. <code>OVERLAY</code> command is used within a <code>SECTIONS</code> command, like an
  77. output section description. The full syntax of the <code>OVERLAY</code>
  78. command is as follows:
  79. </p><div class="smallexample">
  80. <pre class="smallexample">OVERLAY [<var>start</var>] : [NOCROSSREFS] [AT ( <var>ldaddr</var> )]
  81. {
  82. <var>secname1</var>
  83. {
  84. <var>output-section-command</var>
  85. <var>output-section-command</var>
  86. &hellip;
  87. } [:<var>phdr</var>&hellip;] [=<var>fill</var>]
  88. <var>secname2</var>
  89. {
  90. <var>output-section-command</var>
  91. <var>output-section-command</var>
  92. &hellip;
  93. } [:<var>phdr</var>&hellip;] [=<var>fill</var>]
  94. &hellip;
  95. } [&gt;<var>region</var>] [:<var>phdr</var>&hellip;] [=<var>fill</var>] [,]
  96. </pre></div>
  97. <p>Everything is optional except <code>OVERLAY</code> (a keyword), and each
  98. section must have a name (<var>secname1</var> and <var>secname2</var> above). The
  99. section definitions within the <code>OVERLAY</code> construct are identical to
  100. those within the general <code>SECTIONS</code> construct (see <a href="SECTIONS.html#SECTIONS">SECTIONS</a>),
  101. except that no addresses and no memory regions may be defined for
  102. sections within an <code>OVERLAY</code>.
  103. </p>
  104. <p>The comma at the end may be required if a <var>fill</var> is used and
  105. the next <var>sections-command</var> looks like a continuation of the expression.
  106. </p>
  107. <p>The sections are all defined with the same starting address. The load
  108. addresses of the sections are arranged such that they are consecutive in
  109. memory starting at the load address used for the <code>OVERLAY</code> as a
  110. whole (as with normal section definitions, the load address is optional,
  111. and defaults to the start address; the start address is also optional,
  112. and defaults to the current value of the location counter).
  113. </p>
  114. <p>If the <code>NOCROSSREFS</code> keyword is used, and there are any
  115. references among the sections, the linker will report an error. Since
  116. the sections all run at the same address, it normally does not make
  117. sense for one section to refer directly to another.
  118. See <a href="Miscellaneous-Commands.html#Miscellaneous-Commands">NOCROSSREFS</a>.
  119. </p>
  120. <p>For each section within the <code>OVERLAY</code>, the linker automatically
  121. provides two symbols. The symbol <code>__load_start_<var>secname</var></code> is
  122. defined as the starting load address of the section. The symbol
  123. <code>__load_stop_<var>secname</var></code> is defined as the final load address of
  124. the section. Any characters within <var>secname</var> which are not legal
  125. within C identifiers are removed. C (or assembler) code may use these
  126. symbols to move the overlaid sections around as necessary.
  127. </p>
  128. <p>At the end of the overlay, the value of the location counter is set to
  129. the start address of the overlay plus the size of the largest section.
  130. </p>
  131. <p>Here is an example. Remember that this would appear inside a
  132. <code>SECTIONS</code> construct.
  133. </p><div class="smallexample">
  134. <pre class="smallexample"> OVERLAY 0x1000 : AT (0x4000)
  135. {
  136. .text0 { o1/*.o(.text) }
  137. .text1 { o2/*.o(.text) }
  138. }
  139. </pre></div>
  140. <p>This will define both &lsquo;<samp>.text0</samp>&rsquo; and &lsquo;<samp>.text1</samp>&rsquo; to start at
  141. address 0x1000. &lsquo;<samp>.text0</samp>&rsquo; will be loaded at address 0x4000, and
  142. &lsquo;<samp>.text1</samp>&rsquo; will be loaded immediately after &lsquo;<samp>.text0</samp>&rsquo;. The
  143. following symbols will be defined if referenced: <code>__load_start_text0</code>,
  144. <code>__load_stop_text0</code>, <code>__load_start_text1</code>,
  145. <code>__load_stop_text1</code>.
  146. </p>
  147. <p>C code to copy overlay <code>.text1</code> into the overlay area might look
  148. like the following.
  149. </p>
  150. <div class="smallexample">
  151. <pre class="smallexample"> extern char __load_start_text1, __load_stop_text1;
  152. memcpy ((char *) 0x1000, &amp;__load_start_text1,
  153. &amp;__load_stop_text1 - &amp;__load_start_text1);
  154. </pre></div>
  155. <p>Note that the <code>OVERLAY</code> command is just syntactic sugar, since
  156. everything it does can be done using the more basic commands. The above
  157. example could have been written identically as follows.
  158. </p>
  159. <div class="smallexample">
  160. <pre class="smallexample"> .text0 0x1000 : AT (0x4000) { o1/*.o(.text) }
  161. PROVIDE (__load_start_text0 = LOADADDR (.text0));
  162. PROVIDE (__load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0));
  163. .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) { o2/*.o(.text) }
  164. PROVIDE (__load_start_text1 = LOADADDR (.text1));
  165. PROVIDE (__load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1));
  166. . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
  167. </pre></div>
  168. <hr>
  169. <div class="header">
  170. <p>
  171. Previous: <a href="Output-Section-Attributes.html#Output-Section-Attributes" accesskey="p" rel="prev">Output Section Attributes</a>, Up: <a href="SECTIONS.html#SECTIONS" accesskey="u" rel="up">SECTIONS</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>
  172. </div>
  173. </body>
  174. </html>