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