Commit | Line | Data |
---|---|---|
f22eee08 | 1 | \input texinfo |
c8072296 | 2 | @setfilename ld.info |
b4d4e8e3 | 3 | @syncodeindex ky cp |
7f9ae73e | 4 | @include configdoc.texi |
8de26d62 | 5 | @c (configdoc.texi is generated by the Makefile) |
ec40bbb8 DM |
6 | |
7 | @c @smallbook | |
1c48127e RP |
8 | |
9 | @ifinfo | |
10 | @format | |
11 | START-INFO-DIR-ENTRY | |
f9d3d71a | 12 | * Ld: (ld). The GNU linker. |
1c48127e RP |
13 | END-INFO-DIR-ENTRY |
14 | @end format | |
15 | @end ifinfo | |
16 | ||
b4d4e8e3 | 17 | @ifinfo |
c653b370 | 18 | This file documents the @sc{gnu} linker LD. |
b4d4e8e3 | 19 | |
431e1e85 | 20 | Copyright (C) 1991, 92, 93, 94, 95, 1996 Free Software Foundation, Inc. |
b4d4e8e3 RP |
21 | |
22 | Permission is granted to make and distribute verbatim copies of | |
23 | this manual provided the copyright notice and this permission notice | |
24 | are preserved on all copies. | |
25 | ||
d76ae847 RP |
26 | Permission is granted to copy and distribute modified versions of this |
27 | manual under the conditions for verbatim copying, provided also that | |
28 | the entire resulting derived work is distributed under the terms of a | |
29 | permission notice identical to this one. | |
30 | ||
31 | Permission is granted to copy and distribute translations of this manual | |
32 | into another language, under the above conditions for modified versions. | |
33 | ||
b4d4e8e3 RP |
34 | @ignore |
35 | Permission is granted to process this file through Tex and print the | |
36 | results, provided the printed document carries copying permission | |
37 | notice identical to this one except for the removal of this paragraph | |
38 | (this paragraph not being relevant to the printed manual). | |
39 | ||
40 | @end ignore | |
b4d4e8e3 | 41 | @end ifinfo |
2c5c0674 RP |
42 | @iftex |
43 | @finalout | |
b4d4e8e3 | 44 | @setchapternewpage odd |
246504a5 | 45 | @settitle Using LD, the GNU linker |
f22eee08 | 46 | @titlepage |
246504a5 | 47 | @title Using ld |
c8072296 | 48 | @subtitle The GNU linker |
f22eee08 | 49 | @sp 1 |
cb70c872 | 50 | @subtitle @code{ld} version 2 |
d4e5e3c3 | 51 | @subtitle January 1994 |
c653b370 | 52 | @author Steve Chamberlain |
c8072296 | 53 | @author Cygnus Support |
b4d4e8e3 RP |
54 | @page |
55 | ||
56 | @tex | |
b4d4e8e3 RP |
57 | {\parskip=0pt |
58 | \hfill Cygnus Support\par | |
c653b370 | 59 | \hfill steve\@cygnus.com, doc\@cygnus.com\par |
ec40bbb8 | 60 | \hfill {\it Using LD, the GNU linker}\par |
d4e5e3c3 | 61 | \hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com)\par |
b4d4e8e3 RP |
62 | } |
63 | \global\parindent=0pt % Steve likes it this way. | |
64 | @end tex | |
65 | ||
f22eee08 | 66 | @vskip 0pt plus 1filll |
431e1e85 | 67 | Copyright @copyright{} 1991, 92, 93, 94, 95, 1996 Free Software Foundation, Inc. |
f22eee08 RP |
68 | |
69 | Permission is granted to make and distribute verbatim copies of | |
70 | this manual provided the copyright notice and this permission notice | |
71 | are preserved on all copies. | |
72 | ||
73 | Permission is granted to copy and distribute modified versions of this | |
74 | manual under the conditions for verbatim copying, provided also that | |
75 | the entire resulting derived work is distributed under the terms of a | |
76 | permission notice identical to this one. | |
77 | ||
78 | Permission is granted to copy and distribute translations of this manual | |
79 | into another language, under the above conditions for modified versions. | |
f22eee08 | 80 | @end titlepage |
2c5c0674 | 81 | @end iftex |
b4d4e8e3 | 82 | @c FIXME: Talk about importance of *order* of args, cmds to linker! |
f22eee08 | 83 | |
f22eee08 | 84 | @ifinfo |
ec40bbb8 DM |
85 | @node Top |
86 | @top Using ld | |
c653b370 | 87 | This file documents the @sc{gnu} linker ld. |
f22eee08 | 88 | |
2c5c0674 | 89 | @menu |
2d59b2c3 RP |
90 | * Overview:: Overview |
91 | * Invocation:: Invocation | |
92 | * Commands:: Command Language | |
ec40bbb8 | 93 | @ifset GENERIC |
2d59b2c3 | 94 | * Machine Dependent:: Machine Dependent Features |
ec40bbb8 DM |
95 | @end ifset |
96 | @ifclear GENERIC | |
97 | @ifset H8300 | |
98 | * H8/300:: ld and the H8/300 | |
99 | @end ifset | |
f9d3d71a ILT |
100 | @ifset Hitachi |
101 | * Hitachi:: ld and other Hitachi micros | |
102 | @end ifset | |
ec40bbb8 DM |
103 | @ifset I960 |
104 | * i960:: ld and the Intel 960 family | |
105 | @end ifset | |
106 | @end ifclear | |
107 | @ifclear SingleFormat | |
2d59b2c3 | 108 | * BFD:: BFD |
ec40bbb8 DM |
109 | @end ifclear |
110 | @c Following blank line required for remaining bug in makeinfo conds/menus | |
111 | ||
9fde46a4 | 112 | * Reporting Bugs:: Reporting Bugs |
2d59b2c3 RP |
113 | * MRI:: MRI Compatible Script Files |
114 | * Index:: Index | |
2c5c0674 | 115 | @end menu |
ec40bbb8 | 116 | @end ifinfo |
2c5c0674 | 117 | |
ec40bbb8 | 118 | @node Overview |
f22eee08 RP |
119 | @chapter Overview |
120 | ||
c653b370 | 121 | @cindex @sc{gnu} linker |
2c5c0674 | 122 | @cindex what is this? |
246504a5 | 123 | @code{ld} combines a number of object and archive files, relocates |
ec40bbb8 DM |
124 | their data and ties up symbol references. Usually the last step in |
125 | compiling a program is to run @code{ld}. | |
f22eee08 | 126 | |
246504a5 | 127 | @code{ld} accepts Linker Command Language files written in |
2c5c0674 | 128 | a superset of AT&T's Link Editor Command Language syntax, |
b4d4e8e3 | 129 | to provide explicit and total control over the linking process. |
f22eee08 | 130 | |
ec40bbb8 | 131 | @ifclear SingleFormat |
246504a5 RP |
132 | This version of @code{ld} uses the general purpose BFD libraries |
133 | to operate on object files. This allows @code{ld} to read, combine, and | |
b4d4e8e3 RP |
134 | write object files in many different formats---for example, COFF or |
135 | @code{a.out}. Different formats may be linked together to produce any | |
d4e5e3c3 | 136 | available kind of object file. @xref{BFD}, for more information. |
ec40bbb8 | 137 | @end ifclear |
f22eee08 | 138 | |
c653b370 | 139 | Aside from its flexibility, the @sc{gnu} linker is more helpful than other |
2c5c0674 RP |
140 | linkers in providing diagnostic information. Many linkers abandon |
141 | execution immediately upon encountering an error; whenever possible, | |
246504a5 | 142 | @code{ld} continues executing, allowing you to identify other errors |
2c5c0674 RP |
143 | (or, in some cases, to get an output file in spite of the error). |
144 | ||
ec40bbb8 | 145 | @node Invocation |
2c5c0674 RP |
146 | @chapter Invocation |
147 | ||
c653b370 | 148 | The @sc{gnu} linker @code{ld} is meant to cover a broad range of situations, |
2c5c0674 | 149 | and to be as compatible as possible with other linkers. As a result, |
ec40bbb8 | 150 | you have many choices to control its behavior. |
2c5c0674 | 151 | |
ec40bbb8 | 152 | @ifset UsesEnvVars |
2c5c0674 | 153 | @menu |
2d59b2c3 RP |
154 | * Options:: Command Line Options |
155 | * Environment:: Environment Variables | |
2c5c0674 | 156 | @end menu |
f22eee08 | 157 | |
ec40bbb8 | 158 | @node Options |
2c5c0674 | 159 | @section Command Line Options |
ec40bbb8 | 160 | @end ifset |
2c5c0674 RP |
161 | |
162 | @cindex command line | |
163 | @cindex options | |
67afbcea DE |
164 | The linker supports a plethora of command-line options, but in actual |
165 | practice few of them are used in any particular context. | |
2c5c0674 | 166 | @cindex standard Unix system |
246504a5 | 167 | For instance, a frequent use of @code{ld} is to link standard Unix |
b4d4e8e3 RP |
168 | object files on a standard, supported Unix system. On such a system, to |
169 | link a file @code{hello.o}: | |
ec40bbb8 | 170 | |
c653b370 | 171 | @smallexample |
ec40bbb8 | 172 | ld -o @var{output} /lib/crt0.o hello.o -lc |
c653b370 | 173 | @end smallexample |
ec40bbb8 | 174 | |
d76ae847 | 175 | This tells @code{ld} to produce a file called @var{output} as the |
b4d4e8e3 | 176 | result of linking the file @code{/lib/crt0.o} with @code{hello.o} and |
ec40bbb8 DM |
177 | the library @code{libc.a}, which will come from the standard search |
178 | directories. (See the discussion of the @samp{-l} option below.) | |
f22eee08 | 179 | |
246504a5 | 180 | The command-line options to @code{ld} may be specified in any order, and |
67afbcea DE |
181 | may be repeated at will. Repeating most options with a different |
182 | argument will either have no further effect, or override prior | |
ec40bbb8 | 183 | occurrences (those further to the left on the command line) of that |
67afbcea DE |
184 | option. Options which may be meaningfully specified more than once are |
185 | noted in the descriptions below. | |
f22eee08 | 186 | |
2c5c0674 | 187 | @cindex object files |
67afbcea DE |
188 | Non-option arguments are objects files which are to be linked together. |
189 | They may follow, precede, or be mixed in with command-line options, | |
190 | except that an object file argument may not be placed between an option | |
191 | and its argument. | |
f22eee08 | 192 | |
7f9ae73e RP |
193 | Usually the linker is invoked with at least one object file, but you can |
194 | specify other forms of binary input files using @samp{-l}, @samp{-R}, | |
195 | and the script command language. If @emph{no} binary input files at all | |
196 | are specified, the linker does not produce any output, and issues the | |
197 | message @samp{No input files}. | |
2c5c0674 | 198 | |
0b3499f6 ILT |
199 | If the linker can not recognize the format of an object file, it will |
200 | assume that it is a linker script. A script specified in this way | |
201 | augments the main linker script used for the link (either the default | |
202 | linker script or the one specified by using @samp{-T}). This feature | |
203 | permits the linker to link against a file which appears to be an object | |
204 | or an archive, but actually merely defines some symbol values, or uses | |
205 | @code{INPUT} or @code{GROUP} to load other objects. @xref{Commands}. | |
206 | ||
d4e5e3c3 DM |
207 | For options whose names are a single letter, |
208 | option arguments must either follow the option letter without intervening | |
f22eee08 RP |
209 | whitespace, or be given as separate arguments immediately following the |
210 | option that requires them. | |
211 | ||
d4e5e3c3 DM |
212 | For options whose names are multiple letters, either one dash or two can |
213 | precede the option name; for example, @samp{--oformat} and | |
9fde46a4 | 214 | @samp{--oformat} are equivalent. Arguments to multiple-letter options |
d4e5e3c3 DM |
215 | must either be separated from the option name by an equals sign, or be |
216 | given as separate arguments immediately following the option that | |
217 | requires them. For example, @samp{--oformat srec} and | |
218 | @samp{--oformat=srec} are equivalent. Unique abbreviations of the names | |
219 | of multiple-letter options are accepted. | |
220 | ||
f22eee08 | 221 | @table @code |
67afbcea DE |
222 | @kindex -a@var{keyword} |
223 | @item -a@var{keyword} | |
224 | This option is supported for HP/UX compatibility. The @var{keyword} | |
225 | argument must be one of the strings @samp{archive}, @samp{shared}, or | |
226 | @samp{default}. @samp{-aarchive} is functionally equivalent to | |
227 | @samp{-Bstatic}, and the other two keywords are functionally equivalent | |
228 | to @samp{-Bdynamic}. This option may be used any number of times. | |
229 | ||
ec40bbb8 | 230 | @ifset I960 |
2c5c0674 RP |
231 | @cindex architectures |
232 | @kindex -A@var{arch} | |
b4d4e8e3 | 233 | @item -A@var{architecture} |
67afbcea DE |
234 | @kindex --architecture=@var{arch} |
235 | @itemx --architecture=@var{architecture} | |
246504a5 RP |
236 | In the current release of @code{ld}, this option is useful only for the |
237 | Intel 960 family of architectures. In that @code{ld} configuration, the | |
1c48127e RP |
238 | @var{architecture} argument identifies the particular architecture in |
239 | the 960 family, enabling some safeguards and modifying the | |
d76ae847 RP |
240 | archive-library search path. @xref{i960,,@code{ld} and the Intel 960 |
241 | family}, for details. | |
b4d4e8e3 | 242 | |
246504a5 | 243 | Future releases of @code{ld} may support similar functionality for |
b4d4e8e3 | 244 | other architecture families. |
ec40bbb8 | 245 | @end ifset |
b4d4e8e3 | 246 | |
ec40bbb8 | 247 | @ifclear SingleFormat |
2c5c0674 RP |
248 | @cindex binary input format |
249 | @kindex -b @var{format} | |
67afbcea | 250 | @kindex --format=@var{format} |
2c5c0674 | 251 | @cindex input format |
2c5c0674 | 252 | @cindex input format |
c653b370 | 253 | @item -b @var{input-format} |
67afbcea | 254 | @itemx --format=@var{input-format} |
1fb57a5d RP |
255 | @code{ld} may be configured to support more than one kind of object |
256 | file. If your @code{ld} is configured this way, you can use the | |
257 | @samp{-b} option to specify the binary format for input object files | |
258 | that follow this option on the command line. Even when @code{ld} is | |
259 | configured to support alternative object formats, you don't usually need | |
260 | to specify this, as @code{ld} should be configured to expect as a | |
261 | default input format the most usual format on each machine. | |
262 | @var{input-format} is a text string, the name of a particular format | |
263 | supported by the BFD libraries. (You can list the available binary | |
67afbcea | 264 | formats with @samp{objdump -i}.) |
1fb57a5d | 265 | @xref{BFD}. |
2c5c0674 RP |
266 | |
267 | You may want to use this option if you are linking files with an unusual | |
ec40bbb8 | 268 | binary format. You can also use @samp{-b} to switch formats explicitly (when |
2c5c0674 | 269 | linking object files of different formats), by including |
ec40bbb8 | 270 | @samp{-b @var{input-format}} before each group of object files in a |
2c5c0674 RP |
271 | particular format. |
272 | ||
273 | The default format is taken from the environment variable | |
ec40bbb8 DM |
274 | @code{GNUTARGET}. |
275 | @ifset UsesEnvVars | |
276 | @xref{Environment}. | |
277 | @end ifset | |
278 | You can also define the input | |
867a1b8a | 279 | format from a script, using the command @code{TARGET}; see @ref{Option |
d76ae847 | 280 | Commands}. |
ec40bbb8 | 281 | @end ifclear |
2c5c0674 | 282 | |
2d59b2c3 | 283 | @kindex -c @var{MRI-cmdfile} |
67afbcea | 284 | @kindex --mri-script=@var{MRI-cmdfile} |
2d59b2c3 RP |
285 | @cindex compatibility, MRI |
286 | @item -c @var{MRI-commandfile} | |
67afbcea | 287 | @itemx --mri-script=@var{MRI-commandfile} |
2d59b2c3 RP |
288 | For compatibility with linkers produced by MRI, @code{ld} accepts script |
289 | files written in an alternate, restricted command language, described in | |
d76ae847 | 290 | @ref{MRI,,MRI Compatible Script Files}. Introduce MRI script files with |
ec40bbb8 | 291 | the option @samp{-c}; use the @samp{-T} option to run linker |
d76ae847 | 292 | scripts written in the general-purpose @code{ld} scripting language. |
8ddef552 DM |
293 | If @var{MRI-cmdfile} does not exist, @code{ld} looks for it in the directories |
294 | specified by any @samp{-L} options. | |
b4d4e8e3 | 295 | |
2c5c0674 RP |
296 | @cindex common allocation |
297 | @kindex -d | |
2c5c0674 | 298 | @kindex -dc |
2c5c0674 | 299 | @kindex -dp |
c653b370 ILT |
300 | @item -d |
301 | @itemx -dc | |
b4d4e8e3 RP |
302 | @itemx -dp |
303 | These three options are equivalent; multiple forms are supported for | |
ec40bbb8 | 304 | compatibility with other linkers. They |
2c5c0674 | 305 | assign space to common symbols even if a relocatable output file is |
ec40bbb8 | 306 | specified (with @samp{-r}). The script command |
867a1b8a | 307 | @code{FORCE_COMMON_ALLOCATION} has the same effect. @xref{Option |
d76ae847 | 308 | Commands}. |
b4d4e8e3 | 309 | |
2c5c0674 RP |
310 | @cindex entry point, from command line |
311 | @kindex -e @var{entry} | |
67afbcea | 312 | @kindex --entry=@var{entry} |
f22eee08 | 313 | @item -e @var{entry} |
67afbcea | 314 | @itemx --entry=@var{entry} |
f22eee08 | 315 | Use @var{entry} as the explicit symbol for beginning execution of your |
b4d4e8e3 RP |
316 | program, rather than the default entry point. @xref{Entry Point}, for a |
317 | discussion of defaults and other ways of specifying the | |
318 | entry point. | |
f22eee08 | 319 | |
c653b370 | 320 | @cindex dynamic symbol table |
7ec9d825 | 321 | @kindex -E |
9fde46a4 | 322 | @kindex --export-dynamic |
7ec9d825 | 323 | @item -E |
9fde46a4 | 324 | @itemx --export-dynamic |
67afbcea DE |
325 | When creating a dynamically linked executable, add all symbols to the |
326 | dynamic symbol table. Normally, the dynamic symbol table contains only | |
327 | symbols which are used by a dynamic object. This option is needed for | |
328 | some uses of @code{dlopen}. | |
c653b370 | 329 | |
de220cbd ILT |
330 | @kindex -f |
331 | @kindex --auxiliary | |
332 | @item -f | |
333 | @itemx --auxiliary @var{name} | |
334 | When creating an ELF shared object, set the internal DT_AUXILIARY field | |
335 | to the specified name. This tells the dynamic linker that the symbol | |
336 | table of the shared object should be used as an auxiliary filter on the | |
337 | symbol table of the shared object @var{name}. | |
338 | ||
2c5c0674 | 339 | @kindex -F |
de220cbd ILT |
340 | @kindex --filter |
341 | @item -F @var{name} | |
342 | @itemx --filter @var{name} | |
343 | When creating an ELF shared object, set the internal DT_FILTER field to | |
344 | the specified name. This tells the dynamic linker that the symbol table | |
345 | of the shared object should be used as a filter on the symbol table of | |
346 | the shared object @var{name}. | |
347 | ||
348 | Some older linkers used the @code{-F} option throughout a compilation | |
ec40bbb8 | 349 | toolchain for specifying object-file format for both input and output |
de220cbd ILT |
350 | object files. The @sc{gnu} linker uses other mechanisms for this |
351 | purpose: the @code{-b}, @code{--format}, @code{--oformat} options, the | |
352 | @code{TARGET} command in linker scripts, and the @code{GNUTARGET} | |
353 | environment variable. The @sc{gnu} linker will ignore the @code{-F} | |
354 | option when not creating an ELF shared object. | |
2c5c0674 | 355 | |
a1d393cf ILT |
356 | @kindex --force-exe-suffix |
357 | @item --force-exe-suffix | |
358 | Make sure that an output file has a .exe suffix. | |
359 | ||
360 | If a successfully built fully linked output file does not have a | |
361 | @code{.exe} or @code{.dll} suffix, this option forces the linker to copy | |
362 | the output file to one of the same name with a @code{.exe} suffix. This | |
363 | option is useful when using unmodified Unix makefiles on a Microsoft | |
364 | Windows host, since some versions of Windows won't run an image unless | |
365 | it ends in a @code{.exe} suffix. | |
366 | ||
2c5c0674 | 367 | @kindex -g |
b4d4e8e3 | 368 | @item -g |
ec40bbb8 | 369 | Ignored. Provided for compatibility with other tools. |
b4d4e8e3 | 370 | |
8ddef552 | 371 | @kindex -G |
67afbcea | 372 | @kindex --gpsize |
8ddef552 DM |
373 | @cindex object size |
374 | @item -G@var{value} | |
67afbcea | 375 | @itemx --gpsize=@var{value} |
8ddef552 | 376 | Set the maximum size of objects to be optimized using the GP register to |
67afbcea DE |
377 | @var{size}. This is only meaningful for object file formats such as |
378 | MIPS ECOFF which supports putting large and small objects into different | |
379 | sections. This is ignored for other object file formats. | |
8ddef552 | 380 | |
67afbcea DE |
381 | @cindex runtime library name |
382 | @kindex -h@var{name} | |
383 | @kindex -soname=@var{name} | |
384 | @item -h@var{name} | |
385 | @itemx -soname=@var{name} | |
386 | When creating an ELF shared object, set the internal DT_SONAME field to | |
387 | the specified name. When an executable is linked with a shared object | |
388 | which has a DT_SONAME field, then when the executable is run the dynamic | |
389 | linker will attempt to load the shared object specified by the DT_SONAME | |
390 | field rather than the using the file name given to the linker. | |
de87cdb4 | 391 | |
2c5c0674 RP |
392 | @kindex -i |
393 | @cindex incremental link | |
f22eee08 | 394 | @item -i |
ec40bbb8 | 395 | Perform an incremental link (same as option @samp{-r}). |
f22eee08 | 396 | |
2c5c0674 | 397 | @cindex archive files, from cmd line |
de87cdb4 | 398 | @kindex -l@var{archive} |
67afbcea DE |
399 | @kindex --library=@var{archive} |
400 | @item -l@var{archive} | |
401 | @itemx --library=@var{archive} | |
402 | Add archive file @var{archive} to the list of files to link. This | |
f22eee08 | 403 | option may be used any number of times. @code{ld} will search its |
67afbcea | 404 | path-list for occurrences of @code{lib@var{archive}.a} for every |
4164f2d5 ILT |
405 | @var{archive} specified. |
406 | ||
407 | On systems which support shared libraries, @code{ld} may also search for | |
408 | libraries with extensions other than @code{.a}. Specifically, on ELF | |
409 | and SunOS systems, @code{ld} will search a directory for a library with | |
410 | an extension of @code{.so} before searching for one with an extension of | |
411 | @code{.a}. By convention, a @code{.so} extension indicates a shared | |
412 | library. | |
f22eee08 | 413 | |
b61364cc ILT |
414 | The linker will search an archive only once, at the location where it is |
415 | specified on the command line. If the archive defines a symbol which | |
416 | was undefined in some object which appeared before the archive on the | |
417 | command line, the linker will include the appropriate file(s) from the | |
418 | archive. However, an undefined symbol in an object appearing later on | |
419 | the command line will not cause the linker to search the archive again. | |
420 | ||
421 | See the @code{-(} option for a way to force the linker to search | |
422 | archives multiple times. | |
423 | ||
424 | You may list the same archive multiple times on the command line. | |
425 | ||
426 | @ifset GENERIC | |
427 | This type of archive searching is standard for Unix linkers. However, | |
428 | if you are using @code{ld} on AIX, note that it is different from the | |
429 | behaviour of the AIX linker. | |
430 | @end ifset | |
431 | ||
2c5c0674 RP |
432 | @cindex search directory, from cmd line |
433 | @kindex -L@var{dir} | |
67afbcea | 434 | @kindex --library-path=@var{dir} |
b4d4e8e3 | 435 | @item -L@var{searchdir} |
67afbcea | 436 | @itemx --library-path=@var{searchdir} |
ec40bbb8 | 437 | Add path @var{searchdir} to the list of paths that @code{ld} will search |
8ddef552 | 438 | for archive libraries and @code{ld} control scripts. You may use this |
0b0642d6 ILT |
439 | option any number of times. The directories are searched in the order |
440 | in which they are specified on the command line. Directories specified | |
441 | on the command line are searched before the default directories. All | |
442 | @code{-L} options apply to all @code{-l} options, regardless of the | |
443 | order in which the options appear. | |
f22eee08 | 444 | |
ec40bbb8 | 445 | @ifset UsesEnvVars |
2c5c0674 | 446 | The default set of paths searched (without being specified with |
ec40bbb8 DM |
447 | @samp{-L}) depends on which emulation mode @code{ld} is using, and in |
448 | some cases also on how it was configured. @xref{Environment}. | |
449 | @end ifset | |
450 | ||
451 | The paths can also be specified in a link script with the | |
0b0642d6 ILT |
452 | @code{SEARCH_DIR} command. Directories specified this way are searched |
453 | at the point in which the linker script appears in the command line. | |
f22eee08 | 454 | |
8ddef552 DM |
455 | @cindex emulation |
456 | @kindex -m @var{emulation} | |
457 | @item -m@var{emulation} | |
8ddef552 | 458 | Emulate the @var{emulation} linker. You can list the available |
01bc8f35 ILT |
459 | emulations with the @samp{--verbose} or @samp{-V} options. The default |
460 | depends on how your @code{ld} was configured. | |
8ddef552 | 461 | |
67afbcea DE |
462 | @cindex link map |
463 | @kindex -M | |
464 | @kindex --print-map | |
465 | @item -M | |
466 | @itemx --print-map | |
467 | Print (to the standard output) a link map---diagnostic information about | |
468 | where symbols are mapped by @code{ld}, and information on global common | |
469 | storage allocation. | |
470 | ||
471 | @kindex -n | |
472 | @cindex read-only text | |
473 | @cindex NMAGIC | |
474 | @kindex --nmagic | |
475 | @item -n | |
476 | @itemx --nmagic | |
477 | Set the text segment to be read only, and mark the output as | |
478 | @code{NMAGIC} if possible. | |
479 | ||
2c5c0674 | 480 | @kindex -N |
67afbcea | 481 | @kindex --omagic |
2c5c0674 | 482 | @cindex read/write from cmd line |
67afbcea | 483 | @cindex OMAGIC |
f22eee08 | 484 | @item -N |
67afbcea | 485 | @itemx --omagic |
ec40bbb8 DM |
486 | Set the text and data sections to be readable and writable. Also, do |
487 | not page-align the data segment. If the output format supports Unix | |
488 | style magic numbers, mark the output as @code{OMAGIC}. | |
f22eee08 | 489 | |
67afbcea DE |
490 | @kindex -o @var{output} |
491 | @kindex --output=@var{output} | |
492 | @cindex naming the output file | |
493 | @item -o @var{output} | |
494 | @itemx --output=@var{output} | |
495 | Use @var{output} as the name for the program produced by @code{ld}; if this | |
496 | option is not specified, the name @file{a.out} is used by default. The | |
497 | script command @code{OUTPUT} can also specify the output file name. | |
f22eee08 | 498 | |
67afbcea DE |
499 | @cindex partial link |
500 | @cindex relocatable output | |
501 | @kindex -r | |
502 | @kindex --relocateable | |
503 | @item -r | |
504 | @itemx --relocateable | |
505 | Generate relocatable output---i.e., generate an output file that can in | |
506 | turn serve as input to @code{ld}. This is often called @dfn{partial | |
507 | linking}. As a side effect, in environments that support standard Unix | |
508 | magic numbers, this option also sets the output file's magic number to | |
509 | @code{OMAGIC}. | |
510 | @c ; see @code{-N}. | |
511 | If this option is not specified, an absolute file is produced. When | |
512 | linking C++ programs, this option @emph{will not} resolve references to | |
513 | constructors; to do that, use @samp{-Ur}. | |
514 | ||
515 | This option does the same thing as @samp{-i}. | |
516 | ||
517 | @kindex -R @var{file} | |
518 | @kindex --just-symbols=@var{file} | |
519 | @cindex symbol-only input | |
520 | @item -R @var{filename} | |
521 | @itemx --just-symbols=@var{filename} | |
522 | Read symbol names and their addresses from @var{filename}, but do not | |
523 | relocate it or include it in the output. This allows your output file | |
524 | to refer symbolically to absolute locations of memory defined in other | |
525 | programs. You may use this option more than once. | |
526 | ||
527 | For compatibility with other ELF linkers, if the @code{-R} option is | |
528 | followed by a directory name, rather than a file name, it is treated as | |
529 | the @code{-rpath} option. | |
530 | ||
531 | @kindex -s | |
532 | @kindex --strip-all | |
533 | @cindex strip all symbols | |
534 | @item -s | |
535 | @itemx --strip-all | |
536 | Omit all symbol information from the output file. | |
537 | ||
538 | @kindex -S | |
539 | @kindex --strip-debug | |
540 | @cindex strip debugger symbols | |
541 | @item -S | |
542 | @itemx --strip-debug | |
543 | Omit debugger symbol information (but not all symbols) from the output file. | |
544 | ||
545 | @kindex -t | |
546 | @kindex --trace | |
547 | @cindex input files, displaying | |
548 | @item -t | |
549 | @itemx --trace | |
550 | Print the names of the input files as @code{ld} processes them. | |
551 | ||
552 | @kindex -T @var{script} | |
553 | @kindex --script=@var{script} | |
554 | @cindex script files | |
555 | @item -T @var{commandfile} | |
556 | @itemx --script=@var{commandfile} | |
557 | Read link commands from the file @var{commandfile}. These commands | |
558 | replace @code{ld}'s default link script (rather than adding | |
559 | to it), so @var{commandfile} must specify everything necessary to describe | |
560 | the target format. @xref{Commands}. If @var{commandfile} does not | |
561 | exist, @code{ld} looks for it in the directories specified by any | |
562 | preceding @samp{-L} options. Multiple @samp{-T} options accumulate. | |
563 | ||
564 | @kindex -u @var{symbol} | |
565 | @kindex --undefined=@var{symbol} | |
566 | @cindex undefined symbol | |
567 | @item -u @var{symbol} | |
568 | @itemx --undefined=@var{symbol} | |
569 | Force @var{symbol} to be entered in the output file as an undefined symbol. | |
570 | Doing this may, for example, trigger linking of additional modules from | |
571 | standard libraries. @samp{-u} may be repeated with different option | |
572 | arguments to enter additional undefined symbols. | |
573 | @c Nice idea, but no such command: This option is equivalent | |
574 | @c to the @code{EXTERN} linker command. | |
575 | ||
576 | @kindex -v | |
577 | @kindex -V | |
578 | @kindex --version | |
579 | @cindex version | |
580 | @item -v | |
581 | @itemx --version | |
582 | @itemx -V | |
583 | Display the version number for @code{ld}. The @code{-V} option also | |
584 | lists the supported emulations. | |
585 | ||
586 | @kindex -x | |
587 | @kindex --discard-all | |
588 | @cindex deleting local symbols | |
589 | @item -x | |
590 | @itemx --discard-all | |
591 | Delete all local symbols. | |
592 | ||
593 | @kindex -X | |
594 | @kindex --discard-locals | |
595 | @cindex local symbols, deleting | |
596 | @cindex L, deleting symbols beginning | |
597 | @item -X | |
598 | @itemx --discard-locals | |
599 | Delete all temporary local symbols. For most targets, this is all local | |
600 | symbols whose names begin with @samp{L}. | |
601 | ||
602 | @kindex -y @var{symbol} | |
603 | @kindex --trace-symbol=@var{symbol} | |
604 | @cindex symbol tracing | |
605 | @item -y @var{symbol} | |
606 | @itemx --trace-symbol=@var{symbol} | |
607 | Print the name of each linked file in which @var{symbol} appears. This | |
608 | option may be given any number of times. On many systems it is necessary | |
609 | to prepend an underscore. | |
610 | ||
611 | This option is useful when you have an undefined symbol in your link but | |
612 | don't know where the reference is coming from. | |
613 | ||
614 | @kindex -Y @var{path} | |
615 | @item -Y @var{path} | |
616 | Add @var{path} to the default library search path. This option exists | |
617 | for Solaris compatibility. | |
618 | ||
619 | @kindex -z @var{keyword} | |
620 | @item -z @var{keyword} | |
621 | This option is ignored for Solaris compatibility. | |
622 | ||
623 | @kindex -( | |
624 | @cindex groups of archives | |
625 | @item -( @var{archives} -) | |
626 | @itemx --start-group @var{archives} --end-group | |
627 | The @var{archives} should be a list of archive files. They may be | |
628 | either explicit file names, or @samp{-l} options. | |
629 | ||
630 | The specified archives are searched repeatedly until no new undefined | |
631 | references are created. Normally, an archive is searched only once in | |
632 | the order that it is specified on the command line. If a symbol in that | |
633 | archive is needed to resolve an undefined symbol referred to by an | |
634 | object in an archive that appears later on the command line, the linker | |
635 | would not be able to resolve that reference. By grouping the archives, | |
636 | they all be searched repeatedly until all possible references are | |
637 | resolved. | |
638 | ||
639 | Using this option has a significant performance cost. It is best to use | |
640 | it only when there are unavoidable circular references between two or | |
641 | more archives. | |
642 | ||
643 | @kindex -assert @var{keyword} | |
644 | @item -assert @var{keyword} | |
645 | This option is ignored for SunOS compatibility. | |
646 | ||
647 | @kindex -Bdynamic | |
648 | @kindex -dy | |
649 | @kindex -call_shared | |
650 | @item -Bdynamic | |
651 | @itemx -dy | |
652 | @itemx -call_shared | |
653 | Link against dynamic libraries. This is only meaningful on platforms | |
654 | for which shared libraries are supported. This option is normally the | |
655 | default on such platforms. The different variants of this option are | |
656 | for compatibility with various systems. You may use this option | |
657 | multiple times on the command line: it affects library searching for | |
658 | @code{-l} options which follow it. | |
659 | ||
660 | @kindex -Bstatic | |
661 | @kindex -dn | |
662 | @kindex -non_shared | |
663 | @kindex -static | |
664 | @item -Bstatic | |
665 | @itemx -dn | |
666 | @itemx -non_shared | |
667 | @itemx -static | |
668 | Do not link against shared libraries. This is only meaningful on | |
669 | platforms for which shared libraries are supported. The different | |
670 | variants of this option are for compatibility with various systems. You | |
671 | may use this option multiple times on the command line: it affects | |
672 | library searching for @code{-l} options which follow it. | |
673 | ||
674 | @kindex -Bsymbolic | |
675 | @item -Bsymbolic | |
676 | When creating a shared library, bind references to global symbols to the | |
677 | definition within the shared library, if any. Normally, it is possible | |
678 | for a program linked against a shared library to override the definition | |
679 | within the shared library. This option is only meaningful on ELF | |
680 | platforms which support shared libraries. | |
681 | ||
86bc0974 ILT |
682 | @cindex cross reference table |
683 | @kindex --cref | |
684 | @item --cref | |
685 | Output a cross reference table. If a linker map file is being | |
686 | generated, the cross reference table is printed to the map file. | |
687 | Otherwise, it is printed on the standard output. | |
688 | ||
689 | The format of the table is intentionally simple, so that it may be | |
690 | easily processed by a script if necessary. The symbols are printed out, | |
691 | sorted by name. For each symbol, a list of file names is given. If the | |
692 | symbol is defined, the first file listed is the location of the | |
693 | definition. The remaining files contain references to the symbol. | |
694 | ||
67afbcea DE |
695 | @cindex symbols, from command line |
696 | @kindex --defsym @var{symbol}=@var{exp} | |
697 | @item --defsym @var{symbol}=@var{expression} | |
698 | Create a global symbol in the output file, containing the absolute | |
699 | address given by @var{expression}. You may use this option as many | |
700 | times as necessary to define multiple symbols in the command line. A | |
701 | limited form of arithmetic is supported for the @var{expression} in this | |
702 | context: you may give a hexadecimal constant or the name of an existing | |
703 | symbol, or use @code{+} and @code{-} to add or subtract hexadecimal | |
704 | constants or symbols. If you need more elaborate expressions, consider | |
705 | using the linker command language from a script (@pxref{Assignment, , | |
706 | Assignment: Symbol Definitions}). @emph{Note:} there should be no | |
707 | white space between @var{symbol}, the equals sign (``@key{=}''), and | |
708 | @var{expression}. | |
709 | ||
710 | @cindex dynamic linker, from command line | |
711 | @kindex --dynamic-linker @var{file} | |
712 | @item --dynamic-linker @var{file} | |
713 | Set the name of the dynamic linker. This is only meaningful when | |
714 | generating dynamically linked ELF executables. The default dynamic | |
715 | linker is normally correct; don't use this unless you know what you are | |
716 | doing. | |
717 | ||
718 | @cindex big-endian objects | |
719 | @cindex endianness | |
720 | @kindex -EB | |
721 | @item -EB | |
722 | Link big-endian objects. This affects the default output format. | |
723 | ||
724 | @cindex little-endian objects | |
725 | @kindex -EL | |
726 | @item -EL | |
727 | Link little-endian objects. This affects the default output format. | |
728 | ||
729 | @cindex MIPS embedded PIC code | |
9fde46a4 ILT |
730 | @kindex --embedded-relocs |
731 | @item --embedded-relocs | |
67afbcea DE |
732 | This option is only meaningful when linking MIPS embedded PIC code, |
733 | generated by the -membedded-pic option to the @sc{gnu} compiler and | |
734 | assembler. It causes the linker to create a table which may be used at | |
735 | runtime to relocate any data which was statically initialized to pointer | |
736 | values. See the code in testsuite/ld-empic for details. | |
737 | ||
738 | @cindex help | |
739 | @cindex usage | |
740 | @kindex --help | |
741 | @item --help | |
742 | Print a summary of the command-line options on the standard output and exit. | |
743 | ||
744 | @cindex link map | |
745 | @kindex -Map | |
746 | @item -Map @var{mapfile} | |
747 | Print to the file @var{mapfile} a link map---diagnostic information | |
748 | about where symbols are mapped by @code{ld}, and information on global | |
749 | common storage allocation. | |
b4d4e8e3 | 750 | |
4551e108 | 751 | @cindex memory usage |
67afbcea DE |
752 | @kindex --no-keep-memory |
753 | @item --no-keep-memory | |
4551e108 ILT |
754 | @code{ld} normally optimizes for speed over memory usage by caching the |
755 | symbol tables of input files in memory. This option tells @code{ld} to | |
756 | instead optimize for memory usage, by rereading the symbol tables as | |
757 | necessary. This may be required if @code{ld} runs out of memory space | |
758 | while linking a large executable. | |
759 | ||
67afbcea DE |
760 | @kindex --no-whole-archive |
761 | @item --no-whole-archive | |
762 | Turn off the effect of the @code{--whole-archive} option for subsequent | |
763 | archive files. | |
764 | ||
765 | @cindex output file after errors | |
766 | @kindex --noinhibit-exec | |
767 | @item --noinhibit-exec | |
768 | Retain the executable output file whenever it is still usable. | |
769 | Normally, the linker will not produce an output file if it encounters | |
770 | errors during the link process; it exits without writing an output file | |
771 | when it issues any error whatsoever. | |
f22eee08 | 772 | |
7f9ae73e | 773 | @ifclear SingleFormat |
9fde46a4 ILT |
774 | @kindex --oformat |
775 | @item --oformat @var{output-format} | |
1fb57a5d RP |
776 | @code{ld} may be configured to support more than one kind of object |
777 | file. If your @code{ld} is configured this way, you can use the | |
9fde46a4 | 778 | @samp{--oformat} option to specify the binary format for the output |
1fb57a5d RP |
779 | object file. Even when @code{ld} is configured to support alternative |
780 | object formats, you don't usually need to specify this, as @code{ld} | |
781 | should be configured to produce as a default output format the most | |
782 | usual format on each machine. @var{output-format} is a text string, the | |
783 | name of a particular format supported by the BFD libraries. (You can | |
784 | list the available binary formats with @samp{objdump -i}.) The script | |
785 | command @code{OUTPUT_FORMAT} can also specify the output format, but | |
786 | this option overrides it. @xref{BFD}. | |
7f9ae73e | 787 | @end ifclear |
346535cc | 788 | |
67afbcea DE |
789 | @kindex -qmagic |
790 | @item -qmagic | |
791 | This option is ignored for Linux compatibility. | |
c653b370 | 792 | |
67afbcea DE |
793 | @kindex -Qy |
794 | @item -Qy | |
795 | This option is ignored for SVR4 compatibility. | |
c653b370 | 796 | |
67afbcea | 797 | @kindex --relax |
1c48127e RP |
798 | @cindex synthesizing linker |
799 | @cindex relaxing addressing modes | |
67afbcea | 800 | @item --relax |
1fb57a5d RP |
801 | An option with machine dependent effects. |
802 | @ifset GENERIC | |
67afbcea | 803 | This option is only supported on a few targets. |
1fb57a5d | 804 | @end ifset |
ec40bbb8 DM |
805 | @ifset H8300 |
806 | @xref{H8/300,,@code{ld} and the H8/300}. | |
807 | @end ifset | |
1fb57a5d RP |
808 | @ifset I960 |
809 | @xref{i960,, @code{ld} and the Intel 960 family}. | |
810 | @end ifset | |
1c48127e | 811 | |
67afbcea DE |
812 | On some platforms, the @samp{--relax} option performs global |
813 | optimizations that become possible when the linker resolves addressing | |
814 | in the program, such as relaxing address modes and synthesizing new | |
815 | instructions in the output object file. | |
1c48127e | 816 | |
1fb57a5d | 817 | @ifset GENERIC |
9fde46a4 ILT |
818 | On platforms where this is not supported, @samp{--relax} is accepted, |
819 | but ignored. | |
1fb57a5d | 820 | @end ifset |
1c48127e | 821 | |
7c8fab26 RP |
822 | @cindex retaining specified symbols |
823 | @cindex stripping all but some symbols | |
824 | @cindex symbols, retaining selectively | |
67afbcea | 825 | @item --retain-symbols-file @var{filename} |
7c8fab26 RP |
826 | Retain @emph{only} the symbols listed in the file @var{filename}, |
827 | discarding all others. @var{filename} is simply a flat file, with one | |
828 | symbol name per line. This option is especially useful in environments | |
829 | @ifset GENERIC | |
830 | (such as VxWorks) | |
831 | @end ifset | |
832 | where a large global symbol table is accumulated gradually, to conserve | |
833 | run-time memory. | |
834 | ||
9fde46a4 | 835 | @samp{--retain-symbols-file} does @emph{not} discard undefined symbols, |
7c8fab26 RP |
836 | or symbols needed for relocations. |
837 | ||
9fde46a4 | 838 | You may only specify @samp{--retain-symbols-file} once in the command |
7c8fab26 RP |
839 | line. It overrides @samp{-s} and @samp{-S}. |
840 | ||
a1ad915d ILT |
841 | @ifset GENERIC |
842 | @item -rpath @var{dir} | |
843 | @cindex runtime library search path | |
844 | @kindex -rpath | |
0b0642d6 ILT |
845 | Add a directory to the runtime library search path. This is used when |
846 | linking an ELF executable with shared objects. All @code{-rpath} | |
847 | arguments are concatenated and passed to the runtime linker, which uses | |
e54bf1c1 ILT |
848 | them to locate shared objects at runtime. The @code{-rpath} option is |
849 | also used when locating shared objects which are needed by shared | |
850 | objects explicitly included in the link; see the description of the | |
c653b370 ILT |
851 | @code{-rpath-link} option. If @code{-rpath} is not used when linking an |
852 | ELF executable, the contents of the environment variable | |
853 | @code{LD_RUN_PATH} will be used if it is defined. | |
0b0642d6 ILT |
854 | |
855 | The @code{-rpath} option may also be used on SunOS. By default, on | |
856 | SunOS, the linker will form a runtime search patch out of all the | |
e54bf1c1 | 857 | @code{-L} options it is given. If a @code{-rpath} option is used, the |
0b0642d6 ILT |
858 | runtime search path will be formed exclusively using the @code{-rpath} |
859 | options, ignoring the @code{-L} options. This can be useful when using | |
860 | gcc, which adds many @code{-L} options which may be on NFS mounted | |
861 | filesystems. | |
c653b370 ILT |
862 | |
863 | For compatibility with other ELF linkers, if the @code{-R} option is | |
864 | followed by a directory name, rather than a file name, it is treated as | |
865 | the @code{-rpath} option. | |
a1ad915d ILT |
866 | @end ifset |
867 | ||
e54bf1c1 ILT |
868 | @ifset GENERIC |
869 | @cindex link-time runtime library search path | |
870 | @kindex -rpath-link | |
871 | @item -rpath-link @var{DIR} | |
872 | When using ELF or SunOS, one shared library may require another. This | |
873 | happens when an @code{ld -shared} link includes a shared library as one | |
874 | of the input files. | |
875 | ||
876 | When the linker encounters such a dependency when doing a non-shared, | |
877 | non-relocateable link, it will automatically try to locate the required | |
878 | shared library and include it in the link, if it is not included | |
879 | explicitly. In such a case, the @code{-rpath-link} option | |
880 | specifies the first set of directories to search. The | |
881 | @code{-rpath-link} option may specify a sequence of directory names | |
882 | either by specifying a list of names separated by colons, or by | |
883 | appearing multiple times. | |
884 | ||
885 | The linker uses the following search paths to locate required shared | |
886 | libraries. | |
887 | @enumerate | |
888 | @item | |
889 | Any directories specified by @code{-rpath-link} options. | |
890 | @item | |
891 | Any directories specified by @code{-rpath} options. The difference | |
892 | between @code{-rpath} and @code{-rpath-link} is that directories | |
893 | specified by @code{-rpath} options are included in the executable and | |
894 | used at runtime, whereas the @code{-rpath-link} option is only effective | |
895 | at link time. | |
896 | @item | |
c653b370 ILT |
897 | On an ELF system, if the @code{-rpath} and @code{rpath-link} options |
898 | were not used, search the contents of the environment variable | |
899 | @code{LD_RUN_PATH}. | |
900 | @item | |
e54bf1c1 ILT |
901 | On SunOS, if the @code{-rpath} option was not used, search any |
902 | directories specified using @code{-L} options. | |
903 | @item | |
904 | For a native linker, the contents of the environment variable | |
905 | @code{LD_LIBRARY_PATH}. | |
906 | @item | |
907 | The default directories, normally @file{/lib} and @file{/usr/lib}. | |
908 | @end enumerate | |
909 | ||
910 | If the required shared library is not found, the linker will issue a | |
911 | warning and continue with the link. | |
912 | @end ifset | |
913 | ||
67afbcea DE |
914 | @kindex -shared |
915 | @kindex -Bshareable | |
4551e108 | 916 | @item -shared |
67afbcea | 917 | @itemx -Bshareable |
4551e108 | 918 | @cindex shared libraries |
67afbcea DE |
919 | Create a shared library. This is currently only supported on ELF, XCOFF |
920 | and SunOS platforms. On SunOS, the linker will automatically create a | |
e54bf1c1 ILT |
921 | shared library if the @code{-e} option is not used and there are |
922 | undefined symbols in the link. | |
4551e108 | 923 | |
67afbcea DE |
924 | @item --sort-common |
925 | @kindex --sort-common | |
926 | This option tells @code{ld} to sort the common symbols by size when it | |
927 | places them in the appropriate output sections. First come all the one | |
928 | byte symbols, then all the two bytes, then all the four bytes, and then | |
929 | everything else. This is to prevent gaps between symbols due to | |
930 | alignment constraints. | |
931 | ||
932 | @kindex --split-by-file | |
933 | @item --split-by-file | |
934 | Similar to @code{--split-by-reloc} but creates a new output section for | |
935 | each input file. | |
936 | ||
937 | @kindex --split-by-reloc | |
938 | @item --split-by-reloc @var{count} | |
939 | Trys to creates extra sections in the output file so that no single | |
940 | output section in the file contains more than @var{count} relocations. | |
941 | This is useful when generating huge relocatable for downloading into | |
942 | certain real time kernels with the COFF object file format; since COFF | |
943 | cannot represent more than 65535 relocations in a single section. Note | |
944 | that this will fail to work with object file formats which do not | |
945 | support arbitrary sections. The linker will not split up individual | |
946 | input sections for redistribution, so if a single input section contains | |
01bc8f35 ILT |
947 | more than @var{count} relocations one output section will contain that |
948 | many relocations. | |
949 | ||
67afbcea DE |
950 | @kindex --stats |
951 | @item --stats | |
952 | Compute and display statistics about the operation of the linker, such | |
953 | as execution time and memory usage. | |
f22eee08 | 954 | |
9fde46a4 | 955 | @kindex --traditional-format |
c96386c4 | 956 | @cindex traditional format |
9fde46a4 | 957 | @item --traditional-format |
c96386c4 ILT |
958 | For some targets, the output of @code{ld} is different in some ways from |
959 | the output of some existing linker. This switch requests @code{ld} to | |
960 | use the traditional format instead. | |
961 | ||
962 | @cindex dbx | |
963 | For example, on SunOS, @code{ld} combines duplicate entries in the | |
964 | symbol string table. This can reduce the size of an output file with | |
965 | full debugging information by over 30 percent. Unfortunately, the SunOS | |
966 | @code{dbx} program can not read the resulting program (@code{gdb} has no | |
9fde46a4 | 967 | trouble). The @samp{--traditional-format} switch tells @code{ld} to not |
c96386c4 ILT |
968 | combine duplicate entries. |
969 | ||
67afbcea DE |
970 | @kindex -Tbss @var{org} |
971 | @kindex -Tdata @var{org} | |
972 | @kindex -Ttext @var{org} | |
973 | @cindex segment origins, cmd line | |
974 | @item -Tbss @var{org} | |
975 | @itemx -Tdata @var{org} | |
976 | @itemx -Ttext @var{org} | |
977 | Use @var{org} as the starting address for---respectively---the | |
978 | @code{bss}, @code{data}, or the @code{text} segment of the output file. | |
979 | @var{org} must be a single hexadecimal integer; | |
980 | for compatibility with other linkers, you may omit the leading | |
981 | @samp{0x} usually associated with hexadecimal values. | |
f22eee08 | 982 | |
2c5c0674 | 983 | @kindex -Ur |
b4d4e8e3 | 984 | @cindex constructors |
d4e5e3c3 | 985 | @item -Ur |
b4d4e8e3 | 986 | For anything other than C++ programs, this option is equivalent to |
ec40bbb8 DM |
987 | @samp{-r}: it generates relocatable output---i.e., an output file that can in |
988 | turn serve as input to @code{ld}. When linking C++ programs, @samp{-Ur} | |
1fb57a5d | 989 | @emph{does} resolve references to constructors, unlike @samp{-r}. |
3e27cc11 | 990 | It does not work to use @samp{-Ur} on files that were themselves linked |
1fb57a5d | 991 | with @samp{-Ur}; once the constructor table has been built, it cannot |
3e27cc11 DM |
992 | be added to. Use @samp{-Ur} only for the last partial link, and |
993 | @samp{-r} for the others. | |
b4d4e8e3 | 994 | |
01bc8f35 | 995 | @kindex --verbose |
cf2e4f5f | 996 | @cindex verbose |
01bc8f35 | 997 | @item --verbose |
1fb57a5d | 998 | Display the version number for @code{ld} and list the linker emulations |
cf2e4f5f ILT |
999 | supported. Display which input files can and cannot be opened. Display |
1000 | the linker script if using a default builtin script. | |
8ddef552 | 1001 | |
458fc056 | 1002 | @kindex --warn-comon |
7f9ae73e RP |
1003 | @cindex warnings, on combining symbols |
1004 | @cindex combining symbols, warnings on | |
458fc056 | 1005 | @item --warn-common |
2a28d8b0 DM |
1006 | Warn when a common symbol is combined with another common symbol or with |
1007 | a symbol definition. Unix linkers allow this somewhat sloppy practice, | |
1008 | but linkers on some other operating systems do not. This option allows | |
1009 | you to find potential problems from combining global symbols. | |
1cd4cca9 DM |
1010 | Unfortunately, some C libraries use this practice, so you may get some |
1011 | warnings about symbols in the libraries as well as in your programs. | |
2a28d8b0 DM |
1012 | |
1013 | There are three kinds of global symbols, illustrated here by C examples: | |
1014 | ||
1015 | @table @samp | |
1016 | @item int i = 1; | |
1017 | A definition, which goes in the initialized data section of the output | |
1018 | file. | |
1019 | ||
1020 | @item extern int i; | |
1021 | An undefined reference, which does not allocate space. | |
1022 | There must be either a definition or a common symbol for the | |
1023 | variable somewhere. | |
1024 | ||
1025 | @item int i; | |
1026 | A common symbol. If there are only (one or more) common symbols for a | |
1027 | variable, it goes in the uninitialized data area of the output file. | |
1028 | The linker merges multiple common symbols for the same variable into a | |
1029 | single symbol. If they are of different sizes, it picks the largest | |
1030 | size. The linker turns a common symbol into a declaration, if there is | |
1031 | a definition of the same variable. | |
1032 | @end table | |
1033 | ||
458fc056 ILT |
1034 | The @samp{--warn-common} option can produce five kinds of warnings. |
1035 | Each warning consists of a pair of lines: the first describes the symbol | |
1036 | just encountered, and the second describes the previous symbol | |
1037 | encountered with the same name. One or both of the two symbols will be | |
1038 | a common symbol. | |
2a28d8b0 DM |
1039 | |
1040 | @enumerate | |
1041 | @item | |
1042 | Turning a common symbol into a reference, because there is already a | |
1043 | definition for the symbol. | |
1044 | @smallexample | |
8920addc RP |
1045 | @var{file}(@var{section}): warning: common of `@var{symbol}' |
1046 | overridden by definition | |
2a28d8b0 DM |
1047 | @var{file}(@var{section}): warning: defined here |
1048 | @end smallexample | |
1049 | ||
1050 | @item | |
1051 | Turning a common symbol into a reference, because a later definition for | |
1052 | the symbol is encountered. This is the same as the previous case, | |
1053 | except that the symbols are encountered in a different order. | |
1054 | @smallexample | |
8920addc RP |
1055 | @var{file}(@var{section}): warning: definition of `@var{symbol}' |
1056 | overriding common | |
2a28d8b0 DM |
1057 | @var{file}(@var{section}): warning: common is here |
1058 | @end smallexample | |
1059 | ||
1060 | @item | |
1061 | Merging a common symbol with a previous same-sized common symbol. | |
1062 | @smallexample | |
8920addc RP |
1063 | @var{file}(@var{section}): warning: multiple common |
1064 | of `@var{symbol}' | |
2a28d8b0 DM |
1065 | @var{file}(@var{section}): warning: previous common is here |
1066 | @end smallexample | |
1067 | ||
1068 | @item | |
1069 | Merging a common symbol with a previous larger common symbol. | |
1070 | @smallexample | |
8920addc RP |
1071 | @var{file}(@var{section}): warning: common of `@var{symbol}' |
1072 | overridden by larger common | |
2a28d8b0 DM |
1073 | @var{file}(@var{section}): warning: larger common is here |
1074 | @end smallexample | |
1075 | ||
1076 | @item | |
1077 | Merging a common symbol with a previous smaller common symbol. This is | |
1078 | the same as the previous case, except that the symbols are | |
1079 | encountered in a different order. | |
1080 | @smallexample | |
8920addc RP |
1081 | @var{file}(@var{section}): warning: common of `@var{symbol}' |
1082 | overriding smaller common | |
2a28d8b0 DM |
1083 | @var{file}(@var{section}): warning: smaller common is here |
1084 | @end smallexample | |
1085 | @end enumerate | |
1086 | ||
458fc056 ILT |
1087 | @kindex --warn-constructors |
1088 | @item --warn-constructors | |
0b0642d6 ILT |
1089 | Warn if any global constructors are used. This is only useful for a few |
1090 | object file formats. For formats like COFF or ELF, the linker can not | |
1091 | detect the use of global constructors. | |
1092 | ||
458fc056 ILT |
1093 | @kindex --warn-multiple-gp |
1094 | @item --warn-multiple-gp | |
4b7d2399 ILT |
1095 | Warn if multiple global pointer values are required in the output file. |
1096 | This is only meaningful for certain processors, such as the Alpha. | |
1097 | Specifically, some processors put large-valued constants in a special | |
1098 | section. A special register (the global pointer) points into the middle | |
1099 | of this section, so that constants can be loaded efficiently via a | |
1100 | base-register relative addressing mode. Since the offset in | |
1101 | base-register relative mode is fixed and relatively small (e.g., 16 | |
1102 | bits), this limits the maximum size of the constant pool. Thus, in | |
1103 | large programs, it is often necessary to use multiple global pointer | |
1104 | values in order to be able to address all possible constants. This | |
1105 | option causes a warning to be issued whenever this case occurs. | |
1106 | ||
458fc056 | 1107 | @kindex --warn-once |
01bc8f35 ILT |
1108 | @cindex warnings, on undefined symbols |
1109 | @cindex undefined symbols, warnings on | |
458fc056 | 1110 | @item --warn-once |
01bc8f35 ILT |
1111 | Only warn once for each undefined symbol, rather than once per module |
1112 | which refers to it. | |
1113 | ||
458fc056 ILT |
1114 | @kindex --warn-section-align |
1115 | @cindex warnings, on section alignment | |
1116 | @cindex section alignment, warnings on | |
1117 | @item --warn-section-align | |
1118 | Warn if the address of an output section is changed because of | |
1119 | alignment. Typically, the alignment will be set by an input section. | |
1120 | The address will only be changed if it not explicitly specified; that | |
1121 | is, if the @code{SECTIONS} command does not specify a start address for | |
1122 | the section (@pxref{SECTIONS}). | |
1123 | ||
4551e108 ILT |
1124 | @kindex --whole-archive |
1125 | @cindex including an entire archive | |
4b7d2399 | 1126 | @item --whole-archive |
3c8deccc ILT |
1127 | For each archive mentioned on the command line after the |
1128 | @code{--whole-archive} option, include every object file in the archive | |
1129 | in the link, rather than searching the archive for the required object | |
1130 | files. This is normally used to turn an archive file into a shared | |
1131 | library, forcing every object to be included in the resulting shared | |
67afbcea | 1132 | library. This option may be used more than once. |
4551e108 | 1133 | |
e3d73386 ILT |
1134 | @kindex --wrap |
1135 | @item --wrap @var{symbol} | |
1136 | Use a wrapper function for @var{symbol}. Any undefined reference to | |
1137 | @var{symbol} will be resolved to @code{__wrap_@var{symbol}}. Any | |
1138 | undefined reference to @code{__real_@var{symbol}} will be resolved to | |
1139 | @var{symbol}. | |
1140 | ||
1141 | This can be used to provide a wrapper for a system function. The | |
1142 | wrapper function should be called @code{__wrap_@var{symbol}}. If it | |
1143 | wishes to call the system function, it should call | |
1144 | @code{__real_@var{symbol}}. | |
1145 | ||
1146 | Here is a trivial example: | |
1147 | ||
1148 | @smallexample | |
1149 | void * | |
1150 | __wrap_malloc (int c) | |
1151 | @{ | |
1152 | printf ("malloc called with %ld\n", c); | |
1153 | return __real_malloc (c); | |
1154 | @} | |
1155 | @end smallexample | |
1156 | ||
1157 | If you link other code with this file using @code{--wrap malloc}, then | |
1158 | all calls to @code{malloc} will call the function @code{__wrap_malloc} | |
1159 | instead. The call to @code{__real_malloc} in @code{__wrap_malloc} will | |
1160 | call the real @code{malloc} function. | |
1161 | ||
1162 | You may wish to provide a @code{__real_malloc} function as well, so that | |
1163 | links without the @code{--wrap} option will succeed. If you do this, | |
1164 | you should not put the definition of @code{__real_malloc} in the same | |
1165 | file as @code{__wrap_malloc}; if you do, the assembler may resolve the | |
1166 | call before the linker has a chance to wrap it to @code{malloc}. | |
1167 | ||
f22eee08 | 1168 | @end table |
b4d4e8e3 | 1169 | |
ec40bbb8 DM |
1170 | @ifset UsesEnvVars |
1171 | @node Environment | |
2c5c0674 RP |
1172 | @section Environment Variables |
1173 | ||
d76ae847 RP |
1174 | You can change the behavior of @code{ld} with the environment |
1175 | variable @code{GNUTARGET}. | |
2c5c0674 RP |
1176 | |
1177 | @kindex GNUTARGET | |
1178 | @cindex default input format | |
1179 | @code{GNUTARGET} determines the input-file object format if you don't | |
9fde46a4 | 1180 | use @samp{-b} (or its synonym @samp{--format}). Its value should be one |
2c5c0674 | 1181 | of the BFD names for an input format (@pxref{BFD}). If there is no |
246504a5 | 1182 | @code{GNUTARGET} in the environment, @code{ld} uses the natural format |
9fde46a4 ILT |
1183 | of the target. If @code{GNUTARGET} is set to @code{default} then BFD |
1184 | attempts to discover the input format by examining binary input files; | |
1185 | this method often succeeds, but there are potential ambiguities, since | |
1186 | there is no method of ensuring that the magic number used to specify | |
1187 | object-file formats is unique. However, the configuration procedure for | |
1188 | BFD on each system places the conventional format for that system first | |
1189 | in the search-list, so ambiguities are resolved in favor of convention. | |
ec40bbb8 | 1190 | @end ifset |
2c5c0674 | 1191 | |
ec40bbb8 | 1192 | @node Commands |
2c5c0674 | 1193 | @chapter Command Language |
f22eee08 | 1194 | |
2c5c0674 | 1195 | @cindex command files |
ec40bbb8 | 1196 | The command language provides explicit control over the link process, |
b4d4e8e3 | 1197 | allowing complete specification of the mapping between the linker's |
ec40bbb8 | 1198 | input files and its output. It controls: |
b4d4e8e3 | 1199 | @itemize @bullet |
2c5c0674 RP |
1200 | @item |
1201 | input files | |
1202 | @item | |
1203 | file formats | |
1204 | @item | |
867a1b8a | 1205 | output file layout |
2c5c0674 RP |
1206 | @item |
1207 | addresses of sections | |
1208 | @item | |
1209 | placement of common blocks | |
b4d4e8e3 | 1210 | @end itemize |
f22eee08 | 1211 | |
2c5c0674 | 1212 | You may supply a command file (also known as a link script) to the |
ec40bbb8 | 1213 | linker either explicitly through the @samp{-T} option, or implicitly as |
2c5c0674 | 1214 | an ordinary file. If the linker opens a file which it cannot recognize |
867a1b8a | 1215 | as a supported object or archive format, it reports an error. |
2c5c0674 | 1216 | |
2c5c0674 | 1217 | @menu |
2d59b2c3 RP |
1218 | * Scripts:: Linker Scripts |
1219 | * Expressions:: Expressions | |
1220 | * MEMORY:: MEMORY Command | |
1221 | * SECTIONS:: SECTIONS Command | |
c653b370 | 1222 | * PHDRS:: PHDRS Command |
2d59b2c3 | 1223 | * Entry Point:: The Entry Point |
867a1b8a | 1224 | * Option Commands:: Option Commands |
2c5c0674 RP |
1225 | @end menu |
1226 | ||
ec40bbb8 | 1227 | @node Scripts |
b4d4e8e3 | 1228 | @section Linker Scripts |
246504a5 | 1229 | The @code{ld} command language is a collection of statements; some are |
ec40bbb8 DM |
1230 | simple keywords setting a particular option, some are used to select and |
1231 | group input files or name output files; and two statement | |
b4d4e8e3 RP |
1232 | types have a fundamental and pervasive impact on the linking process. |
1233 | ||
2c5c0674 RP |
1234 | @cindex fundamental script commands |
1235 | @cindex commands, fundamental | |
1236 | @cindex output file layout | |
1237 | @cindex layout of output file | |
246504a5 | 1238 | The most fundamental command of the @code{ld} command language is the |
b4d4e8e3 RP |
1239 | @code{SECTIONS} command (@pxref{SECTIONS}). Every meaningful command |
1240 | script must have a @code{SECTIONS} command: it specifies a | |
1241 | ``picture'' of the output file's layout, in varying degrees of detail. | |
1242 | No other command is required in all cases. | |
1243 | ||
1244 | The @code{MEMORY} command complements @code{SECTIONS} by describing the | |
2c5c0674 | 1245 | available memory in the target architecture. This command is optional; |
246504a5 | 1246 | if you don't use a @code{MEMORY} command, @code{ld} assumes sufficient |
2c5c0674 RP |
1247 | memory is available in a contiguous block for all output. |
1248 | @xref{MEMORY}. | |
b4d4e8e3 | 1249 | |
2c5c0674 RP |
1250 | @cindex comments |
1251 | You may include comments in linker scripts just as in C: delimited | |
1252 | by @samp{/*} and @samp{*/}. As in C, comments are syntactically | |
1253 | equivalent to whitespace. | |
1254 | ||
ec40bbb8 | 1255 | @node Expressions |
f22eee08 | 1256 | @section Expressions |
2c5c0674 RP |
1257 | @cindex expression syntax |
1258 | @cindex arithmetic | |
b4d4e8e3 RP |
1259 | Many useful commands involve arithmetic expressions. The syntax for |
1260 | expressions in the command language is identical to that of C | |
1261 | expressions, with the following features: | |
1262 | @itemize @bullet | |
2c5c0674 RP |
1263 | @item |
1264 | All expressions evaluated as integers and | |
f22eee08 | 1265 | are of ``long'' or ``unsigned long'' type. |
2c5c0674 RP |
1266 | @item |
1267 | All constants are integers. | |
1268 | @item | |
1269 | All of the C arithmetic operators are provided. | |
1270 | @item | |
1271 | You may reference, define, and create global variables. | |
1272 | @item | |
1273 | You may call special purpose built-in functions. | |
b4d4e8e3 | 1274 | @end itemize |
f22eee08 | 1275 | |
2c5c0674 | 1276 | @menu |
2d59b2c3 RP |
1277 | * Integers:: Integers |
1278 | * Symbols:: Symbol Names | |
1279 | * Location Counter:: The Location Counter | |
1280 | * Operators:: Operators | |
1281 | * Evaluation:: Evaluation | |
1282 | * Assignment:: Assignment: Defining Symbols | |
867a1b8a | 1283 | * Arithmetic Functions:: Built-In Functions |
67afbcea | 1284 | * Semicolons:: Semicolon Usage |
2c5c0674 RP |
1285 | @end menu |
1286 | ||
ec40bbb8 | 1287 | @node Integers |
f22eee08 | 1288 | @subsection Integers |
2c5c0674 RP |
1289 | @cindex integer notation |
1290 | @cindex octal integers | |
f22eee08 RP |
1291 | An octal integer is @samp{0} followed by zero or more of the octal |
1292 | digits (@samp{01234567}). | |
c653b370 | 1293 | @smallexample |
2c5c0674 | 1294 | _as_octal = 0157255; |
c653b370 | 1295 | @end smallexample |
f22eee08 | 1296 | |
2c5c0674 | 1297 | @cindex decimal integers |
f22eee08 RP |
1298 | A decimal integer starts with a non-zero digit followed by zero or |
1299 | more digits (@samp{0123456789}). | |
c653b370 | 1300 | @smallexample |
2c5c0674 | 1301 | _as_decimal = 57005; |
c653b370 | 1302 | @end smallexample |
f22eee08 | 1303 | |
2c5c0674 RP |
1304 | @cindex hexadecimal integers |
1305 | @kindex 0x | |
f22eee08 RP |
1306 | A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or |
1307 | more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}. | |
c653b370 | 1308 | @smallexample |
b4d4e8e3 | 1309 | _as_hex = 0xdead; |
c653b370 | 1310 | @end smallexample |
f22eee08 | 1311 | |
2c5c0674 | 1312 | @cindex negative integers |
ec40bbb8 | 1313 | To write a negative integer, use |
baaaf6f2 | 1314 | the prefix operator @samp{-} (@pxref{Operators}). |
c653b370 | 1315 | @smallexample |
b4d4e8e3 | 1316 | _as_neg = -57005; |
c653b370 | 1317 | @end smallexample |
f22eee08 | 1318 | |
2c5c0674 RP |
1319 | @cindex scaled integers |
1320 | @cindex K and M integer suffixes | |
1321 | @cindex M and K integer suffixes | |
1322 | @cindex suffixes for integers | |
1323 | @cindex integer suffixes | |
b4d4e8e3 RP |
1324 | Additionally the suffixes @code{K} and @code{M} may be used to scale a |
1325 | constant by | |
c8072296 RP |
1326 | @c TEXI2ROFF-KILL |
1327 | @ifinfo | |
1328 | @c END TEXI2ROFF-KILL | |
1329 | @code{1024} or @code{1024*1024} | |
1330 | @c TEXI2ROFF-KILL | |
1331 | @end ifinfo | |
f22eee08 | 1332 | @tex |
b4d4e8e3 | 1333 | ${\rm 1024}$ or ${\rm 1024}^2$ |
f22eee08 | 1334 | @end tex |
c8072296 | 1335 | @c END TEXI2ROFF-KILL |
ec40bbb8 | 1336 | respectively. For example, the following all refer to the same quantity: |
f22eee08 | 1337 | |
c653b370 | 1338 | @smallexample |
2c5c0674 RP |
1339 | _fourk_1 = 4K; |
1340 | _fourk_2 = 4096; | |
1341 | _fourk_3 = 0x1000; | |
c653b370 | 1342 | @end smallexample |
b4d4e8e3 | 1343 | |
ec40bbb8 | 1344 | @node Symbols |
b4d4e8e3 | 1345 | @subsection Symbol Names |
2c5c0674 RP |
1346 | @cindex symbol names |
1347 | @cindex names | |
1348 | @cindex quoted symbol names | |
1349 | @kindex " | |
1fb57a5d RP |
1350 | Unless quoted, symbol names start with a letter, underscore, or point |
1351 | and may include any letters, underscores, digits, points, | |
1352 | and hyphens. Unquoted symbol names must not conflict with any | |
b4d4e8e3 RP |
1353 | keywords. You can specify a symbol which contains odd characters or has |
1354 | the same name as a keyword, by surrounding the symbol name in double quotes: | |
c653b370 | 1355 | @smallexample |
b4d4e8e3 RP |
1356 | "SECTION" = 9; |
1357 | "with a space" = "also with a space" + 10; | |
c653b370 | 1358 | @end smallexample |
b4d4e8e3 | 1359 | |
1fb57a5d RP |
1360 | Since symbols can contain many non-alphabetic characters, it is safest |
1361 | to delimit symbols with spaces. For example, @samp{A-B} is one symbol, | |
1362 | whereas @samp{A - B} is an expression involving subtraction. | |
1363 | ||
ec40bbb8 | 1364 | @node Location Counter |
b4d4e8e3 | 1365 | @subsection The Location Counter |
2c5c0674 RP |
1366 | @kindex . |
1367 | @cindex dot | |
1368 | @cindex location counter | |
1369 | @cindex current output location | |
b4d4e8e3 RP |
1370 | The special linker variable @dfn{dot} @samp{.} always contains the |
1371 | current output location counter. Since the @code{.} always refers to | |
1372 | a location in an output section, it must always appear in an | |
1373 | expression within a @code{SECTIONS} command. The @code{.} symbol | |
1374 | may appear anywhere that an ordinary symbol is allowed in an | |
1375 | expression, but its assignments have a side effect. Assigning a value | |
1376 | to the @code{.} symbol will cause the location counter to be moved. | |
2c5c0674 | 1377 | @cindex holes |
b4d4e8e3 RP |
1378 | This may be used to create holes in the output section. The location |
1379 | counter may never be moved backwards. | |
c653b370 | 1380 | @smallexample |
2c5c0674 RP |
1381 | SECTIONS |
1382 | @{ | |
d4e5e3c3 DM |
1383 | output : |
1384 | @{ | |
1385 | file1(.text) | |
1386 | . = . + 1000; | |
1387 | file2(.text) | |
1388 | . += 1000; | |
1389 | file3(.text) | |
1390 | @} = 0x1234; | |
2c5c0674 | 1391 | @} |
c653b370 | 1392 | @end smallexample |
2c5c0674 RP |
1393 | @noindent |
1394 | In the previous example, @code{file1} is located at the beginning of the | |
1395 | output section, then there is a 1000 byte gap. Then @code{file2} | |
1396 | appears, also with a 1000 byte gap following before @code{file3} is | |
1397 | loaded. The notation @samp{= 0x1234} specifies what data to write in | |
1398 | the gaps (@pxref{Section Options}). | |
b4d4e8e3 | 1399 | |
d4e5e3c3 DM |
1400 | @iftex |
1401 | @vfill | |
1402 | @end iftex | |
1403 | ||
c653b370 | 1404 | @need 2000 |
ec40bbb8 | 1405 | @node Operators |
f22eee08 | 1406 | @subsection Operators |
2c5c0674 RP |
1407 | @cindex Operators for arithmetic |
1408 | @cindex arithmetic operators | |
1409 | @cindex precedence in expressions | |
b4d4e8e3 | 1410 | The linker recognizes the standard C set of arithmetic operators, with |
f22eee08 | 1411 | the standard bindings and precedence levels: |
c8072296 | 1412 | @c TEXI2ROFF-KILL |
b4d4e8e3 | 1413 | @ifinfo |
c8072296 | 1414 | @c END TEXI2ROFF-KILL |
c653b370 | 1415 | @smallexample |
c8072296 | 1416 | precedence associativity Operators Notes |
b4d4e8e3 | 1417 | (highest) |
c8072296 RP |
1418 | 1 left ! - ~ (1) |
1419 | 2 left * / % | |
1420 | 3 left + - | |
1421 | 4 left >> << | |
1422 | 5 left == != > < <= >= | |
1423 | 6 left & | |
1424 | 7 left | | |
1425 | 8 left && | |
1426 | 9 left || | |
1427 | 10 right ? : | |
1428 | 11 right &= += -= *= /= (2) | |
b4d4e8e3 | 1429 | (lowest) |
c653b370 | 1430 | @end smallexample |
2c5c0674 RP |
1431 | Notes: |
1432 | (1) Prefix operators | |
baaaf6f2 | 1433 | (2) @xref{Assignment}. |
c8072296 | 1434 | @c TEXI2ROFF-KILL |
b4d4e8e3 | 1435 | @end ifinfo |
f22eee08 | 1436 | @tex |
2c5c0674 | 1437 | \vskip \baselineskip |
feb20cfb | 1438 | %"lispnarrowing" is the extra indent used generally for smallexample |
2c5c0674 | 1439 | \hskip\lispnarrowing\vbox{\offinterlineskip |
f22eee08 RP |
1440 | \hrule |
1441 | \halign | |
2c5c0674 RP |
1442 | {\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr |
1443 | height2pt&\omit&&\omit&&\omit&\cr | |
1444 | &Precedence&& Associativity &&{\rm Operators}&\cr | |
1445 | height2pt&\omit&&\omit&&\omit&\cr | |
f22eee08 | 1446 | \noalign{\hrule} |
2c5c0674 | 1447 | height2pt&\omit&&\omit&&\omit&\cr |
b4d4e8e3 | 1448 | &highest&&&&&\cr |
2c5c0674 RP |
1449 | % '176 is tilde, '~' in tt font |
1450 | &1&&left&&\qquad- \char'176\ !\qquad\dag&\cr | |
1451 | &2&&left&&* / \%&\cr | |
1452 | &3&&left&&+ -&\cr | |
1453 | &4&&left&&>> <<&\cr | |
1454 | &5&&left&&== != > < <= >=&\cr | |
f22eee08 | 1455 | &6&&left&&\&&\cr |
f22eee08 | 1456 | &7&&left&&|&\cr |
f22eee08 | 1457 | &8&&left&&{\&\&}&\cr |
f22eee08 | 1458 | &9&&left&&||&\cr |
2c5c0674 RP |
1459 | &10&&right&&? :&\cr |
1460 | &11&&right&&\qquad\&= += -= *= /=\qquad\ddag&\cr | |
b4d4e8e3 | 1461 | &lowest&&&&&\cr |
2c5c0674 | 1462 | height2pt&\omit&&\omit&&\omit&\cr} |
f22eee08 RP |
1463 | \hrule} |
1464 | @end tex | |
2c5c0674 RP |
1465 | @iftex |
1466 | { | |
1467 | @obeylines@parskip=0pt@parindent=0pt | |
1468 | @dag@quad Prefix operators. | |
1469 | @ddag@quad @xref{Assignment}. | |
1470 | } | |
1471 | @end iftex | |
c8072296 | 1472 | @c END TEXI2ROFF-KILL |
f22eee08 | 1473 | |
ec40bbb8 | 1474 | @node Evaluation |
b4d4e8e3 RP |
1475 | @subsection Evaluation |
1476 | ||
2c5c0674 RP |
1477 | @cindex lazy evaluation |
1478 | @cindex expression evaluation order | |
b4d4e8e3 RP |
1479 | The linker uses ``lazy evaluation'' for expressions; it only calculates |
1480 | an expression when absolutely necessary. The linker needs the value of | |
1481 | the start address, and the lengths of memory regions, in order to do any | |
1482 | linking at all; these values are computed as soon as possible when the | |
1483 | linker reads in the command file. However, other values (such as symbol | |
1484 | values) are not known or needed until after storage allocation. Such | |
1485 | values are evaluated later, when other information (such as the sizes of | |
1486 | output sections) is available for use in the symbol assignment | |
1487 | expression. | |
1488 | ||
ec40bbb8 | 1489 | @node Assignment |
b4d4e8e3 | 1490 | @subsection Assignment: Defining Symbols |
2c5c0674 RP |
1491 | @cindex assignment in scripts |
1492 | @cindex symbol definition, scripts | |
1493 | @cindex variables, defining | |
b4d4e8e3 RP |
1494 | You may create global symbols, and assign values (addresses) to global |
1495 | symbols, using any of the C assignment operators: | |
1496 | ||
1497 | @table @code | |
1498 | @item @var{symbol} = @var{expression} ; | |
2c5c0674 | 1499 | @itemx @var{symbol} &= @var{expression} ; |
b4d4e8e3 RP |
1500 | @itemx @var{symbol} += @var{expression} ; |
1501 | @itemx @var{symbol} -= @var{expression} ; | |
1502 | @itemx @var{symbol} *= @var{expression} ; | |
1503 | @itemx @var{symbol} /= @var{expression} ; | |
1504 | @end table | |
1505 | ||
246504a5 | 1506 | Two things distinguish assignment from other operators in @code{ld} |
b4d4e8e3 RP |
1507 | expressions. |
1508 | @itemize @bullet | |
2c5c0674 RP |
1509 | @item |
1510 | Assignment may only be used at the root of an expression; | |
b4d4e8e3 | 1511 | @samp{a=b+3;} is allowed, but @samp{a+b=3;} is an error. |
2c5c0674 RP |
1512 | |
1513 | @kindex ; | |
1514 | @cindex semicolon | |
1515 | @item | |
d76ae847 RP |
1516 | You must place a trailing semicolon (``@key{;}'') at the end of an |
1517 | assignment statement. | |
b4d4e8e3 RP |
1518 | @end itemize |
1519 | ||
1520 | Assignment statements may appear: | |
1521 | @itemize @bullet | |
2c5c0674 | 1522 | @item |
246504a5 | 1523 | as commands in their own right in an @code{ld} script; or |
2c5c0674 RP |
1524 | @item |
1525 | as independent statements within a @code{SECTIONS} command; or | |
1526 | @item | |
1527 | as part of the contents of a section definition in a | |
b4d4e8e3 RP |
1528 | @code{SECTIONS} command. |
1529 | @end itemize | |
1530 | ||
1531 | The first two cases are equivalent in effect---both define a symbol with | |
ec40bbb8 | 1532 | an absolute address. The last case defines a symbol whose address is |
b4d4e8e3 RP |
1533 | relative to a particular section (@pxref{SECTIONS}). |
1534 | ||
2c5c0674 RP |
1535 | @cindex absolute and relocatable symbols |
1536 | @cindex relocatable and absolute symbols | |
1537 | @cindex symbols, relocatable and absolute | |
1538 | When a linker expression is evaluated and assigned to a variable, it is | |
1539 | given either an absolute or a relocatable type. An absolute expression | |
1540 | type is one in which the symbol contains the value that it will have in | |
867a1b8a | 1541 | the output file; a relocatable expression type is one in which the |
2c5c0674 | 1542 | value is expressed as a fixed offset from the base of a section. |
b4d4e8e3 RP |
1543 | |
1544 | The type of the expression is controlled by its position in the script | |
2c5c0674 RP |
1545 | file. A symbol assigned within a section definition is created relative |
1546 | to the base of the section; a symbol assigned in any other place is | |
1547 | created as an absolute symbol. Since a symbol created within a | |
1548 | section definition is relative to the base of the section, it | |
1549 | will remain relocatable if relocatable output is requested. A symbol | |
1550 | may be created with an absolute value even when assigned to within a | |
1551 | section definition by using the absolute assignment function | |
1552 | @code{ABSOLUTE}. For example, to create an absolute symbol whose address | |
1553 | is the last byte of an output section named @code{.data}: | |
c653b370 | 1554 | @smallexample |
2c5c0674 | 1555 | SECTIONS@{ @dots{} |
d4e5e3c3 DM |
1556 | .data : |
1557 | @{ | |
1558 | *(.data) | |
1559 | _edata = ABSOLUTE(.) ; | |
1560 | @} | |
2c5c0674 | 1561 | @dots{} @} |
c653b370 | 1562 | @end smallexample |
b4d4e8e3 | 1563 | |
2c5c0674 RP |
1564 | The linker tries to put off the evaluation of an assignment until all |
1565 | the terms in the source expression are known (@pxref{Evaluation}). For | |
ec40bbb8 | 1566 | instance, the sizes of sections cannot be known until after allocation, |
2c5c0674 RP |
1567 | so assignments dependent upon these are not performed until after |
1568 | allocation. Some expressions, such as those depending upon the location | |
1569 | counter @dfn{dot}, @samp{.} must be evaluated during allocation. If the | |
1570 | result of an expression is required, but the value is not available, | |
1571 | then an error results. For example, a script like the following | |
c653b370 | 1572 | @smallexample |
2c5c0674 | 1573 | SECTIONS @{ @dots{} |
d4e5e3c3 DM |
1574 | text 9+this_isnt_constant : |
1575 | @{ @dots{} | |
1576 | @} | |
2c5c0674 | 1577 | @dots{} @} |
c653b370 | 1578 | @end smallexample |
2c5c0674 RP |
1579 | @kindex Non constant expression |
1580 | @noindent | |
1581 | will cause the error message ``@code{Non constant expression for initial | |
0b3499f6 ILT |
1582 | address}''. |
1583 | ||
1584 | @cindex provide | |
1585 | In some cases, it is desirable for a linker script to define a symbol | |
1586 | only if it is referenced, and only if it is not defined by any object | |
1587 | included in the link. For example, traditional linkers defined the | |
1588 | symbol @samp{etext}. However, ANSI C requires that the user be able to | |
1589 | use @samp{etext} as a function name without encountering an error. | |
1590 | The @code{PROVIDE} keyword may be used to define a symbol, such as | |
1591 | @samp{etext}, only if it is referenced but not defined. The syntax is | |
1592 | @code{PROVIDE(@var{symbol} = @var{expression})}. | |
b4d4e8e3 | 1593 | |
867a1b8a DM |
1594 | @node Arithmetic Functions |
1595 | @subsection Arithmetic Functions | |
2c5c0674 | 1596 | @cindex functions in expression language |
ec40bbb8 | 1597 | The command language includes a number of built-in |
2c5c0674 RP |
1598 | functions for use in link script expressions. |
1599 | @table @code | |
2c5c0674 RP |
1600 | @kindex ABSOLUTE(@var{exp}) |
1601 | @cindex expression, absolute | |
c653b370 | 1602 | @item ABSOLUTE(@var{exp}) |
ec40bbb8 DM |
1603 | Return the absolute (non-relocatable, as opposed to non-negative) value |
1604 | of the expression @var{exp}. Primarily useful to assign an absolute | |
1605 | value to a symbol within a section definition, where symbol values are | |
1606 | normally section-relative. | |
2c5c0674 | 1607 | |
2c5c0674 RP |
1608 | @kindex ADDR(@var{section}) |
1609 | @cindex section address | |
c653b370 | 1610 | @item ADDR(@var{section}) |
ec40bbb8 | 1611 | Return the absolute address of the named @var{section}. Your script must |
b4d4e8e3 | 1612 | previously have defined the location of that section. In the following |
ec40bbb8 | 1613 | example, @code{symbol_1} and @code{symbol_2} are assigned identical |
b4d4e8e3 | 1614 | values: |
c653b370 ILT |
1615 | @smallexample |
1616 | @group | |
2c5c0674 | 1617 | SECTIONS@{ @dots{} |
d4e5e3c3 DM |
1618 | .output1 : |
1619 | @{ | |
1620 | start_of_output_1 = ABSOLUTE(.); | |
1621 | @dots{} | |
1622 | @} | |
1623 | .output : | |
1624 | @{ | |
1625 | symbol_1 = ADDR(.output1); | |
1626 | symbol_2 = start_of_output_1; | |
1627 | @} | |
2c5c0674 | 1628 | @dots{} @} |
c653b370 ILT |
1629 | @end group |
1630 | @end smallexample | |
2c5c0674 | 1631 | |
5735ac9e ILT |
1632 | @kindex LOADADDR(@var{section}) |
1633 | @cindex section load address | |
1634 | @item LOADADDR(@var{section}) | |
1635 | Return the absolute load address of the named @var{section}. This is | |
1636 | normally the same as @code{ADDR}, but it may be different if the | |
1637 | @code{AT} keyword is used in the section definition (@pxref{Section | |
1638 | Options}). | |
1639 | ||
2c5c0674 RP |
1640 | @kindex ALIGN(@var{exp}) |
1641 | @cindex rounding up location counter | |
c653b370 | 1642 | @item ALIGN(@var{exp}) |
ec40bbb8 | 1643 | Return the result of the current location counter (@code{.}) aligned to |
2c5c0674 RP |
1644 | the next @var{exp} boundary. @var{exp} must be an expression whose |
1645 | value is a power of two. This is equivalent to | |
c653b370 | 1646 | @smallexample |
cb70c872 | 1647 | (. + @var{exp} - 1) & ~(@var{exp} - 1) |
c653b370 | 1648 | @end smallexample |
2c5c0674 RP |
1649 | |
1650 | @code{ALIGN} doesn't change the value of the location counter---it just | |
1651 | does arithmetic on it. As an example, to align the output @code{.data} | |
1652 | section to the next @code{0x2000} byte boundary after the preceding | |
1653 | section and to set a variable within the section to the next | |
1654 | @code{0x8000} boundary after the input sections: | |
c653b370 ILT |
1655 | @smallexample |
1656 | @group | |
2c5c0674 | 1657 | SECTIONS@{ @dots{} |
d4e5e3c3 DM |
1658 | .data ALIGN(0x2000): @{ |
1659 | *(.data) | |
1660 | variable = ALIGN(0x8000); | |
1661 | @} | |
2c5c0674 | 1662 | @dots{} @} |
c653b370 ILT |
1663 | @end group |
1664 | @end smallexample | |
2c5c0674 RP |
1665 | @noindent |
1666 | The first use of @code{ALIGN} in this example specifies the location of | |
1667 | a section because it is used as the optional @var{start} attribute of a | |
1668 | section definition (@pxref{Section Options}). The second use simply | |
1669 | defines the value of a variable. | |
1670 | ||
1671 | The built-in @code{NEXT} is closely related to @code{ALIGN}. | |
1672 | ||
2c5c0674 RP |
1673 | @kindex DEFINED(@var{symbol}) |
1674 | @cindex symbol defaults | |
c653b370 | 1675 | @item DEFINED(@var{symbol}) |
ec40bbb8 DM |
1676 | Return 1 if @var{symbol} is in the linker global symbol table and is |
1677 | defined, otherwise return 0. You can use this function to provide default | |
1678 | values for symbols. For example, the following command-file fragment shows how | |
2c5c0674 RP |
1679 | to set a global symbol @code{begin} to the first location in the |
1680 | @code{.text} section---but if a symbol called @code{begin} already | |
1681 | existed, its value is preserved: | |
d4e5e3c3 | 1682 | |
c8072296 | 1683 | @smallexample |
c653b370 | 1684 | @group |
2c5c0674 | 1685 | SECTIONS@{ @dots{} |
d4e5e3c3 DM |
1686 | .text : @{ |
1687 | begin = DEFINED(begin) ? begin : . ; | |
1688 | @dots{} | |
1689 | @} | |
2c5c0674 | 1690 | @dots{} @} |
c653b370 | 1691 | @end group |
c8072296 | 1692 | @end smallexample |
f22eee08 | 1693 | |
2c5c0674 RP |
1694 | @kindex NEXT(@var{exp}) |
1695 | @cindex unallocated address, next | |
c653b370 | 1696 | @item NEXT(@var{exp}) |
ec40bbb8 DM |
1697 | Return the next unallocated address that is a multiple of @var{exp}. |
1698 | This function is closely related to @code{ALIGN(@var{exp})}; unless you | |
2c5c0674 | 1699 | use the @code{MEMORY} command to define discontinuous memory for the |
ec40bbb8 | 1700 | output file, the two functions are equivalent. |
2c5c0674 | 1701 | |
2c5c0674 RP |
1702 | @kindex SIZEOF(@var{section}) |
1703 | @cindex section size | |
c653b370 | 1704 | @item SIZEOF(@var{section}) |
ec40bbb8 DM |
1705 | Return the size in bytes of the named @var{section}, if that section has |
1706 | been allocated. In the following example, @code{symbol_1} and | |
f22eee08 | 1707 | @code{symbol_2} are assigned identical values: |
ec40bbb8 | 1708 | @c What does it return if the section hasn't been allocated? 0? |
c653b370 ILT |
1709 | @smallexample |
1710 | @group | |
2c5c0674 | 1711 | SECTIONS@{ @dots{} |
d4e5e3c3 DM |
1712 | .output @{ |
1713 | .start = . ; | |
1714 | @dots{} | |
1715 | .end = . ; | |
1716 | @} | |
1717 | symbol_1 = .end - .start ; | |
1718 | symbol_2 = SIZEOF(.output); | |
2c5c0674 | 1719 | @dots{} @} |
c653b370 ILT |
1720 | @end group |
1721 | @end smallexample | |
f22eee08 | 1722 | |
2c5c0674 RP |
1723 | @kindex SIZEOF_HEADERS |
1724 | @cindex header size | |
2c5c0674 | 1725 | @kindex sizeof_headers |
c653b370 ILT |
1726 | @item SIZEOF_HEADERS |
1727 | @itemx sizeof_headers | |
ec40bbb8 | 1728 | Return the size in bytes of the output file's headers. You can use this number |
2c5c0674 RP |
1729 | as the start address of the first section, if you choose, to facilitate |
1730 | paging. | |
1731 | ||
b61364cc ILT |
1732 | @kindex MAX |
1733 | @item MAX(@var{exp1}, @var{exp2}) | |
1734 | Returns the maximum of @var{exp1} and @var{exp2}. | |
1735 | ||
1736 | @kindex MIN | |
1737 | @item MIN(@var{exp1}, @var{exp2}) | |
1738 | Returns the minimum of @var{exp1} and @var{exp2}. | |
1739 | ||
2c5c0674 RP |
1740 | @end table |
1741 | ||
67afbcea DE |
1742 | @node Semicolons |
1743 | @subsection Semicolons | |
1744 | ||
1745 | Semicolons (``@key{;}'') are required in the following places. In all | |
1746 | other places they can appear for aesthetic reasons but are otherwise ignored. | |
1747 | ||
1748 | @table @code | |
1749 | @item Assignment | |
1750 | Semicolons must appear at the end of assignment expressions. | |
1751 | @xref{Assignment} | |
1752 | ||
1753 | @item PHDRS | |
1754 | Semicolons must appear at the end of a @code{PHDRS} statement. | |
1755 | @xref{PHDRS} | |
1756 | @end table | |
1757 | ||
ec40bbb8 | 1758 | @node MEMORY |
867a1b8a | 1759 | @section Memory Layout |
2c5c0674 RP |
1760 | @kindex MEMORY |
1761 | @cindex regions of memory | |
1762 | @cindex discontinuous memory | |
1763 | @cindex allocating memory | |
ec40bbb8 DM |
1764 | The linker's default configuration permits allocation of all available memory. |
1765 | You can override this configuration by using the @code{MEMORY} command. The | |
b4d4e8e3 RP |
1766 | @code{MEMORY} command describes the location and size of blocks of |
1767 | memory in the target. By using it carefully, you can describe which | |
1768 | memory regions may be used by the linker, and which memory regions it | |
1769 | must avoid. The linker does not shuffle sections to fit into the | |
1770 | available regions, but does move the requested sections into the correct | |
1771 | regions and issue errors when the regions become too full. | |
1772 | ||
867a1b8a | 1773 | A command file may contain at most one use of the @code{MEMORY} |
b4d4e8e3 RP |
1774 | command; however, you can define as many blocks of memory within it as |
1775 | you wish. The syntax is: | |
c8072296 | 1776 | |
c653b370 ILT |
1777 | @smallexample |
1778 | @group | |
b4d4e8e3 | 1779 | MEMORY |
d4e5e3c3 DM |
1780 | @{ |
1781 | @var{name} (@var{attr}) : ORIGIN = @var{origin}, LENGTH = @var{len} | |
1782 | @dots{} | |
1783 | @} | |
c653b370 ILT |
1784 | @end group |
1785 | @end smallexample | |
f22eee08 | 1786 | @table @code |
2c5c0674 | 1787 | @cindex naming memory regions |
d4e5e3c3 | 1788 | @item @var{name} |
f22eee08 RP |
1789 | is a name used internally by the linker to refer to the region. Any |
1790 | symbol name may be used. The region names are stored in a separate | |
ec40bbb8 | 1791 | name space, and will not conflict with symbols, file names or section |
b4d4e8e3 | 1792 | names. Use distinct names to specify multiple regions. |
d4e5e3c3 | 1793 | |
2c5c0674 | 1794 | @cindex memory region attributes |
d4e5e3c3 | 1795 | @item (@var{attr}) |
2c5c0674 | 1796 | is an optional list of attributes, permitted for compatibility with the |
246504a5 | 1797 | AT&T linker but not used by @code{ld} beyond checking that the |
2c5c0674 RP |
1798 | attribute list is valid. Valid attribute lists must be made up of the |
1799 | characters ``@code{LIRWX}''. If you omit the attribute list, you may | |
1800 | omit the parentheses around it as well. | |
d4e5e3c3 | 1801 | |
cb70c872 RP |
1802 | @kindex ORIGIN = |
1803 | @kindex o = | |
1804 | @kindex org = | |
d4e5e3c3 | 1805 | @item @var{origin} |
ec40bbb8 DM |
1806 | is the start address of the region in physical memory. It is |
1807 | an expression that must evaluate to a constant before | |
f22eee08 | 1808 | memory allocation is performed. The keyword @code{ORIGIN} may be |
867a1b8a | 1809 | abbreviated to @code{org} or @code{o} (but not, for example, @samp{ORG}). |
d4e5e3c3 | 1810 | |
cb70c872 RP |
1811 | @kindex LENGTH = |
1812 | @kindex len = | |
1813 | @kindex l = | |
d4e5e3c3 | 1814 | @item @var{len} |
b4d4e8e3 | 1815 | is the size in bytes of the region (an expression). |
2c5c0674 | 1816 | The keyword @code{LENGTH} may be abbreviated to @code{len} or @code{l}. |
f22eee08 RP |
1817 | @end table |
1818 | ||
1819 | For example, to specify that memory has two regions available for | |
ec40bbb8 | 1820 | allocation---one starting at 0 for 256 kilobytes, and the other |
2c5c0674 | 1821 | starting at @code{0x40000000} for four megabytes: |
f22eee08 | 1822 | |
c653b370 ILT |
1823 | @smallexample |
1824 | @group | |
b4d4e8e3 | 1825 | MEMORY |
d4e5e3c3 DM |
1826 | @{ |
1827 | rom : ORIGIN = 0, LENGTH = 256K | |
1828 | ram : org = 0x40000000, l = 4M | |
1829 | @} | |
c653b370 ILT |
1830 | @end group |
1831 | @end smallexample | |
f22eee08 | 1832 | |
b4d4e8e3 | 1833 | Once you have defined a region of memory named @var{mem}, you can direct |
2c5c0674 RP |
1834 | specific output sections there by using a command ending in |
1835 | @samp{>@var{mem}} within the @code{SECTIONS} command (@pxref{Section | |
1836 | Options}). If the combined output sections directed to a region are too | |
1837 | big for the region, the linker will issue an error message. | |
b4d4e8e3 | 1838 | |
ec40bbb8 | 1839 | @node SECTIONS |
867a1b8a | 1840 | @section Specifying Output Sections |
67c4333b | 1841 | |
2c5c0674 | 1842 | @kindex SECTIONS |
b4d4e8e3 | 1843 | The @code{SECTIONS} command controls exactly where input sections are |
867a1b8a DM |
1844 | placed into output sections, their order in the output file, and to |
1845 | which output sections they are allocated. | |
b4d4e8e3 | 1846 | |
867a1b8a | 1847 | You may use at most one @code{SECTIONS} command in a script file, |
b4d4e8e3 RP |
1848 | but you can have as many statements within it as you wish. Statements |
1849 | within the @code{SECTIONS} command can do one of three things: | |
67c4333b | 1850 | |
b4d4e8e3 RP |
1851 | @itemize @bullet |
1852 | @item | |
1853 | define the entry point; | |
67c4333b | 1854 | |
b4d4e8e3 RP |
1855 | @item |
1856 | assign a value to a symbol; | |
67c4333b | 1857 | |
b4d4e8e3 | 1858 | @item |
867a1b8a DM |
1859 | describe the placement of a named output section, and which input |
1860 | sections go into it. | |
b4d4e8e3 RP |
1861 | @end itemize |
1862 | ||
8920addc RP |
1863 | You can also use the first two operations---defining the entry point and |
1864 | defining symbols---outside the @code{SECTIONS} command: @pxref{Entry | |
baaaf6f2 | 1865 | Point}, and @ref{Assignment}. They are permitted here as well for |
8920addc RP |
1866 | your convenience in reading the script, so that symbols and the entry |
1867 | point can be defined at meaningful points in your output-file layout. | |
f22eee08 | 1868 | |
67c4333b | 1869 | If you do not use a @code{SECTIONS} command, the linker places each input |
867a1b8a DM |
1870 | section into an identically named output section in the order that the |
1871 | sections are first encountered in the input files. If all input sections | |
1872 | are present in the first file, for example, the order of sections in the | |
1873 | output file will match the order in the first input file. | |
b4d4e8e3 | 1874 | |
2c5c0674 | 1875 | @menu |
2d59b2c3 | 1876 | * Section Definition:: Section Definitions |
867a1b8a DM |
1877 | * Section Placement:: Section Placement |
1878 | * Section Data Expressions:: Section Data Expressions | |
2d59b2c3 | 1879 | * Section Options:: Optional Section Attributes |
b61364cc | 1880 | * Overlays:: Overlays |
2c5c0674 RP |
1881 | @end menu |
1882 | ||
ec40bbb8 | 1883 | @node Section Definition |
b4d4e8e3 | 1884 | @subsection Section Definitions |
2c5c0674 | 1885 | @cindex section definition |
b4d4e8e3 | 1886 | The most frequently used statement in the @code{SECTIONS} command is |
867a1b8a | 1887 | the @dfn{section definition}, which specifies the |
b4d4e8e3 | 1888 | properties of an output section: its location, alignment, contents, |
ec40bbb8 | 1889 | fill pattern, and target memory region. Most of |
b4d4e8e3 RP |
1890 | these specifications are optional; the simplest form of a section |
1891 | definition is | |
c653b370 | 1892 | @smallexample |
2c5c0674 | 1893 | SECTIONS @{ @dots{} |
d4e5e3c3 DM |
1894 | @var{secname} : @{ |
1895 | @var{contents} | |
1896 | @} | |
2c5c0674 | 1897 | @dots{} @} |
c653b370 | 1898 | @end smallexample |
2c5c0674 | 1899 | @cindex naming output sections |
b4d4e8e3 RP |
1900 | @noindent |
1901 | @var{secname} is the name of the output section, and @var{contents} a | |
ec40bbb8 | 1902 | specification of what goes there---for example, a list of input files or |
867a1b8a DM |
1903 | sections of input files (@pxref{Section Placement}). As you might |
1904 | assume, the whitespace shown is optional. You do need the colon | |
1905 | @samp{:} and the braces @samp{@{@}}, however. | |
b4d4e8e3 RP |
1906 | |
1907 | @var{secname} must meet the constraints of your output format. In | |
1908 | formats which only support a limited number of sections, such as | |
1909 | @code{a.out}, the name must be one of the names supported by the format | |
2c5c0674 RP |
1910 | (@code{a.out}, for example, allows only @code{.text}, @code{.data} or |
1911 | @code{.bss}). If the output format supports any number of sections, but | |
1912 | with numbers and not names (as is the case for Oasys), the name should be | |
1913 | supplied as a quoted numeric string. A section name may consist of any | |
867a1b8a | 1914 | sequence of characters, but any name which does not conform to the standard |
246504a5 | 1915 | @code{ld} symbol name syntax must be quoted. |
ec40bbb8 | 1916 | @xref{Symbols, , Symbol Names}. |
2c5c0674 | 1917 | |
cf2e4f5f ILT |
1918 | The special @var{secname} @samp{/DISCARD/} may be used to discard input |
1919 | sections. Any sections which are assigned to an output section named | |
1920 | @samp{/DISCARD/} are not included in the final link output. | |
1921 | ||
f9d3d71a ILT |
1922 | The linker will not create output sections which do not have any |
1923 | contents. This is for convenience when referring to input sections that | |
1924 | may or may not exist. For example, | |
c653b370 ILT |
1925 | @smallexample |
1926 | .foo @{ *(.foo) @} | |
1927 | @end smallexample | |
f9d3d71a ILT |
1928 | will only create a @samp{.foo} section in the output file if there is a |
1929 | @samp{.foo} section in at least one input file. | |
1930 | ||
867a1b8a DM |
1931 | @node Section Placement |
1932 | @subsection Section Placement | |
67c4333b | 1933 | |
2c5c0674 | 1934 | @cindex contents of a section |
67c4333b RP |
1935 | In a section definition, you can specify the contents of an output |
1936 | section by listing particular input files, by listing particular | |
1937 | input-file sections, or by a combination of the two. You can also place | |
1938 | arbitrary data in the section, and define symbols relative to the | |
1939 | beginning of the section. | |
b4d4e8e3 RP |
1940 | |
1941 | The @var{contents} of a section definition may include any of the | |
1942 | following kinds of statement. You can include as many of these as you | |
1943 | like in a single section definition, separated from one another by | |
86bc0974 | 1944 | whitespace. |
f22eee08 | 1945 | |
b4d4e8e3 | 1946 | @table @code |
2c5c0674 RP |
1947 | @kindex @var{filename} |
1948 | @cindex input files, section defn | |
1949 | @cindex files, including in output sections | |
d4e5e3c3 | 1950 | @item @var{filename} |
b4d4e8e3 | 1951 | You may simply name a particular input file to be placed in the current |
2c5c0674 | 1952 | output section; @emph{all} sections from that file are placed in the |
867a1b8a DM |
1953 | current section definition. If the file name has already been mentioned |
1954 | in another section definition, with an explicit section name list, then | |
1955 | only those sections which have not yet been allocated are used. | |
1956 | ||
1957 | To specify a list of particular files by name: | |
c653b370 | 1958 | @smallexample |
cb70c872 | 1959 | .data : @{ afile.o bfile.o cfile.o @} |
c653b370 | 1960 | @end smallexample |
2c5c0674 RP |
1961 | @noindent |
1962 | The example also illustrates that multiple statements can be included in | |
ec40bbb8 | 1963 | the contents of a section definition, since each file name is a separate |
2c5c0674 | 1964 | statement. |
f22eee08 | 1965 | |
d4e5e3c3 DM |
1966 | @kindex @var{filename}(@var{section}) |
1967 | @cindex files and sections, section defn | |
2c5c0674 | 1968 | @item @var{filename}( @var{section} ) |
4fea1383 | 1969 | @itemx @var{filename}( @var{section} , @var{section}, @dots{} ) |
2c5c0674 | 1970 | @itemx @var{filename}( @var{section} @var{section} @dots{} ) |
2c5c0674 RP |
1971 | You can name one or more sections from your input files, for |
1972 | insertion in the current output section. If you wish to specify a list | |
1973 | of input-file sections inside the parentheses, you may separate the | |
1974 | section names by either commas or whitespace. | |
1975 | ||
d4e5e3c3 DM |
1976 | @cindex input sections to output section |
1977 | @kindex *(@var{section}) | |
b4d4e8e3 RP |
1978 | @item * (@var{section}) |
1979 | @itemx * (@var{section}, @var{section}, @dots{}) | |
836a5ee4 | 1980 | @itemx * (@var{section} @var{section} @dots{}) |
b4d4e8e3 | 1981 | Instead of explicitly naming particular input files in a link control |
246504a5 | 1982 | script, you can refer to @emph{all} files from the @code{ld} command |
ec40bbb8 | 1983 | line: use @samp{*} instead of a particular file name before the |
b4d4e8e3 RP |
1984 | parenthesized input-file section list. |
1985 | ||
867a1b8a DM |
1986 | If you have already explicitly included some files by name, @samp{*} |
1987 | refers to all @emph{remaining} files---those whose places in the output | |
1988 | file have not yet been defined. | |
1989 | ||
ec40bbb8 | 1990 | For example, to copy sections @code{1} through @code{4} from an Oasys file |
b4d4e8e3 RP |
1991 | into the @code{.text} section of an @code{a.out} file, and sections @code{13} |
1992 | and @code{14} into the @code{.data} section: | |
c653b370 ILT |
1993 | @smallexample |
1994 | @group | |
2c5c0674 | 1995 | SECTIONS @{ |
d4e5e3c3 DM |
1996 | .text :@{ |
1997 | *("1" "2" "3" "4") | |
1998 | @} | |
1999 | ||
2000 | .data :@{ | |
2001 | *("13" "14") | |
2002 | @} | |
b4d4e8e3 | 2003 | @} |
c653b370 ILT |
2004 | @end group |
2005 | @end smallexample | |
f22eee08 | 2006 | |
d4e5e3c3 | 2007 | @cindex @code{[@var{section}@dots{}]}, not supported |
836a5ee4 DM |
2008 | @samp{[ @var{section} @dots{} ]} used to be accepted as an alternate way |
2009 | to specify named sections from all unallocated input files. Because | |
2010 | some operating systems (VMS) allow brackets in file names, that notation | |
2011 | is no longer supported. | |
2012 | ||
2c5c0674 RP |
2013 | @cindex uninitialized data |
2014 | @cindex commons in output | |
d4e5e3c3 DM |
2015 | @kindex *( COMMON ) |
2016 | @item @var{filename}@code{( COMMON )} | |
2017 | @itemx *( COMMON ) | |
b4d4e8e3 | 2018 | Specify where in your output file to place uninitialized data |
d76ae847 | 2019 | with this notation. @code{*(COMMON)} by itself refers to all |
b4d4e8e3 RP |
2020 | uninitialized data from all input files (so far as it is not yet |
2021 | allocated); @var{filename}@code{(COMMON)} refers to uninitialized data | |
2022 | from a particular file. Both are special cases of the general | |
2023 | mechanisms for specifying where to place input-file sections: | |
246504a5 | 2024 | @code{ld} permits you to refer to uninitialized data as if it |
b4d4e8e3 RP |
2025 | were in an input-file section named @code{COMMON}, regardless of the |
2026 | input file's format. | |
2027 | @end table | |
2028 | ||
86bc0974 | 2029 | In any place where you may use a specific file or section name, you may |
c2ba3684 ILT |
2030 | also use a wildcard pattern. The linker handles wildcards much as the |
2031 | Unix shell does. A @samp{*} character matches any number of characters. | |
2032 | A @samp{?} character matches any single character. The sequence | |
2033 | @samp{[@var{chars}]} will match a single instance of any of the | |
86bc0974 ILT |
2034 | @var{chars}; the @samp{-} character may be used to specify a range of |
2035 | characters, as in @samp{[a-z]} to match any lower case letter. A | |
2036 | @samp{\} character may be used to quote the following character. | |
2037 | ||
c2ba3684 ILT |
2038 | When a file name is matched with a wildcard, the wildcard characters |
2039 | will not match a @samp{/} character (used to separate directory names on | |
86bc0974 | 2040 | Unix). A pattern consisting of a single @samp{*} character is an |
c2ba3684 ILT |
2041 | exception; it will always match any file name. In a section name, the |
2042 | wildcard characters will match a @samp{/} character. | |
2043 | ||
2044 | Wildcards only match files which are explicitly specified on the command | |
2045 | line. The linker does not search directories to expand wildcards. | |
2046 | However, if you specify a simple file name---a name with no wildcard | |
2047 | characters---in a linker script, and the file name is not also specified | |
2048 | on the command line, the linker will attempt to open the file as though | |
2049 | it appeared on the command line. | |
86bc0974 ILT |
2050 | |
2051 | In the following example, the command script arranges the output file | |
2052 | into three consecutive sections, named @code{.text}, @code{.data}, and | |
b4d4e8e3 RP |
2053 | @code{.bss}, taking the input for each from the correspondingly named |
2054 | sections of all the input files: | |
d4e5e3c3 | 2055 | |
c653b370 ILT |
2056 | @smallexample |
2057 | @group | |
2c5c0674 | 2058 | SECTIONS @{ |
d76ae847 RP |
2059 | .text : @{ *(.text) @} |
2060 | .data : @{ *(.data) @} | |
2061 | .bss : @{ *(.bss) *(COMMON) @} | |
2c5c0674 | 2062 | @} |
c653b370 ILT |
2063 | @end group |
2064 | @end smallexample | |
b4d4e8e3 RP |
2065 | |
2066 | The following example reads all of the sections from file @code{all.o} | |
2067 | and places them at the start of output section @code{outputa} which | |
2068 | starts at location @code{0x10000}. All of section @code{.input1} from | |
2069 | file @code{foo.o} follows immediately, in the same output section. All | |
2070 | of section @code{.input2} from @code{foo.o} goes into output section | |
2071 | @code{outputb}, followed by section @code{.input1} from @code{foo1.o}. | |
2072 | All of the remaining @code{.input1} and @code{.input2} sections from any | |
2073 | files are written to output section @code{outputc}. | |
2074 | ||
c653b370 ILT |
2075 | @smallexample |
2076 | @group | |
2c5c0674 | 2077 | SECTIONS @{ |
d4e5e3c3 DM |
2078 | outputa 0x10000 : |
2079 | @{ | |
2080 | all.o | |
2081 | foo.o (.input1) | |
2082 | @} | |
2083 | outputb : | |
2084 | @{ | |
2085 | foo.o (.input2) | |
2086 | foo1.o (.input1) | |
2087 | @} | |
2088 | outputc : | |
2089 | @{ | |
2090 | *(.input1) | |
2091 | *(.input2) | |
2092 | @} | |
2c5c0674 | 2093 | @} |
c653b370 ILT |
2094 | @end group |
2095 | @end smallexample | |
b4d4e8e3 | 2096 | |
86bc0974 ILT |
2097 | This example shows how wildcard patterns might be used to partition |
2098 | files. All @code{.text} sections are placed in @code{.text}, and all | |
2099 | @code{.bss} sections are placed in @code{.bss}. For all files beginning | |
2100 | with an upper case character, the @code{.data} section is placed into | |
2101 | @code{.DATA}; for all other files, the @code{.data} section is placed | |
2102 | into @code{.data}. | |
2103 | ||
2104 | @smallexample | |
2105 | @group | |
2106 | SECTIONS @{ | |
2107 | .text : @{ *(.text) @} | |
2108 | .DATA : @{ [A-Z]*(.data) @} | |
2109 | .data : @{ *(.data) @} | |
2110 | .bss : @{ *(.bss) @} | |
2111 | @} | |
2112 | @end group | |
2113 | @end smallexample | |
2114 | ||
867a1b8a DM |
2115 | @node Section Data Expressions |
2116 | @subsection Section Data Expressions | |
67c4333b | 2117 | |
867a1b8a | 2118 | @cindex expressions in a section |
67c4333b RP |
2119 | The foregoing statements arrange, in your output file, data originating |
2120 | from your input files. You can also place data directly in an output | |
2121 | section from the link command script. Most of these additional | |
baaaf6f2 | 2122 | statements involve expressions (@pxref{Expressions}). Although these |
67c4333b RP |
2123 | statements are shown separately here for ease of presentation, no such |
2124 | segregation is needed within a section definition in the @code{SECTIONS} | |
2125 | command; you can intermix them freely with any of the statements we've | |
2126 | just described. | |
f22eee08 | 2127 | |
b4d4e8e3 | 2128 | @table @code |
2c5c0674 RP |
2129 | @cindex input filename symbols |
2130 | @cindex filename symbols | |
d4e5e3c3 DM |
2131 | @kindex CREATE_OBJECT_SYMBOLS |
2132 | @item CREATE_OBJECT_SYMBOLS | |
ec40bbb8 DM |
2133 | Create a symbol for each input file |
2134 | in the current section, set to the address of the first byte of | |
867a1b8a | 2135 | data written from that input file. For instance, with @code{a.out} |
b4d4e8e3 RP |
2136 | files it is conventional to have a symbol for each input file. You can |
2137 | accomplish this by defining the output @code{.text} section as follows: | |
c653b370 ILT |
2138 | @smallexample |
2139 | @group | |
b4d4e8e3 | 2140 | SECTIONS @{ |
d4e5e3c3 DM |
2141 | .text 0x2020 : |
2142 | @{ | |
2143 | CREATE_OBJECT_SYMBOLS | |
2144 | *(.text) | |
2145 | _etext = ALIGN(0x2000); | |
2146 | @} | |
2147 | @dots{} | |
2c5c0674 | 2148 | @} |
c653b370 ILT |
2149 | @end group |
2150 | @end smallexample | |
b4d4e8e3 | 2151 | |
867a1b8a | 2152 | If @code{sample.ld} is a file containing this script, and @code{a.o}, |
b4d4e8e3 RP |
2153 | @code{b.o}, @code{c.o}, and @code{d.o} are four input files with |
2154 | contents like the following--- | |
c653b370 ILT |
2155 | @smallexample |
2156 | @group | |
b4d4e8e3 RP |
2157 | /* a.c */ |
2158 | ||
2c5c0674 | 2159 | afunction() @{ @} |
b4d4e8e3 RP |
2160 | int adata=1; |
2161 | int abss; | |
c653b370 ILT |
2162 | @end group |
2163 | @end smallexample | |
f22eee08 | 2164 | |
b4d4e8e3 | 2165 | @noindent |
867a1b8a | 2166 | @samp{ld -M -T sample.ld a.o b.o c.o d.o} would create a map like this, |
b4d4e8e3 | 2167 | containing symbols matching the object file names: |
c653b370 | 2168 | @smallexample |
f22eee08 RP |
2169 | 00000000 A __DYNAMIC |
2170 | 00004020 B _abss | |
2171 | 00004000 D _adata | |
2172 | 00002020 T _afunction | |
2173 | 00004024 B _bbss | |
2174 | 00004008 D _bdata | |
2175 | 00002038 T _bfunction | |
2176 | 00004028 B _cbss | |
2177 | 00004010 D _cdata | |
2178 | 00002050 T _cfunction | |
2179 | 0000402c B _dbss | |
2180 | 00004018 D _ddata | |
2181 | 00002068 T _dfunction | |
2182 | 00004020 D _edata | |
2183 | 00004030 B _end | |
2184 | 00004000 T _etext | |
2185 | 00002020 t a.o | |
2186 | 00002038 t b.o | |
2187 | 00002050 t c.o | |
2188 | 00002068 t d.o | |
c653b370 | 2189 | @end smallexample |
f22eee08 | 2190 | |
2c5c0674 | 2191 | @kindex @var{symbol} = @var{expression} ; |
2c5c0674 | 2192 | @kindex @var{symbol} @var{f}= @var{expression} ; |
d4e5e3c3 DM |
2193 | @item @var{symbol} = @var{expression} ; |
2194 | @itemx @var{symbol} @var{f}= @var{expression} ; | |
2c5c0674 RP |
2195 | @var{symbol} is any symbol name (@pxref{Symbols}). ``@var{f}='' |
2196 | refers to any of the operators @code{&= += -= *= /=} which combine | |
2197 | arithmetic and assignment. | |
2198 | ||
2199 | @cindex assignment, in section defn | |
2200 | When you assign a value to a symbol within a particular section | |
2201 | definition, the value is relative to the beginning of the section | |
2202 | (@pxref{Assignment}). If you write | |
d4e5e3c3 | 2203 | |
c653b370 ILT |
2204 | @smallexample |
2205 | @group | |
2c5c0674 | 2206 | SECTIONS @{ |
b4d4e8e3 | 2207 | abs = 14 ; |
2c5c0674 | 2208 | @dots{} |
cb70c872 | 2209 | .data : @{ @dots{} rel = 14 ; @dots{} @} |
b4d4e8e3 | 2210 | abs2 = 14 + ADDR(.data); |
2c5c0674 RP |
2211 | @dots{} |
2212 | @} | |
c653b370 ILT |
2213 | @end group |
2214 | @end smallexample | |
d4e5e3c3 | 2215 | |
2c5c0674 | 2216 | @c FIXME: Try above example! |
b4d4e8e3 | 2217 | @noindent |
ec40bbb8 | 2218 | @code{abs} and @code{rel} do not have the same value; @code{rel} has the |
b4d4e8e3 RP |
2219 | same value as @code{abs2}. |
2220 | ||
2c5c0674 | 2221 | @kindex BYTE(@var{expression}) |
2c5c0674 | 2222 | @kindex SHORT(@var{expression}) |
2c5c0674 | 2223 | @kindex LONG(@var{expression}) |
c477527c | 2224 | @kindex QUAD(@var{expression}) |
2c5c0674 | 2225 | @cindex direct output |
d4e5e3c3 DM |
2226 | @item BYTE(@var{expression}) |
2227 | @itemx SHORT(@var{expression}) | |
2228 | @itemx LONG(@var{expression}) | |
2229 | @itemx QUAD(@var{expression}) | |
c477527c ILT |
2230 | By including one of these four statements in a section definition, you |
2231 | can explicitly place one, two, four, or eight bytes (respectively) at | |
2232 | the current address of that section. @code{QUAD} is only supported when | |
2233 | using a 64 bit host or target. | |
ec40bbb8 DM |
2234 | |
2235 | @ifclear SingleFormat | |
2236 | Multiple-byte quantities are represented in whatever byte order is | |
2237 | appropriate for the output file format (@pxref{BFD}). | |
2238 | @end ifclear | |
b4d4e8e3 | 2239 | |
2c5c0674 RP |
2240 | @kindex FILL(@var{expression}) |
2241 | @cindex holes, filling | |
2242 | @cindex unspecified memory | |
c653b370 | 2243 | @item FILL(@var{expression}) |
867a1b8a | 2244 | Specify the ``fill pattern'' for the current section. Any otherwise |
b4d4e8e3 RP |
2245 | unspecified regions of memory within the section (for example, regions |
2246 | you skip over by assigning a new value to the location counter @samp{.}) | |
2247 | are filled with the two least significant bytes from the | |
2248 | @var{expression} argument. A @code{FILL} statement covers memory | |
2249 | locations @emph{after} the point it occurs in the section definition; by | |
2250 | including more than one @code{FILL} statement, you can have different | |
2251 | fill patterns in different parts of an output section. | |
2252 | @end table | |
2253 | ||
ec40bbb8 | 2254 | @node Section Options |
b4d4e8e3 | 2255 | @subsection Optional Section Attributes |
2c5c0674 | 2256 | @cindex section defn, full syntax |
b4d4e8e3 RP |
2257 | Here is the full syntax of a section definition, including all the |
2258 | optional portions: | |
2259 | ||
d76ae847 | 2260 | @smallexample |
c653b370 | 2261 | @group |
2c5c0674 RP |
2262 | SECTIONS @{ |
2263 | @dots{} | |
67c4333b | 2264 | @var{secname} @var{start} BLOCK(@var{align}) (NOLOAD) : AT ( @var{ldadr} ) |
c653b370 | 2265 | @{ @var{contents} @} >@var{region} :@var{phdr} =@var{fill} |
2c5c0674 | 2266 | @dots{} |
b4d4e8e3 | 2267 | @} |
c653b370 | 2268 | @end group |
d76ae847 | 2269 | @end smallexample |
b4d4e8e3 RP |
2270 | |
2271 | @var{secname} and @var{contents} are required. @xref{Section | |
baaaf6f2 | 2272 | Definition}, and @ref{Section Placement}, for details on |
67c4333b RP |
2273 | @var{contents}. The remaining elements---@var{start}, |
2274 | @code{BLOCK(@var{align)}}, @code{(NOLOAD)}, @code{AT ( @var{ldadr} )}, | |
c653b370 ILT |
2275 | @code{>@var{region}}, @code{:@var{phdr}}, and @code{=@var{fill}}---are |
2276 | all optional. | |
f22eee08 | 2277 | |
b4d4e8e3 | 2278 | @table @code |
2c5c0674 RP |
2279 | @cindex start address, section |
2280 | @cindex section start | |
2281 | @cindex section address | |
d4e5e3c3 | 2282 | @item @var{start} |
b4d4e8e3 RP |
2283 | You can force the output section to be loaded at a specified address by |
2284 | specifying @var{start} immediately following the section name. | |
2285 | @var{start} can be represented as any expression. The following | |
2286 | example generates section @var{output} at location | |
2287 | @code{0x40000000}: | |
d4e5e3c3 | 2288 | |
c653b370 ILT |
2289 | @smallexample |
2290 | @group | |
b4d4e8e3 | 2291 | SECTIONS @{ |
d4e5e3c3 DM |
2292 | @dots{} |
2293 | output 0x40000000: @{ | |
2294 | @dots{} | |
2295 | @} | |
2296 | @dots{} | |
b4d4e8e3 | 2297 | @} |
c653b370 ILT |
2298 | @end group |
2299 | @end smallexample | |
f22eee08 | 2300 | |
2c5c0674 RP |
2301 | @kindex BLOCK(@var{align}) |
2302 | @cindex section alignment | |
2303 | @cindex aligning sections | |
d4e5e3c3 | 2304 | @item BLOCK(@var{align}) |
ec40bbb8 | 2305 | You can include @code{BLOCK()} specification to advance |
2c5c0674 RP |
2306 | the location counter @code{.} prior to the beginning of the section, so |
2307 | that the section will begin at the specified alignment. @var{align} is | |
2308 | an expression. | |
f22eee08 | 2309 | |
d76ae847 RP |
2310 | @kindex NOLOAD |
2311 | @cindex prevent unnecessary loading | |
67c4333b RP |
2312 | @cindex loading, preventing |
2313 | @item (NOLOAD) | |
d76ae847 RP |
2314 | Use @samp{(NOLOAD)} to prevent a section from being loaded into memory |
2315 | each time it is accessed. For example, in the script sample below, the | |
2316 | @code{ROM} segment is addressed at memory location @samp{0} and does not | |
2317 | need to be loaded into each object file: | |
67c4333b | 2318 | |
c653b370 ILT |
2319 | @smallexample |
2320 | @group | |
d76ae847 | 2321 | SECTIONS @{ |
d4e5e3c3 DM |
2322 | ROM 0 (NOLOAD) : @{ @dots{} @} |
2323 | @dots{} | |
d76ae847 | 2324 | @} |
c653b370 ILT |
2325 | @end group |
2326 | @end smallexample | |
d76ae847 | 2327 | |
67c4333b RP |
2328 | @kindex AT ( @var{ldadr} ) |
2329 | @cindex specify load address | |
2330 | @cindex load address, specifying | |
2331 | @item AT ( @var{ldadr} ) | |
2332 | The expression @var{ldadr} that follows the @code{AT} keyword specifies | |
2333 | the load address of the section. The default (if you do not use the | |
2334 | @code{AT} keyword) is to make the load address the same as the | |
2335 | relocation address. This feature is designed to make it easy to build a | |
2336 | ROM image. For example, this @code{SECTIONS} definition creates two | |
2337 | output sections: one called @samp{.text}, which starts at @code{0x1000}, | |
2338 | and one called @samp{.mdata}, which is loaded at the end of the | |
2339 | @samp{.text} section even though its relocation address is | |
2340 | @code{0x2000}. The symbol @code{_data} is defined with the value | |
2341 | @code{0x2000}: | |
2342 | ||
2343 | @smallexample | |
c653b370 | 2344 | @group |
67c4333b | 2345 | SECTIONS |
139c8857 RP |
2346 | @{ |
2347 | .text 0x1000 : @{ *(.text) _etext = . ; @} | |
2348 | .mdata 0x2000 : | |
2349 | AT ( ADDR(.text) + SIZEOF ( .text ) ) | |
2350 | @{ _data = . ; *(.data); _edata = . ; @} | |
2351 | .bss 0x3000 : | |
2352 | @{ _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;@} | |
67c4333b | 2353 | @} |
c653b370 | 2354 | @end group |
67c4333b RP |
2355 | @end smallexample |
2356 | ||
2357 | The run-time initialization code (for C programs, usually @code{crt0}) | |
2358 | for use with a ROM generated this way has to include something like | |
2359 | the following, to copy the initialized data from the ROM image to its runtime | |
2360 | address: | |
2361 | ||
139c8857 | 2362 | @smallexample |
c653b370 | 2363 | @group |
67c4333b RP |
2364 | char *src = _etext; |
2365 | char *dst = _data; | |
2366 | ||
139c8857 | 2367 | /* ROM has data at end of text; copy it. */ |
67c4333b | 2368 | while (dst < _edata) @{ |
139c8857 | 2369 | *dst++ = *src++; |
67c4333b RP |
2370 | @} |
2371 | ||
2372 | /* Zero bss */ | |
2373 | for (dst = _bstart; dst< _bend; dst++) | |
139c8857 | 2374 | *dst = 0; |
c653b370 | 2375 | @end group |
139c8857 | 2376 | @end smallexample |
67c4333b | 2377 | |
f9d3d71a ILT |
2378 | @kindex >@var{region} |
2379 | @cindex section, assigning to memory region | |
2380 | @cindex memory regions and sections | |
2381 | @item >@var{region} | |
2382 | Assign this section to a previously defined region of memory. | |
2383 | @xref{MEMORY}. | |
2384 | ||
c653b370 ILT |
2385 | @kindex :@var{phdr} |
2386 | @cindex section, assigning to program header | |
2387 | @cindex program headers and sections | |
2388 | @item :@var{phdr} | |
2389 | Assign this section to a segment described by a program header. | |
baaaf6f2 | 2390 | @xref{PHDRS}. If a section is assigned to one or more segments, then |
c653b370 ILT |
2391 | all subsequent allocated sections will be assigned to those segments as |
2392 | well, unless they use an explicitly @code{:@var{phdr}} modifier. To | |
2393 | prevent a section from being assigned to a segment when it would | |
2394 | normally default to one, use @code{:NONE}. | |
2395 | ||
2c5c0674 RP |
2396 | @kindex =@var{fill} |
2397 | @cindex section fill pattern | |
2398 | @cindex fill pattern, entire section | |
d4e5e3c3 DM |
2399 | @item =@var{fill} |
2400 | Including @code{=@var{fill}} in a section definition specifies the | |
2401 | initial fill value for that section. You may use any expression to | |
2402 | specify @var{fill}. Any unallocated holes in the current output section | |
2403 | when written to the output file will be filled with the two least | |
2404 | significant bytes of the value, repeated as necessary. You can also | |
2405 | change the fill value with a @code{FILL} statement in the @var{contents} | |
2406 | of a section definition. | |
f22eee08 | 2407 | |
f22eee08 | 2408 | @end table |
b4d4e8e3 | 2409 | |
b61364cc ILT |
2410 | @node Overlays |
2411 | @subsection Overlays | |
2412 | @kindex OVERLAY | |
2413 | @cindex overlays | |
2414 | ||
2415 | The @code{OVERLAY} command provides an easy way to describe sections | |
2416 | which are to be loaded as part of a single memory image but are to be | |
2417 | run at the same memory address. At run time, some sort of overlay | |
2418 | manager will copy the overlaid sections in and out of the runtime memory | |
2419 | address as required, perhaps by simply manipulating addressing bits. | |
2420 | This approach can be useful, for example, when a certain region of | |
2421 | memory is faster than another. | |
2422 | ||
2423 | The @code{OVERLAY} command is used within a @code{SECTIONS} command. It | |
2424 | appears as follows: | |
2425 | @smallexample | |
2426 | @group | |
2427 | OVERLAY @var{start} : [ NOCROSSREFS ] AT ( @var{ldaddr} ) | |
2428 | @{ | |
2429 | @var{secname1} @{ @var{contents} @} :@var{phdr} =@var{fill} | |
2430 | @var{secname2} @{ @var{contents} @} :@var{phdr} =@var{fill} | |
2431 | @dots{} | |
2432 | @} >@var{region} :@var{phdr} =@var{fill} | |
2433 | @end group | |
2434 | @end smallexample | |
2435 | ||
2436 | Everything is optional except @code{OVERLAY} (a keyword), and each | |
2437 | section must have a name (@var{secname1} and @var{secname2} above). The | |
2438 | section definitions within the @code{OVERLAY} construct are identical to | |
2439 | those within the general @code{SECTIONS} contruct (@pxref{SECTIONS}), | |
2440 | except that no addresses and no memory regions may be defined for | |
2441 | sections within an @code{OVERLAY}. | |
2442 | ||
2443 | The sections are all defined with the same starting address. The load | |
2444 | addresses of the sections are arranged such that they are consecutive in | |
2445 | memory starting at the load address used for the @code{OVERLAY} as a | |
2446 | whole (as with normal section definitions, the load address is optional, | |
2447 | and defaults to the start address; the start address is also optional, | |
2448 | and defaults to @code{.}). | |
2449 | ||
2450 | If the @code{NOCROSSREFS} keyword is used, and there any references | |
2451 | among the sections, the linker will report an error. Since the sections | |
2452 | all run at the same address, it normally does not make sense for one | |
2453 | section to refer directly to another. @xref{Option Commands, | |
2454 | NOCROSSREFS}. | |
2455 | ||
2456 | For each section within the @code{OVERLAY}, the linker automatically | |
2457 | defines two symbols. The symbol @code{__load_start_@var{secname}} is | |
2458 | defined as the starting load address of the section. The symbol | |
2459 | @code{__load_stop_@var{secname}} is defined as the final load address of | |
2460 | the section. Any characters within @var{secname} which are not legal | |
2461 | within C identifiers are removed. C (or assembler) code may use these | |
2462 | symbols to move the overlaid sections around as necessary. | |
2463 | ||
2464 | At the end of the overlay, the value of @code{.} is set to the start | |
2465 | address of the overlay plus the size of the largest section. | |
2466 | ||
2467 | Here is an example. Remember that this would appear inside a | |
2468 | @code{SECTIONS} construct. | |
2469 | ||
2470 | @smallexample | |
2471 | @group | |
2472 | OVERLAY 0x1000 : AT (0x4000) | |
2473 | @{ | |
2474 | .text0 @{ o1/*.o(.text) @} | |
2475 | .text1 @{ o2/*.o(.text) @} | |
2476 | @} | |
2477 | @end group | |
2478 | @end smallexample | |
2479 | ||
2480 | This will define both @code{.text0} and @code{.text1} to start at | |
2481 | address 0x1000. @code{.text0} will be loaded at address 0x4000, and | |
2482 | @code{.text1} will be loaded immediately after @code{.text0}. The | |
2483 | following symbols will be defined: @code{__load_start_text0}, | |
2484 | @code{__load_stop_text0}, @code{__load_start_text1}, | |
2485 | @code{__load_stop_text1}. | |
2486 | ||
2487 | C code to copy overlay @code{.text1} into the overlay area might look | |
2488 | like the following. | |
2489 | ||
2490 | @smallexample | |
2491 | @group | |
2492 | extern char __load_start_text1, __load_stop_text1; | |
2493 | memcpy ((char *) 0x1000, &__load_start_text1, | |
2494 | &__load_stop_text1 - &__load_start_text1); | |
2495 | @end group | |
2496 | @end smallexample | |
2497 | ||
2498 | Note that the @code{OVERLAY} command is just syntactic sugar, since | |
2499 | everything it does can be done using the more basic commands. The above | |
2500 | example could have been written identically as follows. | |
2501 | ||
2502 | @smallexample | |
2503 | @group | |
2504 | .text0 0x1000 : AT (0x4000) @{ o1/*.o(.text) @} | |
2505 | __load_start_text0 = LOADADDR (.text0); | |
2506 | __load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0); | |
2507 | .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) @{ o2/*.o(.text) @} | |
2508 | __load_start_text1 = LOADADDR (.text1); | |
2509 | __load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1); | |
2510 | . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1)); | |
2511 | @end group | |
2512 | @end smallexample | |
2513 | ||
c653b370 ILT |
2514 | @node PHDRS |
2515 | @section ELF Program Headers | |
2516 | @kindex PHDRS | |
b61364cc ILT |
2517 | @cindex program headers |
2518 | @cindex ELF program headers | |
c653b370 ILT |
2519 | |
2520 | The ELF object file format uses @dfn{program headers}, which are read by | |
2521 | the system loader and describe how the program should be loaded into | |
2522 | memory. These program headers must be set correctly in order to run the | |
2523 | program on a native ELF system. The linker will create reasonable | |
2524 | program headers by default. However, in some cases, it is desirable to | |
2525 | specify the program headers more precisely; the @code{PHDRS} command may | |
2526 | be used for this purpose. When the @code{PHDRS} command is used, the | |
2527 | linker will not generate any program headers itself. | |
2528 | ||
2529 | The @code{PHDRS} command is only meaningful when generating an ELF | |
2530 | output file. It is ignored in other cases. This manual does not | |
2531 | describe the details of how the system loader interprets program | |
2532 | headers; for more information, see the ELF ABI. The program headers of | |
2533 | an ELF file may be displayed using the @samp{-p} option of the | |
2534 | @code{objdump} command. | |
2535 | ||
2536 | This is the syntax of the @code{PHDRS} command. The words @code{PHDRS}, | |
2537 | @code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords. | |
2538 | ||
2539 | @smallexample | |
2540 | @group | |
2541 | PHDRS | |
2542 | @{ | |
2543 | @var{name} @var{type} [ FILEHDR ] [ PHDRS ] [ AT ( @var{address} ) ] | |
2544 | [ FLAGS ( @var{flags} ) ] ; | |
2545 | @} | |
2546 | @end group | |
2547 | @end smallexample | |
2548 | ||
2549 | The @var{name} is used only for reference in the @code{SECTIONS} command | |
2550 | of the linker script. It does not get put into the output file. | |
2551 | ||
2552 | Certain program header types describe segments of memory which are | |
2553 | loaded from the file by the system loader. In the linker script, the | |
2554 | contents of these segments are specified by directing allocated output | |
2555 | sections to be placed in the segment. To do this, the command | |
2556 | describing the output section in the @code{SECTIONS} command should use | |
2557 | @samp{:@var{name}}, where @var{name} is the name of the program header | |
2558 | as it appears in the @code{PHDRS} command. @xref{Section Options}. | |
2559 | ||
2560 | It is normal for certain sections to appear in more than one segment. | |
2561 | This merely implies that one segment of memory contains another. This | |
2562 | is specified by repeating @samp{:@var{name}}, using it once for each | |
2563 | program header in which the section is to appear. | |
2564 | ||
2565 | If a section is placed in one or more segments using @samp{:@var{name}}, | |
2566 | then all subsequent allocated sections which do not specify | |
2567 | @samp{:@var{name}} are placed in the same segments. This is for | |
2568 | convenience, since generally a whole set of contiguous sections will be | |
2569 | placed in a single segment. To prevent a section from being assigned to | |
2570 | a segment when it would normally default to one, use @code{:NONE}. | |
2571 | ||
2572 | The @code{FILEHDR} and @code{PHDRS} keywords which may appear after the | |
2573 | program header type also indicate contents of the segment of memory. | |
2574 | The @code{FILEHDR} keyword means that the segment should include the ELF | |
2575 | file header. The @code{PHDRS} keyword means that the segment should | |
2576 | include the ELF program headers themselves. | |
2577 | ||
2578 | The @var{type} may be one of the following. The numbers indicate the | |
2579 | value of the keyword. | |
2580 | ||
2581 | @table @asis | |
2582 | @item @code{PT_NULL} (0) | |
2583 | Indicates an unused program header. | |
2584 | ||
2585 | @item @code{PT_LOAD} (1) | |
2586 | Indicates that this program header describes a segment to be loaded from | |
2587 | the file. | |
2588 | ||
2589 | @item @code{PT_DYNAMIC} (2) | |
2590 | Indicates a segment where dynamic linking information can be found. | |
2591 | ||
2592 | @item @code{PT_INTERP} (3) | |
2593 | Indicates a segment where the name of the program interpreter may be | |
2594 | found. | |
2595 | ||
2596 | @item @code{PT_NOTE} (4) | |
2597 | Indicates a segment holding note information. | |
2598 | ||
2599 | @item @code{PT_SHLIB} (5) | |
2600 | A reserved program header type, defined but not specified by the ELF | |
2601 | ABI. | |
2602 | ||
2603 | @item @code{PT_PHDR} (6) | |
2604 | Indicates a segment where the program headers may be found. | |
2605 | ||
2606 | @item @var{expression} | |
2607 | An expression giving the numeric type of the program header. This may | |
2608 | be used for types not defined above. | |
2609 | @end table | |
2610 | ||
2611 | It is possible to specify that a segment should be loaded at a | |
2612 | particular address in memory. This is done using an @code{AT} | |
2613 | expression. This is identical to the @code{AT} command used in the | |
2614 | @code{SECTIONS} command (@pxref{Section Options}). Using the @code{AT} | |
2615 | command for a program header overrides any information in the | |
2616 | @code{SECTIONS} command. | |
2617 | ||
2618 | Normally the segment flags are set based on the sections. The | |
2619 | @code{FLAGS} keyword may be used to explicitly specify the segment | |
2620 | flags. The value of @var{flags} must be an integer. It is used to | |
2621 | set the @code{p_flags} field of the program header. | |
2622 | ||
2623 | Here is an example of the use of @code{PHDRS}. This shows a typical set | |
2624 | of program headers used on a native ELF system. | |
2625 | ||
2626 | @example | |
2627 | @group | |
2628 | PHDRS | |
2629 | @{ | |
2630 | headers PT_PHDR PHDRS ; | |
2631 | interp PT_INTERP ; | |
2632 | text PT_LOAD FILEHDR PHDRS ; | |
2633 | data PT_LOAD ; | |
2634 | dynamic PT_DYNAMIC ; | |
2635 | @} | |
2636 | ||
2637 | SECTIONS | |
2638 | @{ | |
2639 | . = SIZEOF_HEADERS; | |
2640 | .interp : @{ *(.interp) @} :text :interp | |
2641 | .text : @{ *(.text) @} :text | |
2642 | .rodata : @{ *(.rodata) @} /* defaults to :text */ | |
2643 | @dots{} | |
2644 | . = . + 0x1000; /* move to a new page in memory */ | |
2645 | .data : @{ *(.data) @} :data | |
2646 | .dynamic : @{ *(.dynamic) @} :data :dynamic | |
2647 | @dots{} | |
2648 | @} | |
2649 | @end group | |
2650 | @end example | |
2651 | ||
ec40bbb8 | 2652 | @node Entry Point |
b4d4e8e3 | 2653 | @section The Entry Point |
2c5c0674 RP |
2654 | @kindex ENTRY(@var{symbol}) |
2655 | @cindex start of execution | |
2656 | @cindex first instruction | |
b4d4e8e3 RP |
2657 | The linker command language includes a command specifically for |
2658 | defining the first executable instruction in an output file (its | |
2659 | @dfn{entry point}). Its argument is a symbol name: | |
c653b370 | 2660 | @smallexample |
b4d4e8e3 | 2661 | ENTRY(@var{symbol}) |
c653b370 | 2662 | @end smallexample |
b4d4e8e3 RP |
2663 | |
2664 | Like symbol assignments, the @code{ENTRY} command may be placed either | |
2665 | as an independent command in the command file, or among the section | |
2666 | definitions within the @code{SECTIONS} command---whatever makes the most | |
2667 | sense for your layout. | |
2668 | ||
2c5c0674 | 2669 | @cindex entry point, defaults |
b4d4e8e3 RP |
2670 | @code{ENTRY} is only one of several ways of choosing the entry point. |
2671 | You may indicate it in any of the following ways (shown in descending | |
2672 | order of priority: methods higher in the list override methods lower down). | |
f22eee08 RP |
2673 | @itemize @bullet |
2674 | @item | |
ec40bbb8 | 2675 | the @samp{-e} @var{entry} command-line option; |
f22eee08 | 2676 | @item |
8de26d62 | 2677 | the @code{ENTRY(@var{symbol})} command in a linker control script; |
f22eee08 | 2678 | @item |
b4d4e8e3 | 2679 | the value of the symbol @code{start}, if present; |
f22eee08 | 2680 | @item |
b4d4e8e3 | 2681 | the address of the first byte of the @code{.text} section, if present; |
f22eee08 | 2682 | @item |
b4d4e8e3 | 2683 | The address @code{0}. |
f22eee08 | 2684 | @end itemize |
b4d4e8e3 | 2685 | |
2c5c0674 RP |
2686 | For example, you can use these rules to generate an entry point with an |
2687 | assignment statement: if no symbol @code{start} is defined within your | |
2688 | input files, you can simply define it, assigning it an appropriate | |
2689 | value--- | |
d4e5e3c3 | 2690 | |
c653b370 | 2691 | @smallexample |
b4d4e8e3 | 2692 | start = 0x2020; |
c653b370 | 2693 | @end smallexample |
b4d4e8e3 RP |
2694 | |
2695 | @noindent | |
2696 | The example shows an absolute address, but you can use any expression. | |
2697 | For example, if your input object files use some other symbol-name | |
2698 | convention for the entry point, you can just assign the value of | |
2699 | whatever symbol contains the start address to @code{start}: | |
d4e5e3c3 | 2700 | |
c653b370 | 2701 | @smallexample |
cb70c872 | 2702 | start = other_symbol ; |
c653b370 | 2703 | @end smallexample |
f22eee08 | 2704 | |
867a1b8a DM |
2705 | @node Option Commands |
2706 | @section Option Commands | |
b4d4e8e3 RP |
2707 | The command language includes a number of other commands that you can |
2708 | use for specialized purposes. They are similar in purpose to | |
2709 | command-line options. | |
2710 | ||
2711 | @table @code | |
1fb57a5d RP |
2712 | @kindex CONSTRUCTORS |
2713 | @cindex C++ constructors, arranging in link | |
2714 | @cindex constructors, arranging in link | |
2715 | @item CONSTRUCTORS | |
a1d393cf ILT |
2716 | When linking using the @code{a.out} object file format, the linker uses |
2717 | an unusual set construct to support C++ global constructors and | |
2718 | destructors. When linking object file formats which do not support | |
2719 | arbitrary sections, such as @code{ECOFF} and @code{XCOFF}, the linker | |
2720 | will automatically recognize C++ global constructors and destructors by | |
2721 | name. For these object file formats, the @code{CONSTRUCTORS} command | |
2722 | tells the linker where this information should be placed. The | |
2723 | @code{CONSTRUCTORS} command is ignored for other object file formats. | |
2724 | ||
2725 | The symbol @w{@code{__CTOR_LIST__}} marks the start of the global | |
2726 | constructors, and the symbol @w{@code{__DTOR_LIST}} marks the end. The | |
2727 | first word in the list is the number of entries, followed by the address | |
2728 | of each constructor or destructor, followed by a zero word. The | |
2729 | compiler must arrange to actually run the code. For these object file | |
2730 | formats @sc{gnu} C++ calls constructors from a subroutine @code{__main}; | |
2731 | a call to @code{__main} is automatically inserted into the startup code | |
2732 | for @code{main}. @sc{gnu} C++ runs destructors either by using | |
2733 | @code{atexit}, or directly from the function @code{exit}. | |
2734 | ||
2735 | For object file formats such as @code{COFF} or @code{ELF} which support | |
2736 | multiple sections, @sc{gnu} C++ will normally arrange to put the | |
2737 | addresses of global constructors and destructors into the @code{.ctors} | |
2738 | and @code{.dtors} sections. Placing the following sequence into your | |
2739 | linker script will build the sort of table which the @sc{gnu} C++ | |
2740 | runtime code expects to see. | |
2741 | ||
2742 | @smallexample | |
2743 | __CTOR_LIST__ = .; | |
2744 | LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) | |
2745 | *(.ctors) | |
2746 | LONG(0) | |
2747 | __CTOR_END__ = .; | |
2748 | __DTOR_LIST__ = .; | |
2749 | LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) | |
2750 | *(.dtors) | |
2751 | LONG(0) | |
2752 | __DTOR_END__ = .; | |
2753 | @end smallexample | |
2754 | ||
2755 | Normally the compiler and linker will handle these issues automatically, | |
2756 | and you will not need to concern yourself with them. However, you may | |
2757 | need to consider this if you are using C++ and writing your own linker | |
2758 | scripts. | |
1fb57a5d | 2759 | |
d4e5e3c3 | 2760 | @need 1000 |
2c5c0674 | 2761 | @kindex FLOAT |
2c5c0674 | 2762 | @kindex NOFLOAT |
1fb57a5d RP |
2763 | @item FLOAT |
2764 | @itemx NOFLOAT | |
2c5c0674 | 2765 | These keywords were used in some older linkers to request a particular |
246504a5 | 2766 | math subroutine library. @code{ld} doesn't use the keywords, assuming |
2c5c0674 RP |
2767 | instead that any necessary subroutines are in libraries specified using |
2768 | the general mechanisms for linking to archives; but to permit the use of | |
2769 | scripts that were written for the older linkers, the keywords | |
2770 | @code{FLOAT} and @code{NOFLOAT} are accepted and ignored. | |
2771 | ||
2c5c0674 RP |
2772 | @kindex FORCE_COMMON_ALLOCATION |
2773 | @cindex common allocation | |
1fb57a5d | 2774 | @item FORCE_COMMON_ALLOCATION |
ec40bbb8 | 2775 | This command has the same effect as the @samp{-d} command-line option: |
2c5c0674 | 2776 | to make @code{ld} assign space to common symbols even if a relocatable |
ec40bbb8 | 2777 | output file is specified (@samp{-r}). |
b4d4e8e3 | 2778 | |
2c5c0674 | 2779 | @kindex INPUT ( @var{files} ) |
2c5c0674 | 2780 | @cindex binary input files |
1fb57a5d RP |
2781 | @item INPUT ( @var{file}, @var{file}, @dots{} ) |
2782 | @itemx INPUT ( @var{file} @var{file} @dots{} ) | |
2c5c0674 | 2783 | Use this command to include binary input files in the link, without |
7f9ae73e RP |
2784 | including them in a particular section definition. |
2785 | Specify the full name for each @var{file}, including @samp{.a} if | |
2786 | required. | |
2787 | ||
2788 | @code{ld} searches for each @var{file} through the archive-library | |
2789 | search path, just as for files you specify on the command line. | |
2790 | See the description of @samp{-L} in @ref{Options,,Command Line | |
2791 | Options}. | |
b4d4e8e3 | 2792 | |
01bc8f35 ILT |
2793 | If you use @samp{-l@var{file}}, @code{ld} will transform the name to |
2794 | @code{lib@var{file}.a} as with the command line argument @samp{-l}. | |
2795 | ||
0b3499f6 ILT |
2796 | @kindex GROUP ( @var{files} ) |
2797 | @cindex grouping input files | |
2798 | @item GROUP ( @var{file}, @var{file}, @dots{} ) | |
2799 | @itemx GROUP ( @var{file} @var{file} @dots{} ) | |
2800 | This command is like @code{INPUT}, except that the named files should | |
2801 | all be archives, and they are searched repeatedly until no new undefined | |
2802 | references are created. See the description of @samp{-(} in | |
2803 | @ref{Options,,Command Line Options}. | |
2804 | ||
2c5c0674 | 2805 | @ignore |
2c5c0674 | 2806 | @kindex MAP ( @var{name} ) |
c653b370 | 2807 | @item MAP ( @var{name} ) |
2c5c0674 RP |
2808 | @c MAP(...) appears to look for an F in the arg, ignoring all other |
2809 | @c chars; if it finds one, it sets "map_option_f" to true. But nothing | |
2810 | @c checks map_option_f. Apparently a stub for the future... | |
2811 | @end ignore | |
b4d4e8e3 | 2812 | |
2c5c0674 RP |
2813 | @kindex OUTPUT ( @var{filename} ) |
2814 | @cindex naming the output file | |
c653b370 | 2815 | @item OUTPUT ( @var{filename} ) |
d76ae847 RP |
2816 | Use this command to name the link output file @var{filename}. The |
2817 | effect of @code{OUTPUT(@var{filename})} is identical to the effect of | |
c477527c ILT |
2818 | @w{@samp{-o @var{filename}}}, which overrides it. You can use this |
2819 | command to supply a default output-file name other than @code{a.out}. | |
2c5c0674 | 2820 | |
ec40bbb8 | 2821 | @ifclear SingleFormat |
2c5c0674 RP |
2822 | @kindex OUTPUT_ARCH ( @var{bfdname} ) |
2823 | @cindex machine architecture, output | |
c653b370 | 2824 | @item OUTPUT_ARCH ( @var{bfdname} ) |
2c5c0674 RP |
2825 | Specify a particular output machine architecture, with one of the names |
2826 | used by the BFD back-end routines (@pxref{BFD}). This command is often | |
2827 | unnecessary; the architecture is most often set implicitly by either the | |
2828 | system BFD configuration or as a side effect of the @code{OUTPUT_FORMAT} | |
ec40bbb8 | 2829 | command. |
2c5c0674 | 2830 | |
2c5c0674 RP |
2831 | @kindex OUTPUT_FORMAT ( @var{bfdname} ) |
2832 | @cindex format, output file | |
c653b370 | 2833 | @item OUTPUT_FORMAT ( @var{bfdname} ) |
1fb57a5d RP |
2834 | When @code{ld} is configured to support multiple object code formats, |
2835 | you can use this command to specify a particular output format. | |
2836 | @var{bfdname} is one of the names used by the BFD back-end routines | |
2837 | (@pxref{BFD}). The effect is identical to the effect of the | |
9fde46a4 ILT |
2838 | @samp{--oformat} command-line option. This selection affects only the |
2839 | output file; the related command @code{TARGET} affects primarily input | |
2840 | files. | |
ec40bbb8 | 2841 | @end ifclear |
2c5c0674 | 2842 | |
2c5c0674 RP |
2843 | @kindex SEARCH_DIR ( @var{path} ) |
2844 | @cindex path for libraries | |
2845 | @cindex search path, libraries | |
c653b370 | 2846 | @item SEARCH_DIR ( @var{path} ) |
246504a5 | 2847 | Add @var{path} to the list of paths where @code{ld} looks for |
2c5c0674 | 2848 | archive libraries. @code{SEARCH_DIR(@var{path})} has the same |
ec40bbb8 | 2849 | effect as @samp{-L@var{path}} on the command line. |
2c5c0674 | 2850 | |
2c5c0674 RP |
2851 | @kindex STARTUP ( @var{filename} ) |
2852 | @cindex first input file | |
c653b370 | 2853 | @item STARTUP ( @var{filename} ) |
2c5c0674 RP |
2854 | Ensure that @var{filename} is the first input file used in the link |
2855 | process. | |
b4d4e8e3 | 2856 | |
ec40bbb8 | 2857 | @ifclear SingleFormat |
2c5c0674 RP |
2858 | @cindex input file format |
2859 | @kindex TARGET ( @var{format} ) | |
c653b370 | 2860 | @item TARGET ( @var{format} ) |
1fb57a5d RP |
2861 | When @code{ld} is configured to support multiple object code formats, |
2862 | you can use this command to change the input-file object code format | |
9fde46a4 | 2863 | (like the command-line option @samp{-b} or its synonym @samp{--format}). |
1fb57a5d RP |
2864 | The argument @var{format} is one of the strings used by BFD to name |
2865 | binary formats. If @code{TARGET} is specified but @code{OUTPUT_FORMAT} | |
2866 | is not, the last @code{TARGET} argument is also used as the default | |
2867 | format for the @code{ld} output file. @xref{BFD}. | |
2c5c0674 RP |
2868 | |
2869 | @kindex GNUTARGET | |
246504a5 | 2870 | If you don't use the @code{TARGET} command, @code{ld} uses the value of |
2c5c0674 | 2871 | the environment variable @code{GNUTARGET}, if available, to select the |
246504a5 | 2872 | output file format. If that variable is also absent, @code{ld} uses |
2c5c0674 | 2873 | the default format configured for your machine in the BFD libraries. |
ec40bbb8 | 2874 | @end ifclear |
582dd77f ILT |
2875 | |
2876 | @cindex cross references | |
2877 | @kindex NOCROSSREFS ( @var{sections} ) | |
2878 | @item NOCROSSREFS ( @var{section} @var{section} @dots{} ) | |
2879 | This command may be used to tell @code{ld} to issue an error about any | |
2880 | references among certain sections. | |
2881 | ||
2882 | In certain types of programs, particularly on embedded systems, when one | |
2883 | section is loaded into memory, another section will not be. Any direct | |
2884 | references between the two sections would be errors. For example, it | |
2885 | would be an error if code in one section called a function defined in | |
2886 | the other section. | |
2887 | ||
2888 | The @code{NOCROSSREFS} command takes a list of section names. If | |
2889 | @code{ld} detects any cross references between the sections, it reports | |
2890 | an error and returns a non-zero exit status. The @code{NOCROSSREFS} | |
2891 | command uses output section names, defined in the @code{SECTIONS} | |
2892 | command. It does not use the names of input sections. | |
b4d4e8e3 RP |
2893 | @end table |
2894 | ||
ec40bbb8 DM |
2895 | @ifset GENERIC |
2896 | @node Machine Dependent | |
1c48127e RP |
2897 | @chapter Machine Dependent Features |
2898 | ||
2899 | @cindex machine dependencies | |
246504a5 RP |
2900 | @code{ld} has additional features on some platforms; the following |
2901 | sections describe them. Machines where @code{ld} has no additional | |
1c48127e RP |
2902 | functionality are not listed. |
2903 | ||
2904 | @menu | |
246504a5 RP |
2905 | * H8/300:: @code{ld} and the H8/300 |
2906 | * i960:: @code{ld} and the Intel 960 family | |
1c48127e | 2907 | @end menu |
ec40bbb8 DM |
2908 | @end ifset |
2909 | ||
7f9ae73e | 2910 | @c FIXME! This could use @raisesections/@lowersections, but there seems to be a conflict |
ec40bbb8 DM |
2911 | @c between those and node-defaulting. |
2912 | @ifset H8300 | |
2913 | @ifclear GENERIC | |
7f9ae73e | 2914 | @raisesections |
ec40bbb8 DM |
2915 | @end ifclear |
2916 | @node H8/300 | |
246504a5 | 2917 | @section @code{ld} and the H8/300 |
1c48127e RP |
2918 | |
2919 | @cindex H8/300 support | |
246504a5 | 2920 | For the H8/300, @code{ld} can perform these global optimizations when |
9fde46a4 | 2921 | you specify the @samp{--relax} command-line option. |
1c48127e RP |
2922 | |
2923 | @table @emph | |
d76ae847 | 2924 | @cindex relaxing on H8/300 |
c653b370 | 2925 | @item relaxing address modes |
246504a5 | 2926 | @code{ld} finds all @code{jsr} and @code{jmp} instructions whose |
1c48127e RP |
2927 | targets are within eight bits, and turns them into eight-bit |
2928 | program-counter relative @code{bsr} and @code{bra} instructions, | |
2929 | respectively. | |
2930 | ||
d76ae847 | 2931 | @cindex synthesizing on H8/300 |
c653b370 | 2932 | @item synthesizing instructions |
1c48127e | 2933 | @c FIXME: specifically mov.b, or any mov instructions really? |
246504a5 | 2934 | @code{ld} finds all @code{mov.b} instructions which use the |
1c48127e RP |
2935 | sixteen-bit absolute address form, but refer to the top |
2936 | page of memory, and changes them to use the eight-bit address form. | |
2937 | (That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into | |
2938 | @samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the | |
2939 | top page of memory). | |
2940 | @end table | |
ec40bbb8 | 2941 | @ifclear GENERIC |
7f9ae73e | 2942 | @lowersections |
ec40bbb8 DM |
2943 | @end ifclear |
2944 | @end ifset | |
2945 | ||
f9d3d71a ILT |
2946 | @ifclear GENERIC |
2947 | @ifset Hitachi | |
2948 | @c This stuff is pointless to say unless you're especially concerned | |
2949 | @c with Hitachi chips; don't enable it for generic case, please. | |
2950 | @node Hitachi | |
2951 | @chapter @code{ld} and other Hitachi chips | |
2952 | ||
2953 | @code{ld} also supports the H8/300H, the H8/500, and the Hitachi SH. No | |
2954 | special features, commands, or command-line options are required for | |
2955 | these chips. | |
2956 | @end ifset | |
2957 | @end ifclear | |
2958 | ||
ec40bbb8 DM |
2959 | @ifset I960 |
2960 | @ifclear GENERIC | |
7f9ae73e | 2961 | @raisesections |
ec40bbb8 DM |
2962 | @end ifclear |
2963 | @node i960 | |
246504a5 | 2964 | @section @code{ld} and the Intel 960 family |
1c48127e RP |
2965 | |
2966 | @cindex i960 support | |
d76ae847 | 2967 | |
1c48127e RP |
2968 | You can use the @samp{-A@var{architecture}} command line option to |
2969 | specify one of the two-letter names identifying members of the 960 | |
2970 | family; the option specifies the desired output target, and warns of any | |
2971 | incompatible instructions in the input files. It also modifies the | |
2972 | linker's search strategy for archive libraries, to support the use of | |
2973 | libraries specific to each particular architecture, by including in the | |
2974 | search loop names suffixed with the string identifying the architecture. | |
2975 | ||
246504a5 | 2976 | For example, if your @code{ld} command line included @w{@samp{-ACA}} as |
1c48127e | 2977 | well as @w{@samp{-ltry}}, the linker would look (in its built-in search |
ec40bbb8 | 2978 | paths, and in any paths you specify with @samp{-L}) for a library with |
1c48127e | 2979 | the names |
ec40bbb8 | 2980 | |
c653b370 ILT |
2981 | @smallexample |
2982 | @group | |
1c48127e RP |
2983 | try |
2984 | libtry.a | |
2985 | tryca | |
2986 | libtryca.a | |
c653b370 ILT |
2987 | @end group |
2988 | @end smallexample | |
ec40bbb8 | 2989 | |
1c48127e RP |
2990 | @noindent |
2991 | The first two possibilities would be considered in any event; the last | |
2992 | two are due to the use of @w{@samp{-ACA}}. | |
2993 | ||
ec40bbb8 | 2994 | You can meaningfully use @samp{-A} more than once on a command line, since |
1c48127e | 2995 | the 960 architecture family allows combination of target architectures; each |
ec40bbb8 | 2996 | use will add another pair of name variants to search for when @w{@samp{-l}} |
1c48127e | 2997 | specifies a library. |
1fb57a5d | 2998 | |
9fde46a4 | 2999 | @cindex @code{--relax} on i960 |
1fb57a5d | 3000 | @cindex relaxing on i960 |
9fde46a4 ILT |
3001 | @code{ld} supports the @samp{--relax} option for the i960 family. If |
3002 | you specify @samp{--relax}, @code{ld} finds all @code{balx} and | |
3003 | @code{calx} instructions whose targets are within 24 bits, and turns | |
3004 | them into 24-bit program-counter relative @code{bal} and @code{cal} | |
1fb57a5d RP |
3005 | instructions, respectively. @code{ld} also turns @code{cal} |
3006 | instructions into @code{bal} instructions when it determines that the | |
3007 | target subroutine is a leaf routine (that is, the target subroutine does | |
3008 | not itself call any subroutines). | |
3009 | ||
ec40bbb8 | 3010 | @ifclear GENERIC |
7f9ae73e | 3011 | @lowersections |
ec40bbb8 DM |
3012 | @end ifclear |
3013 | @end ifset | |
1c48127e | 3014 | |
ec40bbb8 DM |
3015 | @ifclear SingleFormat |
3016 | @node BFD | |
f22eee08 RP |
3017 | @chapter BFD |
3018 | ||
2c5c0674 RP |
3019 | @cindex back end |
3020 | @cindex object file management | |
d4e5e3c3 DM |
3021 | @cindex object formats available |
3022 | @kindex objdump -i | |
2c5c0674 RP |
3023 | The linker accesses object and archive files using the BFD libraries. |
3024 | These libraries allow the linker to use the same routines to operate on | |
3025 | object files whatever the object file format. A different object file | |
3026 | format can be supported simply by creating a new BFD back end and adding | |
d4e5e3c3 DM |
3027 | it to the library. To conserve runtime memory, however, the linker and |
3028 | associated tools are usually configured to support only a subset of the | |
3029 | object file formats available. You can use @code{objdump -i} | |
1c48127e | 3030 | (@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to |
d4e5e3c3 | 3031 | list all the formats available for your configuration. |
f22eee08 | 3032 | |
2c5c0674 RP |
3033 | @cindex BFD requirements |
3034 | @cindex requirements for BFD | |
3035 | As with most implementations, BFD is a compromise between | |
f22eee08 | 3036 | several conflicting requirements. The major factor influencing |
2c5c0674 RP |
3037 | BFD design was efficiency: any time used converting between |
3038 | formats is time which would not have been spent had BFD not | |
f22eee08 | 3039 | been involved. This is partly offset by abstraction payback; since |
2c5c0674 | 3040 | BFD simplifies applications and back ends, more time and care |
f22eee08 RP |
3041 | may be spent optimizing algorithms for a greater speed. |
3042 | ||
2c5c0674 RP |
3043 | One minor artifact of the BFD solution which you should bear in |
3044 | mind is the potential for information loss. There are two places where | |
ec40bbb8 | 3045 | useful information can be lost using the BFD mechanism: during |
2c5c0674 RP |
3046 | conversion and during output. @xref{BFD information loss}. |
3047 | ||
3048 | @menu | |
2d59b2c3 | 3049 | * BFD outline:: How it works: an outline of BFD |
2c5c0674 | 3050 | @end menu |
f22eee08 | 3051 | |
ec40bbb8 | 3052 | @node BFD outline |
b4d4e8e3 | 3053 | @section How it works: an outline of BFD |
2c5c0674 | 3054 | @cindex opening object files |
3e27cc11 | 3055 | @include bfdsumm.texi |
ec40bbb8 | 3056 | @end ifclear |
f22eee08 | 3057 | |
9fde46a4 ILT |
3058 | @node Reporting Bugs |
3059 | @chapter Reporting Bugs | |
3060 | @cindex bugs in @code{ld} | |
3061 | @cindex reporting bugs in @code{ld} | |
3062 | ||
3063 | Your bug reports play an essential role in making @code{ld} reliable. | |
3064 | ||
3065 | Reporting a bug may help you by bringing a solution to your problem, or | |
3066 | it may not. But in any case the principal function of a bug report is | |
3067 | to help the entire community by making the next version of @code{ld} | |
3068 | work better. Bug reports are your contribution to the maintenance of | |
3069 | @code{ld}. | |
3070 | ||
3071 | In order for a bug report to serve its purpose, you must include the | |
3072 | information that enables us to fix the bug. | |
3073 | ||
3074 | @menu | |
3075 | * Bug Criteria:: Have you found a bug? | |
3076 | * Bug Reporting:: How to report bugs | |
3077 | @end menu | |
3078 | ||
3079 | @node Bug Criteria | |
3080 | @section Have you found a bug? | |
3081 | @cindex bug criteria | |
3082 | ||
3083 | If you are not sure whether you have found a bug, here are some guidelines: | |
3084 | ||
3085 | @itemize @bullet | |
3086 | @cindex fatal signal | |
3087 | @cindex linker crash | |
3088 | @cindex crash of linker | |
3089 | @item | |
3090 | If the linker gets a fatal signal, for any input whatever, that is a | |
3091 | @code{ld} bug. Reliable linkers never crash. | |
3092 | ||
3093 | @cindex error on valid input | |
3094 | @item | |
3095 | If @code{ld} produces an error message for valid input, that is a bug. | |
3096 | ||
3097 | @cindex invalid input | |
3098 | @item | |
3099 | If @code{ld} does not produce an error message for invalid input, that | |
3100 | may be a bug. In the general case, the linker can not verify that | |
3101 | object files are correct. | |
3102 | ||
3103 | @item | |
3104 | If you are an experienced user of linkers, your suggestions for | |
3105 | improvement of @code{ld} are welcome in any case. | |
3106 | @end itemize | |
3107 | ||
3108 | @node Bug Reporting | |
3109 | @section How to report bugs | |
3110 | @cindex bug reports | |
3111 | @cindex @code{ld} bugs, reporting | |
3112 | ||
3113 | A number of companies and individuals offer support for @sc{gnu} | |
3114 | products. If you obtained @code{ld} from a support organization, we | |
3115 | recommend you contact that organization first. | |
3116 | ||
3117 | You can find contact information for many support companies and | |
3118 | individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs | |
3119 | distribution. | |
3120 | ||
3121 | In any event, we also recommend that you send bug reports for @code{ld} | |
3122 | to @samp{bug-gnu-utils@@prep.ai.mit.edu}. | |
3123 | ||
3124 | The fundamental principle of reporting bugs usefully is this: | |
3125 | @strong{report all the facts}. If you are not sure whether to state a | |
3126 | fact or leave it out, state it! | |
3127 | ||
3128 | Often people omit facts because they think they know what causes the | |
3129 | problem and assume that some details do not matter. Thus, you might | |
3130 | assume that the name of a symbol you use in an example does not matter. | |
3131 | Well, probably it does not, but one cannot be sure. Perhaps the bug is | |
3132 | a stray memory reference which happens to fetch from the location where | |
3133 | that name is stored in memory; perhaps, if the name were different, the | |
3134 | contents of that location would fool the linker into doing the right | |
3135 | thing despite the bug. Play it safe and give a specific, complete | |
3136 | example. That is the easiest thing for you to do, and the most helpful. | |
3137 | ||
3138 | Keep in mind that the purpose of a bug report is to enable us to fix the bug if | |
3139 | it is new to us. Therefore, always write your bug reports on the assumption | |
3140 | that the bug has not been reported previously. | |
3141 | ||
3142 | Sometimes people give a few sketchy facts and ask, ``Does this ring a | |
3143 | bell?'' Those bug reports are useless, and we urge everyone to | |
3144 | @emph{refuse to respond to them} except to chide the sender to report | |
3145 | bugs properly. | |
3146 | ||
3147 | To enable us to fix the bug, you should include all these things: | |
3148 | ||
3149 | @itemize @bullet | |
3150 | @item | |
3151 | The version of @code{ld}. @code{ld} announces it if you start it with | |
3152 | the @samp{--version} argument. | |
3153 | ||
3154 | Without this, we will not know whether there is any point in looking for | |
3155 | the bug in the current version of @code{ld}. | |
3156 | ||
3157 | @item | |
3158 | Any patches you may have applied to the @code{ld} source, including any | |
3159 | patches made to the @code{BFD} library. | |
3160 | ||
3161 | @item | |
3162 | The type of machine you are using, and the operating system name and | |
3163 | version number. | |
3164 | ||
3165 | @item | |
3166 | What compiler (and its version) was used to compile @code{ld}---e.g. | |
3167 | ``@code{gcc-2.7}''. | |
3168 | ||
3169 | @item | |
3170 | The command arguments you gave the linker to link your example and | |
3171 | observe the bug. To guarantee you will not omit something important, | |
3172 | list them all. A copy of the Makefile (or the output from make) is | |
3173 | sufficient. | |
3174 | ||
3175 | If we were to try to guess the arguments, we would probably guess wrong | |
3176 | and then we might not encounter the bug. | |
3177 | ||
3178 | @item | |
3179 | A complete input file, or set of input files, that will reproduce the | |
3180 | bug. It is generally most helpful to send the actual object files, | |
3181 | uuencoded if necessary to get them through the mail system. Making them | |
3182 | available for anonymous FTP is not as good, but may be the only | |
3183 | reasonable choice for large object files. | |
3184 | ||
3185 | If the source files were assembled using @code{gas} or compiled using | |
3186 | @code{gcc}, then it may be OK to send the source files rather than the | |
3187 | object files. In this case, be sure to say exactly what version of | |
3188 | @code{gas} or @code{gcc} was used to produce the object files. Also say | |
3189 | how @code{gas} or @code{gcc} were configured. | |
3190 | ||
3191 | @item | |
3192 | A description of what behavior you observe that you believe is | |
3193 | incorrect. For example, ``It gets a fatal signal.'' | |
3194 | ||
3195 | Of course, if the bug is that @code{ld} gets a fatal signal, then we | |
3196 | will certainly notice it. But if the bug is incorrect output, we might | |
3197 | not notice unless it is glaringly wrong. You might as well not give us | |
3198 | a chance to make a mistake. | |
3199 | ||
3200 | Even if the problem you experience is a fatal signal, you should still | |
3201 | say so explicitly. Suppose something strange is going on, such as, your | |
3202 | copy of @code{ld} is out of synch, or you have encountered a bug in the | |
3203 | C library on your system. (This has happened!) Your copy might crash | |
3204 | and ours would not. If you told us to expect a crash, then when ours | |
3205 | fails to crash, we would know that the bug was not happening for us. If | |
3206 | you had not told us to expect a crash, then we would not be able to draw | |
3207 | any conclusion from our observations. | |
3208 | ||
3209 | @item | |
3210 | If you wish to suggest changes to the @code{ld} source, send us context | |
3211 | diffs, as generated by @code{diff} with the @samp{-u}, @samp{-c}, or | |
3212 | @samp{-p} option. Always send diffs from the old file to the new file. | |
3213 | If you even discuss something in the @code{ld} source, refer to it by | |
3214 | context, not by line number. | |
3215 | ||
3216 | The line numbers in our development sources will not match those in your | |
3217 | sources. Your line numbers would convey no useful information to us. | |
3218 | @end itemize | |
3219 | ||
3220 | Here are some things that are not necessary: | |
3221 | ||
3222 | @itemize @bullet | |
3223 | @item | |
3224 | A description of the envelope of the bug. | |
3225 | ||
3226 | Often people who encounter a bug spend a lot of time investigating | |
3227 | which changes to the input file will make the bug go away and which | |
3228 | changes will not affect it. | |
3229 | ||
3230 | This is often time consuming and not very useful, because the way we | |
3231 | will find the bug is by running a single example under the debugger | |
3232 | with breakpoints, not by pure deduction from a series of examples. | |
3233 | We recommend that you save your time for something else. | |
3234 | ||
3235 | Of course, if you can find a simpler example to report @emph{instead} | |
3236 | of the original one, that is a convenience for us. Errors in the | |
3237 | output will be easier to spot, running under the debugger will take | |
3238 | less time, and so on. | |
3239 | ||
3240 | However, simplification is not vital; if you do not want to do this, | |
3241 | report the bug anyway and send us the entire test case you used. | |
3242 | ||
3243 | @item | |
3244 | A patch for the bug. | |
3245 | ||
3246 | A patch for the bug does help us if it is a good one. But do not omit | |
3247 | the necessary information, such as the test case, on the assumption that | |
3248 | a patch is all we need. We might see problems with your patch and decide | |
3249 | to fix the problem another way, or we might not understand it at all. | |
3250 | ||
de220cbd ILT |
3251 | Sometimes with a program as complicated as @code{ld} it is very hard to |
3252 | construct an example that will make the program follow a certain path | |
3253 | through the code. If you do not send us the example, we will not be | |
3254 | able to construct one, so we will not be able to verify that the bug is | |
3255 | fixed. | |
9fde46a4 ILT |
3256 | |
3257 | And if we cannot understand what bug you are trying to fix, or why your | |
3258 | patch should be an improvement, we will not install it. A test case will | |
3259 | help us to understand. | |
3260 | ||
3261 | @item | |
3262 | A guess about what the bug is or what it depends on. | |
3263 | ||
3264 | Such guesses are usually wrong. Even we cannot guess right about such | |
3265 | things without first using the debugger to find the facts. | |
3266 | @end itemize | |
3267 | ||
ec40bbb8 | 3268 | @node MRI |
2d59b2c3 RP |
3269 | @appendix MRI Compatible Script Files |
3270 | @cindex MRI compatibility | |
3271 | To aid users making the transition to @sc{gnu} @code{ld} from the MRI | |
3272 | linker, @code{ld} can use MRI compatible linker scripts as an | |
3273 | alternative to the more general-purpose linker scripting language | |
3274 | described in @ref{Commands,,Command Language}. MRI compatible linker | |
3275 | scripts have a much simpler command set than the scripting language | |
3276 | otherwise used with @code{ld}. @sc{gnu} @code{ld} supports the most | |
3277 | commonly used MRI linker commands; these commands are described here. | |
3278 | ||
867a1b8a DM |
3279 | In general, MRI scripts aren't of much use with the @code{a.out} object |
3280 | file format, since it only has three sections and MRI scripts lack some | |
3281 | features to make use of them. | |
3282 | ||
2d59b2c3 RP |
3283 | You can specify a file containing an MRI-compatible script using the |
3284 | @samp{-c} command-line option. | |
3285 | ||
3286 | Each command in an MRI-compatible script occupies its own line; each | |
3287 | command line starts with the keyword that identifies the command (though | |
3288 | blank lines are also allowed for punctuation). If a line of an | |
3289 | MRI-compatible script begins with an unrecognized keyword, @code{ld} | |
3290 | issues a warning message, but continues processing the script. | |
3291 | ||
3292 | Lines beginning with @samp{*} are comments. | |
3293 | ||
3294 | You can write these commands using all upper-case letters, or all | |
3295 | lower case; for example, @samp{chip} is the same as @samp{CHIP}. | |
3296 | The following list shows only the upper-case form of each command. | |
3297 | ||
3298 | @table @code | |
d4e5e3c3 | 3299 | @cindex @code{ABSOLUTE} (MRI) |
2d59b2c3 | 3300 | @item ABSOLUTE @var{secname} |
c653b370 | 3301 | @itemx ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname} |
2d59b2c3 RP |
3302 | Normally, @code{ld} includes in the output file all sections from all |
3303 | the input files. However, in an MRI-compatible script, you can use the | |
3304 | @code{ABSOLUTE} command to restrict the sections that will be present in | |
3305 | your output program. If the @code{ABSOLUTE} command is used at all in a | |
3306 | script, then only the sections named explicitly in @code{ABSOLUTE} | |
3307 | commands will appear in the linker output. You can still use other | |
3308 | input sections (whatever you select on the command line, or using | |
7b015547 | 3309 | @code{LOAD}) to resolve addresses in the output file. |
2d59b2c3 | 3310 | |
2d59b2c3 | 3311 | @cindex @code{ALIAS} (MRI) |
d4e5e3c3 | 3312 | @item ALIAS @var{out-secname}, @var{in-secname} |
2d59b2c3 RP |
3313 | Use this command to place the data from input section @var{in-secname} |
3314 | in a section called @var{out-secname} in the linker output file. | |
3315 | ||
3316 | @var{in-secname} may be an integer. | |
3317 | ||
e54bf1c1 ILT |
3318 | @cindex @code{ALIGN} (MRI) |
3319 | @item ALIGN @var{secname} = @var{expression} | |
3320 | Align the section called @var{secname} to @var{expression}. The | |
3321 | @var{expression} should be a power of two. | |
3322 | ||
2d59b2c3 | 3323 | @cindex @code{BASE} (MRI) |
d4e5e3c3 | 3324 | @item BASE @var{expression} |
2d59b2c3 RP |
3325 | Use the value of @var{expression} as the lowest address (other than |
3326 | absolute addresses) in the output file. | |
3327 | ||
d4e5e3c3 | 3328 | @cindex @code{CHIP} (MRI) |
2d59b2c3 RP |
3329 | @item CHIP @var{expression} |
3330 | @itemx CHIP @var{expression}, @var{expression} | |
ec40bbb8 | 3331 | This command does nothing; it is accepted only for compatibility. |
2d59b2c3 | 3332 | |
2d59b2c3 | 3333 | @cindex @code{END} (MRI) |
d4e5e3c3 | 3334 | @item END |
2d59b2c3 RP |
3335 | This command does nothing whatever; it's only accepted for compatibility. |
3336 | ||
2d59b2c3 | 3337 | @cindex @code{FORMAT} (MRI) |
d4e5e3c3 | 3338 | @item FORMAT @var{output-format} |
2d59b2c3 RP |
3339 | Similar to the @code{OUTPUT_FORMAT} command in the more general linker |
3340 | language, but restricted to one of these output formats: | |
d4e5e3c3 | 3341 | |
2d59b2c3 RP |
3342 | @enumerate |
3343 | @item | |
3344 | S-records, if @var{output-format} is @samp{S} | |
3345 | ||
3346 | @item | |
3347 | IEEE, if @var{output-format} is @samp{IEEE} | |
3348 | ||
3349 | @item | |
3350 | COFF (the @samp{coff-m68k} variant in BFD), if @var{output-format} is | |
3351 | @samp{COFF} | |
3352 | @end enumerate | |
3353 | ||
2d59b2c3 | 3354 | @cindex @code{LIST} (MRI) |
d4e5e3c3 | 3355 | @item LIST @var{anything}@dots{} |
2d59b2c3 RP |
3356 | Print (to the standard output file) a link map, as produced by the |
3357 | @code{ld} command-line option @samp{-M}. | |
3358 | ||
ec40bbb8 DM |
3359 | The keyword @code{LIST} may be followed by anything on the |
3360 | same line, with no change in its effect. | |
2d59b2c3 | 3361 | |
d4e5e3c3 | 3362 | @cindex @code{LOAD} (MRI) |
2d59b2c3 | 3363 | @item LOAD @var{filename} |
c653b370 | 3364 | @itemx LOAD @var{filename}, @var{filename}, @dots{} @var{filename} |
2d59b2c3 RP |
3365 | Include one or more object file @var{filename} in the link; this has the |
3366 | same effect as specifying @var{filename} directly on the @code{ld} | |
3367 | command line. | |
3368 | ||
2d59b2c3 | 3369 | @cindex @code{NAME} (MRI) |
d4e5e3c3 | 3370 | @item NAME @var{output-name} |
2d59b2c3 RP |
3371 | @var{output-name} is the name for the program produced by @code{ld}; the |
3372 | MRI-compatible command @code{NAME} is equivalent to the command-line | |
3373 | option @samp{-o} or the general script language command @code{OUTPUT}. | |
3374 | ||
d4e5e3c3 | 3375 | @cindex @code{ORDER} (MRI) |
2d59b2c3 RP |
3376 | @item ORDER @var{secname}, @var{secname}, @dots{} @var{secname} |
3377 | @itemx ORDER @var{secname} @var{secname} @var{secname} | |
ec40bbb8 DM |
3378 | Normally, @code{ld} orders the sections in its output file in the |
3379 | order in which they first appear in the input files. In an MRI-compatible | |
3380 | script, you can override this ordering with the @code{ORDER} command. The | |
2d59b2c3 RP |
3381 | sections you list with @code{ORDER} will appear first in your output |
3382 | file, in the order specified. | |
3383 | ||
d4e5e3c3 | 3384 | @cindex @code{PUBLIC} (MRI) |
2d59b2c3 RP |
3385 | @item PUBLIC @var{name}=@var{expression} |
3386 | @itemx PUBLIC @var{name},@var{expression} | |
3387 | @itemx PUBLIC @var{name} @var{expression} | |
ec40bbb8 | 3388 | Supply a value (@var{expression}) for external symbol |
2d59b2c3 RP |
3389 | @var{name} used in the linker input files. |
3390 | ||
d4e5e3c3 | 3391 | @cindex @code{SECT} (MRI) |
2d59b2c3 RP |
3392 | @item SECT @var{secname}, @var{expression} |
3393 | @itemx SECT @var{secname}=@var{expression} | |
3394 | @itemx SECT @var{secname} @var{expression} | |
2d59b2c3 RP |
3395 | You can use any of these three forms of the @code{SECT} command to |
3396 | specify the start address (@var{expression}) for section @var{secname}. | |
3397 | If you have more than one @code{SECT} statement for the same | |
3398 | @var{secname}, only the @emph{first} sets the start address. | |
3399 | @end table | |
3400 | ||
ec40bbb8 | 3401 | @node Index |
2c5c0674 RP |
3402 | @unnumbered Index |
3403 | ||
3404 | @printindex cp | |
3405 | ||
3406 | @tex | |
3407 | % I think something like @colophon should be in texinfo. In the | |
3408 | % meantime: | |
3409 | \long\def\colophon{\hbox to0pt{}\vfill | |
3410 | \centerline{The body of this manual is set in} | |
3411 | \centerline{\fontname\tenrm,} | |
3412 | \centerline{with headings in {\bf\fontname\tenbf}} | |
3413 | \centerline{and examples in {\tt\fontname\tentt}.} | |
3414 | \centerline{{\it\fontname\tenit\/} and} | |
3415 | \centerline{{\sl\fontname\tensl\/}} | |
3416 | \centerline{are used for emphasis.}\vfill} | |
3417 | \page\colophon | |
c653b370 | 3418 | % Blame: doc@cygnus.com, 28mar91. |
2c5c0674 RP |
3419 | @end tex |
3420 | ||
3421 | ||
b4d4e8e3 | 3422 | @contents |
f22eee08 RP |
3423 | @bye |
3424 | ||
3425 |