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.3-2021.07 (arm-10.29))
5version 2.36.1.
6
7Copyright (C) 1991-2021 Free Software Foundation, Inc.
8
9Permission is granted to copy, distribute and/or modify this document
10under the terms of the GNU Free Documentation License, Version 1.3
11or any later version published by the Free Software Foundation;
12with no Invariant Sections, with no Front-Cover Texts, and with no
13Back-Cover Texts.  A copy of the license is included in the
14section entitled "GNU Free Documentation License". -->
15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
16<head>
17<title>LD: File Commands</title>
18
19<meta name="description" content="LD: File Commands">
20<meta name="keywords" content="LD: File Commands">
21<meta name="resource-type" content="document">
22<meta name="distribution" content="global">
23<meta name="Generator" content="makeinfo">
24<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
25<link href="index.html#Top" rel="start" title="Top">
26<link href="LD-Index.html#LD-Index" rel="index" title="LD Index">
27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
28<link href="Simple-Commands.html#Simple-Commands" rel="up" title="Simple Commands">
29<link href="Format-Commands.html#Format-Commands" rel="next" title="Format Commands">
30<link href="Entry-Point.html#Entry-Point" rel="previous" title="Entry Point">
31<style type="text/css">
32<!--
33a.summary-letter {text-decoration: none}
34blockquote.smallquotation {font-size: smaller}
35div.display {margin-left: 3.2em}
36div.example {margin-left: 3.2em}
37div.indentedblock {margin-left: 3.2em}
38div.lisp {margin-left: 3.2em}
39div.smalldisplay {margin-left: 3.2em}
40div.smallexample {margin-left: 3.2em}
41div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
42div.smalllisp {margin-left: 3.2em}
43kbd {font-style:oblique}
44pre.display {font-family: inherit}
45pre.format {font-family: inherit}
46pre.menu-comment {font-family: serif}
47pre.menu-preformatted {font-family: serif}
48pre.smalldisplay {font-family: inherit; font-size: smaller}
49pre.smallexample {font-size: smaller}
50pre.smallformat {font-family: inherit; font-size: smaller}
51pre.smalllisp {font-size: smaller}
52span.nocodebreak {white-space:nowrap}
53span.nolinebreak {white-space:nowrap}
54span.roman {font-family:serif; font-weight:normal}
55span.sansserif {font-family:sans-serif; font-weight:normal}
56ul.no-bullet {list-style: none}
57-->
58</style>
59
60
61</head>
62
63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
64<a name="File-Commands"></a>
65<div class="header">
66<p>
67Next: <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>
68</div>
69<hr>
70<a name="Commands-Dealing-with-Files"></a>
71<h4 class="subsection">3.4.2 Commands Dealing with Files</h4>
72<a name="index-linker-script-file-commands"></a>
73<p>Several linker script commands deal with files.
74</p>
75<dl compact="compact">
76<dt><code>INCLUDE <var>filename</var></code></dt>
77<dd><a name="index-INCLUDE-filename"></a>
78<a name="index-including-a-linker-script"></a>
79<p>Include the linker script <var>filename</var> at this point.  The file will
80be searched for in the current directory, and in any directory specified
81with the <samp>-L</samp> option.  You can nest calls to <code>INCLUDE</code> up to
8210 levels deep.
83</p>
84<p>You can place <code>INCLUDE</code> directives at the top level, in <code>MEMORY</code> or
85<code>SECTIONS</code> commands, or in output section descriptions.
86</p>
87</dd>
88<dt><code>INPUT(<var>file</var>, <var>file</var>, &hellip;)</code></dt>
89<dt><code>INPUT(<var>file</var> <var>file</var> &hellip;)</code></dt>
90<dd><a name="index-INPUT_0028files_0029"></a>
91<a name="index-input-files-in-linker-scripts"></a>
92<a name="index-input-object-files-in-linker-scripts"></a>
93<a name="index-linker-script-input-object-files"></a>
94<p>The <code>INPUT</code> command directs the linker to include the named files
95in the link, as though they were named on the command line.
96</p>
97<p>For example, if you always want to include <samp>subr.o</samp> any time you do
98a link, but you can&rsquo;t be bothered to put it on every link command line,
99then you can put &lsquo;<samp>INPUT (subr.o)</samp>&rsquo; in your linker script.
100</p>
101<p>In fact, if you like, you can list all of your input files in the linker
102script, and then invoke the linker with nothing but a &lsquo;<samp>-T</samp>&rsquo; option.
103</p>
104<p>In case a <em>sysroot prefix</em> is configured, and the filename starts
105with the &lsquo;<samp>/</samp>&rsquo; character, and the script being processed was
106located inside the <em>sysroot prefix</em>, the filename will be looked
107for in the <em>sysroot prefix</em>.  The <em>sysroot prefix</em> can also be forced by specifying
108<code>=</code> as the first character in the filename path, or prefixing the
109filename path with <code>$SYSROOT</code>. See also the description of
110&lsquo;<samp>-L</samp>&rsquo; in <a href="Options.html#Options">Command-line Options</a>.
111</p>
112<p>If a <em>sysroot prefix</em> is not used then the linker will try to open
113the file in the directory containing the linker script.  If it is not
114found the linker will then search the current directory.  If it is still
115not found the linker will search through the archive library search
116path.
117</p>
118<p>If you use &lsquo;<samp>INPUT (-l<var>file</var>)</samp>&rsquo;, <code>ld</code> will transform the
119name to <code>lib<var>file</var>.a</code>, as with the command-line argument
120&lsquo;<samp>-l</samp>&rsquo;.
121</p>
122<p>When you use the <code>INPUT</code> command in an implicit linker script, the
123files will be included in the link at the point at which the linker
124script file is included.  This can affect archive searching.
125</p>
126</dd>
127<dt><code>GROUP(<var>file</var>, <var>file</var>, &hellip;)</code></dt>
128<dt><code>GROUP(<var>file</var> <var>file</var> &hellip;)</code></dt>
129<dd><a name="index-GROUP_0028files_0029"></a>
130<a name="index-grouping-input-files"></a>
131<p>The <code>GROUP</code> command is like <code>INPUT</code>, except that the named
132files should all be archives, and they are searched repeatedly until no
133new undefined references are created.  See the description of &lsquo;<samp>-(</samp>&rsquo;
134in <a href="Options.html#Options">Command-line Options</a>.
135</p>
136</dd>
137<dt><code>AS_NEEDED(<var>file</var>, <var>file</var>, &hellip;)</code></dt>
138<dt><code>AS_NEEDED(<var>file</var> <var>file</var> &hellip;)</code></dt>
139<dd><a name="index-AS_005fNEEDED_0028files_0029"></a>
140<p>This construct can appear only inside of the <code>INPUT</code> or <code>GROUP</code>
141commands, among other filenames.  The files listed will be handled
142as if they appear directly in the <code>INPUT</code> or <code>GROUP</code> commands,
143with the exception of ELF shared libraries, that will be added only
144when they are actually needed.  This construct essentially enables
145<samp>--as-needed</samp> option for all the files listed inside of it
146and restores previous <samp>--as-needed</samp> resp. <samp>--no-as-needed</samp>
147setting afterwards.
148</p>
149</dd>
150<dt><code>OUTPUT(<var>filename</var>)</code></dt>
151<dd><a name="index-OUTPUT_0028filename_0029"></a>
152<a name="index-output-file-name-in-linker-script"></a>
153<p>The <code>OUTPUT</code> command names the output file.  Using
154<code>OUTPUT(<var>filename</var>)</code> in the linker script is exactly like using
155&lsquo;<samp>-o <var>filename</var></samp>&rsquo; on the command line (see <a href="Options.html#Options">Command
156Line Options</a>).  If both are used, the command-line option takes
157precedence.
158</p>
159<p>You can use the <code>OUTPUT</code> command to define a default name for the
160output file other than the usual default of <samp>a.out</samp>.
161</p>
162</dd>
163<dt><code>SEARCH_DIR(<var>path</var>)</code></dt>
164<dd><a name="index-SEARCH_005fDIR_0028path_0029"></a>
165<a name="index-library-search-path-in-linker-script"></a>
166<a name="index-archive-search-path-in-linker-script"></a>
167<a name="index-search-path-in-linker-script"></a>
168<p>The <code>SEARCH_DIR</code> command adds <var>path</var> to the list of paths where
169<code>ld</code> looks for archive libraries.  Using
170<code>SEARCH_DIR(<var>path</var>)</code> is exactly like using &lsquo;<samp>-L <var>path</var></samp>&rsquo;
171on the command line (see <a href="Options.html#Options">Command-line Options</a>).  If both
172are used, then the linker will search both paths.  Paths specified using
173the command-line option are searched first.
174</p>
175</dd>
176<dt><code>STARTUP(<var>filename</var>)</code></dt>
177<dd><a name="index-STARTUP_0028filename_0029"></a>
178<a name="index-first-input-file"></a>
179<p>The <code>STARTUP</code> command is just like the <code>INPUT</code> command, except
180that <var>filename</var> will become the first input file to be linked, as
181though it were specified first on the command line.  This may be useful
182when using a system in which the entry point is always the start of the
183first file.
184</p></dd>
185</dl>
186
187<hr>
188<div class="header">
189<p>
190Next: <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>
191</div>
192
193
194
195</body>
196</html>
197