Miscellaneous-Commands.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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: 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="prev" 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="prev">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>INSERT [ AFTER | BEFORE ] <var>output_section</var></code></dt>
  131. <dd><a name="index-INSERT"></a>
  132. <a name="index-insert-user-script-into-default-script"></a>
  133. <p>This command is typically used in a script specified by &lsquo;<samp>-T</samp>&rsquo; to
  134. augment the default <code>SECTIONS</code> with, for example, overlays. It
  135. inserts all prior linker script statements after (or before)
  136. <var>output_section</var>, and also causes &lsquo;<samp>-T</samp>&rsquo; to not override the
  137. default linker script. The exact insertion point is as for orphan
  138. sections. See <a href="Location-Counter.html#Location-Counter">Location Counter</a>. The insertion happens after the
  139. linker has mapped input sections to output sections. Prior to the
  140. insertion, since &lsquo;<samp>-T</samp>&rsquo; scripts are parsed before the default
  141. linker script, statements in the &lsquo;<samp>-T</samp>&rsquo; script occur before the
  142. default linker script statements in the internal linker representation
  143. of the script. In particular, input section assignments will be made
  144. to &lsquo;<samp>-T</samp>&rsquo; output sections before those in the default script. Here
  145. is an example of how a &lsquo;<samp>-T</samp>&rsquo; script using <code>INSERT</code> might look:
  146. </p>
  147. <div class="smallexample">
  148. <pre class="smallexample">SECTIONS
  149. {
  150. OVERLAY :
  151. {
  152. .ov1 { ov1*(.text) }
  153. .ov2 { ov2*(.text) }
  154. }
  155. }
  156. INSERT AFTER .text;
  157. </pre></div>
  158. </dd>
  159. <dt><code>NOCROSSREFS(<var>section</var> <var>section</var> &hellip;)</code></dt>
  160. <dd><a name="index-NOCROSSREFS_0028sections_0029"></a>
  161. <a name="index-cross-references"></a>
  162. <p>This command may be used to tell <code>ld</code> to issue an error about any
  163. references among certain output sections.
  164. </p>
  165. <p>In certain types of programs, particularly on embedded systems when
  166. using overlays, when one section is loaded into memory, another section
  167. will not be. Any direct references between the two sections would be
  168. errors. For example, it would be an error if code in one section called
  169. a function defined in the other section.
  170. </p>
  171. <p>The <code>NOCROSSREFS</code> command takes a list of output section names. If
  172. <code>ld</code> detects any cross references between the sections, it reports
  173. an error and returns a non-zero exit status. Note that the
  174. <code>NOCROSSREFS</code> command uses output section names, not input section
  175. names.
  176. </p>
  177. </dd>
  178. <dt><code>NOCROSSREFS_TO(<var>tosection</var> <var>fromsection</var> &hellip;)</code></dt>
  179. <dd><a name="index-NOCROSSREFS_005fTO_0028tosection-fromsections_0029"></a>
  180. <a name="index-cross-references-1"></a>
  181. <p>This command may be used to tell <code>ld</code> to issue an error about any
  182. references to one section from a list of other sections.
  183. </p>
  184. <p>The <code>NOCROSSREFS</code> command is useful when ensuring that two or more
  185. output sections are entirely independent but there are situations where
  186. a one-way dependency is needed. For example, in a multi-core application
  187. there may be shared code that can be called from each core but for safety
  188. must never call back.
  189. </p>
  190. <p>The <code>NOCROSSREFS_TO</code> command takes a list of output section names.
  191. The first section can not be referenced from any of the other sections.
  192. If <code>ld</code> detects any references to the first section from any of
  193. the other sections, it reports an error and returns a non-zero exit
  194. status. Note that the <code>NOCROSSREFS_TO</code> command uses output section
  195. names, not input section names.
  196. </p>
  197. </dd>
  198. <dt><code>OUTPUT_ARCH(<var>bfdarch</var>)</code></dt>
  199. <dd><a name="index-OUTPUT_005fARCH_0028bfdarch_0029"></a>
  200. <a name="index-machine-architecture"></a>
  201. <a name="index-architecture"></a>
  202. <p>Specify a particular output machine architecture. The argument is one
  203. of the names used by the BFD library (see <a href="BFD.html#BFD">BFD</a>). You can see the
  204. architecture of an object file by using the <code>objdump</code> program with
  205. the &lsquo;<samp>-f</samp>&rsquo; option.
  206. </p>
  207. </dd>
  208. <dt><code>LD_FEATURE(<var>string</var>)</code></dt>
  209. <dd><a name="index-LD_005fFEATURE_0028string_0029"></a>
  210. <p>This command may be used to modify <code>ld</code> behavior. If
  211. <var>string</var> is <code>&quot;SANE_EXPR&quot;</code> then absolute symbols and numbers
  212. in a script are simply treated as numbers everywhere.
  213. See <a href="Expression-Section.html#Expression-Section">Expression Section</a>.
  214. </p></dd>
  215. </dl>
  216. <hr>
  217. <div class="header">
  218. <p>
  219. Previous: <a href="REGION_005fALIAS.html#REGION_005fALIAS" accesskey="p" rel="prev">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>
  220. </div>
  221. </body>
  222. </html>