Overlay-Description.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 Binutils)
  5. version 2.28.
  6. Copyright (C) 1991-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>LD: Overlay Description</title>
  16. <meta name="description" content="LD: Overlay Description">
  17. <meta name="keywords" content="LD: Overlay Description">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Overlay-Description"></a>
  59. <div class="header">
  60. <p>
  61. 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>
  62. </div>
  63. <hr>
  64. <a name="Overlay-Description-1"></a>
  65. <h4 class="subsection">3.6.9 Overlay Description</h4>
  66. <a name="index-OVERLAY"></a>
  67. <a name="index-overlays"></a>
  68. <p>An overlay description provides an easy way to describe sections which
  69. are to be loaded as part of a single memory image but are to be run at
  70. the same memory address. At run time, some sort of overlay manager will
  71. copy the overlaid sections in and out of the runtime memory address as
  72. required, perhaps by simply manipulating addressing bits. This approach
  73. can be useful, for example, when a certain region of memory is faster
  74. than another.
  75. </p>
  76. <p>Overlays are described using the <code>OVERLAY</code> command. The
  77. <code>OVERLAY</code> command is used within a <code>SECTIONS</code> command, like an
  78. output section description. The full syntax of the <code>OVERLAY</code>
  79. command is as follows:
  80. </p><div class="smallexample">
  81. <pre class="smallexample">OVERLAY [<var>start</var>] : [NOCROSSREFS] [AT ( <var>ldaddr</var> )]
  82. {
  83. <var>secname1</var>
  84. {
  85. <var>output-section-command</var>
  86. <var>output-section-command</var>
  87. &hellip;
  88. } [:<var>phdr</var>&hellip;] [=<var>fill</var>]
  89. <var>secname2</var>
  90. {
  91. <var>output-section-command</var>
  92. <var>output-section-command</var>
  93. &hellip;
  94. } [:<var>phdr</var>&hellip;] [=<var>fill</var>]
  95. &hellip;
  96. } [&gt;<var>region</var>] [:<var>phdr</var>&hellip;] [=<var>fill</var>] [,]
  97. </pre></div>
  98. <p>Everything is optional except <code>OVERLAY</code> (a keyword), and each
  99. section must have a name (<var>secname1</var> and <var>secname2</var> above). The
  100. section definitions within the <code>OVERLAY</code> construct are identical to
  101. those within the general <code>SECTIONS</code> construct (see <a href="SECTIONS.html#SECTIONS">SECTIONS</a>),
  102. except that no addresses and no memory regions may be defined for
  103. sections within an <code>OVERLAY</code>.
  104. </p>
  105. <p>The comma at the end may be required if a <var>fill</var> is used and
  106. the next <var>sections-command</var> looks like a continuation of the expression.
  107. </p>
  108. <p>The sections are all defined with the same starting address. The load
  109. addresses of the sections are arranged such that they are consecutive in
  110. memory starting at the load address used for the <code>OVERLAY</code> as a
  111. whole (as with normal section definitions, the load address is optional,
  112. and defaults to the start address; the start address is also optional,
  113. and defaults to the current value of the location counter).
  114. </p>
  115. <p>If the <code>NOCROSSREFS</code> keyword is used, and there are any
  116. references among the sections, the linker will report an error. Since
  117. the sections all run at the same address, it normally does not make
  118. sense for one section to refer directly to another.
  119. See <a href="Miscellaneous-Commands.html#Miscellaneous-Commands">NOCROSSREFS</a>.
  120. </p>
  121. <p>For each section within the <code>OVERLAY</code>, the linker automatically
  122. provides two symbols. The symbol <code>__load_start_<var>secname</var></code> is
  123. defined as the starting load address of the section. The symbol
  124. <code>__load_stop_<var>secname</var></code> is defined as the final load address of
  125. the section. Any characters within <var>secname</var> which are not legal
  126. within C identifiers are removed. C (or assembler) code may use these
  127. symbols to move the overlaid sections around as necessary.
  128. </p>
  129. <p>At the end of the overlay, the value of the location counter is set to
  130. the start address of the overlay plus the size of the largest section.
  131. </p>
  132. <p>Here is an example. Remember that this would appear inside a
  133. <code>SECTIONS</code> construct.
  134. </p><div class="smallexample">
  135. <pre class="smallexample"> OVERLAY 0x1000 : AT (0x4000)
  136. {
  137. .text0 { o1/*.o(.text) }
  138. .text1 { o2/*.o(.text) }
  139. }
  140. </pre></div>
  141. <p>This will define both &lsquo;<samp>.text0</samp>&rsquo; and &lsquo;<samp>.text1</samp>&rsquo; to start at
  142. address 0x1000. &lsquo;<samp>.text0</samp>&rsquo; will be loaded at address 0x4000, and
  143. &lsquo;<samp>.text1</samp>&rsquo; will be loaded immediately after &lsquo;<samp>.text0</samp>&rsquo;. The
  144. following symbols will be defined if referenced: <code>__load_start_text0</code>,
  145. <code>__load_stop_text0</code>, <code>__load_start_text1</code>,
  146. <code>__load_stop_text1</code>.
  147. </p>
  148. <p>C code to copy overlay <code>.text1</code> into the overlay area might look
  149. like the following.
  150. </p>
  151. <div class="smallexample">
  152. <pre class="smallexample"> extern char __load_start_text1, __load_stop_text1;
  153. memcpy ((char *) 0x1000, &amp;__load_start_text1,
  154. &amp;__load_stop_text1 - &amp;__load_start_text1);
  155. </pre></div>
  156. <p>Note that the <code>OVERLAY</code> command is just syntactic sugar, since
  157. everything it does can be done using the more basic commands. The above
  158. example could have been written identically as follows.
  159. </p>
  160. <div class="smallexample">
  161. <pre class="smallexample"> .text0 0x1000 : AT (0x4000) { o1/*.o(.text) }
  162. PROVIDE (__load_start_text0 = LOADADDR (.text0));
  163. PROVIDE (__load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0));
  164. .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) { o2/*.o(.text) }
  165. PROVIDE (__load_start_text1 = LOADADDR (.text1));
  166. PROVIDE (__load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1));
  167. . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
  168. </pre></div>
  169. <hr>
  170. <div class="header">
  171. <p>
  172. 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>
  173. </div>
  174. </body>
  175. </html>