File-Commands.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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: 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="prev" 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="prev">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>. Otherwise, the linker will try to
  102. open the file in the current directory. If it is not found, the
  103. linker will search through the archive library search path.
  104. The <em>sysroot prefix</em> can also be forced by specifying <code>=</code>
  105. as the first character in the filename path. See also the
  106. description of &lsquo;<samp>-L</samp>&rsquo; in <a href="Options.html#Options">Command Line Options</a>.
  107. </p>
  108. <p>If you use &lsquo;<samp>INPUT (-l<var>file</var>)</samp>&rsquo;, <code>ld</code> will transform the
  109. name to <code>lib<var>file</var>.a</code>, as with the command line argument
  110. &lsquo;<samp>-l</samp>&rsquo;.
  111. </p>
  112. <p>When you use the <code>INPUT</code> command in an implicit linker script, the
  113. files will be included in the link at the point at which the linker
  114. script file is included. This can affect archive searching.
  115. </p>
  116. </dd>
  117. <dt><code>GROUP(<var>file</var>, <var>file</var>, &hellip;)</code></dt>
  118. <dt><code>GROUP(<var>file</var> <var>file</var> &hellip;)</code></dt>
  119. <dd><a name="index-GROUP_0028files_0029"></a>
  120. <a name="index-grouping-input-files"></a>
  121. <p>The <code>GROUP</code> command is like <code>INPUT</code>, except that the named
  122. files should all be archives, and they are searched repeatedly until no
  123. new undefined references are created. See the description of &lsquo;<samp>-(</samp>&rsquo;
  124. in <a href="Options.html#Options">Command Line Options</a>.
  125. </p>
  126. </dd>
  127. <dt><code>AS_NEEDED(<var>file</var>, <var>file</var>, &hellip;)</code></dt>
  128. <dt><code>AS_NEEDED(<var>file</var> <var>file</var> &hellip;)</code></dt>
  129. <dd><a name="index-AS_005fNEEDED_0028files_0029"></a>
  130. <p>This construct can appear only inside of the <code>INPUT</code> or <code>GROUP</code>
  131. commands, among other filenames. The files listed will be handled
  132. as if they appear directly in the <code>INPUT</code> or <code>GROUP</code> commands,
  133. with the exception of ELF shared libraries, that will be added only
  134. when they are actually needed. This construct essentially enables
  135. <samp>--as-needed</samp> option for all the files listed inside of it
  136. and restores previous <samp>--as-needed</samp> resp. <samp>--no-as-needed</samp>
  137. setting afterwards.
  138. </p>
  139. </dd>
  140. <dt><code>OUTPUT(<var>filename</var>)</code></dt>
  141. <dd><a name="index-OUTPUT_0028filename_0029"></a>
  142. <a name="index-output-file-name-in-linker-script"></a>
  143. <p>The <code>OUTPUT</code> command names the output file. Using
  144. <code>OUTPUT(<var>filename</var>)</code> in the linker script is exactly like using
  145. &lsquo;<samp>-o <var>filename</var></samp>&rsquo; on the command line (see <a href="Options.html#Options">Command
  146. Line Options</a>). If both are used, the command line option takes
  147. precedence.
  148. </p>
  149. <p>You can use the <code>OUTPUT</code> command to define a default name for the
  150. output file other than the usual default of <samp>a.out</samp>.
  151. </p>
  152. </dd>
  153. <dt><code>SEARCH_DIR(<var>path</var>)</code></dt>
  154. <dd><a name="index-SEARCH_005fDIR_0028path_0029"></a>
  155. <a name="index-library-search-path-in-linker-script"></a>
  156. <a name="index-archive-search-path-in-linker-script"></a>
  157. <a name="index-search-path-in-linker-script"></a>
  158. <p>The <code>SEARCH_DIR</code> command adds <var>path</var> to the list of paths where
  159. <code>ld</code> looks for archive libraries. Using
  160. <code>SEARCH_DIR(<var>path</var>)</code> is exactly like using &lsquo;<samp>-L <var>path</var></samp>&rsquo;
  161. on the command line (see <a href="Options.html#Options">Command Line Options</a>). If both
  162. are used, then the linker will search both paths. Paths specified using
  163. the command line option are searched first.
  164. </p>
  165. </dd>
  166. <dt><code>STARTUP(<var>filename</var>)</code></dt>
  167. <dd><a name="index-STARTUP_0028filename_0029"></a>
  168. <a name="index-first-input-file"></a>
  169. <p>The <code>STARTUP</code> command is just like the <code>INPUT</code> command, except
  170. that <var>filename</var> will become the first input file to be linked, as
  171. though it were specified first on the command line. This may be useful
  172. when using a system in which the entry point is always the start of the
  173. first file.
  174. </p></dd>
  175. </dl>
  176. <hr>
  177. <div class="header">
  178. <p>
  179. 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="prev">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>
  180. </div>
  181. </body>
  182. </html>