Miscellaneous-Commands.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 Toolchain for the A-profile Architecture 10.2-2020.11 (arm-10.16))
  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 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>LD: Miscellaneous Commands</title>
  16. <meta name="description" content="LD: Miscellaneous Commands">
  17. <meta name="keywords" content="LD: Miscellaneous Commands">
  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="Simple-Commands.html#Simple-Commands" rel="up" title="Simple Commands">
  26. <link href="Assignments.html#Assignments" rel="next" title="Assignments">
  27. <link href="REGION_005fALIAS.html#REGION_005fALIAS" rel="previous" title="REGION_ALIAS">
  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="Miscellaneous-Commands"></a>
  59. <div class="header">
  60. <p>
  61. Previous: <a href="REGION_005fALIAS.html#REGION_005fALIAS" accesskey="p" rel="previous">REGION_ALIAS</a>, Up: <a href="Simple-Commands.html#Simple-Commands" accesskey="u" rel="up">Simple Commands</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="Other-Linker-Script-Commands"></a>
  65. <h4 class="subsection">3.4.5 Other Linker Script Commands</h4>
  66. <p>There are a few other linker scripts commands.
  67. </p>
  68. <dl compact="compact">
  69. <dt><code>ASSERT(<var>exp</var>, <var>message</var>)</code></dt>
  70. <dd><a name="index-ASSERT"></a>
  71. <a name="index-assertion-in-linker-script"></a>
  72. <p>Ensure that <var>exp</var> is non-zero. If it is zero, then exit the linker
  73. with an error code, and print <var>message</var>.
  74. </p>
  75. <p>Note that assertions are checked before the final stages of linking
  76. take place. This means that expressions involving symbols PROVIDEd
  77. inside section definitions will fail if the user has not set values
  78. for those symbols. The only exception to this rule is PROVIDEd
  79. symbols that just reference dot. Thus an assertion like this:
  80. </p>
  81. <div class="smallexample">
  82. <pre class="smallexample"> .stack :
  83. {
  84. PROVIDE (__stack = .);
  85. PROVIDE (__stack_size = 0x100);
  86. ASSERT ((__stack &gt; (_end + __stack_size)), &quot;Error: No room left for the stack&quot;);
  87. }
  88. </pre></div>
  89. <p>will fail if <code>__stack_size</code> is not defined elsewhere. Symbols
  90. PROVIDEd outside of section definitions are evaluated earlier, so they
  91. can be used inside ASSERTions. Thus:
  92. </p>
  93. <div class="smallexample">
  94. <pre class="smallexample"> PROVIDE (__stack_size = 0x100);
  95. .stack :
  96. {
  97. PROVIDE (__stack = .);
  98. ASSERT ((__stack &gt; (_end + __stack_size)), &quot;Error: No room left for the stack&quot;);
  99. }
  100. </pre></div>
  101. <p>will work.
  102. </p>
  103. </dd>
  104. <dt><code>EXTERN(<var>symbol</var> <var>symbol</var> &hellip;)</code></dt>
  105. <dd><a name="index-EXTERN"></a>
  106. <a name="index-undefined-symbol-in-linker-script"></a>
  107. <p>Force <var>symbol</var> to be entered in the output file as an undefined
  108. symbol. Doing this may, for example, trigger linking of additional
  109. modules from standard libraries. You may list several <var>symbol</var>s for
  110. each <code>EXTERN</code>, and you may use <code>EXTERN</code> multiple times. This
  111. command has the same effect as the &lsquo;<samp>-u</samp>&rsquo; command-line option.
  112. </p>
  113. </dd>
  114. <dt><code>FORCE_COMMON_ALLOCATION</code></dt>
  115. <dd><a name="index-FORCE_005fCOMMON_005fALLOCATION"></a>
  116. <a name="index-common-allocation-in-linker-script"></a>
  117. <p>This command has the same effect as the &lsquo;<samp>-d</samp>&rsquo; command-line option:
  118. to make <code>ld</code> assign space to common symbols even if a relocatable
  119. output file is specified (&lsquo;<samp>-r</samp>&rsquo;).
  120. </p>
  121. </dd>
  122. <dt><code>INHIBIT_COMMON_ALLOCATION</code></dt>
  123. <dd><a name="index-INHIBIT_005fCOMMON_005fALLOCATION"></a>
  124. <a name="index-common-allocation-in-linker-script-1"></a>
  125. <p>This command has the same effect as the &lsquo;<samp>--no-define-common</samp>&rsquo;
  126. command-line option: to make <code>ld</code> omit the assignment of addresses
  127. to common symbols even for a non-relocatable output file.
  128. </p>
  129. </dd>
  130. <dt><code>FORCE_GROUP_ALLOCATION</code></dt>
  131. <dd><a name="index-FORCE_005fGROUP_005fALLOCATION"></a>
  132. <a name="index-group-allocation-in-linker-script-1"></a>
  133. <a name="index-section-groups-1"></a>
  134. <a name="index-COMDAT-1"></a>
  135. <p>This command has the same effect as the
  136. &lsquo;<samp>--force-group-allocation</samp>&rsquo; command-line option: to make
  137. <code>ld</code> place section group members like normal input sections,
  138. and to delete the section groups even if a relocatable output file is
  139. specified (&lsquo;<samp>-r</samp>&rsquo;).
  140. </p>
  141. </dd>
  142. <dt><code>INSERT [ AFTER | BEFORE ] <var>output_section</var></code></dt>
  143. <dd><a name="index-INSERT"></a>
  144. <a name="index-insert-user-script-into-default-script"></a>
  145. <p>This command is typically used in a script specified by &lsquo;<samp>-T</samp>&rsquo; to
  146. augment the default <code>SECTIONS</code> with, for example, overlays. It
  147. inserts all prior linker script statements after (or before)
  148. <var>output_section</var>, and also causes &lsquo;<samp>-T</samp>&rsquo; to not override the
  149. default linker script. The exact insertion point is as for orphan
  150. sections. See <a href="Location-Counter.html#Location-Counter">Location Counter</a>. The insertion happens after the
  151. linker has mapped input sections to output sections. Prior to the
  152. insertion, since &lsquo;<samp>-T</samp>&rsquo; scripts are parsed before the default
  153. linker script, statements in the &lsquo;<samp>-T</samp>&rsquo; script occur before the
  154. default linker script statements in the internal linker representation
  155. of the script. In particular, input section assignments will be made
  156. to &lsquo;<samp>-T</samp>&rsquo; output sections before those in the default script. Here
  157. is an example of how a &lsquo;<samp>-T</samp>&rsquo; script using <code>INSERT</code> might look:
  158. </p>
  159. <div class="smallexample">
  160. <pre class="smallexample">SECTIONS
  161. {
  162. OVERLAY :
  163. {
  164. .ov1 { ov1*(.text) }
  165. .ov2 { ov2*(.text) }
  166. }
  167. }
  168. INSERT AFTER .text;
  169. </pre></div>
  170. </dd>
  171. <dt><code>NOCROSSREFS(<var>section</var> <var>section</var> &hellip;)</code></dt>
  172. <dd><a name="index-NOCROSSREFS_0028sections_0029"></a>
  173. <a name="index-cross-references"></a>
  174. <p>This command may be used to tell <code>ld</code> to issue an error about any
  175. references among certain output sections.
  176. </p>
  177. <p>In certain types of programs, particularly on embedded systems when
  178. using overlays, when one section is loaded into memory, another section
  179. will not be. Any direct references between the two sections would be
  180. errors. For example, it would be an error if code in one section called
  181. a function defined in the other section.
  182. </p>
  183. <p>The <code>NOCROSSREFS</code> command takes a list of output section names. If
  184. <code>ld</code> detects any cross references between the sections, it reports
  185. an error and returns a non-zero exit status. Note that the
  186. <code>NOCROSSREFS</code> command uses output section names, not input section
  187. names.
  188. </p>
  189. </dd>
  190. <dt><code>NOCROSSREFS_TO(<var>tosection</var> <var>fromsection</var> &hellip;)</code></dt>
  191. <dd><a name="index-NOCROSSREFS_005fTO_0028tosection-fromsections_0029"></a>
  192. <a name="index-cross-references-1"></a>
  193. <p>This command may be used to tell <code>ld</code> to issue an error about any
  194. references to one section from a list of other sections.
  195. </p>
  196. <p>The <code>NOCROSSREFS</code> command is useful when ensuring that two or more
  197. output sections are entirely independent but there are situations where
  198. a one-way dependency is needed. For example, in a multi-core application
  199. there may be shared code that can be called from each core but for safety
  200. must never call back.
  201. </p>
  202. <p>The <code>NOCROSSREFS_TO</code> command takes a list of output section names.
  203. The first section can not be referenced from any of the other sections.
  204. If <code>ld</code> detects any references to the first section from any of
  205. the other sections, it reports an error and returns a non-zero exit
  206. status. Note that the <code>NOCROSSREFS_TO</code> command uses output section
  207. names, not input section names.
  208. </p>
  209. </dd>
  210. <dt><code>OUTPUT_ARCH(<var>bfdarch</var>)</code></dt>
  211. <dd><a name="index-OUTPUT_005fARCH_0028bfdarch_0029"></a>
  212. <a name="index-machine-architecture"></a>
  213. <a name="index-architecture"></a>
  214. <p>Specify a particular output machine architecture. The argument is one
  215. of the names used by the BFD library (see <a href="BFD.html#BFD">BFD</a>). You can see the
  216. architecture of an object file by using the <code>objdump</code> program with
  217. the &lsquo;<samp>-f</samp>&rsquo; option.
  218. </p>
  219. </dd>
  220. <dt><code>LD_FEATURE(<var>string</var>)</code></dt>
  221. <dd><a name="index-LD_005fFEATURE_0028string_0029"></a>
  222. <p>This command may be used to modify <code>ld</code> behavior. If
  223. <var>string</var> is <code>&quot;SANE_EXPR&quot;</code> then absolute symbols and numbers
  224. in a script are simply treated as numbers everywhere.
  225. See <a href="Expression-Section.html#Expression-Section">Expression Section</a>.
  226. </p></dd>
  227. </dl>
  228. <hr>
  229. <div class="header">
  230. <p>
  231. Previous: <a href="REGION_005fALIAS.html#REGION_005fALIAS" accesskey="p" rel="previous">REGION_ALIAS</a>, Up: <a href="Simple-Commands.html#Simple-Commands" accesskey="u" rel="up">Simple Commands</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>
  232. </div>
  233. </body>
  234. </html>