File-Commands.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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: File Commands</title>
  16. <meta name="description" content="LD: File Commands">
  17. <meta name="keywords" content="LD: File 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="Format-Commands.html#Format-Commands" rel="next" title="Format Commands">
  27. <link href="Entry-Point.html#Entry-Point" rel="previous" title="Entry Point">
  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="File-Commands"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Format-Commands.html#Format-Commands" accesskey="n" rel="next">Format Commands</a>, Previous: <a href="Entry-Point.html#Entry-Point" accesskey="p" rel="previous">Entry Point</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="Commands-Dealing-with-Files"></a>
  65. <h4 class="subsection">3.4.2 Commands Dealing with Files</h4>
  66. <a name="index-linker-script-file-commands"></a>
  67. <p>Several linker script commands deal with files.
  68. </p>
  69. <dl compact="compact">
  70. <dt><code>INCLUDE <var>filename</var></code></dt>
  71. <dd><a name="index-INCLUDE-filename"></a>
  72. <a name="index-including-a-linker-script"></a>
  73. <p>Include the linker script <var>filename</var> at this point. The file will
  74. be searched for in the current directory, and in any directory specified
  75. with the <samp>-L</samp> option. You can nest calls to <code>INCLUDE</code> up to
  76. 10 levels deep.
  77. </p>
  78. <p>You can place <code>INCLUDE</code> directives at the top level, in <code>MEMORY</code> or
  79. <code>SECTIONS</code> commands, or in output section descriptions.
  80. </p>
  81. </dd>
  82. <dt><code>INPUT(<var>file</var>, <var>file</var>, &hellip;)</code></dt>
  83. <dt><code>INPUT(<var>file</var> <var>file</var> &hellip;)</code></dt>
  84. <dd><a name="index-INPUT_0028files_0029"></a>
  85. <a name="index-input-files-in-linker-scripts"></a>
  86. <a name="index-input-object-files-in-linker-scripts"></a>
  87. <a name="index-linker-script-input-object-files"></a>
  88. <p>The <code>INPUT</code> command directs the linker to include the named files
  89. in the link, as though they were named on the command line.
  90. </p>
  91. <p>For example, if you always want to include <samp>subr.o</samp> any time you do
  92. a link, but you can&rsquo;t be bothered to put it on every link command line,
  93. then you can put &lsquo;<samp>INPUT (subr.o)</samp>&rsquo; in your linker script.
  94. </p>
  95. <p>In fact, if you like, you can list all of your input files in the linker
  96. script, and then invoke the linker with nothing but a &lsquo;<samp>-T</samp>&rsquo; option.
  97. </p>
  98. <p>In case a <em>sysroot prefix</em> is configured, and the filename starts
  99. with the &lsquo;<samp>/</samp>&rsquo; character, and the script being processed was
  100. located inside the <em>sysroot prefix</em>, the filename will be looked
  101. for in the <em>sysroot prefix</em>. The <em>sysroot prefix</em> can also be forced by specifying
  102. <code>=</code> as the first character in the filename path, or prefixing the
  103. filename path with <code>$SYSROOT</code>. See also the description of
  104. &lsquo;<samp>-L</samp>&rsquo; in <a href="Options.html#Options">Command-line Options</a>.
  105. </p>
  106. <p>If a <em>sysroot prefix</em> is not used then the linker will try to open
  107. the file in the directory containing the linker script. If it is not
  108. found the linker will then search the current directory. If it is still
  109. not found the linker will search through the archive library search
  110. path.
  111. </p>
  112. <p>If you use &lsquo;<samp>INPUT (-l<var>file</var>)</samp>&rsquo;, <code>ld</code> will transform the
  113. name to <code>lib<var>file</var>.a</code>, as with the command-line argument
  114. &lsquo;<samp>-l</samp>&rsquo;.
  115. </p>
  116. <p>When you use the <code>INPUT</code> command in an implicit linker script, the
  117. files will be included in the link at the point at which the linker
  118. script file is included. This can affect archive searching.
  119. </p>
  120. </dd>
  121. <dt><code>GROUP(<var>file</var>, <var>file</var>, &hellip;)</code></dt>
  122. <dt><code>GROUP(<var>file</var> <var>file</var> &hellip;)</code></dt>
  123. <dd><a name="index-GROUP_0028files_0029"></a>
  124. <a name="index-grouping-input-files"></a>
  125. <p>The <code>GROUP</code> command is like <code>INPUT</code>, except that the named
  126. files should all be archives, and they are searched repeatedly until no
  127. new undefined references are created. See the description of &lsquo;<samp>-(</samp>&rsquo;
  128. in <a href="Options.html#Options">Command-line Options</a>.
  129. </p>
  130. </dd>
  131. <dt><code>AS_NEEDED(<var>file</var>, <var>file</var>, &hellip;)</code></dt>
  132. <dt><code>AS_NEEDED(<var>file</var> <var>file</var> &hellip;)</code></dt>
  133. <dd><a name="index-AS_005fNEEDED_0028files_0029"></a>
  134. <p>This construct can appear only inside of the <code>INPUT</code> or <code>GROUP</code>
  135. commands, among other filenames. The files listed will be handled
  136. as if they appear directly in the <code>INPUT</code> or <code>GROUP</code> commands,
  137. with the exception of ELF shared libraries, that will be added only
  138. when they are actually needed. This construct essentially enables
  139. <samp>--as-needed</samp> option for all the files listed inside of it
  140. and restores previous <samp>--as-needed</samp> resp. <samp>--no-as-needed</samp>
  141. setting afterwards.
  142. </p>
  143. </dd>
  144. <dt><code>OUTPUT(<var>filename</var>)</code></dt>
  145. <dd><a name="index-OUTPUT_0028filename_0029"></a>
  146. <a name="index-output-file-name-in-linker-script"></a>
  147. <p>The <code>OUTPUT</code> command names the output file. Using
  148. <code>OUTPUT(<var>filename</var>)</code> in the linker script is exactly like using
  149. &lsquo;<samp>-o <var>filename</var></samp>&rsquo; on the command line (see <a href="Options.html#Options">Command
  150. Line Options</a>). If both are used, the command-line option takes
  151. precedence.
  152. </p>
  153. <p>You can use the <code>OUTPUT</code> command to define a default name for the
  154. output file other than the usual default of <samp>a.out</samp>.
  155. </p>
  156. </dd>
  157. <dt><code>SEARCH_DIR(<var>path</var>)</code></dt>
  158. <dd><a name="index-SEARCH_005fDIR_0028path_0029"></a>
  159. <a name="index-library-search-path-in-linker-script"></a>
  160. <a name="index-archive-search-path-in-linker-script"></a>
  161. <a name="index-search-path-in-linker-script"></a>
  162. <p>The <code>SEARCH_DIR</code> command adds <var>path</var> to the list of paths where
  163. <code>ld</code> looks for archive libraries. Using
  164. <code>SEARCH_DIR(<var>path</var>)</code> is exactly like using &lsquo;<samp>-L <var>path</var></samp>&rsquo;
  165. on the command line (see <a href="Options.html#Options">Command-line Options</a>). If both
  166. are used, then the linker will search both paths. Paths specified using
  167. the command-line option are searched first.
  168. </p>
  169. </dd>
  170. <dt><code>STARTUP(<var>filename</var>)</code></dt>
  171. <dd><a name="index-STARTUP_0028filename_0029"></a>
  172. <a name="index-first-input-file"></a>
  173. <p>The <code>STARTUP</code> command is just like the <code>INPUT</code> command, except
  174. that <var>filename</var> will become the first input file to be linked, as
  175. though it were specified first on the command line. This may be useful
  176. when using a system in which the entry point is always the start of the
  177. first file.
  178. </p></dd>
  179. </dl>
  180. <hr>
  181. <div class="header">
  182. <p>
  183. Next: <a href="Format-Commands.html#Format-Commands" accesskey="n" rel="next">Format Commands</a>, Previous: <a href="Entry-Point.html#Entry-Point" accesskey="p" rel="previous">Entry Point</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>
  184. </div>
  185. </body>
  186. </html>