Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | \input texinfo |
2 | @setfilename ld.info | |
a2b64bed | 3 | @c Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
9c8ebd6a | 4 | @c 2001, 2002, 2003 Free Software Foundation, Inc. |
252b5132 RH |
5 | @syncodeindex ky cp |
6 | @include configdoc.texi | |
7 | @c (configdoc.texi is generated by the Makefile) | |
8 | @include ldver.texi | |
9 | ||
10 | @c @smallbook | |
11 | ||
ff5dcc92 SC |
12 | @macro gcctabopt{body} |
13 | @code{\body\} | |
14 | @end macro | |
15 | ||
0285c67d NC |
16 | @c man begin NAME |
17 | @ifset man | |
18 | @c Configure for the generation of man pages | |
19 | @set UsesEnvVars | |
20 | @set GENERIC | |
21 | @set A29K | |
22 | @set ARC | |
23 | @set ARM | |
24 | @set D10V | |
25 | @set D30V | |
26 | @set H8/300 | |
27 | @set H8/500 | |
28 | @set HPPA | |
29 | @set I370 | |
30 | @set I80386 | |
31 | @set I860 | |
32 | @set I960 | |
33 | @set M32R | |
34 | @set M68HC11 | |
35 | @set M680X0 | |
36 | @set MCORE | |
37 | @set MIPS | |
3c3bdf30 | 38 | @set MMIX |
2469cfa2 | 39 | @set MSP430 |
0285c67d NC |
40 | @set PDP11 |
41 | @set PJ | |
42 | @set SH | |
43 | @set SPARC | |
44 | @set C54X | |
45 | @set V850 | |
46 | @set VAX | |
2ca22b03 | 47 | @set WIN32 |
0285c67d NC |
48 | @end ifset |
49 | @c man end | |
50 | ||
252b5132 RH |
51 | @ifinfo |
52 | @format | |
53 | START-INFO-DIR-ENTRY | |
54 | * Ld: (ld). The GNU linker. | |
55 | END-INFO-DIR-ENTRY | |
56 | @end format | |
57 | @end ifinfo | |
58 | ||
59 | @ifinfo | |
60 | This file documents the @sc{gnu} linker LD version @value{VERSION}. | |
61 | ||
62bf86b4 | 62 | Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, |
9c8ebd6a | 63 | 2001, 2002, 2003 Free Software Foundation, Inc. |
252b5132 | 64 | |
252b5132 | 65 | @ignore |
cf055d54 NC |
66 | |
67 | Permission is granted to copy, distribute and/or modify this document | |
68 | under the terms of the GNU Free Documentation License, Version 1.1 | |
69 | or any later version published by the Free Software Foundation; | |
70 | with no Invariant Sections, with no Front-Cover Texts, and with no | |
71 | Back-Cover Texts. A copy of the license is included in the | |
72 | section entitled "GNU Free Documentation License". | |
73 | ||
252b5132 RH |
74 | Permission is granted to process this file through Tex and print the |
75 | results, provided the printed document carries copying permission | |
76 | notice identical to this one except for the removal of this paragraph | |
77 | (this paragraph not being relevant to the printed manual). | |
78 | ||
79 | @end ignore | |
80 | @end ifinfo | |
81 | @iftex | |
82 | @finalout | |
83 | @setchapternewpage odd | |
84 | @settitle Using LD, the GNU linker | |
85 | @titlepage | |
86 | @title Using ld | |
87 | @subtitle The GNU linker | |
88 | @sp 1 | |
89 | @subtitle @code{ld} version 2 | |
90 | @subtitle Version @value{VERSION} | |
91 | @author Steve Chamberlain | |
92 | @author Ian Lance Taylor | |
252b5132 RH |
93 | @page |
94 | ||
95 | @tex | |
96 | {\parskip=0pt | |
704c465c NC |
97 | \hfill Red Hat Inc\par |
98 | \hfill nickc\@credhat.com, doc\@redhat.com\par | |
252b5132 RH |
99 | \hfill {\it Using LD, the GNU linker}\par |
100 | \hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com)\par | |
101 | } | |
102 | \global\parindent=0pt % Steve likes it this way. | |
103 | @end tex | |
104 | ||
105 | @vskip 0pt plus 1filll | |
0285c67d | 106 | @c man begin COPYRIGHT |
9c8ebd6a DJ |
107 | Copyright @copyright{} 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, |
108 | 2002, 2003 Free Software Foundation, Inc. | |
252b5132 | 109 | |
0285c67d NC |
110 | Permission is granted to copy, distribute and/or modify this document |
111 | under the terms of the GNU Free Documentation License, Version 1.1 | |
112 | or any later version published by the Free Software Foundation; | |
113 | with no Invariant Sections, with no Front-Cover Texts, and with no | |
114 | Back-Cover Texts. A copy of the license is included in the | |
115 | section entitled "GNU Free Documentation License". | |
116 | @c man end | |
252b5132 | 117 | |
252b5132 RH |
118 | @end titlepage |
119 | @end iftex | |
120 | @c FIXME: Talk about importance of *order* of args, cmds to linker! | |
121 | ||
84ec0e6d | 122 | @ifnottex |
252b5132 RH |
123 | @node Top |
124 | @top Using ld | |
125 | This file documents the @sc{gnu} linker ld version @value{VERSION}. | |
126 | ||
cf055d54 NC |
127 | This document is distributed under the terms of the GNU Free |
128 | Documentation License. A copy of the license is included in the | |
129 | section entitled "GNU Free Documentation License". | |
130 | ||
252b5132 RH |
131 | @menu |
132 | * Overview:: Overview | |
133 | * Invocation:: Invocation | |
134 | * Scripts:: Linker Scripts | |
135 | @ifset GENERIC | |
136 | * Machine Dependent:: Machine Dependent Features | |
137 | @end ifset | |
138 | @ifclear GENERIC | |
139 | @ifset H8300 | |
140 | * H8/300:: ld and the H8/300 | |
141 | @end ifset | |
142 | @ifset Hitachi | |
143 | * Hitachi:: ld and other Hitachi micros | |
144 | @end ifset | |
145 | @ifset I960 | |
146 | * i960:: ld and the Intel 960 family | |
147 | @end ifset | |
74459f0e TW |
148 | @ifset TICOFF |
149 | * TI COFF:: ld and the TI COFF | |
150 | @end ifset | |
2ca22b03 NC |
151 | @ifset WIN32 |
152 | * Win32:: ld and WIN32 (cygwin/mingw) | |
153 | @end ifset | |
252b5132 RH |
154 | @end ifclear |
155 | @ifclear SingleFormat | |
156 | * BFD:: BFD | |
157 | @end ifclear | |
158 | @c Following blank line required for remaining bug in makeinfo conds/menus | |
159 | ||
160 | * Reporting Bugs:: Reporting Bugs | |
161 | * MRI:: MRI Compatible Script Files | |
704c465c | 162 | * GNU Free Documentation License:: GNU Free Documentation License |
252b5132 RH |
163 | * Index:: Index |
164 | @end menu | |
84ec0e6d | 165 | @end ifnottex |
252b5132 RH |
166 | |
167 | @node Overview | |
168 | @chapter Overview | |
169 | ||
170 | @cindex @sc{gnu} linker | |
171 | @cindex what is this? | |
0285c67d | 172 | |
0879a67a | 173 | @ifset man |
0285c67d | 174 | @c man begin SYNOPSIS |
ff5dcc92 | 175 | ld [@b{options}] @var{objfile} @dots{} |
0285c67d NC |
176 | @c man end |
177 | ||
178 | @c man begin SEEALSO | |
179 | ar(1), nm(1), objcopy(1), objdump(1), readelf(1) and | |
180 | the Info entries for @file{binutils} and | |
181 | @file{ld}. | |
182 | @c man end | |
183 | @end ifset | |
184 | ||
185 | @c man begin DESCRIPTION | |
186 | ||
ff5dcc92 | 187 | @command{ld} combines a number of object and archive files, relocates |
252b5132 | 188 | their data and ties up symbol references. Usually the last step in |
ff5dcc92 | 189 | compiling a program is to run @command{ld}. |
252b5132 | 190 | |
ff5dcc92 | 191 | @command{ld} accepts Linker Command Language files written in |
252b5132 RH |
192 | a superset of AT&T's Link Editor Command Language syntax, |
193 | to provide explicit and total control over the linking process. | |
194 | ||
0285c67d NC |
195 | @ifset man |
196 | @c For the man only | |
197 | This man page does not describe the command language; see the | |
ff5dcc92 | 198 | @command{ld} entry in @code{info}, or the manual |
0285c67d NC |
199 | ld: the GNU linker, for full details on the command language and |
200 | on other aspects of the GNU linker. | |
201 | @end ifset | |
202 | ||
252b5132 | 203 | @ifclear SingleFormat |
ff5dcc92 SC |
204 | This version of @command{ld} uses the general purpose BFD libraries |
205 | to operate on object files. This allows @command{ld} to read, combine, and | |
252b5132 RH |
206 | write object files in many different formats---for example, COFF or |
207 | @code{a.out}. Different formats may be linked together to produce any | |
208 | available kind of object file. @xref{BFD}, for more information. | |
209 | @end ifclear | |
210 | ||
211 | Aside from its flexibility, the @sc{gnu} linker is more helpful than other | |
212 | linkers in providing diagnostic information. Many linkers abandon | |
213 | execution immediately upon encountering an error; whenever possible, | |
ff5dcc92 | 214 | @command{ld} continues executing, allowing you to identify other errors |
252b5132 RH |
215 | (or, in some cases, to get an output file in spite of the error). |
216 | ||
0285c67d NC |
217 | @c man end |
218 | ||
252b5132 RH |
219 | @node Invocation |
220 | @chapter Invocation | |
221 | ||
0285c67d NC |
222 | @c man begin DESCRIPTION |
223 | ||
ff5dcc92 | 224 | The @sc{gnu} linker @command{ld} is meant to cover a broad range of situations, |
252b5132 RH |
225 | and to be as compatible as possible with other linkers. As a result, |
226 | you have many choices to control its behavior. | |
227 | ||
0285c67d NC |
228 | @c man end |
229 | ||
252b5132 RH |
230 | @ifset UsesEnvVars |
231 | @menu | |
232 | * Options:: Command Line Options | |
233 | * Environment:: Environment Variables | |
234 | @end menu | |
235 | ||
236 | @node Options | |
237 | @section Command Line Options | |
238 | @end ifset | |
239 | ||
240 | @cindex command line | |
241 | @cindex options | |
0285c67d NC |
242 | |
243 | @c man begin OPTIONS | |
244 | ||
252b5132 RH |
245 | The linker supports a plethora of command-line options, but in actual |
246 | practice few of them are used in any particular context. | |
247 | @cindex standard Unix system | |
ff5dcc92 | 248 | For instance, a frequent use of @command{ld} is to link standard Unix |
252b5132 RH |
249 | object files on a standard, supported Unix system. On such a system, to |
250 | link a file @code{hello.o}: | |
251 | ||
252 | @smallexample | |
253 | ld -o @var{output} /lib/crt0.o hello.o -lc | |
254 | @end smallexample | |
255 | ||
ff5dcc92 | 256 | This tells @command{ld} to produce a file called @var{output} as the |
252b5132 RH |
257 | result of linking the file @code{/lib/crt0.o} with @code{hello.o} and |
258 | the library @code{libc.a}, which will come from the standard search | |
259 | directories. (See the discussion of the @samp{-l} option below.) | |
260 | ||
ff5dcc92 | 261 | Some of the command-line options to @command{ld} may be specified at any |
511ab9e9 ILT |
262 | point in the command line. However, options which refer to files, such |
263 | as @samp{-l} or @samp{-T}, cause the file to be read at the point at | |
264 | which the option appears in the command line, relative to the object | |
265 | files and other file options. Repeating non-file options with a | |
266 | different argument will either have no further effect, or override prior | |
252b5132 RH |
267 | occurrences (those further to the left on the command line) of that |
268 | option. Options which may be meaningfully specified more than once are | |
269 | noted in the descriptions below. | |
270 | ||
271 | @cindex object files | |
511ab9e9 ILT |
272 | Non-option arguments are object files or archives which are to be linked |
273 | together. They may follow, precede, or be mixed in with command-line | |
274 | options, except that an object file argument may not be placed between | |
275 | an option and its argument. | |
252b5132 RH |
276 | |
277 | Usually the linker is invoked with at least one object file, but you can | |
278 | specify other forms of binary input files using @samp{-l}, @samp{-R}, | |
279 | and the script command language. If @emph{no} binary input files at all | |
280 | are specified, the linker does not produce any output, and issues the | |
281 | message @samp{No input files}. | |
282 | ||
283 | If the linker can not recognize the format of an object file, it will | |
284 | assume that it is a linker script. A script specified in this way | |
285 | augments the main linker script used for the link (either the default | |
286 | linker script or the one specified by using @samp{-T}). This feature | |
287 | permits the linker to link against a file which appears to be an object | |
288 | or an archive, but actually merely defines some symbol values, or uses | |
289 | @code{INPUT} or @code{GROUP} to load other objects. Note that | |
114283d8 NC |
290 | specifying a script in this way merely augments the main linker script; |
291 | use the @samp{-T} option to replace the default linker script entirely. | |
252b5132 RH |
292 | @xref{Scripts}. |
293 | ||
294 | For options whose names are a single letter, | |
295 | option arguments must either follow the option letter without intervening | |
296 | whitespace, or be given as separate arguments immediately following the | |
297 | option that requires them. | |
298 | ||
299 | For options whose names are multiple letters, either one dash or two can | |
e4897a32 NC |
300 | precede the option name; for example, @samp{-trace-symbol} and |
301 | @samp{--trace-symbol} are equivalent. Note - there is one exception to | |
302 | this rule. Multiple letter options that start with a lower case 'o' can | |
303 | only be preceeded by two dashes. This is to reduce confusion with the | |
304 | @samp{-o} option. So for example @samp{-omagic} sets the output file | |
305 | name to @samp{magic} whereas @samp{--omagic} sets the NMAGIC flag on the | |
306 | output. | |
307 | ||
308 | Arguments to multiple-letter options must either be separated from the | |
309 | option name by an equals sign, or be given as separate arguments | |
310 | immediately following the option that requires them. For example, | |
311 | @samp{--trace-symbol foo} and @samp{--trace-symbol=foo} are equivalent. | |
312 | Unique abbreviations of the names of multiple-letter options are | |
313 | accepted. | |
252b5132 | 314 | |
4e53152f NC |
315 | Note - if the linker is being invoked indirectly, via a compiler driver |
316 | (eg @samp{gcc}) then all the linker command line options should be | |
fa19fce0 NC |
317 | prefixed by @samp{-Wl,} (or whatever is appropriate for the particular |
318 | compiler driver) like this: | |
4e53152f NC |
319 | |
320 | @smallexample | |
321 | gcc -Wl,--startgroup foo.o bar.o -Wl,--endgroup | |
322 | @end smallexample | |
323 | ||
324 | This is important, because otherwise the compiler driver program may | |
325 | silently drop the linker options, resulting in a bad link. | |
326 | ||
327 | Here is a table of the generic command line switches accepted by the GNU | |
328 | linker: | |
329 | ||
ff5dcc92 | 330 | @table @gcctabopt |
252b5132 RH |
331 | @kindex -a@var{keyword} |
332 | @item -a@var{keyword} | |
333 | This option is supported for HP/UX compatibility. The @var{keyword} | |
334 | argument must be one of the strings @samp{archive}, @samp{shared}, or | |
335 | @samp{default}. @samp{-aarchive} is functionally equivalent to | |
336 | @samp{-Bstatic}, and the other two keywords are functionally equivalent | |
337 | to @samp{-Bdynamic}. This option may be used any number of times. | |
338 | ||
339 | @ifset I960 | |
340 | @cindex architectures | |
341 | @kindex -A@var{arch} | |
342 | @item -A@var{architecture} | |
343 | @kindex --architecture=@var{arch} | |
344 | @itemx --architecture=@var{architecture} | |
ff5dcc92 SC |
345 | In the current release of @command{ld}, this option is useful only for the |
346 | Intel 960 family of architectures. In that @command{ld} configuration, the | |
252b5132 RH |
347 | @var{architecture} argument identifies the particular architecture in |
348 | the 960 family, enabling some safeguards and modifying the | |
ff5dcc92 | 349 | archive-library search path. @xref{i960,,@command{ld} and the Intel 960 |
252b5132 RH |
350 | family}, for details. |
351 | ||
ff5dcc92 | 352 | Future releases of @command{ld} may support similar functionality for |
252b5132 RH |
353 | other architecture families. |
354 | @end ifset | |
355 | ||
356 | @ifclear SingleFormat | |
357 | @cindex binary input format | |
358 | @kindex -b @var{format} | |
359 | @kindex --format=@var{format} | |
360 | @cindex input format | |
361 | @cindex input format | |
362 | @item -b @var{input-format} | |
363 | @itemx --format=@var{input-format} | |
ff5dcc92 SC |
364 | @command{ld} may be configured to support more than one kind of object |
365 | file. If your @command{ld} is configured this way, you can use the | |
252b5132 | 366 | @samp{-b} option to specify the binary format for input object files |
ff5dcc92 | 367 | that follow this option on the command line. Even when @command{ld} is |
252b5132 | 368 | configured to support alternative object formats, you don't usually need |
ff5dcc92 | 369 | to specify this, as @command{ld} should be configured to expect as a |
252b5132 RH |
370 | default input format the most usual format on each machine. |
371 | @var{input-format} is a text string, the name of a particular format | |
372 | supported by the BFD libraries. (You can list the available binary | |
373 | formats with @samp{objdump -i}.) | |
374 | @xref{BFD}. | |
375 | ||
376 | You may want to use this option if you are linking files with an unusual | |
377 | binary format. You can also use @samp{-b} to switch formats explicitly (when | |
378 | linking object files of different formats), by including | |
379 | @samp{-b @var{input-format}} before each group of object files in a | |
a1ab1d2a | 380 | particular format. |
252b5132 RH |
381 | |
382 | The default format is taken from the environment variable | |
383 | @code{GNUTARGET}. | |
384 | @ifset UsesEnvVars | |
385 | @xref{Environment}. | |
386 | @end ifset | |
387 | You can also define the input format from a script, using the command | |
0285c67d NC |
388 | @code{TARGET}; |
389 | @ifclear man | |
390 | see @ref{Format Commands}. | |
391 | @end ifclear | |
252b5132 RH |
392 | @end ifclear |
393 | ||
394 | @kindex -c @var{MRI-cmdfile} | |
395 | @kindex --mri-script=@var{MRI-cmdfile} | |
396 | @cindex compatibility, MRI | |
397 | @item -c @var{MRI-commandfile} | |
398 | @itemx --mri-script=@var{MRI-commandfile} | |
ff5dcc92 | 399 | For compatibility with linkers produced by MRI, @command{ld} accepts script |
252b5132 | 400 | files written in an alternate, restricted command language, described in |
0285c67d NC |
401 | @ifclear man |
402 | @ref{MRI,,MRI Compatible Script Files}. | |
403 | @end ifclear | |
404 | @ifset man | |
405 | the MRI Compatible Script Files section of GNU ld documentation. | |
406 | @end ifset | |
407 | Introduce MRI script files with | |
252b5132 | 408 | the option @samp{-c}; use the @samp{-T} option to run linker |
ff5dcc92 SC |
409 | scripts written in the general-purpose @command{ld} scripting language. |
410 | If @var{MRI-cmdfile} does not exist, @command{ld} looks for it in the directories | |
252b5132 RH |
411 | specified by any @samp{-L} options. |
412 | ||
413 | @cindex common allocation | |
414 | @kindex -d | |
415 | @kindex -dc | |
416 | @kindex -dp | |
a1ab1d2a | 417 | @item -d |
252b5132 RH |
418 | @itemx -dc |
419 | @itemx -dp | |
420 | These three options are equivalent; multiple forms are supported for | |
421 | compatibility with other linkers. They assign space to common symbols | |
422 | even if a relocatable output file is specified (with @samp{-r}). The | |
423 | script command @code{FORCE_COMMON_ALLOCATION} has the same effect. | |
424 | @xref{Miscellaneous Commands}. | |
425 | ||
426 | @cindex entry point, from command line | |
427 | @kindex -e @var{entry} | |
428 | @kindex --entry=@var{entry} | |
a1ab1d2a | 429 | @item -e @var{entry} |
252b5132 RH |
430 | @itemx --entry=@var{entry} |
431 | Use @var{entry} as the explicit symbol for beginning execution of your | |
432 | program, rather than the default entry point. If there is no symbol | |
433 | named @var{entry}, the linker will try to parse @var{entry} as a number, | |
434 | and use that as the entry address (the number will be interpreted in | |
435 | base 10; you may use a leading @samp{0x} for base 16, or a leading | |
436 | @samp{0} for base 8). @xref{Entry Point}, for a discussion of defaults | |
437 | and other ways of specifying the entry point. | |
438 | ||
439 | @cindex dynamic symbol table | |
440 | @kindex -E | |
441 | @kindex --export-dynamic | |
442 | @item -E | |
443 | @itemx --export-dynamic | |
444 | When creating a dynamically linked executable, add all symbols to the | |
445 | dynamic symbol table. The dynamic symbol table is the set of symbols | |
446 | which are visible from dynamic objects at run time. | |
447 | ||
448 | If you do not use this option, the dynamic symbol table will normally | |
449 | contain only those symbols which are referenced by some dynamic object | |
450 | mentioned in the link. | |
451 | ||
452 | If you use @code{dlopen} to load a dynamic object which needs to refer | |
453 | back to the symbols defined by the program, rather than some other | |
454 | dynamic object, then you will probably need to use this option when | |
455 | linking the program itself. | |
456 | ||
cb840a31 L |
457 | You can also use the version script to control what symbols should |
458 | be added to the dynamic symbol table if the output format supports it. | |
459 | See the description of @samp{--version-script} in @ref{VERSION}. | |
460 | ||
252b5132 RH |
461 | @cindex big-endian objects |
462 | @cindex endianness | |
463 | @kindex -EB | |
464 | @item -EB | |
465 | Link big-endian objects. This affects the default output format. | |
466 | ||
467 | @cindex little-endian objects | |
468 | @kindex -EL | |
469 | @item -EL | |
470 | Link little-endian objects. This affects the default output format. | |
471 | ||
472 | @kindex -f | |
473 | @kindex --auxiliary | |
474 | @item -f | |
475 | @itemx --auxiliary @var{name} | |
476 | When creating an ELF shared object, set the internal DT_AUXILIARY field | |
477 | to the specified name. This tells the dynamic linker that the symbol | |
478 | table of the shared object should be used as an auxiliary filter on the | |
479 | symbol table of the shared object @var{name}. | |
480 | ||
481 | If you later link a program against this filter object, then, when you | |
482 | run the program, the dynamic linker will see the DT_AUXILIARY field. If | |
483 | the dynamic linker resolves any symbols from the filter object, it will | |
484 | first check whether there is a definition in the shared object | |
485 | @var{name}. If there is one, it will be used instead of the definition | |
486 | in the filter object. The shared object @var{name} need not exist. | |
487 | Thus the shared object @var{name} may be used to provide an alternative | |
488 | implementation of certain functions, perhaps for debugging or for | |
489 | machine specific performance. | |
490 | ||
491 | This option may be specified more than once. The DT_AUXILIARY entries | |
492 | will be created in the order in which they appear on the command line. | |
493 | ||
494 | @kindex -F | |
495 | @kindex --filter | |
496 | @item -F @var{name} | |
497 | @itemx --filter @var{name} | |
498 | When creating an ELF shared object, set the internal DT_FILTER field to | |
499 | the specified name. This tells the dynamic linker that the symbol table | |
500 | of the shared object which is being created should be used as a filter | |
501 | on the symbol table of the shared object @var{name}. | |
502 | ||
503 | If you later link a program against this filter object, then, when you | |
504 | run the program, the dynamic linker will see the DT_FILTER field. The | |
505 | dynamic linker will resolve symbols according to the symbol table of the | |
506 | filter object as usual, but it will actually link to the definitions | |
507 | found in the shared object @var{name}. Thus the filter object can be | |
508 | used to select a subset of the symbols provided by the object | |
509 | @var{name}. | |
510 | ||
ff5dcc92 | 511 | Some older linkers used the @option{-F} option throughout a compilation |
252b5132 RH |
512 | toolchain for specifying object-file format for both input and output |
513 | object files. The @sc{gnu} linker uses other mechanisms for this | |
ff5dcc92 | 514 | purpose: the @option{-b}, @option{--format}, @option{--oformat} options, the |
252b5132 | 515 | @code{TARGET} command in linker scripts, and the @code{GNUTARGET} |
ff5dcc92 | 516 | environment variable. The @sc{gnu} linker will ignore the @option{-F} |
252b5132 RH |
517 | option when not creating an ELF shared object. |
518 | ||
3dbf70a2 MM |
519 | @cindex finalization function |
520 | @kindex -fini | |
521 | @item -fini @var{name} | |
522 | When creating an ELF executable or shared object, call NAME when the | |
523 | executable or shared object is unloaded, by setting DT_FINI to the | |
524 | address of the function. By default, the linker uses @code{_fini} as | |
525 | the function to call. | |
526 | ||
252b5132 RH |
527 | @kindex -g |
528 | @item -g | |
529 | Ignored. Provided for compatibility with other tools. | |
530 | ||
531 | @kindex -G | |
532 | @kindex --gpsize | |
533 | @cindex object size | |
534 | @item -G@var{value} | |
535 | @itemx --gpsize=@var{value} | |
536 | Set the maximum size of objects to be optimized using the GP register to | |
537 | @var{size}. This is only meaningful for object file formats such as | |
538 | MIPS ECOFF which supports putting large and small objects into different | |
539 | sections. This is ignored for other object file formats. | |
540 | ||
541 | @cindex runtime library name | |
542 | @kindex -h@var{name} | |
543 | @kindex -soname=@var{name} | |
544 | @item -h@var{name} | |
545 | @itemx -soname=@var{name} | |
546 | When creating an ELF shared object, set the internal DT_SONAME field to | |
547 | the specified name. When an executable is linked with a shared object | |
548 | which has a DT_SONAME field, then when the executable is run the dynamic | |
549 | linker will attempt to load the shared object specified by the DT_SONAME | |
550 | field rather than the using the file name given to the linker. | |
551 | ||
552 | @kindex -i | |
553 | @cindex incremental link | |
554 | @item -i | |
555 | Perform an incremental link (same as option @samp{-r}). | |
556 | ||
3dbf70a2 MM |
557 | @cindex initialization function |
558 | @kindex -init | |
559 | @item -init @var{name} | |
560 | When creating an ELF executable or shared object, call NAME when the | |
561 | executable or shared object is loaded, by setting DT_INIT to the address | |
562 | of the function. By default, the linker uses @code{_init} as the | |
563 | function to call. | |
564 | ||
252b5132 RH |
565 | @cindex archive files, from cmd line |
566 | @kindex -l@var{archive} | |
567 | @kindex --library=@var{archive} | |
568 | @item -l@var{archive} | |
569 | @itemx --library=@var{archive} | |
570 | Add archive file @var{archive} to the list of files to link. This | |
ff5dcc92 | 571 | option may be used any number of times. @command{ld} will search its |
252b5132 RH |
572 | path-list for occurrences of @code{lib@var{archive}.a} for every |
573 | @var{archive} specified. | |
574 | ||
ff5dcc92 | 575 | On systems which support shared libraries, @command{ld} may also search for |
252b5132 | 576 | libraries with extensions other than @code{.a}. Specifically, on ELF |
ff5dcc92 | 577 | and SunOS systems, @command{ld} will search a directory for a library with |
252b5132 RH |
578 | an extension of @code{.so} before searching for one with an extension of |
579 | @code{.a}. By convention, a @code{.so} extension indicates a shared | |
580 | library. | |
581 | ||
582 | The linker will search an archive only once, at the location where it is | |
583 | specified on the command line. If the archive defines a symbol which | |
584 | was undefined in some object which appeared before the archive on the | |
585 | command line, the linker will include the appropriate file(s) from the | |
586 | archive. However, an undefined symbol in an object appearing later on | |
587 | the command line will not cause the linker to search the archive again. | |
588 | ||
ff5dcc92 | 589 | See the @option{-(} option for a way to force the linker to search |
252b5132 RH |
590 | archives multiple times. |
591 | ||
592 | You may list the same archive multiple times on the command line. | |
593 | ||
594 | @ifset GENERIC | |
595 | This type of archive searching is standard for Unix linkers. However, | |
ff5dcc92 | 596 | if you are using @command{ld} on AIX, note that it is different from the |
252b5132 RH |
597 | behaviour of the AIX linker. |
598 | @end ifset | |
599 | ||
600 | @cindex search directory, from cmd line | |
601 | @kindex -L@var{dir} | |
602 | @kindex --library-path=@var{dir} | |
a1ab1d2a | 603 | @item -L@var{searchdir} |
252b5132 | 604 | @itemx --library-path=@var{searchdir} |
ff5dcc92 SC |
605 | Add path @var{searchdir} to the list of paths that @command{ld} will search |
606 | for archive libraries and @command{ld} control scripts. You may use this | |
252b5132 RH |
607 | option any number of times. The directories are searched in the order |
608 | in which they are specified on the command line. Directories specified | |
609 | on the command line are searched before the default directories. All | |
ff5dcc92 | 610 | @option{-L} options apply to all @option{-l} options, regardless of the |
252b5132 RH |
611 | order in which the options appear. |
612 | ||
9c8ebd6a DJ |
613 | If @var{searchdir} begins with @code{=}, then the @code{=} will be replaced |
614 | by the @dfn{sysroot prefix}, a path specified when the linker is configured. | |
615 | ||
252b5132 RH |
616 | @ifset UsesEnvVars |
617 | The default set of paths searched (without being specified with | |
ff5dcc92 | 618 | @samp{-L}) depends on which emulation mode @command{ld} is using, and in |
252b5132 RH |
619 | some cases also on how it was configured. @xref{Environment}. |
620 | @end ifset | |
621 | ||
622 | The paths can also be specified in a link script with the | |
623 | @code{SEARCH_DIR} command. Directories specified this way are searched | |
624 | at the point in which the linker script appears in the command line. | |
625 | ||
626 | @cindex emulation | |
627 | @kindex -m @var{emulation} | |
628 | @item -m@var{emulation} | |
629 | Emulate the @var{emulation} linker. You can list the available | |
630 | emulations with the @samp{--verbose} or @samp{-V} options. | |
631 | ||
632 | If the @samp{-m} option is not used, the emulation is taken from the | |
633 | @code{LDEMULATION} environment variable, if that is defined. | |
634 | ||
635 | Otherwise, the default emulation depends upon how the linker was | |
636 | configured. | |
637 | ||
638 | @cindex link map | |
639 | @kindex -M | |
640 | @kindex --print-map | |
641 | @item -M | |
642 | @itemx --print-map | |
643 | Print a link map to the standard output. A link map provides | |
644 | information about the link, including the following: | |
645 | ||
646 | @itemize @bullet | |
647 | @item | |
648 | Where object files and symbols are mapped into memory. | |
649 | @item | |
650 | How common symbols are allocated. | |
651 | @item | |
652 | All archive members included in the link, with a mention of the symbol | |
653 | which caused the archive member to be brought in. | |
654 | @end itemize | |
655 | ||
656 | @kindex -n | |
657 | @cindex read-only text | |
658 | @cindex NMAGIC | |
659 | @kindex --nmagic | |
660 | @item -n | |
661 | @itemx --nmagic | |
fa19fce0 | 662 | Turn off page alignment of sections, and mark the output as |
a1ab1d2a | 663 | @code{NMAGIC} if possible. |
252b5132 RH |
664 | |
665 | @kindex -N | |
666 | @kindex --omagic | |
667 | @cindex read/write from cmd line | |
668 | @cindex OMAGIC | |
a1ab1d2a | 669 | @item -N |
252b5132 RH |
670 | @itemx --omagic |
671 | Set the text and data sections to be readable and writable. Also, do | |
63fd3b82 NC |
672 | not page-align the data segment, and disable linking against shared |
673 | libraries. If the output format supports Unix style magic numbers, | |
674 | mark the output as @code{OMAGIC}. | |
675 | ||
676 | @kindex --no-omagic | |
677 | @cindex OMAGIC | |
678 | @item --no-omagic | |
679 | This option negates most of the effects of the @option{-N} option. It | |
680 | sets the text section to be read-only, and forces the data segment to | |
681 | be page-aligned. Note - this option does not enable linking against | |
682 | shared libraries. Use @option{-Bdynamic} for this. | |
252b5132 RH |
683 | |
684 | @kindex -o @var{output} | |
685 | @kindex --output=@var{output} | |
686 | @cindex naming the output file | |
687 | @item -o @var{output} | |
688 | @itemx --output=@var{output} | |
ff5dcc92 | 689 | Use @var{output} as the name for the program produced by @command{ld}; if this |
252b5132 RH |
690 | option is not specified, the name @file{a.out} is used by default. The |
691 | script command @code{OUTPUT} can also specify the output file name. | |
692 | ||
693 | @kindex -O @var{level} | |
694 | @cindex generating optimized output | |
695 | @item -O @var{level} | |
ff5dcc92 | 696 | If @var{level} is a numeric values greater than zero @command{ld} optimizes |
252b5132 RH |
697 | the output. This might take significantly longer and therefore probably |
698 | should only be enabled for the final binary. | |
699 | ||
a712da20 NC |
700 | @kindex -q |
701 | @kindex --emit-relocs | |
702 | @cindex retain relocations in final executable | |
703 | @item -q | |
704 | @itemx --emit-relocs | |
705 | Leave relocation sections and contents in fully linked exececutables. | |
706 | Post link analysis and optimization tools may need this information in | |
707 | order to perform correct modifications of executables. This results | |
708 | in larger executables. | |
709 | ||
dbab7a7b NC |
710 | This option is currently only supported on ELF platforms. |
711 | ||
252b5132 RH |
712 | @cindex partial link |
713 | @cindex relocatable output | |
714 | @kindex -r | |
715 | @kindex --relocateable | |
716 | @item -r | |
717 | @itemx --relocateable | |
718 | Generate relocatable output---i.e., generate an output file that can in | |
ff5dcc92 | 719 | turn serve as input to @command{ld}. This is often called @dfn{partial |
252b5132 RH |
720 | linking}. As a side effect, in environments that support standard Unix |
721 | magic numbers, this option also sets the output file's magic number to | |
722 | @code{OMAGIC}. | |
ff5dcc92 | 723 | @c ; see @option{-N}. |
252b5132 RH |
724 | If this option is not specified, an absolute file is produced. When |
725 | linking C++ programs, this option @emph{will not} resolve references to | |
726 | constructors; to do that, use @samp{-Ur}. | |
727 | ||
62bf86b4 HPN |
728 | When an input file does not have the same format as the output file, |
729 | partial linking is only supported if that input file does not contain any | |
730 | relocations. Different output formats can have further restrictions; for | |
731 | example some @code{a.out}-based formats do not support partial linking | |
732 | with input files in other formats at all. | |
733 | ||
252b5132 RH |
734 | This option does the same thing as @samp{-i}. |
735 | ||
736 | @kindex -R @var{file} | |
737 | @kindex --just-symbols=@var{file} | |
738 | @cindex symbol-only input | |
739 | @item -R @var{filename} | |
740 | @itemx --just-symbols=@var{filename} | |
741 | Read symbol names and their addresses from @var{filename}, but do not | |
742 | relocate it or include it in the output. This allows your output file | |
743 | to refer symbolically to absolute locations of memory defined in other | |
744 | programs. You may use this option more than once. | |
745 | ||
ff5dcc92 | 746 | For compatibility with other ELF linkers, if the @option{-R} option is |
252b5132 | 747 | followed by a directory name, rather than a file name, it is treated as |
ff5dcc92 | 748 | the @option{-rpath} option. |
252b5132 RH |
749 | |
750 | @kindex -s | |
751 | @kindex --strip-all | |
752 | @cindex strip all symbols | |
a1ab1d2a | 753 | @item -s |
252b5132 RH |
754 | @itemx --strip-all |
755 | Omit all symbol information from the output file. | |
756 | ||
757 | @kindex -S | |
758 | @kindex --strip-debug | |
759 | @cindex strip debugger symbols | |
a1ab1d2a | 760 | @item -S |
252b5132 RH |
761 | @itemx --strip-debug |
762 | Omit debugger symbol information (but not all symbols) from the output file. | |
763 | ||
764 | @kindex -t | |
765 | @kindex --trace | |
766 | @cindex input files, displaying | |
a1ab1d2a | 767 | @item -t |
252b5132 | 768 | @itemx --trace |
ff5dcc92 | 769 | Print the names of the input files as @command{ld} processes them. |
252b5132 RH |
770 | |
771 | @kindex -T @var{script} | |
772 | @kindex --script=@var{script} | |
773 | @cindex script files | |
774 | @item -T @var{scriptfile} | |
775 | @itemx --script=@var{scriptfile} | |
776 | Use @var{scriptfile} as the linker script. This script replaces | |
ff5dcc92 | 777 | @command{ld}'s default linker script (rather than adding to it), so |
252b5132 | 778 | @var{commandfile} must specify everything necessary to describe the |
114283d8 NC |
779 | output file. @xref{Scripts}. If @var{scriptfile} does not exist in |
780 | the current directory, @code{ld} looks for it in the directories | |
781 | specified by any preceding @samp{-L} options. Multiple @samp{-T} | |
782 | options accumulate. | |
252b5132 RH |
783 | |
784 | @kindex -u @var{symbol} | |
785 | @kindex --undefined=@var{symbol} | |
786 | @cindex undefined symbol | |
787 | @item -u @var{symbol} | |
788 | @itemx --undefined=@var{symbol} | |
789 | Force @var{symbol} to be entered in the output file as an undefined | |
790 | symbol. Doing this may, for example, trigger linking of additional | |
791 | modules from standard libraries. @samp{-u} may be repeated with | |
792 | different option arguments to enter additional undefined symbols. This | |
793 | option is equivalent to the @code{EXTERN} linker script command. | |
794 | ||
795 | @kindex -Ur | |
796 | @cindex constructors | |
a1ab1d2a | 797 | @item -Ur |
252b5132 RH |
798 | For anything other than C++ programs, this option is equivalent to |
799 | @samp{-r}: it generates relocatable output---i.e., an output file that can in | |
ff5dcc92 | 800 | turn serve as input to @command{ld}. When linking C++ programs, @samp{-Ur} |
252b5132 RH |
801 | @emph{does} resolve references to constructors, unlike @samp{-r}. |
802 | It does not work to use @samp{-Ur} on files that were themselves linked | |
803 | with @samp{-Ur}; once the constructor table has been built, it cannot | |
804 | be added to. Use @samp{-Ur} only for the last partial link, and | |
805 | @samp{-r} for the others. | |
806 | ||
577a0623 AM |
807 | @kindex --unique[=@var{SECTION}] |
808 | @item --unique[=@var{SECTION}] | |
809 | Creates a separate output section for every input section matching | |
810 | @var{SECTION}, or if the optional wildcard @var{SECTION} argument is | |
811 | missing, for every orphan input section. An orphan section is one not | |
812 | specifically mentioned in a linker script. You may use this option | |
813 | multiple times on the command line; It prevents the normal merging of | |
814 | input sections with the same name, overriding output section assignments | |
815 | in a linker script. | |
a854a4a7 | 816 | |
252b5132 RH |
817 | @kindex -v |
818 | @kindex -V | |
819 | @kindex --version | |
820 | @cindex version | |
821 | @item -v | |
822 | @itemx --version | |
823 | @itemx -V | |
ff5dcc92 | 824 | Display the version number for @command{ld}. The @option{-V} option also |
252b5132 RH |
825 | lists the supported emulations. |
826 | ||
827 | @kindex -x | |
828 | @kindex --discard-all | |
829 | @cindex deleting local symbols | |
830 | @item -x | |
831 | @itemx --discard-all | |
832 | Delete all local symbols. | |
833 | ||
834 | @kindex -X | |
835 | @kindex --discard-locals | |
836 | @cindex local symbols, deleting | |
837 | @cindex L, deleting symbols beginning | |
a1ab1d2a | 838 | @item -X |
252b5132 RH |
839 | @itemx --discard-locals |
840 | Delete all temporary local symbols. For most targets, this is all local | |
841 | symbols whose names begin with @samp{L}. | |
842 | ||
843 | @kindex -y @var{symbol} | |
844 | @kindex --trace-symbol=@var{symbol} | |
845 | @cindex symbol tracing | |
846 | @item -y @var{symbol} | |
847 | @itemx --trace-symbol=@var{symbol} | |
848 | Print the name of each linked file in which @var{symbol} appears. This | |
849 | option may be given any number of times. On many systems it is necessary | |
850 | to prepend an underscore. | |
851 | ||
852 | This option is useful when you have an undefined symbol in your link but | |
853 | don't know where the reference is coming from. | |
854 | ||
855 | @kindex -Y @var{path} | |
856 | @item -Y @var{path} | |
857 | Add @var{path} to the default library search path. This option exists | |
858 | for Solaris compatibility. | |
859 | ||
860 | @kindex -z @var{keyword} | |
861 | @item -z @var{keyword} | |
e0ee487b L |
862 | The recognized keywords are @code{initfirst}, @code{interpose}, |
863 | @code{loadfltr}, @code{nodefaultlib}, @code{nodelete}, @code{nodlopen}, | |
8bd621d8 AM |
864 | @code{nodump}, @code{now}, @code{origin}, @code{combreloc}, @code{nocombreloc} |
865 | and @code{nocopyreloc}. | |
866 | The other keywords are | |
e0ee487b L |
867 | ignored for Solaris compatibility. @code{initfirst} marks the object |
868 | to be initialized first at runtime before any other objects. | |
869 | @code{interpose} marks the object that its symbol table interposes | |
870 | before all symbols but the primary executable. @code{loadfltr} marks | |
871 | the object that its filtees be processed immediately at runtime. | |
872 | @code{nodefaultlib} marks the object that the search for dependencies | |
873 | of this object will ignore any default library search paths. | |
874 | @code{nodelete} marks the object shouldn't be unloaded at runtime. | |
875 | @code{nodlopen} marks the object not available to @code{dlopen}. | |
876 | @code{nodump} marks the object can not be dumped by @code{dldump}. | |
877 | @code{now} marks the object with the non-lazy runtime binding. | |
878 | @code{origin} marks the object may contain $ORIGIN. | |
a1ab1d2a | 879 | @code{defs} disallows undefined symbols. |
aa713662 | 880 | @code{muldefs} allows multiple definitions. |
db6751f2 JJ |
881 | @code{combreloc} combines multiple reloc sections and sorts them |
882 | to make dynamic symbol lookup caching possible. | |
883 | @code{nocombreloc} disables multiple reloc sections combining. | |
8bd621d8 | 884 | @code{nocopyreloc} disables production of copy relocs. |
252b5132 RH |
885 | |
886 | @kindex -( | |
887 | @cindex groups of archives | |
888 | @item -( @var{archives} -) | |
889 | @itemx --start-group @var{archives} --end-group | |
890 | The @var{archives} should be a list of archive files. They may be | |
891 | either explicit file names, or @samp{-l} options. | |
892 | ||
893 | The specified archives are searched repeatedly until no new undefined | |
894 | references are created. Normally, an archive is searched only once in | |
895 | the order that it is specified on the command line. If a symbol in that | |
896 | archive is needed to resolve an undefined symbol referred to by an | |
897 | object in an archive that appears later on the command line, the linker | |
898 | would not be able to resolve that reference. By grouping the archives, | |
899 | they all be searched repeatedly until all possible references are | |
900 | resolved. | |
901 | ||
902 | Using this option has a significant performance cost. It is best to use | |
903 | it only when there are unavoidable circular references between two or | |
904 | more archives. | |
905 | ||
69da35b5 NC |
906 | @kindex --accept-unknown-input-arch |
907 | @kindex --no-accept-unknown-input-arch | |
908 | @item --accept-unknown-input-arch | |
909 | @itemx --no-accept-unknown-input-arch | |
910 | Tells the linker to accept input files whose architecture cannot be | |
2ca22b03 | 911 | recognised. The assumption is that the user knows what they are doing |
69da35b5 NC |
912 | and deliberately wants to link in these unknown input files. This was |
913 | the default behaviour of the linker, before release 2.14. The default | |
914 | behaviour from release 2.14 onwards is to reject such input files, and | |
915 | so the @samp{--accept-unknown-input-arch} option has been added to | |
916 | restore the old behaviour. | |
2ca22b03 | 917 | |
252b5132 RH |
918 | @kindex -assert @var{keyword} |
919 | @item -assert @var{keyword} | |
920 | This option is ignored for SunOS compatibility. | |
921 | ||
922 | @kindex -Bdynamic | |
923 | @kindex -dy | |
924 | @kindex -call_shared | |
925 | @item -Bdynamic | |
926 | @itemx -dy | |
927 | @itemx -call_shared | |
928 | Link against dynamic libraries. This is only meaningful on platforms | |
929 | for which shared libraries are supported. This option is normally the | |
930 | default on such platforms. The different variants of this option are | |
931 | for compatibility with various systems. You may use this option | |
932 | multiple times on the command line: it affects library searching for | |
ff5dcc92 | 933 | @option{-l} options which follow it. |
252b5132 | 934 | |
a1ab1d2a UD |
935 | @kindex -Bgroup |
936 | @item -Bgroup | |
937 | Set the @code{DF_1_GROUP} flag in the @code{DT_FLAGS_1} entry in the dynamic | |
938 | section. This causes the runtime linker to handle lookups in this | |
939 | object and its dependencies to be performed only inside the group. | |
ff5dcc92 | 940 | @option{--no-undefined} is implied. This option is only meaningful on ELF |
a1ab1d2a UD |
941 | platforms which support shared libraries. |
942 | ||
252b5132 RH |
943 | @kindex -Bstatic |
944 | @kindex -dn | |
945 | @kindex -non_shared | |
946 | @kindex -static | |
a1ab1d2a | 947 | @item -Bstatic |
252b5132 RH |
948 | @itemx -dn |
949 | @itemx -non_shared | |
950 | @itemx -static | |
951 | Do not link against shared libraries. This is only meaningful on | |
952 | platforms for which shared libraries are supported. The different | |
953 | variants of this option are for compatibility with various systems. You | |
954 | may use this option multiple times on the command line: it affects | |
ff5dcc92 | 955 | library searching for @option{-l} options which follow it. |
252b5132 RH |
956 | |
957 | @kindex -Bsymbolic | |
958 | @item -Bsymbolic | |
959 | When creating a shared library, bind references to global symbols to the | |
960 | definition within the shared library, if any. Normally, it is possible | |
961 | for a program linked against a shared library to override the definition | |
962 | within the shared library. This option is only meaningful on ELF | |
963 | platforms which support shared libraries. | |
964 | ||
965 | @kindex --check-sections | |
966 | @kindex --no-check-sections | |
967 | @item --check-sections | |
308b1ffd | 968 | @itemx --no-check-sections |
252b5132 RH |
969 | Asks the linker @emph{not} to check section addresses after they have |
970 | been assigned to see if there any overlaps. Normally the linker will | |
971 | perform this check, and if it finds any overlaps it will produce | |
972 | suitable error messages. The linker does know about, and does make | |
973 | allowances for sections in overlays. The default behaviour can be | |
974 | restored by using the command line switch @samp{--check-sections}. | |
975 | ||
976 | @cindex cross reference table | |
977 | @kindex --cref | |
978 | @item --cref | |
979 | Output a cross reference table. If a linker map file is being | |
980 | generated, the cross reference table is printed to the map file. | |
981 | Otherwise, it is printed on the standard output. | |
982 | ||
983 | The format of the table is intentionally simple, so that it may be | |
984 | easily processed by a script if necessary. The symbols are printed out, | |
985 | sorted by name. For each symbol, a list of file names is given. If the | |
986 | symbol is defined, the first file listed is the location of the | |
987 | definition. The remaining files contain references to the symbol. | |
988 | ||
4818e05f AM |
989 | @cindex common allocation |
990 | @kindex --no-define-common | |
991 | @item --no-define-common | |
992 | This option inhibits the assignment of addresses to common symbols. | |
993 | The script command @code{INHIBIT_COMMON_ALLOCATION} has the same effect. | |
994 | @xref{Miscellaneous Commands}. | |
995 | ||
996 | The @samp{--no-define-common} option allows decoupling | |
997 | the decision to assign addresses to Common symbols from the choice | |
998 | of the output file type; otherwise a non-Relocatable output type | |
999 | forces assigning addresses to Common symbols. | |
1000 | Using @samp{--no-define-common} allows Common symbols that are referenced | |
1001 | from a shared library to be assigned addresses only in the main program. | |
1002 | This eliminates the unused duplicate space in the shared library, | |
1003 | and also prevents any possible confusion over resolving to the wrong | |
1004 | duplicate when there are many dynamic modules with specialized search | |
1005 | paths for runtime symbol resolution. | |
1006 | ||
252b5132 RH |
1007 | @cindex symbols, from command line |
1008 | @kindex --defsym @var{symbol}=@var{exp} | |
1009 | @item --defsym @var{symbol}=@var{expression} | |
1010 | Create a global symbol in the output file, containing the absolute | |
1011 | address given by @var{expression}. You may use this option as many | |
1012 | times as necessary to define multiple symbols in the command line. A | |
1013 | limited form of arithmetic is supported for the @var{expression} in this | |
1014 | context: you may give a hexadecimal constant or the name of an existing | |
1015 | symbol, or use @code{+} and @code{-} to add or subtract hexadecimal | |
1016 | constants or symbols. If you need more elaborate expressions, consider | |
1017 | using the linker command language from a script (@pxref{Assignments,, | |
1018 | Assignment: Symbol Definitions}). @emph{Note:} there should be no white | |
1019 | space between @var{symbol}, the equals sign (``@key{=}''), and | |
1020 | @var{expression}. | |
1021 | ||
1022 | @cindex demangling, from command line | |
28c309a2 | 1023 | @kindex --demangle[=@var{style}] |
252b5132 | 1024 | @kindex --no-demangle |
28c309a2 | 1025 | @item --demangle[=@var{style}] |
252b5132 RH |
1026 | @itemx --no-demangle |
1027 | These options control whether to demangle symbol names in error messages | |
1028 | and other output. When the linker is told to demangle, it tries to | |
1029 | present symbol names in a readable fashion: it strips leading | |
1030 | underscores if they are used by the object file format, and converts C++ | |
a1ab1d2a UD |
1031 | mangled symbol names into user readable names. Different compilers have |
1032 | different mangling styles. The optional demangling style argument can be used | |
1033 | to choose an appropriate demangling style for your compiler. The linker will | |
28c309a2 NC |
1034 | demangle by default unless the environment variable @samp{COLLECT_NO_DEMANGLE} |
1035 | is set. These options may be used to override the default. | |
252b5132 RH |
1036 | |
1037 | @cindex dynamic linker, from command line | |
506eee22 | 1038 | @kindex -I@var{file} |
252b5132 RH |
1039 | @kindex --dynamic-linker @var{file} |
1040 | @item --dynamic-linker @var{file} | |
1041 | Set the name of the dynamic linker. This is only meaningful when | |
1042 | generating dynamically linked ELF executables. The default dynamic | |
1043 | linker is normally correct; don't use this unless you know what you are | |
1044 | doing. | |
1045 | ||
1046 | @cindex MIPS embedded PIC code | |
1047 | @kindex --embedded-relocs | |
1048 | @item --embedded-relocs | |
1049 | This option is only meaningful when linking MIPS embedded PIC code, | |
1050 | generated by the -membedded-pic option to the @sc{gnu} compiler and | |
1051 | assembler. It causes the linker to create a table which may be used at | |
1052 | runtime to relocate any data which was statically initialized to pointer | |
1053 | values. See the code in testsuite/ld-empic for details. | |
1054 | ||
7ce691ae C |
1055 | |
1056 | @kindex --fatal-warnings | |
1057 | @item --fatal-warnings | |
1058 | Treat all warnings as errors. | |
1059 | ||
252b5132 RH |
1060 | @kindex --force-exe-suffix |
1061 | @item --force-exe-suffix | |
1062 | Make sure that an output file has a .exe suffix. | |
1063 | ||
1064 | If a successfully built fully linked output file does not have a | |
1065 | @code{.exe} or @code{.dll} suffix, this option forces the linker to copy | |
1066 | the output file to one of the same name with a @code{.exe} suffix. This | |
1067 | option is useful when using unmodified Unix makefiles on a Microsoft | |
1068 | Windows host, since some versions of Windows won't run an image unless | |
1069 | it ends in a @code{.exe} suffix. | |
1070 | ||
1071 | @kindex --gc-sections | |
1072 | @kindex --no-gc-sections | |
1073 | @cindex garbage collection | |
1074 | @item --no-gc-sections | |
1075 | @itemx --gc-sections | |
1076 | Enable garbage collection of unused input sections. It is ignored on | |
1077 | targets that do not support this option. This option is not compatible | |
1078 | with @samp{-r}, nor should it be used with dynamic linking. The default | |
1079 | behaviour (of not performing this garbage collection) can be restored by | |
1080 | specifying @samp{--no-gc-sections} on the command line. | |
1081 | ||
1082 | @cindex help | |
1083 | @cindex usage | |
1084 | @kindex --help | |
1085 | @item --help | |
1086 | Print a summary of the command-line options on the standard output and exit. | |
1087 | ||
ea20a7da CC |
1088 | @kindex --target-help |
1089 | @item --target-help | |
1090 | Print a summary of all target specific options on the standard output and exit. | |
1091 | ||
252b5132 RH |
1092 | @kindex -Map |
1093 | @item -Map @var{mapfile} | |
1094 | Print a link map to the file @var{mapfile}. See the description of the | |
1095 | @samp{-M} option, above. | |
1096 | ||
1097 | @cindex memory usage | |
1098 | @kindex --no-keep-memory | |
1099 | @item --no-keep-memory | |
ff5dcc92 SC |
1100 | @command{ld} normally optimizes for speed over memory usage by caching the |
1101 | symbol tables of input files in memory. This option tells @command{ld} to | |
252b5132 | 1102 | instead optimize for memory usage, by rereading the symbol tables as |
ff5dcc92 | 1103 | necessary. This may be required if @command{ld} runs out of memory space |
252b5132 RH |
1104 | while linking a large executable. |
1105 | ||
1106 | @kindex --no-undefined | |
a1ab1d2a | 1107 | @kindex -z defs |
252b5132 | 1108 | @item --no-undefined |
a1ab1d2a | 1109 | @itemx -z defs |
252b5132 | 1110 | Normally when creating a non-symbolic shared library, undefined symbols |
a1ab1d2a | 1111 | are allowed and left to be resolved by the runtime loader. These options |
252b5132 RH |
1112 | disallows such undefined symbols. |
1113 | ||
aa713662 L |
1114 | @kindex --allow-multiple-definition |
1115 | @kindex -z muldefs | |
1116 | @item --allow-multiple-definition | |
1117 | @itemx -z muldefs | |
1118 | Normally when a symbol is defined multiple times, the linker will | |
1119 | report a fatal error. These options allow multiple definitions and the | |
1120 | first definition will be used. | |
1121 | ||
b79e8c78 NC |
1122 | @kindex --allow-shlib-undefined |
1123 | @item --allow-shlib-undefined | |
1124 | Allow undefined symbols in shared objects even when --no-undefined is | |
1125 | set. The net result will be that undefined symbols in regular objects | |
1126 | will still trigger an error, but undefined symbols in shared objects | |
1127 | will be ignored. The implementation of no_undefined makes the | |
1128 | assumption that the runtime linker will choke on undefined symbols. | |
1129 | However there is at least one system (BeOS) where undefined symbols in | |
1130 | shared libraries is normal since the kernel patches them at load time to | |
1131 | select which function is most appropriate for the current architecture. | |
1132 | I.E. dynamically select an appropriate memset function. Apparently it | |
1133 | is also normal for HPPA shared libraries to have undefined symbols. | |
1134 | ||
31941635 L |
1135 | @kindex --no-undefined-version |
1136 | @item --no-undefined-version | |
1137 | Normally when a symbol has an undefined version, the linker will ignore | |
1138 | it. This option disallows symbols with undefined version and a fatal error | |
1139 | will be issued instead. | |
1140 | ||
252b5132 RH |
1141 | @kindex --no-warn-mismatch |
1142 | @item --no-warn-mismatch | |
ff5dcc92 | 1143 | Normally @command{ld} will give an error if you try to link together input |
252b5132 RH |
1144 | files that are mismatched for some reason, perhaps because they have |
1145 | been compiled for different processors or for different endiannesses. | |
ff5dcc92 | 1146 | This option tells @command{ld} that it should silently permit such possible |
252b5132 RH |
1147 | errors. This option should only be used with care, in cases when you |
1148 | have taken some special action that ensures that the linker errors are | |
1149 | inappropriate. | |
1150 | ||
1151 | @kindex --no-whole-archive | |
1152 | @item --no-whole-archive | |
ff5dcc92 | 1153 | Turn off the effect of the @option{--whole-archive} option for subsequent |
252b5132 RH |
1154 | archive files. |
1155 | ||
1156 | @cindex output file after errors | |
1157 | @kindex --noinhibit-exec | |
1158 | @item --noinhibit-exec | |
1159 | Retain the executable output file whenever it is still usable. | |
1160 | Normally, the linker will not produce an output file if it encounters | |
1161 | errors during the link process; it exits without writing an output file | |
1162 | when it issues any error whatsoever. | |
1163 | ||
0a9c1c8e CD |
1164 | @kindex -nostdlib |
1165 | @item -nostdlib | |
1166 | Only search library directories explicitly specified on the | |
1167 | command line. Library directories specified in linker scripts | |
1168 | (including linker scripts specified on the command line) are ignored. | |
1169 | ||
252b5132 RH |
1170 | @ifclear SingleFormat |
1171 | @kindex --oformat | |
1172 | @item --oformat @var{output-format} | |
ff5dcc92 SC |
1173 | @command{ld} may be configured to support more than one kind of object |
1174 | file. If your @command{ld} is configured this way, you can use the | |
252b5132 | 1175 | @samp{--oformat} option to specify the binary format for the output |
ff5dcc92 SC |
1176 | object file. Even when @command{ld} is configured to support alternative |
1177 | object formats, you don't usually need to specify this, as @command{ld} | |
252b5132 RH |
1178 | should be configured to produce as a default output format the most |
1179 | usual format on each machine. @var{output-format} is a text string, the | |
1180 | name of a particular format supported by the BFD libraries. (You can | |
1181 | list the available binary formats with @samp{objdump -i}.) The script | |
1182 | command @code{OUTPUT_FORMAT} can also specify the output format, but | |
1183 | this option overrides it. @xref{BFD}. | |
1184 | @end ifclear | |
1185 | ||
1186 | @kindex -qmagic | |
1187 | @item -qmagic | |
1188 | This option is ignored for Linux compatibility. | |
1189 | ||
1190 | @kindex -Qy | |
1191 | @item -Qy | |
1192 | This option is ignored for SVR4 compatibility. | |
1193 | ||
1194 | @kindex --relax | |
1195 | @cindex synthesizing linker | |
1196 | @cindex relaxing addressing modes | |
1197 | @item --relax | |
a1ab1d2a | 1198 | An option with machine dependent effects. |
252b5132 RH |
1199 | @ifset GENERIC |
1200 | This option is only supported on a few targets. | |
1201 | @end ifset | |
1202 | @ifset H8300 | |
ff5dcc92 | 1203 | @xref{H8/300,,@command{ld} and the H8/300}. |
252b5132 RH |
1204 | @end ifset |
1205 | @ifset I960 | |
ff5dcc92 | 1206 | @xref{i960,, @command{ld} and the Intel 960 family}. |
252b5132 RH |
1207 | @end ifset |
1208 | ||
1209 | ||
1210 | On some platforms, the @samp{--relax} option performs global | |
1211 | optimizations that become possible when the linker resolves addressing | |
1212 | in the program, such as relaxing address modes and synthesizing new | |
1213 | instructions in the output object file. | |
1214 | ||
1215 | On some platforms these link time global optimizations may make symbolic | |
1216 | debugging of the resulting executable impossible. | |
1217 | @ifset GENERIC | |
1218 | This is known to be | |
1219 | the case for the Matsushita MN10200 and MN10300 family of processors. | |
1220 | @end ifset | |
1221 | ||
1222 | @ifset GENERIC | |
1223 | On platforms where this is not supported, @samp{--relax} is accepted, | |
1224 | but ignored. | |
1225 | @end ifset | |
1226 | ||
1227 | @cindex retaining specified symbols | |
1228 | @cindex stripping all but some symbols | |
1229 | @cindex symbols, retaining selectively | |
1230 | @item --retain-symbols-file @var{filename} | |
1231 | Retain @emph{only} the symbols listed in the file @var{filename}, | |
1232 | discarding all others. @var{filename} is simply a flat file, with one | |
1233 | symbol name per line. This option is especially useful in environments | |
1234 | @ifset GENERIC | |
1235 | (such as VxWorks) | |
1236 | @end ifset | |
1237 | where a large global symbol table is accumulated gradually, to conserve | |
1238 | run-time memory. | |
1239 | ||
1240 | @samp{--retain-symbols-file} does @emph{not} discard undefined symbols, | |
1241 | or symbols needed for relocations. | |
1242 | ||
1243 | You may only specify @samp{--retain-symbols-file} once in the command | |
1244 | line. It overrides @samp{-s} and @samp{-S}. | |
1245 | ||
1246 | @ifset GENERIC | |
1247 | @item -rpath @var{dir} | |
1248 | @cindex runtime library search path | |
1249 | @kindex -rpath | |
1250 | Add a directory to the runtime library search path. This is used when | |
ff5dcc92 | 1251 | linking an ELF executable with shared objects. All @option{-rpath} |
252b5132 | 1252 | arguments are concatenated and passed to the runtime linker, which uses |
ff5dcc92 | 1253 | them to locate shared objects at runtime. The @option{-rpath} option is |
252b5132 RH |
1254 | also used when locating shared objects which are needed by shared |
1255 | objects explicitly included in the link; see the description of the | |
ff5dcc92 | 1256 | @option{-rpath-link} option. If @option{-rpath} is not used when linking an |
252b5132 RH |
1257 | ELF executable, the contents of the environment variable |
1258 | @code{LD_RUN_PATH} will be used if it is defined. | |
1259 | ||
ff5dcc92 | 1260 | The @option{-rpath} option may also be used on SunOS. By default, on |
252b5132 | 1261 | SunOS, the linker will form a runtime search patch out of all the |
ff5dcc92 SC |
1262 | @option{-L} options it is given. If a @option{-rpath} option is used, the |
1263 | runtime search path will be formed exclusively using the @option{-rpath} | |
1264 | options, ignoring the @option{-L} options. This can be useful when using | |
1265 | gcc, which adds many @option{-L} options which may be on NFS mounted | |
252b5132 RH |
1266 | filesystems. |
1267 | ||
ff5dcc92 | 1268 | For compatibility with other ELF linkers, if the @option{-R} option is |
252b5132 | 1269 | followed by a directory name, rather than a file name, it is treated as |
ff5dcc92 | 1270 | the @option{-rpath} option. |
252b5132 RH |
1271 | @end ifset |
1272 | ||
1273 | @ifset GENERIC | |
1274 | @cindex link-time runtime library search path | |
1275 | @kindex -rpath-link | |
1276 | @item -rpath-link @var{DIR} | |
1277 | When using ELF or SunOS, one shared library may require another. This | |
1278 | happens when an @code{ld -shared} link includes a shared library as one | |
1279 | of the input files. | |
1280 | ||
1281 | When the linker encounters such a dependency when doing a non-shared, | |
1282 | non-relocatable link, it will automatically try to locate the required | |
1283 | shared library and include it in the link, if it is not included | |
ff5dcc92 | 1284 | explicitly. In such a case, the @option{-rpath-link} option |
252b5132 | 1285 | specifies the first set of directories to search. The |
ff5dcc92 | 1286 | @option{-rpath-link} option may specify a sequence of directory names |
252b5132 RH |
1287 | either by specifying a list of names separated by colons, or by |
1288 | appearing multiple times. | |
1289 | ||
28c309a2 NC |
1290 | This option should be used with caution as it overrides the search path |
1291 | that may have been hard compiled into a shared library. In such a case it | |
1292 | is possible to use unintentionally a different search path than the | |
1293 | runtime linker would do. | |
1294 | ||
252b5132 RH |
1295 | The linker uses the following search paths to locate required shared |
1296 | libraries. | |
1297 | @enumerate | |
1298 | @item | |
ff5dcc92 | 1299 | Any directories specified by @option{-rpath-link} options. |
252b5132 | 1300 | @item |
ff5dcc92 SC |
1301 | Any directories specified by @option{-rpath} options. The difference |
1302 | between @option{-rpath} and @option{-rpath-link} is that directories | |
1303 | specified by @option{-rpath} options are included in the executable and | |
1304 | used at runtime, whereas the @option{-rpath-link} option is only effective | |
dcb0bd0e | 1305 | at link time. It is for the native linker only. |
252b5132 | 1306 | @item |
ff5dcc92 | 1307 | On an ELF system, if the @option{-rpath} and @code{rpath-link} options |
252b5132 | 1308 | were not used, search the contents of the environment variable |
dcb0bd0e | 1309 | @code{LD_RUN_PATH}. It is for the native linker only. |
252b5132 | 1310 | @item |
ff5dcc92 SC |
1311 | On SunOS, if the @option{-rpath} option was not used, search any |
1312 | directories specified using @option{-L} options. | |
252b5132 RH |
1313 | @item |
1314 | For a native linker, the contents of the environment variable | |
1315 | @code{LD_LIBRARY_PATH}. | |
1316 | @item | |
ec4eb78a L |
1317 | For a native ELF linker, the directories in @code{DT_RUNPATH} or |
1318 | @code{DT_RPATH} of a shared library are searched for shared | |
1319 | libraries needed by it. The @code{DT_RPATH} entries are ignored if | |
1320 | @code{DT_RUNPATH} entries exist. | |
1321 | @item | |
252b5132 RH |
1322 | The default directories, normally @file{/lib} and @file{/usr/lib}. |
1323 | @item | |
1324 | For a native linker on an ELF system, if the file @file{/etc/ld.so.conf} | |
1325 | exists, the list of directories found in that file. | |
1326 | @end enumerate | |
1327 | ||
1328 | If the required shared library is not found, the linker will issue a | |
1329 | warning and continue with the link. | |
1330 | @end ifset | |
1331 | ||
1332 | @kindex -shared | |
1333 | @kindex -Bshareable | |
1334 | @item -shared | |
1335 | @itemx -Bshareable | |
1336 | @cindex shared libraries | |
1337 | Create a shared library. This is currently only supported on ELF, XCOFF | |
1338 | and SunOS platforms. On SunOS, the linker will automatically create a | |
ff5dcc92 | 1339 | shared library if the @option{-e} option is not used and there are |
252b5132 RH |
1340 | undefined symbols in the link. |
1341 | ||
1342 | @item --sort-common | |
1343 | @kindex --sort-common | |
ff5dcc92 | 1344 | This option tells @command{ld} to sort the common symbols by size when it |
252b5132 | 1345 | places them in the appropriate output sections. First come all the one |
563e308f | 1346 | byte symbols, then all the two byte, then all the four byte, and then |
252b5132 RH |
1347 | everything else. This is to prevent gaps between symbols due to |
1348 | alignment constraints. | |
1349 | ||
1350 | @kindex --split-by-file | |
a854a4a7 | 1351 | @item --split-by-file [@var{size}] |
ff5dcc92 | 1352 | Similar to @option{--split-by-reloc} but creates a new output section for |
a854a4a7 AM |
1353 | each input file when @var{size} is reached. @var{size} defaults to a |
1354 | size of 1 if not given. | |
252b5132 RH |
1355 | |
1356 | @kindex --split-by-reloc | |
a854a4a7 AM |
1357 | @item --split-by-reloc [@var{count}] |
1358 | Tries to creates extra sections in the output file so that no single | |
252b5132 | 1359 | output section in the file contains more than @var{count} relocations. |
a854a4a7 | 1360 | This is useful when generating huge relocatable files for downloading into |
252b5132 RH |
1361 | certain real time kernels with the COFF object file format; since COFF |
1362 | cannot represent more than 65535 relocations in a single section. Note | |
1363 | that this will fail to work with object file formats which do not | |
1364 | support arbitrary sections. The linker will not split up individual | |
1365 | input sections for redistribution, so if a single input section contains | |
1366 | more than @var{count} relocations one output section will contain that | |
a854a4a7 | 1367 | many relocations. @var{count} defaults to a value of 32768. |
252b5132 RH |
1368 | |
1369 | @kindex --stats | |
1370 | @item --stats | |
1371 | Compute and display statistics about the operation of the linker, such | |
1372 | as execution time and memory usage. | |
1373 | ||
1374 | @kindex --traditional-format | |
1375 | @cindex traditional format | |
1376 | @item --traditional-format | |
ff5dcc92 SC |
1377 | For some targets, the output of @command{ld} is different in some ways from |
1378 | the output of some existing linker. This switch requests @command{ld} to | |
252b5132 RH |
1379 | use the traditional format instead. |
1380 | ||
1381 | @cindex dbx | |
ff5dcc92 | 1382 | For example, on SunOS, @command{ld} combines duplicate entries in the |
252b5132 RH |
1383 | symbol string table. This can reduce the size of an output file with |
1384 | full debugging information by over 30 percent. Unfortunately, the SunOS | |
1385 | @code{dbx} program can not read the resulting program (@code{gdb} has no | |
ff5dcc92 | 1386 | trouble). The @samp{--traditional-format} switch tells @command{ld} to not |
252b5132 RH |
1387 | combine duplicate entries. |
1388 | ||
176355da NC |
1389 | @kindex --section-start @var{sectionname}=@var{org} |
1390 | @item --section-start @var{sectionname}=@var{org} | |
1391 | Locate a section in the output file at the absolute | |
1392 | address given by @var{org}. You may use this option as many | |
1393 | times as necessary to locate multiple sections in the command | |
1394 | line. | |
1395 | @var{org} must be a single hexadecimal integer; | |
1396 | for compatibility with other linkers, you may omit the leading | |
1397 | @samp{0x} usually associated with hexadecimal values. @emph{Note:} there | |
1398 | should be no white space between @var{sectionname}, the equals | |
1399 | sign (``@key{=}''), and @var{org}. | |
1400 | ||
252b5132 RH |
1401 | @kindex -Tbss @var{org} |
1402 | @kindex -Tdata @var{org} | |
1403 | @kindex -Ttext @var{org} | |
1404 | @cindex segment origins, cmd line | |
1405 | @item -Tbss @var{org} | |
1406 | @itemx -Tdata @var{org} | |
1407 | @itemx -Ttext @var{org} | |
1408 | Use @var{org} as the starting address for---respectively---the | |
1409 | @code{bss}, @code{data}, or the @code{text} segment of the output file. | |
1410 | @var{org} must be a single hexadecimal integer; | |
1411 | for compatibility with other linkers, you may omit the leading | |
1412 | @samp{0x} usually associated with hexadecimal values. | |
1413 | ||
1414 | @kindex --verbose | |
1415 | @cindex verbose | |
1416 | @item --dll-verbose | |
308b1ffd | 1417 | @itemx --verbose |
ff5dcc92 | 1418 | Display the version number for @command{ld} and list the linker emulations |
252b5132 | 1419 | supported. Display which input files can and cannot be opened. Display |
b9a8de1e | 1420 | the linker script being used by the linker. |
252b5132 RH |
1421 | |
1422 | @kindex --version-script=@var{version-scriptfile} | |
1423 | @cindex version script, symbol versions | |
1424 | @itemx --version-script=@var{version-scriptfile} | |
1425 | Specify the name of a version script to the linker. This is typically | |
1426 | used when creating shared libraries to specify additional information | |
1427 | about the version heirarchy for the library being created. This option | |
1428 | is only meaningful on ELF platforms which support shared libraries. | |
1429 | @xref{VERSION}. | |
1430 | ||
7ce691ae | 1431 | @kindex --warn-common |
252b5132 RH |
1432 | @cindex warnings, on combining symbols |
1433 | @cindex combining symbols, warnings on | |
1434 | @item --warn-common | |
1435 | Warn when a common symbol is combined with another common symbol or with | |
1436 | a symbol definition. Unix linkers allow this somewhat sloppy practice, | |
1437 | but linkers on some other operating systems do not. This option allows | |
1438 | you to find potential problems from combining global symbols. | |
1439 | Unfortunately, some C libraries use this practice, so you may get some | |
1440 | warnings about symbols in the libraries as well as in your programs. | |
1441 | ||
1442 | There are three kinds of global symbols, illustrated here by C examples: | |
1443 | ||
1444 | @table @samp | |
1445 | @item int i = 1; | |
1446 | A definition, which goes in the initialized data section of the output | |
1447 | file. | |
1448 | ||
1449 | @item extern int i; | |
1450 | An undefined reference, which does not allocate space. | |
1451 | There must be either a definition or a common symbol for the | |
1452 | variable somewhere. | |
1453 | ||
1454 | @item int i; | |
1455 | A common symbol. If there are only (one or more) common symbols for a | |
1456 | variable, it goes in the uninitialized data area of the output file. | |
1457 | The linker merges multiple common symbols for the same variable into a | |
1458 | single symbol. If they are of different sizes, it picks the largest | |
1459 | size. The linker turns a common symbol into a declaration, if there is | |
1460 | a definition of the same variable. | |
1461 | @end table | |
1462 | ||
1463 | The @samp{--warn-common} option can produce five kinds of warnings. | |
1464 | Each warning consists of a pair of lines: the first describes the symbol | |
1465 | just encountered, and the second describes the previous symbol | |
1466 | encountered with the same name. One or both of the two symbols will be | |
1467 | a common symbol. | |
1468 | ||
1469 | @enumerate | |
1470 | @item | |
1471 | Turning a common symbol into a reference, because there is already a | |
1472 | definition for the symbol. | |
1473 | @smallexample | |
1474 | @var{file}(@var{section}): warning: common of `@var{symbol}' | |
1475 | overridden by definition | |
1476 | @var{file}(@var{section}): warning: defined here | |
1477 | @end smallexample | |
1478 | ||
1479 | @item | |
1480 | Turning a common symbol into a reference, because a later definition for | |
1481 | the symbol is encountered. This is the same as the previous case, | |
1482 | except that the symbols are encountered in a different order. | |
1483 | @smallexample | |
1484 | @var{file}(@var{section}): warning: definition of `@var{symbol}' | |
1485 | overriding common | |
1486 | @var{file}(@var{section}): warning: common is here | |
1487 | @end smallexample | |
1488 | ||
1489 | @item | |
1490 | Merging a common symbol with a previous same-sized common symbol. | |
1491 | @smallexample | |
1492 | @var{file}(@var{section}): warning: multiple common | |
1493 | of `@var{symbol}' | |
1494 | @var{file}(@var{section}): warning: previous common is here | |
1495 | @end smallexample | |
1496 | ||
1497 | @item | |
1498 | Merging a common symbol with a previous larger common symbol. | |
1499 | @smallexample | |
1500 | @var{file}(@var{section}): warning: common of `@var{symbol}' | |
1501 | overridden by larger common | |
1502 | @var{file}(@var{section}): warning: larger common is here | |
1503 | @end smallexample | |
1504 | ||
1505 | @item | |
1506 | Merging a common symbol with a previous smaller common symbol. This is | |
1507 | the same as the previous case, except that the symbols are | |
1508 | encountered in a different order. | |
1509 | @smallexample | |
1510 | @var{file}(@var{section}): warning: common of `@var{symbol}' | |
1511 | overriding smaller common | |
1512 | @var{file}(@var{section}): warning: smaller common is here | |
1513 | @end smallexample | |
1514 | @end enumerate | |
1515 | ||
1516 | @kindex --warn-constructors | |
1517 | @item --warn-constructors | |
1518 | Warn if any global constructors are used. This is only useful for a few | |
1519 | object file formats. For formats like COFF or ELF, the linker can not | |
1520 | detect the use of global constructors. | |
1521 | ||
1522 | @kindex --warn-multiple-gp | |
1523 | @item --warn-multiple-gp | |
1524 | Warn if multiple global pointer values are required in the output file. | |
1525 | This is only meaningful for certain processors, such as the Alpha. | |
1526 | Specifically, some processors put large-valued constants in a special | |
1527 | section. A special register (the global pointer) points into the middle | |
1528 | of this section, so that constants can be loaded efficiently via a | |
1529 | base-register relative addressing mode. Since the offset in | |
1530 | base-register relative mode is fixed and relatively small (e.g., 16 | |
1531 | bits), this limits the maximum size of the constant pool. Thus, in | |
1532 | large programs, it is often necessary to use multiple global pointer | |
1533 | values in order to be able to address all possible constants. This | |
1534 | option causes a warning to be issued whenever this case occurs. | |
1535 | ||
1536 | @kindex --warn-once | |
1537 | @cindex warnings, on undefined symbols | |
1538 | @cindex undefined symbols, warnings on | |
1539 | @item --warn-once | |
1540 | Only warn once for each undefined symbol, rather than once per module | |
1541 | which refers to it. | |
1542 | ||
1543 | @kindex --warn-section-align | |
1544 | @cindex warnings, on section alignment | |
1545 | @cindex section alignment, warnings on | |
1546 | @item --warn-section-align | |
1547 | Warn if the address of an output section is changed because of | |
1548 | alignment. Typically, the alignment will be set by an input section. | |
1549 | The address will only be changed if it not explicitly specified; that | |
1550 | is, if the @code{SECTIONS} command does not specify a start address for | |
1551 | the section (@pxref{SECTIONS}). | |
1552 | ||
1553 | @kindex --whole-archive | |
1554 | @cindex including an entire archive | |
1555 | @item --whole-archive | |
1556 | For each archive mentioned on the command line after the | |
ff5dcc92 | 1557 | @option{--whole-archive} option, include every object file in the archive |
252b5132 RH |
1558 | in the link, rather than searching the archive for the required object |
1559 | files. This is normally used to turn an archive file into a shared | |
1560 | library, forcing every object to be included in the resulting shared | |
1561 | library. This option may be used more than once. | |
1562 | ||
7ec229ce | 1563 | Two notes when using this option from gcc: First, gcc doesn't know |
ff5dcc92 SC |
1564 | about this option, so you have to use @option{-Wl,-whole-archive}. |
1565 | Second, don't forget to use @option{-Wl,-no-whole-archive} after your | |
7ec229ce DD |
1566 | list of archives, because gcc will add its own list of archives to |
1567 | your link and you may not want this flag to affect those as well. | |
1568 | ||
252b5132 RH |
1569 | @kindex --wrap |
1570 | @item --wrap @var{symbol} | |
1571 | Use a wrapper function for @var{symbol}. Any undefined reference to | |
1572 | @var{symbol} will be resolved to @code{__wrap_@var{symbol}}. Any | |
1573 | undefined reference to @code{__real_@var{symbol}} will be resolved to | |
1574 | @var{symbol}. | |
1575 | ||
1576 | This can be used to provide a wrapper for a system function. The | |
1577 | wrapper function should be called @code{__wrap_@var{symbol}}. If it | |
1578 | wishes to call the system function, it should call | |
1579 | @code{__real_@var{symbol}}. | |
1580 | ||
1581 | Here is a trivial example: | |
1582 | ||
1583 | @smallexample | |
1584 | void * | |
1585 | __wrap_malloc (int c) | |
1586 | @{ | |
1587 | printf ("malloc called with %ld\n", c); | |
1588 | return __real_malloc (c); | |
1589 | @} | |
1590 | @end smallexample | |
1591 | ||
ff5dcc92 | 1592 | If you link other code with this file using @option{--wrap malloc}, then |
252b5132 RH |
1593 | all calls to @code{malloc} will call the function @code{__wrap_malloc} |
1594 | instead. The call to @code{__real_malloc} in @code{__wrap_malloc} will | |
1595 | call the real @code{malloc} function. | |
1596 | ||
1597 | You may wish to provide a @code{__real_malloc} function as well, so that | |
ff5dcc92 | 1598 | links without the @option{--wrap} option will succeed. If you do this, |
252b5132 RH |
1599 | you should not put the definition of @code{__real_malloc} in the same |
1600 | file as @code{__wrap_malloc}; if you do, the assembler may resolve the | |
1601 | call before the linker has a chance to wrap it to @code{malloc}. | |
1602 | ||
6c1439be L |
1603 | @kindex --enable-new-dtags |
1604 | @kindex --disable-new-dtags | |
1605 | @item --enable-new-dtags | |
1606 | @itemx --disable-new-dtags | |
1607 | This linker can create the new dynamic tags in ELF. But the older ELF | |
1608 | systems may not understand them. If you specify | |
ff5dcc92 SC |
1609 | @option{--enable-new-dtags}, the dynamic tags will be created as needed. |
1610 | If you specify @option{--disable-new-dtags}, no new dynamic tags will be | |
6c1439be L |
1611 | created. By default, the new dynamic tags are not created. Note that |
1612 | those options are only available for ELF systems. | |
1613 | ||
252b5132 RH |
1614 | @end table |
1615 | ||
0285c67d NC |
1616 | @c man end |
1617 | ||
252b5132 RH |
1618 | @subsection Options specific to i386 PE targets |
1619 | ||
0285c67d NC |
1620 | @c man begin OPTIONS |
1621 | ||
ff5dcc92 | 1622 | The i386 PE linker supports the @option{-shared} option, which causes |
252b5132 RH |
1623 | the output to be a dynamically linked library (DLL) instead of a |
1624 | normal executable. You should name the output @code{*.dll} when you | |
1625 | use this option. In addition, the linker fully supports the standard | |
1626 | @code{*.def} files, which may be specified on the linker command line | |
1627 | like an object file (in fact, it should precede archives it exports | |
1628 | symbols from, to ensure that they get linked in, just like a normal | |
1629 | object file). | |
1630 | ||
1631 | In addition to the options common to all targets, the i386 PE linker | |
1632 | support additional command line options that are specific to the i386 | |
1633 | PE target. Options that take values may be separated from their | |
1634 | values by either a space or an equals sign. | |
1635 | ||
ff5dcc92 | 1636 | @table @gcctabopt |
252b5132 RH |
1637 | |
1638 | @kindex --add-stdcall-alias | |
1639 | @item --add-stdcall-alias | |
1640 | If given, symbols with a stdcall suffix (@@@var{nn}) will be exported | |
1641 | as-is and also with the suffix stripped. | |
1642 | ||
1643 | @kindex --base-file | |
1644 | @item --base-file @var{file} | |
1645 | Use @var{file} as the name of a file in which to save the base | |
1646 | addresses of all the relocations needed for generating DLLs with | |
1647 | @file{dlltool}. | |
1648 | ||
1649 | @kindex --dll | |
1650 | @item --dll | |
1651 | Create a DLL instead of a regular executable. You may also use | |
ff5dcc92 | 1652 | @option{-shared} or specify a @code{LIBRARY} in a given @code{.def} |
252b5132 RH |
1653 | file. |
1654 | ||
1655 | @kindex --enable-stdcall-fixup | |
1656 | @kindex --disable-stdcall-fixup | |
1657 | @item --enable-stdcall-fixup | |
1658 | @itemx --disable-stdcall-fixup | |
1659 | If the link finds a symbol that it cannot resolve, it will attempt to | |
1660 | do "fuzzy linking" by looking for another defined symbol that differs | |
1661 | only in the format of the symbol name (cdecl vs stdcall) and will | |
1662 | resolve that symbol by linking to the match. For example, the | |
1663 | undefined symbol @code{_foo} might be linked to the function | |
1664 | @code{_foo@@12}, or the undefined symbol @code{_bar@@16} might be linked | |
1665 | to the function @code{_bar}. When the linker does this, it prints a | |
1666 | warning, since it normally should have failed to link, but sometimes | |
1667 | import libraries generated from third-party dlls may need this feature | |
ff5dcc92 | 1668 | to be usable. If you specify @option{--enable-stdcall-fixup}, this |
252b5132 | 1669 | feature is fully enabled and warnings are not printed. If you specify |
ff5dcc92 | 1670 | @option{--disable-stdcall-fixup}, this feature is disabled and such |
252b5132 RH |
1671 | mismatches are considered to be errors. |
1672 | ||
1673 | @cindex DLLs, creating | |
1674 | @kindex --export-all-symbols | |
1675 | @item --export-all-symbols | |
1676 | If given, all global symbols in the objects used to build a DLL will | |
1677 | be exported by the DLL. Note that this is the default if there | |
1678 | otherwise wouldn't be any exported symbols. When symbols are | |
1679 | explicitly exported via DEF files or implicitly exported via function | |
1680 | attributes, the default is to not export anything else unless this | |
1681 | option is given. Note that the symbols @code{DllMain@@12}, | |
b044cda1 CW |
1682 | @code{DllEntryPoint@@0}, @code{DllMainCRTStartup@@12}, and |
1683 | @code{impure_ptr} will not be automatically | |
1684 | exported. Also, symbols imported from other DLLs will not be | |
1685 | re-exported, nor will symbols specifying the DLL's internal layout | |
1686 | such as those beginning with @code{_head_} or ending with | |
1687 | @code{_iname}. In addition, no symbols from @code{libgcc}, | |
1688 | @code{libstd++}, @code{libmingw32}, or @code{crtX.o} will be exported. | |
1689 | Symbols whose names begin with @code{__rtti_} or @code{__builtin_} will | |
1690 | not be exported, to help with C++ DLLs. Finally, there is an | |
1691 | extensive list of cygwin-private symbols that are not exported | |
1692 | (obviously, this applies on when building DLLs for cygwin targets). | |
1693 | These cygwin-excludes are: @code{_cygwin_dll_entry@@12}, | |
1694 | @code{_cygwin_crt0_common@@8}, @code{_cygwin_noncygwin_dll_entry@@12}, | |
1695 | @code{_fmode}, @code{_impure_ptr}, @code{cygwin_attach_dll}, | |
1696 | @code{cygwin_premain0}, @code{cygwin_premain1}, @code{cygwin_premain2}, | |
1697 | @code{cygwin_premain3}, and @code{environ}. | |
252b5132 RH |
1698 | |
1699 | @kindex --exclude-symbols | |
1d0a3c9c | 1700 | @item --exclude-symbols @var{symbol},@var{symbol},... |
252b5132 RH |
1701 | Specifies a list of symbols which should not be automatically |
1702 | exported. The symbol names may be delimited by commas or colons. | |
1703 | ||
70b0be79 CF |
1704 | @kindex --exclude-libs |
1705 | @item --exclude-libs @var{lib},@var{lib},... | |
1706 | Specifies a list of archive libraries from which symbols should not be automatically | |
1707 | exported. The library names may be delimited by commas or colons. Specifying | |
1708 | @code{--exclude-libs ALL} excludes symbols in all archive libraries from | |
1709 | automatic export. Symbols explicitly listed in a .def file are still exported, | |
1710 | regardless of this option. | |
1711 | ||
252b5132 RH |
1712 | @kindex --file-alignment |
1713 | @item --file-alignment | |
1714 | Specify the file alignment. Sections in the file will always begin at | |
1715 | file offsets which are multiples of this number. This defaults to | |
1716 | 512. | |
1717 | ||
1718 | @cindex heap size | |
1719 | @kindex --heap | |
1720 | @item --heap @var{reserve} | |
1721 | @itemx --heap @var{reserve},@var{commit} | |
1722 | Specify the amount of memory to reserve (and optionally commit) to be | |
1723 | used as heap for this program. The default is 1Mb reserved, 4K | |
1724 | committed. | |
1725 | ||
1726 | @cindex image base | |
1727 | @kindex --image-base | |
1728 | @item --image-base @var{value} | |
1729 | Use @var{value} as the base address of your program or dll. This is | |
1730 | the lowest memory location that will be used when your program or dll | |
1731 | is loaded. To reduce the need to relocate and improve performance of | |
1732 | your dlls, each should have a unique base address and not overlap any | |
1733 | other dlls. The default is 0x400000 for executables, and 0x10000000 | |
1734 | for dlls. | |
1735 | ||
1736 | @kindex --kill-at | |
1737 | @item --kill-at | |
1738 | If given, the stdcall suffixes (@@@var{nn}) will be stripped from | |
1739 | symbols before they are exported. | |
1740 | ||
1741 | @kindex --major-image-version | |
1742 | @item --major-image-version @var{value} | |
1743 | Sets the major number of the "image version". Defaults to 1. | |
1744 | ||
1745 | @kindex --major-os-version | |
1746 | @item --major-os-version @var{value} | |
1747 | Sets the major number of the "os version". Defaults to 4. | |
1748 | ||
1749 | @kindex --major-subsystem-version | |
1750 | @item --major-subsystem-version @var{value} | |
1751 | Sets the major number of the "subsystem version". Defaults to 4. | |
1752 | ||
1753 | @kindex --minor-image-version | |
1754 | @item --minor-image-version @var{value} | |
1755 | Sets the minor number of the "image version". Defaults to 0. | |
1756 | ||
1757 | @kindex --minor-os-version | |
1758 | @item --minor-os-version @var{value} | |
1759 | Sets the minor number of the "os version". Defaults to 0. | |
1760 | ||
1761 | @kindex --minor-subsystem-version | |
1762 | @item --minor-subsystem-version @var{value} | |
1763 | Sets the minor number of the "subsystem version". Defaults to 0. | |
1764 | ||
1765 | @cindex DEF files, creating | |
1766 | @cindex DLLs, creating | |
1767 | @kindex --output-def | |
1768 | @item --output-def @var{file} | |
1769 | The linker will create the file @var{file} which will contain a DEF | |
1770 | file corresponding to the DLL the linker is generating. This DEF file | |
1771 | (which should be called @code{*.def}) may be used to create an import | |
1772 | library with @code{dlltool} or may be used as a reference to | |
1773 | automatically or implicitly exported symbols. | |
1774 | ||
b044cda1 CW |
1775 | @cindex DLLs, creating |
1776 | @kindex --out-implib | |
1777 | @item --out-implib @var{file} | |
1778 | The linker will create the file @var{file} which will contain an | |
1779 | import lib corresponding to the DLL the linker is generating. This | |
1780 | import lib (which should be called @code{*.dll.a} or @code{*.a} | |
1781 | may be used to link clients against the generated DLL; this behavior | |
1782 | makes it possible to skip a separate @code{dlltool} import library | |
1783 | creation step. | |
1784 | ||
1785 | @kindex --enable-auto-image-base | |
1786 | @item --enable-auto-image-base | |
1787 | Automatically choose the image base for DLLs, unless one is specified | |
1788 | using the @code{--image-base} argument. By using a hash generated | |
1789 | from the dllname to create unique image bases for each DLL, in-memory | |
1790 | collisions and relocations which can delay program execution are | |
1791 | avoided. | |
1792 | ||
1793 | @kindex --disable-auto-image-base | |
1794 | @item --disable-auto-image-base | |
1795 | Do not automatically generate a unique image base. If there is no | |
1796 | user-specified image base (@code{--image-base}) then use the platform | |
1797 | default. | |
1798 | ||
1799 | @cindex DLLs, linking to | |
1800 | @kindex --dll-search-prefix | |
1801 | @item --dll-search-prefix @var{string} | |
1802 | When linking dynamically to a dll without an import library, i | |
1803 | search for @code{<string><basename>.dll} in preference to | |
1804 | @code{lib<basename>.dll}. This behavior allows easy distinction | |
1805 | between DLLs built for the various "subplatforms": native, cygwin, | |
1806 | uwin, pw, etc. For instance, cygwin DLLs typically use | |
1807 | @code{--dll-search-prefix=cyg}. | |
1808 | ||
1809 | @kindex --enable-auto-import | |
1810 | @item --enable-auto-import | |
0d888aac | 1811 | Do sophisticated linking of @code{_symbol} to @code{__imp__symbol} for |
b044cda1 | 1812 | DATA imports from DLLs, and create the necessary thunking symbols when |
2ca22b03 NC |
1813 | building the import libraries with those DATA exports. This generally |
1814 | will 'just work' -- but sometimes you may see this message: | |
0d888aac CW |
1815 | |
1816 | "variable '<var>' can't be auto-imported. Please read the | |
1817 | documentation for ld's @code{--enable-auto-import} for details." | |
1818 | ||
1819 | This message occurs when some (sub)expression accesses an address | |
1820 | ultimately given by the sum of two constants (Win32 import tables only | |
1821 | allow one). Instances where this may occur include accesses to member | |
1822 | fields of struct variables imported from a DLL, as well as using a | |
2f8d8971 NC |
1823 | constant index into an array variable imported from a DLL. Any |
1824 | multiword variable (arrays, structs, long long, etc) may trigger | |
1825 | this error condition. However, regardless of the exact data type | |
1826 | of the offending exported variable, ld will always detect it, issue | |
1827 | the warning, and exit. | |
1828 | ||
1829 | There are several ways to address this difficulty, regardless of the | |
1830 | data type of the exported variable: | |
0d888aac | 1831 | |
2fa9fc65 NC |
1832 | One way is to use --enable-runtime-pseudo-reloc switch. This leaves the task |
1833 | of adjusting references in your client code for runtime environment, so | |
1834 | this method works only when runtime environtment supports this feature. | |
1835 | ||
1836 | A second solution is to force one of the 'constants' to be a variable -- | |
0d888aac CW |
1837 | that is, unknown and un-optimizable at compile time. For arrays, |
1838 | there are two possibilities: a) make the indexee (the array's address) | |
1839 | a variable, or b) make the 'constant' index a variable. Thus: | |
1840 | ||
1841 | @example | |
1842 | extern type extern_array[]; | |
1843 | extern_array[1] --> | |
1844 | @{ volatile type *t=extern_array; t[1] @} | |
1845 | @end example | |
1846 | ||
1847 | or | |
1848 | ||
1849 | @example | |
1850 | extern type extern_array[]; | |
1851 | extern_array[1] --> | |
1852 | @{ volatile int t=1; extern_array[t] @} | |
1853 | @end example | |
1854 | ||
2f8d8971 NC |
1855 | For structs (and most other multiword data types) the only option |
1856 | is to make the struct itself (or the long long, or the ...) variable: | |
0d888aac CW |
1857 | |
1858 | @example | |
1859 | extern struct s extern_struct; | |
1860 | extern_struct.field --> | |
1861 | @{ volatile struct s *t=&extern_struct; t->field @} | |
1862 | @end example | |
1863 | ||
c406afaf NC |
1864 | or |
1865 | ||
1866 | @example | |
1867 | extern long long extern_ll; | |
1868 | extern_ll --> | |
1869 | @{ volatile long long * local_ll=&extern_ll; *local_ll @} | |
1870 | @end example | |
1871 | ||
2fa9fc65 | 1872 | A third method of dealing with this difficulty is to abandon |
0d888aac CW |
1873 | 'auto-import' for the offending symbol and mark it with |
1874 | @code{__declspec(dllimport)}. However, in practice that | |
1875 | requires using compile-time #defines to indicate whether you are | |
1876 | building a DLL, building client code that will link to the DLL, or | |
1877 | merely building/linking to a static library. In making the choice | |
1878 | between the various methods of resolving the 'direct address with | |
1879 | constant offset' problem, you should consider typical real-world usage: | |
1880 | ||
1881 | Original: | |
1882 | @example | |
1883 | --foo.h | |
1884 | extern int arr[]; | |
1885 | --foo.c | |
1886 | #include "foo.h" | |
1887 | void main(int argc, char **argv)@{ | |
1888 | printf("%d\n",arr[1]); | |
1889 | @} | |
1890 | @end example | |
1891 | ||
1892 | Solution 1: | |
1893 | @example | |
1894 | --foo.h | |
1895 | extern int arr[]; | |
1896 | --foo.c | |
1897 | #include "foo.h" | |
1898 | void main(int argc, char **argv)@{ | |
1899 | /* This workaround is for win32 and cygwin; do not "optimize" */ | |
1900 | volatile int *parr = arr; | |
1901 | printf("%d\n",parr[1]); | |
1902 | @} | |
1903 | @end example | |
1904 | ||
1905 | Solution 2: | |
1906 | @example | |
1907 | --foo.h | |
1908 | /* Note: auto-export is assumed (no __declspec(dllexport)) */ | |
1909 | #if (defined(_WIN32) || defined(__CYGWIN__)) && \ | |
1910 | !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC)) | |
1911 | #define FOO_IMPORT __declspec(dllimport) | |
1912 | #else | |
1913 | #define FOO_IMPORT | |
1914 | #endif | |
1915 | extern FOO_IMPORT int arr[]; | |
1916 | --foo.c | |
1917 | #include "foo.h" | |
1918 | void main(int argc, char **argv)@{ | |
1919 | printf("%d\n",arr[1]); | |
1920 | @} | |
1921 | @end example | |
1922 | ||
2fa9fc65 | 1923 | A fourth way to avoid this problem is to re-code your |
0d888aac CW |
1924 | library to use a functional interface rather than a data interface |
1925 | for the offending variables (e.g. set_foo() and get_foo() accessor | |
1926 | functions). | |
b044cda1 CW |
1927 | |
1928 | @kindex --disable-auto-import | |
1929 | @item --disable-auto-import | |
1930 | Do not attempt to do sophisticalted linking of @code{_symbol} to | |
1931 | @code{__imp__symbol} for DATA imports from DLLs. | |
1932 | ||
2fa9fc65 NC |
1933 | @kindex --enable-runtime-pseudo-reloc |
1934 | @item --enable-runtime-pseudo-reloc | |
1935 | If your code contains expressions described in --enable-auto-import section, | |
1936 | that is, DATA imports from DLL with non-zero offset, this switch will create | |
1937 | a vector of 'runtime pseudo relocations' which can be used by runtime | |
1938 | environment to adjust references to such data in your client code. | |
1939 | ||
1940 | @kindex --disable-runtime-pseudo-reloc | |
1941 | @item --disable-runtime-pseudo-reloc | |
1942 | Do not create pseudo relocations for non-zero offset DATA imports from | |
1943 | DLLs. This is the default. | |
1944 | ||
b044cda1 CW |
1945 | @kindex --enable-extra-pe-debug |
1946 | @item --enable-extra-pe-debug | |
1947 | Show additional debug info related to auto-import symbol thunking. | |
1948 | ||
252b5132 RH |
1949 | @kindex --section-alignment |
1950 | @item --section-alignment | |
1951 | Sets the section alignment. Sections in memory will always begin at | |
1952 | addresses which are a multiple of this number. Defaults to 0x1000. | |
1953 | ||
1954 | @cindex stack size | |
1955 | @kindex --stack | |
1956 | @item --stack @var{reserve} | |
1957 | @itemx --stack @var{reserve},@var{commit} | |
1958 | Specify the amount of memory to reserve (and optionally commit) to be | |
559e4713 | 1959 | used as stack for this program. The default is 2Mb reserved, 4K |
252b5132 RH |
1960 | committed. |
1961 | ||
1962 | @kindex --subsystem | |
1963 | @item --subsystem @var{which} | |
1964 | @itemx --subsystem @var{which}:@var{major} | |
1965 | @itemx --subsystem @var{which}:@var{major}.@var{minor} | |
1966 | Specifies the subsystem under which your program will execute. The | |
1967 | legal values for @var{which} are @code{native}, @code{windows}, | |
1968 | @code{console}, and @code{posix}. You may optionally set the | |
1969 | subsystem version also. | |
1970 | ||
1971 | @end table | |
1972 | ||
0285c67d NC |
1973 | @c man end |
1974 | ||
252b5132 RH |
1975 | @ifset UsesEnvVars |
1976 | @node Environment | |
1977 | @section Environment Variables | |
1978 | ||
0285c67d NC |
1979 | @c man begin ENVIRONMENT |
1980 | ||
ff5dcc92 | 1981 | You can change the behavior of @command{ld} with the environment variables |
252b5132 RH |
1982 | @code{GNUTARGET}, @code{LDEMULATION}, and @code{COLLECT_NO_DEMANGLE}. |
1983 | ||
1984 | @kindex GNUTARGET | |
1985 | @cindex default input format | |
1986 | @code{GNUTARGET} determines the input-file object format if you don't | |
1987 | use @samp{-b} (or its synonym @samp{--format}). Its value should be one | |
1988 | of the BFD names for an input format (@pxref{BFD}). If there is no | |
ff5dcc92 | 1989 | @code{GNUTARGET} in the environment, @command{ld} uses the natural format |
252b5132 RH |
1990 | of the target. If @code{GNUTARGET} is set to @code{default} then BFD |
1991 | attempts to discover the input format by examining binary input files; | |
1992 | this method often succeeds, but there are potential ambiguities, since | |
1993 | there is no method of ensuring that the magic number used to specify | |
1994 | object-file formats is unique. However, the configuration procedure for | |
1995 | BFD on each system places the conventional format for that system first | |
1996 | in the search-list, so ambiguities are resolved in favor of convention. | |
1997 | ||
1998 | @kindex LDEMULATION | |
1999 | @cindex default emulation | |
2000 | @cindex emulation, default | |
2001 | @code{LDEMULATION} determines the default emulation if you don't use the | |
2002 | @samp{-m} option. The emulation can affect various aspects of linker | |
2003 | behaviour, particularly the default linker script. You can list the | |
2004 | available emulations with the @samp{--verbose} or @samp{-V} options. If | |
2005 | the @samp{-m} option is not used, and the @code{LDEMULATION} environment | |
2006 | variable is not defined, the default emulation depends upon how the | |
2007 | linker was configured. | |
252b5132 RH |
2008 | |
2009 | @kindex COLLECT_NO_DEMANGLE | |
2010 | @cindex demangling, default | |
2011 | Normally, the linker will default to demangling symbols. However, if | |
2012 | @code{COLLECT_NO_DEMANGLE} is set in the environment, then it will | |
2013 | default to not demangling symbols. This environment variable is used in | |
2014 | a similar fashion by the @code{gcc} linker wrapper program. The default | |
2015 | may be overridden by the @samp{--demangle} and @samp{--no-demangle} | |
2016 | options. | |
2017 | ||
0285c67d NC |
2018 | @c man end |
2019 | @end ifset | |
2020 | ||
252b5132 RH |
2021 | @node Scripts |
2022 | @chapter Linker Scripts | |
2023 | ||
2024 | @cindex scripts | |
2025 | @cindex linker scripts | |
2026 | @cindex command files | |
2027 | Every link is controlled by a @dfn{linker script}. This script is | |
2028 | written in the linker command language. | |
2029 | ||
2030 | The main purpose of the linker script is to describe how the sections in | |
2031 | the input files should be mapped into the output file, and to control | |
2032 | the memory layout of the output file. Most linker scripts do nothing | |
2033 | more than this. However, when necessary, the linker script can also | |
2034 | direct the linker to perform many other operations, using the commands | |
2035 | described below. | |
2036 | ||
2037 | The linker always uses a linker script. If you do not supply one | |
2038 | yourself, the linker will use a default script that is compiled into the | |
2039 | linker executable. You can use the @samp{--verbose} command line option | |
2040 | to display the default linker script. Certain command line options, | |
2041 | such as @samp{-r} or @samp{-N}, will affect the default linker script. | |
2042 | ||
2043 | You may supply your own linker script by using the @samp{-T} command | |
2044 | line option. When you do this, your linker script will replace the | |
2045 | default linker script. | |
2046 | ||
2047 | You may also use linker scripts implicitly by naming them as input files | |
2048 | to the linker, as though they were files to be linked. @xref{Implicit | |
2049 | Linker Scripts}. | |
2050 | ||
2051 | @menu | |
2052 | * Basic Script Concepts:: Basic Linker Script Concepts | |
2053 | * Script Format:: Linker Script Format | |
2054 | * Simple Example:: Simple Linker Script Example | |
2055 | * Simple Commands:: Simple Linker Script Commands | |
2056 | * Assignments:: Assigning Values to Symbols | |
2057 | * SECTIONS:: SECTIONS Command | |
2058 | * MEMORY:: MEMORY Command | |
2059 | * PHDRS:: PHDRS Command | |
2060 | * VERSION:: VERSION Command | |
2061 | * Expressions:: Expressions in Linker Scripts | |
2062 | * Implicit Linker Scripts:: Implicit Linker Scripts | |
2063 | @end menu | |
2064 | ||
2065 | @node Basic Script Concepts | |
2066 | @section Basic Linker Script Concepts | |
2067 | @cindex linker script concepts | |
2068 | We need to define some basic concepts and vocabulary in order to | |
2069 | describe the linker script language. | |
2070 | ||
2071 | The linker combines input files into a single output file. The output | |
2072 | file and each input file are in a special data format known as an | |
2073 | @dfn{object file format}. Each file is called an @dfn{object file}. | |
2074 | The output file is often called an @dfn{executable}, but for our | |
2075 | purposes we will also call it an object file. Each object file has, | |
2076 | among other things, a list of @dfn{sections}. We sometimes refer to a | |
2077 | section in an input file as an @dfn{input section}; similarly, a section | |
2078 | in the output file is an @dfn{output section}. | |
2079 | ||
2080 | Each section in an object file has a name and a size. Most sections | |
2081 | also have an associated block of data, known as the @dfn{section | |
2082 | contents}. A section may be marked as @dfn{loadable}, which mean that | |
2083 | the contents should be loaded into memory when the output file is run. | |
2084 | A section with no contents may be @dfn{allocatable}, which means that an | |
2085 | area in memory should be set aside, but nothing in particular should be | |
2086 | loaded there (in some cases this memory must be zeroed out). A section | |
2087 | which is neither loadable nor allocatable typically contains some sort | |
2088 | of debugging information. | |
2089 | ||
2090 | Every loadable or allocatable output section has two addresses. The | |
2091 | first is the @dfn{VMA}, or virtual memory address. This is the address | |
2092 | the section will have when the output file is run. The second is the | |
2093 | @dfn{LMA}, or load memory address. This is the address at which the | |
2094 | section will be loaded. In most cases the two addresses will be the | |
2095 | same. An example of when they might be different is when a data section | |
2096 | is loaded into ROM, and then copied into RAM when the program starts up | |
2097 | (this technique is often used to initialize global variables in a ROM | |
2098 | based system). In this case the ROM address would be the LMA, and the | |
2099 | RAM address would be the VMA. | |
2100 | ||
2101 | You can see the sections in an object file by using the @code{objdump} | |
2102 | program with the @samp{-h} option. | |
2103 | ||
2104 | Every object file also has a list of @dfn{symbols}, known as the | |
2105 | @dfn{symbol table}. A symbol may be defined or undefined. Each symbol | |
2106 | has a name, and each defined symbol has an address, among other | |
2107 | information. If you compile a C or C++ program into an object file, you | |
2108 | will get a defined symbol for every defined function and global or | |
2109 | static variable. Every undefined function or global variable which is | |
2110 | referenced in the input file will become an undefined symbol. | |
2111 | ||
2112 | You can see the symbols in an object file by using the @code{nm} | |
2113 | program, or by using the @code{objdump} program with the @samp{-t} | |
2114 | option. | |
2115 | ||
2116 | @node Script Format | |
2117 | @section Linker Script Format | |
2118 | @cindex linker script format | |
2119 | Linker scripts are text files. | |
2120 | ||
2121 | You write a linker script as a series of commands. Each command is | |
2122 | either a keyword, possibly followed by arguments, or an assignment to a | |
2123 | symbol. You may separate commands using semicolons. Whitespace is | |
2124 | generally ignored. | |
2125 | ||
2126 | Strings such as file or format names can normally be entered directly. | |
2127 | If the file name contains a character such as a comma which would | |
2128 | otherwise serve to separate file names, you may put the file name in | |
2129 | double quotes. There is no way to use a double quote character in a | |
2130 | file name. | |
2131 | ||
2132 | You may include comments in linker scripts just as in C, delimited by | |
2133 | @samp{/*} and @samp{*/}. As in C, comments are syntactically equivalent | |
2134 | to whitespace. | |
2135 | ||
2136 | @node Simple Example | |
2137 | @section Simple Linker Script Example | |
2138 | @cindex linker script example | |
2139 | @cindex example of linker script | |
2140 | Many linker scripts are fairly simple. | |
2141 | ||
2142 | The simplest possible linker script has just one command: | |
2143 | @samp{SECTIONS}. You use the @samp{SECTIONS} command to describe the | |
2144 | memory layout of the output file. | |
2145 | ||
2146 | The @samp{SECTIONS} command is a powerful command. Here we will | |
2147 | describe a simple use of it. Let's assume your program consists only of | |
2148 | code, initialized data, and uninitialized data. These will be in the | |
2149 | @samp{.text}, @samp{.data}, and @samp{.bss} sections, respectively. | |
2150 | Let's assume further that these are the only sections which appear in | |
2151 | your input files. | |
2152 | ||
2153 | For this example, let's say that the code should be loaded at address | |
2154 | 0x10000, and that the data should start at address 0x8000000. Here is a | |
2155 | linker script which will do that: | |
2156 | @smallexample | |
2157 | SECTIONS | |
2158 | @{ | |
2159 | . = 0x10000; | |
2160 | .text : @{ *(.text) @} | |
2161 | . = 0x8000000; | |
2162 | .data : @{ *(.data) @} | |
2163 | .bss : @{ *(.bss) @} | |
2164 | @} | |
2165 | @end smallexample | |
2166 | ||
2167 | You write the @samp{SECTIONS} command as the keyword @samp{SECTIONS}, | |
2168 | followed by a series of symbol assignments and output section | |
2169 | descriptions enclosed in curly braces. | |
2170 | ||
252b5132 RH |
2171 | The first line inside the @samp{SECTIONS} command of the above example |
2172 | sets the value of the special symbol @samp{.}, which is the location | |
2173 | counter. If you do not specify the address of an output section in some | |
2174 | other way (other ways are described later), the address is set from the | |
2175 | current value of the location counter. The location counter is then | |
2176 | incremented by the size of the output section. At the start of the | |
2177 | @samp{SECTIONS} command, the location counter has the value @samp{0}. | |
2178 | ||
2179 | The second line defines an output section, @samp{.text}. The colon is | |
2180 | required syntax which may be ignored for now. Within the curly braces | |
2181 | after the output section name, you list the names of the input sections | |
2182 | which should be placed into this output section. The @samp{*} is a | |
2183 | wildcard which matches any file name. The expression @samp{*(.text)} | |
2184 | means all @samp{.text} input sections in all input files. | |
2185 | ||
2186 | Since the location counter is @samp{0x10000} when the output section | |
2187 | @samp{.text} is defined, the linker will set the address of the | |
2188 | @samp{.text} section in the output file to be @samp{0x10000}. | |
2189 | ||
2190 | The remaining lines define the @samp{.data} and @samp{.bss} sections in | |
2191 | the output file. The linker will place the @samp{.data} output section | |
2192 | at address @samp{0x8000000}. After the linker places the @samp{.data} | |
2193 | output section, the value of the location counter will be | |
2194 | @samp{0x8000000} plus the size of the @samp{.data} output section. The | |
2195 | effect is that the linker will place the @samp{.bss} output section | |
2196 | immediately after the @samp{.data} output section in memory | |
2197 | ||
2198 | The linker will ensure that each output section has the required | |
2199 | alignment, by increasing the location counter if necessary. In this | |
2200 | example, the specified addresses for the @samp{.text} and @samp{.data} | |
2201 | sections will probably satisfy any alignment constraints, but the linker | |
2202 | may have to create a small gap between the @samp{.data} and @samp{.bss} | |
2203 | sections. | |
2204 | ||
2205 | That's it! That's a simple and complete linker script. | |
2206 | ||
2207 | @node Simple Commands | |
2208 | @section Simple Linker Script Commands | |
2209 | @cindex linker script simple commands | |
2210 | In this section we describe the simple linker script commands. | |
2211 | ||
2212 | @menu | |
2213 | * Entry Point:: Setting the entry point | |
2214 | * File Commands:: Commands dealing with files | |
2215 | @ifclear SingleFormat | |
2216 | * Format Commands:: Commands dealing with object file formats | |
2217 | @end ifclear | |
2218 | ||
2219 | * Miscellaneous Commands:: Other linker script commands | |
2220 | @end menu | |
2221 | ||
2222 | @node Entry Point | |
2223 | @subsection Setting the entry point | |
2224 | @kindex ENTRY(@var{symbol}) | |
2225 | @cindex start of execution | |
2226 | @cindex first instruction | |
2227 | @cindex entry point | |
2228 | The first instruction to execute in a program is called the @dfn{entry | |
2229 | point}. You can use the @code{ENTRY} linker script command to set the | |
2230 | entry point. The argument is a symbol name: | |
2231 | @smallexample | |
2232 | ENTRY(@var{symbol}) | |
2233 | @end smallexample | |
2234 | ||
2235 | There are several ways to set the entry point. The linker will set the | |
2236 | entry point by trying each of the following methods in order, and | |
2237 | stopping when one of them succeeds: | |
2238 | @itemize @bullet | |
a1ab1d2a | 2239 | @item |
252b5132 | 2240 | the @samp{-e} @var{entry} command-line option; |
a1ab1d2a | 2241 | @item |
252b5132 | 2242 | the @code{ENTRY(@var{symbol})} command in a linker script; |
a1ab1d2a | 2243 | @item |
252b5132 | 2244 | the value of the symbol @code{start}, if defined; |
a1ab1d2a | 2245 | @item |
252b5132 | 2246 | the address of the first byte of the @samp{.text} section, if present; |
a1ab1d2a | 2247 | @item |
252b5132 RH |
2248 | The address @code{0}. |
2249 | @end itemize | |
2250 | ||
2251 | @node File Commands | |
2252 | @subsection Commands dealing with files | |
2253 | @cindex linker script file commands | |
2254 | Several linker script commands deal with files. | |
2255 | ||
2256 | @table @code | |
2257 | @item INCLUDE @var{filename} | |
2258 | @kindex INCLUDE @var{filename} | |
2259 | @cindex including a linker script | |
2260 | Include the linker script @var{filename} at this point. The file will | |
2261 | be searched for in the current directory, and in any directory specified | |
ff5dcc92 | 2262 | with the @option{-L} option. You can nest calls to @code{INCLUDE} up to |
252b5132 RH |
2263 | 10 levels deep. |
2264 | ||
2265 | @item INPUT(@var{file}, @var{file}, @dots{}) | |
2266 | @itemx INPUT(@var{file} @var{file} @dots{}) | |
2267 | @kindex INPUT(@var{files}) | |
2268 | @cindex input files in linker scripts | |
2269 | @cindex input object files in linker scripts | |
2270 | @cindex linker script input object files | |
2271 | The @code{INPUT} command directs the linker to include the named files | |
2272 | in the link, as though they were named on the command line. | |
2273 | ||
2274 | For example, if you always want to include @file{subr.o} any time you do | |
2275 | a link, but you can't be bothered to put it on every link command line, | |
2276 | then you can put @samp{INPUT (subr.o)} in your linker script. | |
2277 | ||
2278 | In fact, if you like, you can list all of your input files in the linker | |
2279 | script, and then invoke the linker with nothing but a @samp{-T} option. | |
2280 | ||
2281 | The linker will first try to open the file in the current directory. If | |
2282 | it is not found, the linker will search through the archive library | |
2283 | search path. See the description of @samp{-L} in @ref{Options,,Command | |
2284 | Line Options}. | |
2285 | ||
ff5dcc92 | 2286 | If you use @samp{INPUT (-l@var{file})}, @command{ld} will transform the |
252b5132 RH |
2287 | name to @code{lib@var{file}.a}, as with the command line argument |
2288 | @samp{-l}. | |
2289 | ||
2290 | When you use the @code{INPUT} command in an implicit linker script, the | |
2291 | files will be included in the link at the point at which the linker | |
2292 | script file is included. This can affect archive searching. | |
2293 | ||
2294 | @item GROUP(@var{file}, @var{file}, @dots{}) | |
2295 | @itemx GROUP(@var{file} @var{file} @dots{}) | |
2296 | @kindex GROUP(@var{files}) | |
2297 | @cindex grouping input files | |
2298 | The @code{GROUP} command is like @code{INPUT}, except that the named | |
2299 | files should all be archives, and they are searched repeatedly until no | |
2300 | new undefined references are created. See the description of @samp{-(} | |
2301 | in @ref{Options,,Command Line Options}. | |
2302 | ||
2303 | @item OUTPUT(@var{filename}) | |
2304 | @kindex OUTPUT(@var{filename}) | |
2305 | @cindex output file name in linker scripot | |
2306 | The @code{OUTPUT} command names the output file. Using | |
2307 | @code{OUTPUT(@var{filename})} in the linker script is exactly like using | |
2308 | @samp{-o @var{filename}} on the command line (@pxref{Options,,Command | |
2309 | Line Options}). If both are used, the command line option takes | |
2310 | precedence. | |
2311 | ||
2312 | You can use the @code{OUTPUT} command to define a default name for the | |
2313 | output file other than the usual default of @file{a.out}. | |
2314 | ||
2315 | @item SEARCH_DIR(@var{path}) | |
2316 | @kindex SEARCH_DIR(@var{path}) | |
2317 | @cindex library search path in linker script | |
2318 | @cindex archive search path in linker script | |
2319 | @cindex search path in linker script | |
2320 | The @code{SEARCH_DIR} command adds @var{path} to the list of paths where | |
ff5dcc92 | 2321 | @command{ld} looks for archive libraries. Using |
252b5132 RH |
2322 | @code{SEARCH_DIR(@var{path})} is exactly like using @samp{-L @var{path}} |
2323 | on the command line (@pxref{Options,,Command Line Options}). If both | |
2324 | are used, then the linker will search both paths. Paths specified using | |
2325 | the command line option are searched first. | |
2326 | ||
2327 | @item STARTUP(@var{filename}) | |
2328 | @kindex STARTUP(@var{filename}) | |
2329 | @cindex first input file | |
2330 | The @code{STARTUP} command is just like the @code{INPUT} command, except | |
2331 | that @var{filename} will become the first input file to be linked, as | |
2332 | though it were specified first on the command line. This may be useful | |
2333 | when using a system in which the entry point is always the start of the | |
2334 | first file. | |
2335 | @end table | |
2336 | ||
2337 | @ifclear SingleFormat | |
2338 | @node Format Commands | |
2339 | @subsection Commands dealing with object file formats | |
2340 | A couple of linker script commands deal with object file formats. | |
2341 | ||
2342 | @table @code | |
2343 | @item OUTPUT_FORMAT(@var{bfdname}) | |
2344 | @itemx OUTPUT_FORMAT(@var{default}, @var{big}, @var{little}) | |
2345 | @kindex OUTPUT_FORMAT(@var{bfdname}) | |
2346 | @cindex output file format in linker script | |
2347 | The @code{OUTPUT_FORMAT} command names the BFD format to use for the | |
2348 | output file (@pxref{BFD}). Using @code{OUTPUT_FORMAT(@var{bfdname})} is | |
024531e2 | 2349 | exactly like using @samp{--oformat @var{bfdname}} on the command line |
252b5132 RH |
2350 | (@pxref{Options,,Command Line Options}). If both are used, the command |
2351 | line option takes precedence. | |
2352 | ||
2353 | You can use @code{OUTPUT_FORMAT} with three arguments to use different | |
2354 | formats based on the @samp{-EB} and @samp{-EL} command line options. | |
2355 | This permits the linker script to set the output format based on the | |
2356 | desired endianness. | |
2357 | ||
2358 | If neither @samp{-EB} nor @samp{-EL} are used, then the output format | |
2359 | will be the first argument, @var{default}. If @samp{-EB} is used, the | |
2360 | output format will be the second argument, @var{big}. If @samp{-EL} is | |
2361 | used, the output format will be the third argument, @var{little}. | |
2362 | ||
2363 | For example, the default linker script for the MIPS ELF target uses this | |
2364 | command: | |
2365 | @smallexample | |
2366 | OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips) | |
2367 | @end smallexample | |
2368 | This says that the default format for the output file is | |
2369 | @samp{elf32-bigmips}, but if the user uses the @samp{-EL} command line | |
2370 | option, the output file will be created in the @samp{elf32-littlemips} | |
2371 | format. | |
2372 | ||
2373 | @item TARGET(@var{bfdname}) | |
2374 | @kindex TARGET(@var{bfdname}) | |
2375 | @cindex input file format in linker script | |
2376 | The @code{TARGET} command names the BFD format to use when reading input | |
2377 | files. It affects subsequent @code{INPUT} and @code{GROUP} commands. | |
2378 | This command is like using @samp{-b @var{bfdname}} on the command line | |
2379 | (@pxref{Options,,Command Line Options}). If the @code{TARGET} command | |
2380 | is used but @code{OUTPUT_FORMAT} is not, then the last @code{TARGET} | |
2381 | command is also used to set the format for the output file. @xref{BFD}. | |
2382 | @end table | |
2383 | @end ifclear | |
2384 | ||
2385 | @node Miscellaneous Commands | |
2386 | @subsection Other linker script commands | |
2387 | There are a few other linker scripts commands. | |
2388 | ||
2389 | @table @code | |
2390 | @item ASSERT(@var{exp}, @var{message}) | |
2391 | @kindex ASSERT | |
2392 | @cindex assertion in linker script | |
2393 | Ensure that @var{exp} is non-zero. If it is zero, then exit the linker | |
2394 | with an error code, and print @var{message}. | |
2395 | ||
2396 | @item EXTERN(@var{symbol} @var{symbol} @dots{}) | |
2397 | @kindex EXTERN | |
2398 | @cindex undefined symbol in linker script | |
2399 | Force @var{symbol} to be entered in the output file as an undefined | |
2400 | symbol. Doing this may, for example, trigger linking of additional | |
2401 | modules from standard libraries. You may list several @var{symbol}s for | |
2402 | each @code{EXTERN}, and you may use @code{EXTERN} multiple times. This | |
2403 | command has the same effect as the @samp{-u} command-line option. | |
2404 | ||
2405 | @item FORCE_COMMON_ALLOCATION | |
2406 | @kindex FORCE_COMMON_ALLOCATION | |
2407 | @cindex common allocation in linker script | |
2408 | This command has the same effect as the @samp{-d} command-line option: | |
ff5dcc92 | 2409 | to make @command{ld} assign space to common symbols even if a relocatable |
252b5132 RH |
2410 | output file is specified (@samp{-r}). |
2411 | ||
4818e05f AM |
2412 | @item INHIBIT_COMMON_ALLOCATION |
2413 | @kindex INHIBIT_COMMON_ALLOCATION | |
2414 | @cindex common allocation in linker script | |
2415 | This command has the same effect as the @samp{--no-define-common} | |
2416 | command-line option: to make @code{ld} omit the assignment of addresses | |
2417 | to common symbols even for a non-relocatable output file. | |
2418 | ||
252b5132 RH |
2419 | @item NOCROSSREFS(@var{section} @var{section} @dots{}) |
2420 | @kindex NOCROSSREFS(@var{sections}) | |
2421 | @cindex cross references | |
ff5dcc92 | 2422 | This command may be used to tell @command{ld} to issue an error about any |
252b5132 RH |
2423 | references among certain output sections. |
2424 | ||
2425 | In certain types of programs, particularly on embedded systems when | |
2426 | using overlays, when one section is loaded into memory, another section | |
2427 | will not be. Any direct references between the two sections would be | |
2428 | errors. For example, it would be an error if code in one section called | |
2429 | a function defined in the other section. | |
2430 | ||
2431 | The @code{NOCROSSREFS} command takes a list of output section names. If | |
ff5dcc92 | 2432 | @command{ld} detects any cross references between the sections, it reports |
252b5132 RH |
2433 | an error and returns a non-zero exit status. Note that the |
2434 | @code{NOCROSSREFS} command uses output section names, not input section | |
2435 | names. | |
2436 | ||
2437 | @ifclear SingleFormat | |
2438 | @item OUTPUT_ARCH(@var{bfdarch}) | |
2439 | @kindex OUTPUT_ARCH(@var{bfdarch}) | |
2440 | @cindex machine architecture | |
2441 | @cindex architecture | |
2442 | Specify a particular output machine architecture. The argument is one | |
2443 | of the names used by the BFD library (@pxref{BFD}). You can see the | |
2444 | architecture of an object file by using the @code{objdump} program with | |
2445 | the @samp{-f} option. | |
2446 | @end ifclear | |
2447 | @end table | |
2448 | ||
2449 | @node Assignments | |
2450 | @section Assigning Values to Symbols | |
2451 | @cindex assignment in scripts | |
2452 | @cindex symbol definition, scripts | |
2453 | @cindex variables, defining | |
2454 | You may assign a value to a symbol in a linker script. This will define | |
2455 | the symbol as a global symbol. | |
2456 | ||
2457 | @menu | |
2458 | * Simple Assignments:: Simple Assignments | |
2459 | * PROVIDE:: PROVIDE | |
2460 | @end menu | |
2461 | ||
2462 | @node Simple Assignments | |
2463 | @subsection Simple Assignments | |
2464 | ||
2465 | You may assign to a symbol using any of the C assignment operators: | |
2466 | ||
2467 | @table @code | |
2468 | @item @var{symbol} = @var{expression} ; | |
2469 | @itemx @var{symbol} += @var{expression} ; | |
2470 | @itemx @var{symbol} -= @var{expression} ; | |
2471 | @itemx @var{symbol} *= @var{expression} ; | |
2472 | @itemx @var{symbol} /= @var{expression} ; | |
2473 | @itemx @var{symbol} <<= @var{expression} ; | |
2474 | @itemx @var{symbol} >>= @var{expression} ; | |
2475 | @itemx @var{symbol} &= @var{expression} ; | |
2476 | @itemx @var{symbol} |= @var{expression} ; | |
2477 | @end table | |
2478 | ||
2479 | The first case will define @var{symbol} to the value of | |
2480 | @var{expression}. In the other cases, @var{symbol} must already be | |
2481 | defined, and the value will be adjusted accordingly. | |
2482 | ||
2483 | The special symbol name @samp{.} indicates the location counter. You | |
2484 | may only use this within a @code{SECTIONS} command. | |
2485 | ||
2486 | The semicolon after @var{expression} is required. | |
2487 | ||
2488 | Expressions are defined below; see @ref{Expressions}. | |
2489 | ||
2490 | You may write symbol assignments as commands in their own right, or as | |
2491 | statements within a @code{SECTIONS} command, or as part of an output | |
2492 | section description in a @code{SECTIONS} command. | |
2493 | ||
2494 | The section of the symbol will be set from the section of the | |
2495 | expression; for more information, see @ref{Expression Section}. | |
2496 | ||
2497 | Here is an example showing the three different places that symbol | |
2498 | assignments may be used: | |
2499 | ||
2500 | @smallexample | |
2501 | floating_point = 0; | |
2502 | SECTIONS | |
2503 | @{ | |
2504 | .text : | |
2505 | @{ | |
2506 | *(.text) | |
2507 | _etext = .; | |
2508 | @} | |
156e34dd | 2509 | _bdata = (. + 3) & ~ 3; |
252b5132 RH |
2510 | .data : @{ *(.data) @} |
2511 | @} | |
2512 | @end smallexample | |
2513 | @noindent | |
2514 | In this example, the symbol @samp{floating_point} will be defined as | |
2515 | zero. The symbol @samp{_etext} will be defined as the address following | |
2516 | the last @samp{.text} input section. The symbol @samp{_bdata} will be | |
2517 | defined as the address following the @samp{.text} output section aligned | |
2518 | upward to a 4 byte boundary. | |
2519 | ||
2520 | @node PROVIDE | |
2521 | @subsection PROVIDE | |
2522 | @cindex PROVIDE | |
2523 | In some cases, it is desirable for a linker script to define a symbol | |
2524 | only if it is referenced and is not defined by any object included in | |
2525 | the link. For example, traditional linkers defined the symbol | |
2526 | @samp{etext}. However, ANSI C requires that the user be able to use | |
2527 | @samp{etext} as a function name without encountering an error. The | |
2528 | @code{PROVIDE} keyword may be used to define a symbol, such as | |
2529 | @samp{etext}, only if it is referenced but not defined. The syntax is | |
2530 | @code{PROVIDE(@var{symbol} = @var{expression})}. | |
2531 | ||
2532 | Here is an example of using @code{PROVIDE} to define @samp{etext}: | |
2533 | @smallexample | |
2534 | SECTIONS | |
2535 | @{ | |
2536 | .text : | |
2537 | @{ | |
2538 | *(.text) | |
2539 | _etext = .; | |
2540 | PROVIDE(etext = .); | |
2541 | @} | |
2542 | @} | |
2543 | @end smallexample | |
2544 | ||
2545 | In this example, if the program defines @samp{_etext} (with a leading | |
2546 | underscore), the linker will give a multiple definition error. If, on | |
2547 | the other hand, the program defines @samp{etext} (with no leading | |
2548 | underscore), the linker will silently use the definition in the program. | |
2549 | If the program references @samp{etext} but does not define it, the | |
2550 | linker will use the definition in the linker script. | |
2551 | ||
2552 | @node SECTIONS | |
2553 | @section SECTIONS command | |
2554 | @kindex SECTIONS | |
2555 | The @code{SECTIONS} command tells the linker how to map input sections | |
2556 | into output sections, and how to place the output sections in memory. | |
2557 | ||
2558 | The format of the @code{SECTIONS} command is: | |
2559 | @smallexample | |
2560 | SECTIONS | |
2561 | @{ | |
2562 | @var{sections-command} | |
2563 | @var{sections-command} | |
2564 | @dots{} | |
2565 | @} | |
2566 | @end smallexample | |
2567 | ||
2568 | Each @var{sections-command} may of be one of the following: | |
2569 | ||
2570 | @itemize @bullet | |
2571 | @item | |
2572 | an @code{ENTRY} command (@pxref{Entry Point,,Entry command}) | |
2573 | @item | |
2574 | a symbol assignment (@pxref{Assignments}) | |
2575 | @item | |
2576 | an output section description | |
2577 | @item | |
2578 | an overlay description | |
2579 | @end itemize | |
2580 | ||
2581 | The @code{ENTRY} command and symbol assignments are permitted inside the | |
2582 | @code{SECTIONS} command for convenience in using the location counter in | |
2583 | those commands. This can also make the linker script easier to | |
2584 | understand because you can use those commands at meaningful points in | |
2585 | the layout of the output file. | |
2586 | ||
2587 | Output section descriptions and overlay descriptions are described | |
2588 | below. | |
2589 | ||
2590 | If you do not use a @code{SECTIONS} command in your linker script, the | |
2591 | linker will place each input section into an identically named output | |
2592 | section in the order that the sections are first encountered in the | |
2593 | input files. If all input sections are present in the first file, for | |
2594 | example, the order of sections in the output file will match the order | |
2595 | in the first input file. The first section will be at address zero. | |
2596 | ||
2597 | @menu | |
2598 | * Output Section Description:: Output section description | |
2599 | * Output Section Name:: Output section name | |
2600 | * Output Section Address:: Output section address | |
2601 | * Input Section:: Input section description | |
2602 | * Output Section Data:: Output section data | |
2603 | * Output Section Keywords:: Output section keywords | |
2604 | * Output Section Discarding:: Output section discarding | |
2605 | * Output Section Attributes:: Output section attributes | |
2606 | * Overlay Description:: Overlay description | |
2607 | @end menu | |
2608 | ||
2609 | @node Output Section Description | |
2610 | @subsection Output section description | |
2611 | The full description of an output section looks like this: | |
2612 | @smallexample | |
a1ab1d2a | 2613 | @group |
252b5132 RH |
2614 | @var{section} [@var{address}] [(@var{type})] : [AT(@var{lma})] |
2615 | @{ | |
2616 | @var{output-section-command} | |
2617 | @var{output-section-command} | |
2618 | @dots{} | |
562d3460 | 2619 | @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}] |
252b5132 RH |
2620 | @end group |
2621 | @end smallexample | |
2622 | ||
2623 | Most output sections do not use most of the optional section attributes. | |
2624 | ||
2625 | The whitespace around @var{section} is required, so that the section | |
2626 | name is unambiguous. The colon and the curly braces are also required. | |
2627 | The line breaks and other white space are optional. | |
2628 | ||
2629 | Each @var{output-section-command} may be one of the following: | |
2630 | ||
2631 | @itemize @bullet | |
2632 | @item | |
2633 | a symbol assignment (@pxref{Assignments}) | |
2634 | @item | |
2635 | an input section description (@pxref{Input Section}) | |
2636 | @item | |
2637 | data values to include directly (@pxref{Output Section Data}) | |
2638 | @item | |
2639 | a special output section keyword (@pxref{Output Section Keywords}) | |
2640 | @end itemize | |
2641 | ||
2642 | @node Output Section Name | |
2643 | @subsection Output section name | |
2644 | @cindex name, section | |
2645 | @cindex section name | |
2646 | The name of the output section is @var{section}. @var{section} must | |
2647 | meet the constraints of your output format. In formats which only | |
2648 | support a limited number of sections, such as @code{a.out}, the name | |
2649 | must be one of the names supported by the format (@code{a.out}, for | |
2650 | example, allows only @samp{.text}, @samp{.data} or @samp{.bss}). If the | |
2651 | output format supports any number of sections, but with numbers and not | |
2652 | names (as is the case for Oasys), the name should be supplied as a | |
2653 | quoted numeric string. A section name may consist of any sequence of | |
2654 | characters, but a name which contains any unusual characters such as | |
2655 | commas must be quoted. | |
2656 | ||
2657 | The output section name @samp{/DISCARD/} is special; @ref{Output Section | |
2658 | Discarding}. | |
2659 | ||
2660 | @node Output Section Address | |
2661 | @subsection Output section address | |
2662 | @cindex address, section | |
2663 | @cindex section address | |
2664 | The @var{address} is an expression for the VMA (the virtual memory | |
2665 | address) of the output section. If you do not provide @var{address}, | |
2666 | the linker will set it based on @var{region} if present, or otherwise | |
2667 | based on the current value of the location counter. | |
2668 | ||
2669 | If you provide @var{address}, the address of the output section will be | |
2670 | set to precisely that. If you provide neither @var{address} nor | |
2671 | @var{region}, then the address of the output section will be set to the | |
2672 | current value of the location counter aligned to the alignment | |
2673 | requirements of the output section. The alignment requirement of the | |
2674 | output section is the strictest alignment of any input section contained | |
2675 | within the output section. | |
2676 | ||
2677 | For example, | |
2678 | @smallexample | |
2679 | .text . : @{ *(.text) @} | |
2680 | @end smallexample | |
2681 | @noindent | |
2682 | and | |
2683 | @smallexample | |
2684 | .text : @{ *(.text) @} | |
2685 | @end smallexample | |
2686 | @noindent | |
2687 | are subtly different. The first will set the address of the | |
2688 | @samp{.text} output section to the current value of the location | |
2689 | counter. The second will set it to the current value of the location | |
2690 | counter aligned to the strictest alignment of a @samp{.text} input | |
2691 | section. | |
2692 | ||
2693 | The @var{address} may be an arbitrary expression; @ref{Expressions}. | |
2694 | For example, if you want to align the section on a 0x10 byte boundary, | |
2695 | so that the lowest four bits of the section address are zero, you could | |
2696 | do something like this: | |
2697 | @smallexample | |
2698 | .text ALIGN(0x10) : @{ *(.text) @} | |
2699 | @end smallexample | |
2700 | @noindent | |
2701 | This works because @code{ALIGN} returns the current location counter | |
2702 | aligned upward to the specified value. | |
2703 | ||
2704 | Specifying @var{address} for a section will change the value of the | |
2705 | location counter. | |
2706 | ||
2707 | @node Input Section | |
2708 | @subsection Input section description | |
2709 | @cindex input sections | |
2710 | @cindex mapping input sections to output sections | |
2711 | The most common output section command is an input section description. | |
2712 | ||
2713 | The input section description is the most basic linker script operation. | |
2714 | You use output sections to tell the linker how to lay out your program | |
2715 | in memory. You use input section descriptions to tell the linker how to | |
2716 | map the input files into your memory layout. | |
2717 | ||
2718 | @menu | |
2719 | * Input Section Basics:: Input section basics | |
2720 | * Input Section Wildcards:: Input section wildcard patterns | |
2721 | * Input Section Common:: Input section for common symbols | |
2722 | * Input Section Keep:: Input section and garbage collection | |
2723 | * Input Section Example:: Input section example | |
2724 | @end menu | |
2725 | ||
2726 | @node Input Section Basics | |
2727 | @subsubsection Input section basics | |
2728 | @cindex input section basics | |
2729 | An input section description consists of a file name optionally followed | |
2730 | by a list of section names in parentheses. | |
2731 | ||
2732 | The file name and the section name may be wildcard patterns, which we | |
2733 | describe further below (@pxref{Input Section Wildcards}). | |
2734 | ||
2735 | The most common input section description is to include all input | |
2736 | sections with a particular name in the output section. For example, to | |
2737 | include all input @samp{.text} sections, you would write: | |
2738 | @smallexample | |
2739 | *(.text) | |
2740 | @end smallexample | |
2741 | @noindent | |
18625d54 CM |
2742 | Here the @samp{*} is a wildcard which matches any file name. To exclude a list |
2743 | of files from matching the file name wildcard, EXCLUDE_FILE may be used to | |
2744 | match all files except the ones specified in the EXCLUDE_FILE list. For | |
2745 | example: | |
252b5132 | 2746 | @smallexample |
765b7cbe | 2747 | (*(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)) |
252b5132 | 2748 | @end smallexample |
765b7cbe JB |
2749 | will cause all .ctors sections from all files except @file{crtend.o} and |
2750 | @file{otherfile.o} to be included. | |
252b5132 RH |
2751 | |
2752 | There are two ways to include more than one section: | |
2753 | @smallexample | |
2754 | *(.text .rdata) | |
2755 | *(.text) *(.rdata) | |
2756 | @end smallexample | |
2757 | @noindent | |
2758 | The difference between these is the order in which the @samp{.text} and | |
2759 | @samp{.rdata} input sections will appear in the output section. In the | |
b6bf44ba AM |
2760 | first example, they will be intermingled, appearing in the same order as |
2761 | they are found in the linker input. In the second example, all | |
252b5132 RH |
2762 | @samp{.text} input sections will appear first, followed by all |
2763 | @samp{.rdata} input sections. | |
2764 | ||
2765 | You can specify a file name to include sections from a particular file. | |
2766 | You would do this if one or more of your files contain special data that | |
2767 | needs to be at a particular location in memory. For example: | |
2768 | @smallexample | |
2769 | data.o(.data) | |
2770 | @end smallexample | |
2771 | ||
2772 | If you use a file name without a list of sections, then all sections in | |
2773 | the input file will be included in the output section. This is not | |
2774 | commonly done, but it may by useful on occasion. For example: | |
2775 | @smallexample | |
2776 | data.o | |
2777 | @end smallexample | |
2778 | ||
2779 | When you use a file name which does not contain any wild card | |
2780 | characters, the linker will first see if you also specified the file | |
2781 | name on the linker command line or in an @code{INPUT} command. If you | |
2782 | did not, the linker will attempt to open the file as an input file, as | |
2783 | though it appeared on the command line. Note that this differs from an | |
2784 | @code{INPUT} command, because the linker will not search for the file in | |
2785 | the archive search path. | |
2786 | ||
2787 | @node Input Section Wildcards | |
2788 | @subsubsection Input section wildcard patterns | |
2789 | @cindex input section wildcards | |
2790 | @cindex wildcard file name patterns | |
2791 | @cindex file name wildcard patterns | |
2792 | @cindex section name wildcard patterns | |
2793 | In an input section description, either the file name or the section | |
2794 | name or both may be wildcard patterns. | |
2795 | ||
2796 | The file name of @samp{*} seen in many examples is a simple wildcard | |
2797 | pattern for the file name. | |
2798 | ||
2799 | The wildcard patterns are like those used by the Unix shell. | |
2800 | ||
2801 | @table @samp | |
2802 | @item * | |
2803 | matches any number of characters | |
2804 | @item ? | |
2805 | matches any single character | |
2806 | @item [@var{chars}] | |
2807 | matches a single instance of any of the @var{chars}; the @samp{-} | |
2808 | character may be used to specify a range of characters, as in | |
2809 | @samp{[a-z]} to match any lower case letter | |
2810 | @item \ | |
2811 | quotes the following character | |
2812 | @end table | |
2813 | ||
2814 | When a file name is matched with a wildcard, the wildcard characters | |
2815 | will not match a @samp{/} character (used to separate directory names on | |
2816 | Unix). A pattern consisting of a single @samp{*} character is an | |
2817 | exception; it will always match any file name, whether it contains a | |
2818 | @samp{/} or not. In a section name, the wildcard characters will match | |
2819 | a @samp{/} character. | |
2820 | ||
2821 | File name wildcard patterns only match files which are explicitly | |
2822 | specified on the command line or in an @code{INPUT} command. The linker | |
2823 | does not search directories to expand wildcards. | |
2824 | ||
2825 | If a file name matches more than one wildcard pattern, or if a file name | |
2826 | appears explicitly and is also matched by a wildcard pattern, the linker | |
2827 | will use the first match in the linker script. For example, this | |
2828 | sequence of input section descriptions is probably in error, because the | |
2829 | @file{data.o} rule will not be used: | |
2830 | @smallexample | |
2831 | .data : @{ *(.data) @} | |
2832 | .data1 : @{ data.o(.data) @} | |
2833 | @end smallexample | |
2834 | ||
2835 | @cindex SORT | |
2836 | Normally, the linker will place files and sections matched by wildcards | |
2837 | in the order in which they are seen during the link. You can change | |
2838 | this by using the @code{SORT} keyword, which appears before a wildcard | |
2839 | pattern in parentheses (e.g., @code{SORT(.text*)}). When the | |
2840 | @code{SORT} keyword is used, the linker will sort the files or sections | |
2841 | into ascending order by name before placing them in the output file. | |
2842 | ||
2843 | If you ever get confused about where input sections are going, use the | |
2844 | @samp{-M} linker option to generate a map file. The map file shows | |
2845 | precisely how input sections are mapped to output sections. | |
2846 | ||
2847 | This example shows how wildcard patterns might be used to partition | |
2848 | files. This linker script directs the linker to place all @samp{.text} | |
2849 | sections in @samp{.text} and all @samp{.bss} sections in @samp{.bss}. | |
2850 | The linker will place the @samp{.data} section from all files beginning | |
2851 | with an upper case character in @samp{.DATA}; for all other files, the | |
2852 | linker will place the @samp{.data} section in @samp{.data}. | |
2853 | @smallexample | |
2854 | @group | |
2855 | SECTIONS @{ | |
2856 | .text : @{ *(.text) @} | |
2857 | .DATA : @{ [A-Z]*(.data) @} | |
2858 | .data : @{ *(.data) @} | |
2859 | .bss : @{ *(.bss) @} | |
2860 | @} | |
2861 | @end group | |
2862 | @end smallexample | |
2863 | ||
2864 | @node Input Section Common | |
2865 | @subsubsection Input section for common symbols | |
2866 | @cindex common symbol placement | |
2867 | @cindex uninitialized data placement | |
2868 | A special notation is needed for common symbols, because in many object | |
2869 | file formats common symbols do not have a particular input section. The | |
2870 | linker treats common symbols as though they are in an input section | |
2871 | named @samp{COMMON}. | |
2872 | ||
2873 | You may use file names with the @samp{COMMON} section just as with any | |
2874 | other input sections. You can use this to place common symbols from a | |
2875 | particular input file in one section while common symbols from other | |
2876 | input files are placed in another section. | |
2877 | ||
2878 | In most cases, common symbols in input files will be placed in the | |
2879 | @samp{.bss} section in the output file. For example: | |
2880 | @smallexample | |
2881 | .bss @{ *(.bss) *(COMMON) @} | |
2882 | @end smallexample | |
2883 | ||
2884 | @cindex scommon section | |
2885 | @cindex small common symbols | |
2886 | Some object file formats have more than one type of common symbol. For | |
2887 | example, the MIPS ELF object file format distinguishes standard common | |
2888 | symbols and small common symbols. In this case, the linker will use a | |
2889 | different special section name for other types of common symbols. In | |
2890 | the case of MIPS ELF, the linker uses @samp{COMMON} for standard common | |
2891 | symbols and @samp{.scommon} for small common symbols. This permits you | |
2892 | to map the different types of common symbols into memory at different | |
2893 | locations. | |
2894 | ||
2895 | @cindex [COMMON] | |
2896 | You will sometimes see @samp{[COMMON]} in old linker scripts. This | |
2897 | notation is now considered obsolete. It is equivalent to | |
2898 | @samp{*(COMMON)}. | |
2899 | ||
2900 | @node Input Section Keep | |
2901 | @subsubsection Input section and garbage collection | |
2902 | @cindex KEEP | |
2903 | @cindex garbage collection | |
2904 | When link-time garbage collection is in use (@samp{--gc-sections}), | |
a1ab1d2a | 2905 | it is often useful to mark sections that should not be eliminated. |
252b5132 RH |
2906 | This is accomplished by surrounding an input section's wildcard entry |
2907 | with @code{KEEP()}, as in @code{KEEP(*(.init))} or | |
2908 | @code{KEEP(SORT(*)(.ctors))}. | |
2909 | ||
2910 | @node Input Section Example | |
2911 | @subsubsection Input section example | |
2912 | The following example is a complete linker script. It tells the linker | |
2913 | to read all of the sections from file @file{all.o} and place them at the | |
2914 | start of output section @samp{outputa} which starts at location | |
2915 | @samp{0x10000}. All of section @samp{.input1} from file @file{foo.o} | |
2916 | follows immediately, in the same output section. All of section | |
2917 | @samp{.input2} from @file{foo.o} goes into output section | |
2918 | @samp{outputb}, followed by section @samp{.input1} from @file{foo1.o}. | |
2919 | All of the remaining @samp{.input1} and @samp{.input2} sections from any | |
2920 | files are written to output section @samp{outputc}. | |
2921 | ||
2922 | @smallexample | |
2923 | @group | |
2924 | SECTIONS @{ | |
2925 | outputa 0x10000 : | |
2926 | @{ | |
2927 | all.o | |
2928 | foo.o (.input1) | |
2929 | @} | |
2930 | outputb : | |
2931 | @{ | |
2932 | foo.o (.input2) | |
2933 | foo1.o (.input1) | |
2934 | @} | |
2935 | outputc : | |
2936 | @{ | |
2937 | *(.input1) | |
2938 | *(.input2) | |
2939 | @} | |
2940 | @} | |
2941 | @end group | |
a1ab1d2a | 2942 | @end smallexample |
252b5132 RH |
2943 | |
2944 | @node Output Section Data | |
2945 | @subsection Output section data | |
2946 | @cindex data | |
2947 | @cindex section data | |
2948 | @cindex output section data | |
2949 | @kindex BYTE(@var{expression}) | |
2950 | @kindex SHORT(@var{expression}) | |
2951 | @kindex LONG(@var{expression}) | |
2952 | @kindex QUAD(@var{expression}) | |
2953 | @kindex SQUAD(@var{expression}) | |
2954 | You can include explicit bytes of data in an output section by using | |
2955 | @code{BYTE}, @code{SHORT}, @code{LONG}, @code{QUAD}, or @code{SQUAD} as | |
2956 | an output section command. Each keyword is followed by an expression in | |
2957 | parentheses providing the value to store (@pxref{Expressions}). The | |
2958 | value of the expression is stored at the current value of the location | |
2959 | counter. | |
2960 | ||
2961 | The @code{BYTE}, @code{SHORT}, @code{LONG}, and @code{QUAD} commands | |
2962 | store one, two, four, and eight bytes (respectively). After storing the | |
2963 | bytes, the location counter is incremented by the number of bytes | |
2964 | stored. | |
2965 | ||
2966 | For example, this will store the byte 1 followed by the four byte value | |
2967 | of the symbol @samp{addr}: | |
2968 | @smallexample | |
2969 | BYTE(1) | |
2970 | LONG(addr) | |
2971 | @end smallexample | |
2972 | ||
2973 | When using a 64 bit host or target, @code{QUAD} and @code{SQUAD} are the | |
2974 | same; they both store an 8 byte, or 64 bit, value. When both host and | |
2975 | target are 32 bits, an expression is computed as 32 bits. In this case | |
2976 | @code{QUAD} stores a 32 bit value zero extended to 64 bits, and | |
2977 | @code{SQUAD} stores a 32 bit value sign extended to 64 bits. | |
2978 | ||
2979 | If the object file format of the output file has an explicit endianness, | |
2980 | which is the normal case, the value will be stored in that endianness. | |
2981 | When the object file format does not have an explicit endianness, as is | |
2982 | true of, for example, S-records, the value will be stored in the | |
2983 | endianness of the first input object file. | |
2984 | ||
2b5fc1f5 NC |
2985 | Note - these commands only work inside a section description and not |
2986 | between them, so the following will produce an error from the linker: | |
2987 | @smallexample | |
2988 | SECTIONS @{@ .text : @{@ *(.text) @}@ LONG(1) .data : @{@ *(.data) @}@ @}@ | |
2989 | @end smallexample | |
2990 | whereas this will work: | |
2991 | @smallexample | |
2992 | SECTIONS @{@ .text : @{@ *(.text) ; LONG(1) @}@ .data : @{@ *(.data) @}@ @}@ | |
2993 | @end smallexample | |
2994 | ||
252b5132 RH |
2995 | @kindex FILL(@var{expression}) |
2996 | @cindex holes, filling | |
2997 | @cindex unspecified memory | |
2998 | You may use the @code{FILL} command to set the fill pattern for the | |
2999 | current section. It is followed by an expression in parentheses. Any | |
3000 | otherwise unspecified regions of memory within the section (for example, | |
3001 | gaps left due to the required alignment of input sections) are filled | |
a139d329 | 3002 | with the value of the expression, repeated as |
252b5132 RH |
3003 | necessary. A @code{FILL} statement covers memory locations after the |
3004 | point at which it occurs in the section definition; by including more | |
3005 | than one @code{FILL} statement, you can have different fill patterns in | |
3006 | different parts of an output section. | |
3007 | ||
3008 | This example shows how to fill unspecified regions of memory with the | |
563e308f | 3009 | value @samp{0x90}: |
252b5132 | 3010 | @smallexample |
563e308f | 3011 | FILL(0x90909090) |
252b5132 RH |
3012 | @end smallexample |
3013 | ||
3014 | The @code{FILL} command is similar to the @samp{=@var{fillexp}} output | |
9673c93c | 3015 | section attribute, but it only affects the |
252b5132 RH |
3016 | part of the section following the @code{FILL} command, rather than the |
3017 | entire section. If both are used, the @code{FILL} command takes | |
9673c93c | 3018 | precedence. @xref{Output Section Fill}, for details on the fill |
a139d329 | 3019 | expression. |
252b5132 RH |
3020 | |
3021 | @node Output Section Keywords | |
3022 | @subsection Output section keywords | |
3023 | There are a couple of keywords which can appear as output section | |
3024 | commands. | |
3025 | ||
3026 | @table @code | |
3027 | @kindex CREATE_OBJECT_SYMBOLS | |
3028 | @cindex input filename symbols | |
3029 | @cindex filename symbols | |
3030 | @item CREATE_OBJECT_SYMBOLS | |
3031 | The command tells the linker to create a symbol for each input file. | |
3032 | The name of each symbol will be the name of the corresponding input | |
3033 | file. The section of each symbol will be the output section in which | |
3034 | the @code{CREATE_OBJECT_SYMBOLS} command appears. | |
3035 | ||
3036 | This is conventional for the a.out object file format. It is not | |
3037 | normally used for any other object file format. | |
3038 | ||
3039 | @kindex CONSTRUCTORS | |
3040 | @cindex C++ constructors, arranging in link | |
3041 | @cindex constructors, arranging in link | |
3042 | @item CONSTRUCTORS | |
3043 | When linking using the a.out object file format, the linker uses an | |
3044 | unusual set construct to support C++ global constructors and | |
3045 | destructors. When linking object file formats which do not support | |
3046 | arbitrary sections, such as ECOFF and XCOFF, the linker will | |
3047 | automatically recognize C++ global constructors and destructors by name. | |
3048 | For these object file formats, the @code{CONSTRUCTORS} command tells the | |
3049 | linker to place constructor information in the output section where the | |
3050 | @code{CONSTRUCTORS} command appears. The @code{CONSTRUCTORS} command is | |
3051 | ignored for other object file formats. | |
3052 | ||
3053 | The symbol @w{@code{__CTOR_LIST__}} marks the start of the global | |
3054 | constructors, and the symbol @w{@code{__DTOR_LIST}} marks the end. The | |
3055 | first word in the list is the number of entries, followed by the address | |
3056 | of each constructor or destructor, followed by a zero word. The | |
3057 | compiler must arrange to actually run the code. For these object file | |
3058 | formats @sc{gnu} C++ normally calls constructors from a subroutine | |
3059 | @code{__main}; a call to @code{__main} is automatically inserted into | |
3060 | the startup code for @code{main}. @sc{gnu} C++ normally runs | |
3061 | destructors either by using @code{atexit}, or directly from the function | |
3062 | @code{exit}. | |
3063 | ||
3064 | For object file formats such as @code{COFF} or @code{ELF} which support | |
3065 | arbitrary section names, @sc{gnu} C++ will normally arrange to put the | |
3066 | addresses of global constructors and destructors into the @code{.ctors} | |
3067 | and @code{.dtors} sections. Placing the following sequence into your | |
3068 | linker script will build the sort of table which the @sc{gnu} C++ | |
3069 | runtime code expects to see. | |
3070 | ||
3071 | @smallexample | |
3072 | __CTOR_LIST__ = .; | |
3073 | LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) | |
3074 | *(.ctors) | |
3075 | LONG(0) | |
3076 | __CTOR_END__ = .; | |
3077 | __DTOR_LIST__ = .; | |
3078 | LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) | |
3079 | *(.dtors) | |
3080 | LONG(0) | |
3081 | __DTOR_END__ = .; | |
3082 | @end smallexample | |
3083 | ||
3084 | If you are using the @sc{gnu} C++ support for initialization priority, | |
3085 | which provides some control over the order in which global constructors | |
3086 | are run, you must sort the constructors at link time to ensure that they | |
3087 | are executed in the correct order. When using the @code{CONSTRUCTORS} | |
3088 | command, use @samp{SORT(CONSTRUCTORS)} instead. When using the | |
3089 | @code{.ctors} and @code{.dtors} sections, use @samp{*(SORT(.ctors))} and | |
3090 | @samp{*(SORT(.dtors))} instead of just @samp{*(.ctors)} and | |
3091 | @samp{*(.dtors)}. | |
3092 | ||
3093 | Normally the compiler and linker will handle these issues automatically, | |
3094 | and you will not need to concern yourself with them. However, you may | |
3095 | need to consider this if you are using C++ and writing your own linker | |
3096 | scripts. | |
3097 | ||
3098 | @end table | |
3099 | ||
3100 | @node Output Section Discarding | |
3101 | @subsection Output section discarding | |
3102 | @cindex discarding sections | |
3103 | @cindex sections, discarding | |
3104 | @cindex removing sections | |
3105 | The linker will not create output section which do not have any | |
3106 | contents. This is for convenience when referring to input sections that | |
3107 | may or may not be present in any of the input files. For example: | |
3108 | @smallexample | |
3109 | .foo @{ *(.foo) @} | |
3110 | @end smallexample | |
3111 | @noindent | |
3112 | will only create a @samp{.foo} section in the output file if there is a | |
3113 | @samp{.foo} section in at least one input file. | |
3114 | ||
3115 | If you use anything other than an input section description as an output | |
3116 | section command, such as a symbol assignment, then the output section | |
3117 | will always be created, even if there are no matching input sections. | |
3118 | ||
3119 | @cindex /DISCARD/ | |
3120 | The special output section name @samp{/DISCARD/} may be used to discard | |
3121 | input sections. Any input sections which are assigned to an output | |
3122 | section named @samp{/DISCARD/} are not included in the output file. | |
3123 | ||
3124 | @node Output Section Attributes | |
3125 | @subsection Output section attributes | |
3126 | @cindex output section attributes | |
3127 | We showed above that the full description of an output section looked | |
3128 | like this: | |
3129 | @smallexample | |
a1ab1d2a | 3130 | @group |
252b5132 RH |
3131 | @var{section} [@var{address}] [(@var{type})] : [AT(@var{lma})] |
3132 | @{ | |
3133 | @var{output-section-command} | |
3134 | @var{output-section-command} | |
3135 | @dots{} | |
562d3460 | 3136 | @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}] |
252b5132 RH |
3137 | @end group |
3138 | @end smallexample | |
3139 | We've already described @var{section}, @var{address}, and | |
3140 | @var{output-section-command}. In this section we will describe the | |
3141 | remaining section attributes. | |
3142 | ||
a1ab1d2a | 3143 | @menu |
252b5132 RH |
3144 | * Output Section Type:: Output section type |
3145 | * Output Section LMA:: Output section LMA | |
3146 | * Output Section Region:: Output section region | |
3147 | * Output Section Phdr:: Output section phdr | |
3148 | * Output Section Fill:: Output section fill | |
3149 | @end menu | |
3150 | ||
3151 | @node Output Section Type | |
3152 | @subsubsection Output section type | |
3153 | Each output section may have a type. The type is a keyword in | |
3154 | parentheses. The following types are defined: | |
3155 | ||
3156 | @table @code | |
3157 | @item NOLOAD | |
3158 | The section should be marked as not loadable, so that it will not be | |
3159 | loaded into memory when the program is run. | |
3160 | @item DSECT | |
3161 | @itemx COPY | |
3162 | @itemx INFO | |
3163 | @itemx OVERLAY | |
3164 | These type names are supported for backward compatibility, and are | |
3165 | rarely used. They all have the same effect: the section should be | |
3166 | marked as not allocatable, so that no memory is allocated for the | |
3167 | section when the program is run. | |
3168 | @end table | |
3169 | ||
3170 | @kindex NOLOAD | |
3171 | @cindex prevent unnecessary loading | |
3172 | @cindex loading, preventing | |
3173 | The linker normally sets the attributes of an output section based on | |
3174 | the input sections which map into it. You can override this by using | |
3175 | the section type. For example, in the script sample below, the | |
3176 | @samp{ROM} section is addressed at memory location @samp{0} and does not | |
3177 | need to be loaded when the program is run. The contents of the | |
3178 | @samp{ROM} section will appear in the linker output file as usual. | |
3179 | @smallexample | |
3180 | @group | |
3181 | SECTIONS @{ | |
3182 | ROM 0 (NOLOAD) : @{ @dots{} @} | |
3183 | @dots{} | |
3184 | @} | |
3185 | @end group | |
3186 | @end smallexample | |
3187 | ||
3188 | @node Output Section LMA | |
3189 | @subsubsection Output section LMA | |
562d3460 | 3190 | @kindex AT>@var{lma_region} |
252b5132 RH |
3191 | @kindex AT(@var{lma}) |
3192 | @cindex load address | |
3193 | @cindex section load address | |
3194 | Every section has a virtual address (VMA) and a load address (LMA); see | |
3195 | @ref{Basic Script Concepts}. The address expression which may appear in | |
3196 | an output section description sets the VMA (@pxref{Output Section | |
3197 | Address}). | |
3198 | ||
3199 | The linker will normally set the LMA equal to the VMA. You can change | |
3200 | that by using the @code{AT} keyword. The expression @var{lma} that | |
562d3460 TW |
3201 | follows the @code{AT} keyword specifies the load address of the |
3202 | section. Alternatively, with @samp{AT>@var{lma_region}} expression, | |
3203 | you may specify a memory region for the section's load address. @xref{MEMORY}. | |
252b5132 RH |
3204 | |
3205 | @cindex ROM initialized data | |
3206 | @cindex initialized data in ROM | |
3207 | This feature is designed to make it easy to build a ROM image. For | |
3208 | example, the following linker script creates three output sections: one | |
3209 | called @samp{.text}, which starts at @code{0x1000}, one called | |
3210 | @samp{.mdata}, which is loaded at the end of the @samp{.text} section | |
3211 | even though its VMA is @code{0x2000}, and one called @samp{.bss} to hold | |
3212 | uninitialized data at address @code{0x3000}. The symbol @code{_data} is | |
3213 | defined with the value @code{0x2000}, which shows that the location | |
3214 | counter holds the VMA value, not the LMA value. | |
3215 | ||
3216 | @smallexample | |
3217 | @group | |
3218 | SECTIONS | |
3219 | @{ | |
3220 | .text 0x1000 : @{ *(.text) _etext = . ; @} | |
a1ab1d2a | 3221 | .mdata 0x2000 : |
252b5132 RH |
3222 | AT ( ADDR (.text) + SIZEOF (.text) ) |
3223 | @{ _data = . ; *(.data); _edata = . ; @} | |
3224 | .bss 0x3000 : | |
3225 | @{ _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;@} | |
3226 | @} | |
3227 | @end group | |
3228 | @end smallexample | |
3229 | ||
3230 | The run-time initialization code for use with a program generated with | |
3231 | this linker script would include something like the following, to copy | |
3232 | the initialized data from the ROM image to its runtime address. Notice | |
3233 | how this code takes advantage of the symbols defined by the linker | |
3234 | script. | |
3235 | ||
3236 | @smallexample | |
3237 | @group | |
3238 | extern char _etext, _data, _edata, _bstart, _bend; | |
3239 | char *src = &_etext; | |
3240 | char *dst = &_data; | |
3241 | ||
3242 | /* ROM has data at end of text; copy it. */ | |
3243 | while (dst < &_edata) @{ | |
3244 | *dst++ = *src++; | |
3245 | @} | |
3246 | ||
3247 | /* Zero bss */ | |
3248 | for (dst = &_bstart; dst< &_bend; dst++) | |
3249 | *dst = 0; | |
3250 | @end group | |
3251 | @end smallexample | |
3252 | ||
3253 | @node Output Section Region | |
3254 | @subsubsection Output section region | |
3255 | @kindex >@var{region} | |
3256 | @cindex section, assigning to memory region | |
3257 | @cindex memory regions and sections | |
3258 | You can assign a section to a previously defined region of memory by | |
3259 | using @samp{>@var{region}}. @xref{MEMORY}. | |
3260 | ||
3261 | Here is a simple example: | |
3262 | @smallexample | |
3263 | @group | |
3264 | MEMORY @{ rom : ORIGIN = 0x1000, LENGTH = 0x1000 @} | |
3265 | SECTIONS @{ ROM : @{ *(.text) @} >rom @} | |
3266 | @end group | |
3267 | @end smallexample | |
3268 | ||
3269 | @node Output Section Phdr | |
3270 | @subsubsection Output section phdr | |
3271 | @kindex :@var{phdr} | |
3272 | @cindex section, assigning to program header | |
3273 | @cindex program headers and sections | |
3274 | You can assign a section to a previously defined program segment by | |
3275 | using @samp{:@var{phdr}}. @xref{PHDRS}. If a section is assigned to | |
3276 | one or more segments, then all subsequent allocated sections will be | |
3277 | assigned to those segments as well, unless they use an explicitly | |
3278 | @code{:@var{phdr}} modifier. You can use @code{:NONE} to tell the | |
3279 | linker to not put the section in any segment at all. | |
3280 | ||
3281 | Here is a simple example: | |
3282 | @smallexample | |
3283 | @group | |
3284 | PHDRS @{ text PT_LOAD ; @} | |
3285 | SECTIONS @{ .text : @{ *(.text) @} :text @} | |
3286 | @end group | |
3287 | @end smallexample | |
3288 | ||
3289 | @node Output Section Fill | |
3290 | @subsubsection Output section fill | |
3291 | @kindex =@var{fillexp} | |
3292 | @cindex section fill pattern | |
3293 | @cindex fill pattern, entire section | |
3294 | You can set the fill pattern for an entire section by using | |
3295 | @samp{=@var{fillexp}}. @var{fillexp} is an expression | |
3296 | (@pxref{Expressions}). Any otherwise unspecified regions of memory | |
3297 | within the output section (for example, gaps left due to the required | |
a139d329 AM |
3298 | alignment of input sections) will be filled with the value, repeated as |
3299 | necessary. If the fill expression is a simple hex number, ie. a string | |
9673c93c | 3300 | of hex digit starting with @samp{0x} and without a trailing @samp{k} or @samp{M}, then |
a139d329 AM |
3301 | an arbitrarily long sequence of hex digits can be used to specify the |
3302 | fill pattern; Leading zeros become part of the pattern too. For all | |
9673c93c | 3303 | other cases, including extra parentheses or a unary @code{+}, the fill |
a139d329 AM |
3304 | pattern is the four least significant bytes of the value of the |
3305 | expression. In all cases, the number is big-endian. | |
252b5132 RH |
3306 | |
3307 | You can also change the fill value with a @code{FILL} command in the | |
9673c93c | 3308 | output section commands; (@pxref{Output Section Data}). |
252b5132 RH |
3309 | |
3310 | Here is a simple example: | |
3311 | @smallexample | |
3312 | @group | |
563e308f | 3313 | SECTIONS @{ .text : @{ *(.text) @} =0x90909090 @} |
252b5132 RH |
3314 | @end group |
3315 | @end smallexample | |
3316 | ||
3317 | @node Overlay Description | |
3318 | @subsection Overlay description | |
3319 | @kindex OVERLAY | |
3320 | @cindex overlays | |
3321 | An overlay description provides an easy way to describe sections which | |
3322 | are to be loaded as part of a single memory image but are to be run at | |
3323 | the same memory address. At run time, some sort of overlay manager will | |
3324 | copy the overlaid sections in and out of the runtime memory address as | |
3325 | required, perhaps by simply manipulating addressing bits. This approach | |
3326 | can be useful, for example, when a certain region of memory is faster | |
3327 | than another. | |
3328 | ||
3329 | Overlays are described using the @code{OVERLAY} command. The | |
3330 | @code{OVERLAY} command is used within a @code{SECTIONS} command, like an | |
3331 | output section description. The full syntax of the @code{OVERLAY} | |
3332 | command is as follows: | |
3333 | @smallexample | |
3334 | @group | |
3335 | OVERLAY [@var{start}] : [NOCROSSREFS] [AT ( @var{ldaddr} )] | |
3336 | @{ | |
3337 | @var{secname1} | |
3338 | @{ | |
3339 | @var{output-section-command} | |
3340 | @var{output-section-command} | |
3341 | @dots{} | |
3342 | @} [:@var{phdr}@dots{}] [=@var{fill}] | |
3343 | @var{secname2} | |
3344 | @{ | |
3345 | @var{output-section-command} | |
3346 | @var{output-section-command} | |
3347 | @dots{} | |
3348 | @} [:@var{phdr}@dots{}] [=@var{fill}] | |
3349 | @dots{} | |
3350 | @} [>@var{region}] [:@var{phdr}@dots{}] [=@var{fill}] | |
3351 | @end group | |
3352 | @end smallexample | |
3353 | ||
3354 | Everything is optional except @code{OVERLAY} (a keyword), and each | |
3355 | section must have a name (@var{secname1} and @var{secname2} above). The | |
3356 | section definitions within the @code{OVERLAY} construct are identical to | |
3357 | those within the general @code{SECTIONS} contruct (@pxref{SECTIONS}), | |
3358 | except that no addresses and no memory regions may be defined for | |
3359 | sections within an @code{OVERLAY}. | |
3360 | ||
3361 | The sections are all defined with the same starting address. The load | |
3362 | addresses of the sections are arranged such that they are consecutive in | |
3363 | memory starting at the load address used for the @code{OVERLAY} as a | |
3364 | whole (as with normal section definitions, the load address is optional, | |
3365 | and defaults to the start address; the start address is also optional, | |
3366 | and defaults to the current value of the location counter). | |
3367 | ||
3368 | If the @code{NOCROSSREFS} keyword is used, and there any references | |
3369 | among the sections, the linker will report an error. Since the sections | |
3370 | all run at the same address, it normally does not make sense for one | |
3371 | section to refer directly to another. @xref{Miscellaneous Commands, | |
3372 | NOCROSSREFS}. | |
3373 | ||
3374 | For each section within the @code{OVERLAY}, the linker automatically | |
3375 | defines two symbols. The symbol @code{__load_start_@var{secname}} is | |
3376 | defined as the starting load address of the section. The symbol | |
3377 | @code{__load_stop_@var{secname}} is defined as the final load address of | |
3378 | the section. Any characters within @var{secname} which are not legal | |
3379 | within C identifiers are removed. C (or assembler) code may use these | |
3380 | symbols to move the overlaid sections around as necessary. | |
3381 | ||
3382 | At the end of the overlay, the value of the location counter is set to | |
3383 | the start address of the overlay plus the size of the largest section. | |
3384 | ||
3385 | Here is an example. Remember that this would appear inside a | |
3386 | @code{SECTIONS} construct. | |
3387 | @smallexample | |
3388 | @group | |
3389 | OVERLAY 0x1000 : AT (0x4000) | |
3390 | @{ | |
3391 | .text0 @{ o1/*.o(.text) @} | |
3392 | .text1 @{ o2/*.o(.text) @} | |
3393 | @} | |
3394 | @end group | |
3395 | @end smallexample | |
3396 | @noindent | |
3397 | This will define both @samp{.text0} and @samp{.text1} to start at | |
3398 | address 0x1000. @samp{.text0} will be loaded at address 0x4000, and | |
3399 | @samp{.text1} will be loaded immediately after @samp{.text0}. The | |
3400 | following symbols will be defined: @code{__load_start_text0}, | |
3401 | @code{__load_stop_text0}, @code{__load_start_text1}, | |
3402 | @code{__load_stop_text1}. | |
3403 | ||
3404 | C code to copy overlay @code{.text1} into the overlay area might look | |
3405 | like the following. | |
3406 | ||
3407 | @smallexample | |
3408 | @group | |
3409 | extern char __load_start_text1, __load_stop_text1; | |
3410 | memcpy ((char *) 0x1000, &__load_start_text1, | |
3411 | &__load_stop_text1 - &__load_start_text1); | |
3412 | @end group | |
3413 | @end smallexample | |
3414 | ||
3415 | Note that the @code{OVERLAY} command is just syntactic sugar, since | |
3416 | everything it does can be done using the more basic commands. The above | |
3417 | example could have been written identically as follows. | |
3418 | ||
3419 | @smallexample | |
3420 | @group | |
3421 | .text0 0x1000 : AT (0x4000) @{ o1/*.o(.text) @} | |
3422 | __load_start_text0 = LOADADDR (.text0); | |
3423 | __load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0); | |
3424 | .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) @{ o2/*.o(.text) @} | |
3425 | __load_start_text1 = LOADADDR (.text1); | |
3426 | __load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1); | |
3427 | . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1)); | |
3428 | @end group | |
3429 | @end smallexample | |
3430 | ||
3431 | @node MEMORY | |
3432 | @section MEMORY command | |
3433 | @kindex MEMORY | |
3434 | @cindex memory regions | |
3435 | @cindex regions of memory | |
3436 | @cindex allocating memory | |
3437 | @cindex discontinuous memory | |
3438 | The linker's default configuration permits allocation of all available | |
3439 | memory. You can override this by using the @code{MEMORY} command. | |
3440 | ||
3441 | The @code{MEMORY} command describes the location and size of blocks of | |
3442 | memory in the target. You can use it to describe which memory regions | |
3443 | may be used by the linker, and which memory regions it must avoid. You | |
3444 | can then assign sections to particular memory regions. The linker will | |
3445 | set section addresses based on the memory regions, and will warn about | |
3446 | regions that become too full. The linker will not shuffle sections | |
3447 | around to fit into the available regions. | |
3448 | ||
3449 | A linker script may contain at most one use of the @code{MEMORY} | |
3450 | command. However, you can define as many blocks of memory within it as | |
3451 | you wish. The syntax is: | |
3452 | @smallexample | |
3453 | @group | |
a1ab1d2a | 3454 | MEMORY |
252b5132 RH |
3455 | @{ |
3456 | @var{name} [(@var{attr})] : ORIGIN = @var{origin}, LENGTH = @var{len} | |
3457 | @dots{} | |
3458 | @} | |
3459 | @end group | |
3460 | @end smallexample | |
3461 | ||
3462 | The @var{name} is a name used in the linker script to refer to the | |
3463 | region. The region name has no meaning outside of the linker script. | |
3464 | Region names are stored in a separate name space, and will not conflict | |
3465 | with symbol names, file names, or section names. Each memory region | |
3466 | must have a distinct name. | |
3467 | ||
3468 | @cindex memory region attributes | |
3469 | The @var{attr} string is an optional list of attributes that specify | |
3470 | whether to use a particular memory region for an input section which is | |
3471 | not explicitly mapped in the linker script. As described in | |
3472 | @ref{SECTIONS}, if you do not specify an output section for some input | |
3473 | section, the linker will create an output section with the same name as | |
3474 | the input section. If you define region attributes, the linker will use | |
3475 | them to select the memory region for the output section that it creates. | |
3476 | ||
3477 | The @var{attr} string must consist only of the following characters: | |
3478 | @table @samp | |
3479 | @item R | |
3480 | Read-only section | |
3481 | @item W | |
3482 | Read/write section | |
3483 | @item X | |
3484 | Executable section | |
3485 | @item A | |
3486 | Allocatable section | |
3487 | @item I | |
3488 | Initialized section | |
3489 | @item L | |
3490 | Same as @samp{I} | |
3491 | @item ! | |
3492 | Invert the sense of any of the preceding attributes | |
3493 | @end table | |
3494 | ||
3495 | If a unmapped section matches any of the listed attributes other than | |
3496 | @samp{!}, it will be placed in the memory region. The @samp{!} | |
3497 | attribute reverses this test, so that an unmapped section will be placed | |
3498 | in the memory region only if it does not match any of the listed | |
3499 | attributes. | |
3500 | ||
3501 | @kindex ORIGIN = | |
3502 | @kindex o = | |
3503 | @kindex org = | |
3504 | The @var{origin} is an expression for the start address of the memory | |
3505 | region. The expression must evaluate to a constant before memory | |
3506 | allocation is performed, which means that you may not use any section | |
3507 | relative symbols. The keyword @code{ORIGIN} may be abbreviated to | |
3508 | @code{org} or @code{o} (but not, for example, @code{ORG}). | |
3509 | ||
3510 | @kindex LENGTH = | |
3511 | @kindex len = | |
3512 | @kindex l = | |
3513 | The @var{len} is an expression for the size in bytes of the memory | |
3514 | region. As with the @var{origin} expression, the expression must | |
3515 | evaluate to a constant before memory allocation is performed. The | |
3516 | keyword @code{LENGTH} may be abbreviated to @code{len} or @code{l}. | |
3517 | ||
3518 | In the following example, we specify that there are two memory regions | |
3519 | available for allocation: one starting at @samp{0} for 256 kilobytes, | |
3520 | and the other starting at @samp{0x40000000} for four megabytes. The | |
3521 | linker will place into the @samp{rom} memory region every section which | |
3522 | is not explicitly mapped into a memory region, and is either read-only | |
3523 | or executable. The linker will place other sections which are not | |
3524 | explicitly mapped into a memory region into the @samp{ram} memory | |
3525 | region. | |
3526 | ||
3527 | @smallexample | |
3528 | @group | |
a1ab1d2a | 3529 | MEMORY |
252b5132 RH |
3530 | @{ |
3531 | rom (rx) : ORIGIN = 0, LENGTH = 256K | |
3532 | ram (!rx) : org = 0x40000000, l = 4M | |
3533 | @} | |
3534 | @end group | |
3535 | @end smallexample | |
3536 | ||
3537 | Once you define a memory region, you can direct the linker to place | |
3538 | specific output sections into that memory region by using the | |
3539 | @samp{>@var{region}} output section attribute. For example, if you have | |
3540 | a memory region named @samp{mem}, you would use @samp{>mem} in the | |
3541 | output section definition. @xref{Output Section Region}. If no address | |
3542 | was specified for the output section, the linker will set the address to | |
3543 | the next available address within the memory region. If the combined | |
3544 | output sections directed to a memory region are too large for the | |
3545 | region, the linker will issue an error message. | |
3546 | ||
3547 | @node PHDRS | |
3548 | @section PHDRS Command | |
3549 | @kindex PHDRS | |
3550 | @cindex program headers | |
3551 | @cindex ELF program headers | |
3552 | @cindex program segments | |
3553 | @cindex segments, ELF | |
3554 | The ELF object file format uses @dfn{program headers}, also knows as | |
3555 | @dfn{segments}. The program headers describe how the program should be | |
3556 | loaded into memory. You can print them out by using the @code{objdump} | |
3557 | program with the @samp{-p} option. | |
3558 | ||
3559 | When you run an ELF program on a native ELF system, the system loader | |
3560 | reads the program headers in order to figure out how to load the | |
3561 | program. This will only work if the program headers are set correctly. | |
3562 | This manual does not describe the details of how the system loader | |
3563 | interprets program headers; for more information, see the ELF ABI. | |
3564 | ||
3565 | The linker will create reasonable program headers by default. However, | |
3566 | in some cases, you may need to specify the program headers more | |
3567 | precisely. You may use the @code{PHDRS} command for this purpose. When | |
3568 | the linker sees the @code{PHDRS} command in the linker script, it will | |
3569 | not create any program headers other than the ones specified. | |
3570 | ||
3571 | The linker only pays attention to the @code{PHDRS} command when | |
3572 | generating an ELF output file. In other cases, the linker will simply | |
3573 | ignore @code{PHDRS}. | |
3574 | ||
3575 | This is the syntax of the @code{PHDRS} command. The words @code{PHDRS}, | |
3576 | @code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords. | |
3577 | ||
3578 | @smallexample | |
3579 | @group | |
3580 | PHDRS | |
3581 | @{ | |
3582 | @var{name} @var{type} [ FILEHDR ] [ PHDRS ] [ AT ( @var{address} ) ] | |
3583 | [ FLAGS ( @var{flags} ) ] ; | |
3584 | @} | |
3585 | @end group | |
3586 | @end smallexample | |
3587 | ||
3588 | The @var{name} is used only for reference in the @code{SECTIONS} command | |
3589 | of the linker script. It is not put into the output file. Program | |
3590 | header names are stored in a separate name space, and will not conflict | |
3591 | with symbol names, file names, or section names. Each program header | |
3592 | must have a distinct name. | |
3593 | ||
3594 | Certain program header types describe segments of memory which the | |
3595 | system loader will load from the file. In the linker script, you | |
3596 | specify the contents of these segments by placing allocatable output | |
3597 | sections in the segments. You use the @samp{:@var{phdr}} output section | |
3598 | attribute to place a section in a particular segment. @xref{Output | |
3599 | Section Phdr}. | |
3600 | ||
3601 | It is normal to put certain sections in more than one segment. This | |
3602 | merely implies that one segment of memory contains another. You may | |
3603 | repeat @samp{:@var{phdr}}, using it once for each segment which should | |
3604 | contain the section. | |
3605 | ||
3606 | If you place a section in one or more segments using @samp{:@var{phdr}}, | |
3607 | then the linker will place all subsequent allocatable sections which do | |
3608 | not specify @samp{:@var{phdr}} in the same segments. This is for | |
3609 | convenience, since generally a whole set of contiguous sections will be | |
3610 | placed in a single segment. You can use @code{:NONE} to override the | |
3611 | default segment and tell the linker to not put the section in any | |
3612 | segment at all. | |
3613 | ||
3614 | @kindex FILEHDR | |
3615 | @kindex PHDRS | |
3616 | You may use the @code{FILEHDR} and @code{PHDRS} keywords appear after | |
3617 | the program header type to further describe the contents of the segment. | |
3618 | The @code{FILEHDR} keyword means that the segment should include the ELF | |
3619 | file header. The @code{PHDRS} keyword means that the segment should | |
3620 | include the ELF program headers themselves. | |
3621 | ||
3622 | The @var{type} may be one of the following. The numbers indicate the | |
3623 | value of the keyword. | |
3624 | ||
3625 | @table @asis | |
3626 | @item @code{PT_NULL} (0) | |
3627 | Indicates an unused program header. | |
3628 | ||
3629 | @item @code{PT_LOAD} (1) | |
3630 | Indicates that this program header describes a segment to be loaded from | |
3631 | the file. | |
3632 | ||
3633 | @item @code{PT_DYNAMIC} (2) | |
3634 | Indicates a segment where dynamic linking information can be found. | |
3635 | ||
3636 | @item @code{PT_INTERP} (3) | |
3637 | Indicates a segment where the name of the program interpreter may be | |
3638 | found. | |
3639 | ||
3640 | @item @code{PT_NOTE} (4) | |
3641 | Indicates a segment holding note information. | |
3642 | ||
3643 | @item @code{PT_SHLIB} (5) | |
3644 | A reserved program header type, defined but not specified by the ELF | |
3645 | ABI. | |
3646 | ||
3647 | @item @code{PT_PHDR} (6) | |
3648 | Indicates a segment where the program headers may be found. | |
3649 | ||
3650 | @item @var{expression} | |
3651 | An expression giving the numeric type of the program header. This may | |
3652 | be used for types not defined above. | |
3653 | @end table | |
3654 | ||
3655 | You can specify that a segment should be loaded at a particular address | |
3656 | in memory by using an @code{AT} expression. This is identical to the | |
3657 | @code{AT} command used as an output section attribute (@pxref{Output | |
3658 | Section LMA}). The @code{AT} command for a program header overrides the | |
3659 | output section attribute. | |
3660 | ||
3661 | The linker will normally set the segment flags based on the sections | |
3662 | which comprise the segment. You may use the @code{FLAGS} keyword to | |
3663 | explicitly specify the segment flags. The value of @var{flags} must be | |
3664 | an integer. It is used to set the @code{p_flags} field of the program | |
3665 | header. | |
3666 | ||
3667 | Here is an example of @code{PHDRS}. This shows a typical set of program | |
3668 | headers used on a native ELF system. | |
3669 | ||
3670 | @example | |
3671 | @group | |
3672 | PHDRS | |
3673 | @{ | |
3674 | headers PT_PHDR PHDRS ; | |
3675 | interp PT_INTERP ; | |
3676 | text PT_LOAD FILEHDR PHDRS ; | |
3677 | data PT_LOAD ; | |
3678 | dynamic PT_DYNAMIC ; | |
3679 | @} | |
3680 | ||
3681 | SECTIONS | |
3682 | @{ | |
3683 | . = SIZEOF_HEADERS; | |
3684 | .interp : @{ *(.interp) @} :text :interp | |
3685 | .text : @{ *(.text) @} :text | |
3686 | .rodata : @{ *(.rodata) @} /* defaults to :text */ | |
3687 | @dots{} | |
3688 | . = . + 0x1000; /* move to a new page in memory */ | |
3689 | .data : @{ *(.data) @} :data | |
3690 | .dynamic : @{ *(.dynamic) @} :data :dynamic | |
3691 | @dots{} | |
3692 | @} | |
3693 | @end group | |
3694 | @end example | |
3695 | ||
3696 | @node VERSION | |
3697 | @section VERSION Command | |
3698 | @kindex VERSION @{script text@} | |
3699 | @cindex symbol versions | |
3700 | @cindex version script | |
3701 | @cindex versions of symbols | |
3702 | The linker supports symbol versions when using ELF. Symbol versions are | |
3703 | only useful when using shared libraries. The dynamic linker can use | |
3704 | symbol versions to select a specific version of a function when it runs | |
3705 | a program that may have been linked against an earlier version of the | |
3706 | shared library. | |
3707 | ||
3708 | You can include a version script directly in the main linker script, or | |
3709 | you can supply the version script as an implicit linker script. You can | |
3710 | also use the @samp{--version-script} linker option. | |
3711 | ||
3712 | The syntax of the @code{VERSION} command is simply | |
3713 | @smallexample | |
3714 | VERSION @{ version-script-commands @} | |
3715 | @end smallexample | |
3716 | ||
3717 | The format of the version script commands is identical to that used by | |
3718 | Sun's linker in Solaris 2.5. The version script defines a tree of | |
3719 | version nodes. You specify the node names and interdependencies in the | |
3720 | version script. You can specify which symbols are bound to which | |
3721 | version nodes, and you can reduce a specified set of symbols to local | |
3722 | scope so that they are not globally visible outside of the shared | |
3723 | library. | |
3724 | ||
3725 | The easiest way to demonstrate the version script language is with a few | |
3726 | examples. | |
3727 | ||
3728 | @smallexample | |
3729 | VERS_1.1 @{ | |
3730 | global: | |
3731 | foo1; | |
3732 | local: | |
a1ab1d2a UD |
3733 | old*; |
3734 | original*; | |
3735 | new*; | |
252b5132 RH |
3736 | @}; |
3737 | ||
3738 | VERS_1.2 @{ | |
3739 | foo2; | |
3740 | @} VERS_1.1; | |
3741 | ||
3742 | VERS_2.0 @{ | |
3743 | bar1; bar2; | |
3744 | @} VERS_1.2; | |
3745 | @end smallexample | |
3746 | ||
3747 | This example version script defines three version nodes. The first | |
3748 | version node defined is @samp{VERS_1.1}; it has no other dependencies. | |
3749 | The script binds the symbol @samp{foo1} to @samp{VERS_1.1}. It reduces | |
3750 | a number of symbols to local scope so that they are not visible outside | |
313e35ee AM |
3751 | of the shared library; this is done using wildcard patterns, so that any |
3752 | symbol whose name begins with @samp{old}, @samp{original}, or @samp{new} | |
3753 | is matched. The wildcard patterns available are the same as those used | |
3754 | in the shell when matching filenames (also known as ``globbing''). | |
252b5132 RH |
3755 | |
3756 | Next, the version script defines node @samp{VERS_1.2}. This node | |
3757 | depends upon @samp{VERS_1.1}. The script binds the symbol @samp{foo2} | |
3758 | to the version node @samp{VERS_1.2}. | |
3759 | ||
3760 | Finally, the version script defines node @samp{VERS_2.0}. This node | |
3761 | depends upon @samp{VERS_1.2}. The scripts binds the symbols @samp{bar1} | |
3762 | and @samp{bar2} are bound to the version node @samp{VERS_2.0}. | |
3763 | ||
3764 | When the linker finds a symbol defined in a library which is not | |
3765 | specifically bound to a version node, it will effectively bind it to an | |
3766 | unspecified base version of the library. You can bind all otherwise | |
a981ed6f | 3767 | unspecified symbols to a given version node by using @samp{global: *;} |
252b5132 RH |
3768 | somewhere in the version script. |
3769 | ||
3770 | The names of the version nodes have no specific meaning other than what | |
3771 | they might suggest to the person reading them. The @samp{2.0} version | |
3772 | could just as well have appeared in between @samp{1.1} and @samp{1.2}. | |
3773 | However, this would be a confusing way to write a version script. | |
3774 | ||
6b9b879a JJ |
3775 | Node name can be omited, provided it is the only version node |
3776 | in the version script. Such version script doesn't assign any versions to | |
3777 | symbols, only selects which symbols will be globally visible out and which | |
3778 | won't. | |
3779 | ||
3780 | @smallexample | |
7c9c73be | 3781 | @{ global: foo; bar; local: *; @}; |
9d201f2f | 3782 | @end smallexample |
6b9b879a | 3783 | |
252b5132 RH |
3784 | When you link an application against a shared library that has versioned |
3785 | symbols, the application itself knows which version of each symbol it | |
3786 | requires, and it also knows which version nodes it needs from each | |
3787 | shared library it is linked against. Thus at runtime, the dynamic | |
3788 | loader can make a quick check to make sure that the libraries you have | |
3789 | linked against do in fact supply all of the version nodes that the | |
3790 | application will need to resolve all of the dynamic symbols. In this | |
3791 | way it is possible for the dynamic linker to know with certainty that | |
3792 | all external symbols that it needs will be resolvable without having to | |
3793 | search for each symbol reference. | |
3794 | ||
3795 | The symbol versioning is in effect a much more sophisticated way of | |
3796 | doing minor version checking that SunOS does. The fundamental problem | |
3797 | that is being addressed here is that typically references to external | |
3798 | functions are bound on an as-needed basis, and are not all bound when | |
3799 | the application starts up. If a shared library is out of date, a | |
3800 | required interface may be missing; when the application tries to use | |
3801 | that interface, it may suddenly and unexpectedly fail. With symbol | |
3802 | versioning, the user will get a warning when they start their program if | |
3803 | the libraries being used with the application are too old. | |
3804 | ||
3805 | There are several GNU extensions to Sun's versioning approach. The | |
3806 | first of these is the ability to bind a symbol to a version node in the | |
3807 | source file where the symbol is defined instead of in the versioning | |
3808 | script. This was done mainly to reduce the burden on the library | |
3809 | maintainer. You can do this by putting something like: | |
3810 | @smallexample | |
3811 | __asm__(".symver original_foo,foo@@VERS_1.1"); | |
3812 | @end smallexample | |
3813 | @noindent | |
3814 | in the C source file. This renames the function @samp{original_foo} to | |
3815 | be an alias for @samp{foo} bound to the version node @samp{VERS_1.1}. | |
3816 | The @samp{local:} directive can be used to prevent the symbol | |
96a94295 L |
3817 | @samp{original_foo} from being exported. A @samp{.symver} directive |
3818 | takes precedence over a version script. | |
252b5132 RH |
3819 | |
3820 | The second GNU extension is to allow multiple versions of the same | |
3821 | function to appear in a given shared library. In this way you can make | |
3822 | an incompatible change to an interface without increasing the major | |
3823 | version number of the shared library, while still allowing applications | |
3824 | linked against the old interface to continue to function. | |
3825 | ||
3826 | To do this, you must use multiple @samp{.symver} directives in the | |
3827 | source file. Here is an example: | |
3828 | ||
3829 | @smallexample | |
3830 | __asm__(".symver original_foo,foo@@"); | |
3831 | __asm__(".symver old_foo,foo@@VERS_1.1"); | |
3832 | __asm__(".symver old_foo1,foo@@VERS_1.2"); | |
3833 | __asm__(".symver new_foo,foo@@@@VERS_2.0"); | |
3834 | @end smallexample | |
3835 | ||
3836 | In this example, @samp{foo@@} represents the symbol @samp{foo} bound to the | |
3837 | unspecified base version of the symbol. The source file that contains this | |
3838 | example would define 4 C functions: @samp{original_foo}, @samp{old_foo}, | |
3839 | @samp{old_foo1}, and @samp{new_foo}. | |
3840 | ||
3841 | When you have multiple definitions of a given symbol, there needs to be | |
3842 | some way to specify a default version to which external references to | |
3843 | this symbol will be bound. You can do this with the | |
3844 | @samp{foo@@@@VERS_2.0} type of @samp{.symver} directive. You can only | |
3845 | declare one version of a symbol as the default in this manner; otherwise | |
3846 | you would effectively have multiple definitions of the same symbol. | |
3847 | ||
3848 | If you wish to bind a reference to a specific version of the symbol | |
3849 | within the shared library, you can use the aliases of convenience | |
3850 | (i.e. @samp{old_foo}), or you can use the @samp{.symver} directive to | |
3851 | specifically bind to an external version of the function in question. | |
3852 | ||
cb840a31 L |
3853 | You can also specify the language in the version script: |
3854 | ||
3855 | @smallexample | |
3856 | VERSION extern "lang" @{ version-script-commands @} | |
3857 | @end smallexample | |
3858 | ||
3859 | The supported @samp{lang}s are @samp{C}, @samp{C++}, and @samp{Java}. | |
3860 | The linker will iterate over the list of symbols at the link time and | |
3861 | demangle them according to @samp{lang} before matching them to the | |
3862 | patterns specified in @samp{version-script-commands}. | |
3863 | ||
252b5132 RH |
3864 | @node Expressions |
3865 | @section Expressions in Linker Scripts | |
3866 | @cindex expressions | |
3867 | @cindex arithmetic | |
3868 | The syntax for expressions in the linker script language is identical to | |
3869 | that of C expressions. All expressions are evaluated as integers. All | |
3870 | expressions are evaluated in the same size, which is 32 bits if both the | |
3871 | host and target are 32 bits, and is otherwise 64 bits. | |
3872 | ||
3873 | You can use and set symbol values in expressions. | |
3874 | ||
3875 | The linker defines several special purpose builtin functions for use in | |
3876 | expressions. | |
3877 | ||
3878 | @menu | |
3879 | * Constants:: Constants | |
3880 | * Symbols:: Symbol Names | |
3881 | * Location Counter:: The Location Counter | |
3882 | * Operators:: Operators | |
3883 | * Evaluation:: Evaluation | |
3884 | * Expression Section:: The Section of an Expression | |
3885 | * Builtin Functions:: Builtin Functions | |
3886 | @end menu | |
3887 | ||
3888 | @node Constants | |
3889 | @subsection Constants | |
3890 | @cindex integer notation | |
3891 | @cindex constants in linker scripts | |
3892 | All constants are integers. | |
3893 | ||
3894 | As in C, the linker considers an integer beginning with @samp{0} to be | |
3895 | octal, and an integer beginning with @samp{0x} or @samp{0X} to be | |
3896 | hexadecimal. The linker considers other integers to be decimal. | |
3897 | ||
3898 | @cindex scaled integers | |
3899 | @cindex K and M integer suffixes | |
3900 | @cindex M and K integer suffixes | |
3901 | @cindex suffixes for integers | |
3902 | @cindex integer suffixes | |
3903 | In addition, you can use the suffixes @code{K} and @code{M} to scale a | |
3904 | constant by | |
3905 | @c TEXI2ROFF-KILL | |
3906 | @ifinfo | |
3907 | @c END TEXI2ROFF-KILL | |
3908 | @code{1024} or @code{1024*1024} | |
3909 | @c TEXI2ROFF-KILL | |
3910 | @end ifinfo | |
3911 | @tex | |
3912 | ${\rm 1024}$ or ${\rm 1024}^2$ | |
3913 | @end tex | |
3914 | @c END TEXI2ROFF-KILL | |
3915 | respectively. For example, the following all refer to the same quantity: | |
3916 | @smallexample | |
3917 | _fourk_1 = 4K; | |
3918 | _fourk_2 = 4096; | |
3919 | _fourk_3 = 0x1000; | |
3920 | @end smallexample | |
3921 | ||
3922 | @node Symbols | |
3923 | @subsection Symbol Names | |
3924 | @cindex symbol names | |
3925 | @cindex names | |
3926 | @cindex quoted symbol names | |
3927 | @kindex " | |
3928 | Unless quoted, symbol names start with a letter, underscore, or period | |
3929 | and may include letters, digits, underscores, periods, and hyphens. | |
3930 | Unquoted symbol names must not conflict with any keywords. You can | |
3931 | specify a symbol which contains odd characters or has the same name as a | |
3932 | keyword by surrounding the symbol name in double quotes: | |
3933 | @smallexample | |
3934 | "SECTION" = 9; | |
3935 | "with a space" = "also with a space" + 10; | |
3936 | @end smallexample | |
3937 | ||
3938 | Since symbols can contain many non-alphabetic characters, it is safest | |
3939 | to delimit symbols with spaces. For example, @samp{A-B} is one symbol, | |
3940 | whereas @samp{A - B} is an expression involving subtraction. | |
3941 | ||
3942 | @node Location Counter | |
3943 | @subsection The Location Counter | |
3944 | @kindex . | |
3945 | @cindex dot | |
3946 | @cindex location counter | |
3947 | @cindex current output location | |
3948 | The special linker variable @dfn{dot} @samp{.} always contains the | |
3949 | current output location counter. Since the @code{.} always refers to a | |
3950 | location in an output section, it may only appear in an expression | |
3951 | within a @code{SECTIONS} command. The @code{.} symbol may appear | |
3952 | anywhere that an ordinary symbol is allowed in an expression. | |
3953 | ||
3954 | @cindex holes | |
3955 | Assigning a value to @code{.} will cause the location counter to be | |
3956 | moved. This may be used to create holes in the output section. The | |
3957 | location counter may never be moved backwards. | |
3958 | ||
3959 | @smallexample | |
3960 | SECTIONS | |
3961 | @{ | |
3962 | output : | |
3963 | @{ | |
3964 | file1(.text) | |
3965 | . = . + 1000; | |
3966 | file2(.text) | |
3967 | . += 1000; | |
3968 | file3(.text) | |
563e308f | 3969 | @} = 0x12345678; |
252b5132 RH |
3970 | @} |
3971 | @end smallexample | |
3972 | @noindent | |
3973 | In the previous example, the @samp{.text} section from @file{file1} is | |
3974 | located at the beginning of the output section @samp{output}. It is | |
3975 | followed by a 1000 byte gap. Then the @samp{.text} section from | |
3976 | @file{file2} appears, also with a 1000 byte gap following before the | |
563e308f | 3977 | @samp{.text} section from @file{file3}. The notation @samp{= 0x12345678} |
252b5132 RH |
3978 | specifies what data to write in the gaps (@pxref{Output Section Fill}). |
3979 | ||
5c6bbab8 NC |
3980 | @cindex dot inside sections |
3981 | Note: @code{.} actually refers to the byte offset from the start of the | |
3982 | current containing object. Normally this is the @code{SECTIONS} | |
69da35b5 | 3983 | statement, whose start address is 0, hence @code{.} can be used as an |
5c6bbab8 NC |
3984 | absolute address. If @code{.} is used inside a section description |
3985 | however, it refers to the byte offset from the start of that section, | |
3986 | not an absolute address. Thus in a script like this: | |
3987 | ||
3988 | @smallexample | |
3989 | SECTIONS | |
3990 | @{ | |
3991 | . = 0x100 | |
3992 | .text: @{ | |
3993 | *(.text) | |
3994 | . = 0x200 | |
3995 | @} | |
3996 | . = 0x500 | |
3997 | .data: @{ | |
3998 | *(.data) | |
3999 | . += 0x600 | |
4000 | @} | |
4001 | @} | |
4002 | @end smallexample | |
4003 | ||
4004 | The @samp{.text} section will be assigned a starting address of 0x100 | |
4005 | and a size of exactly 0x200 bytes, even if there is not enough data in | |
4006 | the @samp{.text} input sections to fill this area. (If there is too | |
4007 | much data, an error will be produced because this would be an attempt to | |
4008 | move @code{.} backwards). The @samp{.data} section will start at 0x500 | |
4009 | and it will have an extra 0x600 bytes worth of space after the end of | |
4010 | the values from the @samp{.data} input sections and before the end of | |
4011 | the @samp{.data} output section itself. | |
4012 | ||
252b5132 RH |
4013 | @need 2000 |
4014 | @node Operators | |
4015 | @subsection Operators | |
4016 | @cindex operators for arithmetic | |
4017 | @cindex arithmetic operators | |
4018 | @cindex precedence in expressions | |
4019 | The linker recognizes the standard C set of arithmetic operators, with | |
4020 | the standard bindings and precedence levels: | |
4021 | @c TEXI2ROFF-KILL | |
4022 | @ifinfo | |
4023 | @c END TEXI2ROFF-KILL | |
4024 | @smallexample | |
4025 | precedence associativity Operators Notes | |
4026 | (highest) | |
4027 | 1 left ! - ~ (1) | |
4028 | 2 left * / % | |
4029 | 3 left + - | |
4030 | 4 left >> << | |
4031 | 5 left == != > < <= >= | |
4032 | 6 left & | |
4033 | 7 left | | |
4034 | 8 left && | |
4035 | 9 left || | |
4036 | 10 right ? : | |
4037 | 11 right &= += -= *= /= (2) | |
4038 | (lowest) | |
4039 | @end smallexample | |
4040 | Notes: | |
a1ab1d2a | 4041 | (1) Prefix operators |
252b5132 RH |
4042 | (2) @xref{Assignments}. |
4043 | @c TEXI2ROFF-KILL | |
4044 | @end ifinfo | |
4045 | @tex | |
4046 | \vskip \baselineskip | |
4047 | %"lispnarrowing" is the extra indent used generally for smallexample | |
4048 | \hskip\lispnarrowing\vbox{\offinterlineskip | |
4049 | \hrule | |
4050 | \halign | |
4051 | {\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr | |
4052 | height2pt&\omit&&\omit&&\omit&\cr | |
4053 | &Precedence&& Associativity &&{\rm Operators}&\cr | |
4054 | height2pt&\omit&&\omit&&\omit&\cr | |
4055 | \noalign{\hrule} | |
4056 | height2pt&\omit&&\omit&&\omit&\cr | |
4057 | &highest&&&&&\cr | |
4058 | % '176 is tilde, '~' in tt font | |
a1ab1d2a | 4059 | &1&&left&&\qquad- \char'176\ !\qquad\dag&\cr |
252b5132 RH |
4060 | &2&&left&&* / \%&\cr |
4061 | &3&&left&&+ -&\cr | |
4062 | &4&&left&&>> <<&\cr | |
4063 | &5&&left&&== != > < <= >=&\cr | |
4064 | &6&&left&&\&&\cr | |
4065 | &7&&left&&|&\cr | |
4066 | &8&&left&&{\&\&}&\cr | |
4067 | &9&&left&&||&\cr | |
4068 | &10&&right&&? :&\cr | |
4069 | &11&&right&&\qquad\&= += -= *= /=\qquad\ddag&\cr | |
4070 | &lowest&&&&&\cr | |
4071 | height2pt&\omit&&\omit&&\omit&\cr} | |
4072 | \hrule} | |
4073 | @end tex | |
4074 | @iftex | |
4075 | { | |
4076 | @obeylines@parskip=0pt@parindent=0pt | |
4077 | @dag@quad Prefix operators. | |
4078 | @ddag@quad @xref{Assignments}. | |
4079 | } | |
4080 | @end iftex | |
4081 | @c END TEXI2ROFF-KILL | |
4082 | ||
4083 | @node Evaluation | |
4084 | @subsection Evaluation | |
4085 | @cindex lazy evaluation | |
4086 | @cindex expression evaluation order | |
4087 | The linker evaluates expressions lazily. It only computes the value of | |
4088 | an expression when absolutely necessary. | |
4089 | ||
4090 | The linker needs some information, such as the value of the start | |
4091 | address of the first section, and the origins and lengths of memory | |
4092 | regions, in order to do any linking at all. These values are computed | |
4093 | as soon as possible when the linker reads in the linker script. | |
4094 | ||
4095 | However, other values (such as symbol values) are not known or needed | |
4096 | until after storage allocation. Such values are evaluated later, when | |
4097 | other information (such as the sizes of output sections) is available | |
4098 | for use in the symbol assignment expression. | |
4099 | ||
4100 | The sizes of sections cannot be known until after allocation, so | |
4101 | assignments dependent upon these are not performed until after | |
4102 | allocation. | |
4103 | ||
4104 | Some expressions, such as those depending upon the location counter | |
4105 | @samp{.}, must be evaluated during section allocation. | |
4106 | ||
4107 | If the result of an expression is required, but the value is not | |
4108 | available, then an error results. For example, a script like the | |
4109 | following | |
4110 | @smallexample | |
4111 | @group | |
4112 | SECTIONS | |
4113 | @{ | |
a1ab1d2a | 4114 | .text 9+this_isnt_constant : |
252b5132 RH |
4115 | @{ *(.text) @} |
4116 | @} | |
4117 | @end group | |
4118 | @end smallexample | |
4119 | @noindent | |
4120 | will cause the error message @samp{non constant expression for initial | |
4121 | address}. | |
4122 | ||
4123 | @node Expression Section | |
4124 | @subsection The Section of an Expression | |
4125 | @cindex expression sections | |
4126 | @cindex absolute expressions | |
4127 | @cindex relative expressions | |
4128 | @cindex absolute and relocatable symbols | |
4129 | @cindex relocatable and absolute symbols | |
4130 | @cindex symbols, relocatable and absolute | |
4131 | When the linker evaluates an expression, the result is either absolute | |
4132 | or relative to some section. A relative expression is expressed as a | |
4133 | fixed offset from the base of a section. | |
4134 | ||
4135 | The position of the expression within the linker script determines | |
4136 | whether it is absolute or relative. An expression which appears within | |
4137 | an output section definition is relative to the base of the output | |
4138 | section. An expression which appears elsewhere will be absolute. | |
4139 | ||
4140 | A symbol set to a relative expression will be relocatable if you request | |
4141 | relocatable output using the @samp{-r} option. That means that a | |
4142 | further link operation may change the value of the symbol. The symbol's | |
4143 | section will be the section of the relative expression. | |
4144 | ||
4145 | A symbol set to an absolute expression will retain the same value | |
4146 | through any further link operation. The symbol will be absolute, and | |
4147 | will not have any particular associated section. | |
4148 | ||
4149 | You can use the builtin function @code{ABSOLUTE} to force an expression | |
4150 | to be absolute when it would otherwise be relative. For example, to | |
4151 | create an absolute symbol set to the address of the end of the output | |
4152 | section @samp{.data}: | |
4153 | @smallexample | |
4154 | SECTIONS | |
4155 | @{ | |
4156 | .data : @{ *(.data) _edata = ABSOLUTE(.); @} | |
4157 | @} | |
4158 | @end smallexample | |
4159 | @noindent | |
4160 | If @samp{ABSOLUTE} were not used, @samp{_edata} would be relative to the | |
4161 | @samp{.data} section. | |
4162 | ||
4163 | @node Builtin Functions | |
4164 | @subsection Builtin Functions | |
4165 | @cindex functions in expressions | |
4166 | The linker script language includes a number of builtin functions for | |
4167 | use in linker script expressions. | |
4168 | ||
4169 | @table @code | |
4170 | @item ABSOLUTE(@var{exp}) | |
4171 | @kindex ABSOLUTE(@var{exp}) | |
4172 | @cindex expression, absolute | |
4173 | Return the absolute (non-relocatable, as opposed to non-negative) value | |
4174 | of the expression @var{exp}. Primarily useful to assign an absolute | |
4175 | value to a symbol within a section definition, where symbol values are | |
4176 | normally section relative. @xref{Expression Section}. | |
4177 | ||
4178 | @item ADDR(@var{section}) | |
4179 | @kindex ADDR(@var{section}) | |
4180 | @cindex section address in expression | |
4181 | Return the absolute address (the VMA) of the named @var{section}. Your | |
4182 | script must previously have defined the location of that section. In | |
4183 | the following example, @code{symbol_1} and @code{symbol_2} are assigned | |
4184 | identical values: | |
4185 | @smallexample | |
4186 | @group | |
4187 | SECTIONS @{ @dots{} | |
4188 | .output1 : | |
a1ab1d2a | 4189 | @{ |
252b5132 RH |
4190 | start_of_output_1 = ABSOLUTE(.); |
4191 | @dots{} | |
4192 | @} | |
4193 | .output : | |
4194 | @{ | |
4195 | symbol_1 = ADDR(.output1); | |
4196 | symbol_2 = start_of_output_1; | |
4197 | @} | |
4198 | @dots{} @} | |
4199 | @end group | |
4200 | @end smallexample | |
4201 | ||
4202 | @item ALIGN(@var{exp}) | |
4203 | @kindex ALIGN(@var{exp}) | |
4204 | @cindex round up location counter | |
4205 | @cindex align location counter | |
4206 | Return the location counter (@code{.}) aligned to the next @var{exp} | |
3c6706bb | 4207 | boundary. |
252b5132 RH |
4208 | @code{ALIGN} doesn't change the value of the location counter---it just |
4209 | does arithmetic on it. Here is an example which aligns the output | |
4210 | @code{.data} section to the next @code{0x2000} byte boundary after the | |
4211 | preceding section and sets a variable within the section to the next | |
4212 | @code{0x8000} boundary after the input sections: | |
4213 | @smallexample | |
4214 | @group | |
4215 | SECTIONS @{ @dots{} | |
4216 | .data ALIGN(0x2000): @{ | |
4217 | *(.data) | |
4218 | variable = ALIGN(0x8000); | |
4219 | @} | |
4220 | @dots{} @} | |
4221 | @end group | |
4222 | @end smallexample | |
4223 | @noindent | |
4224 | The first use of @code{ALIGN} in this example specifies the location of | |
4225 | a section because it is used as the optional @var{address} attribute of | |
4226 | a section definition (@pxref{Output Section Address}). The second use | |
4227 | of @code{ALIGN} is used to defines the value of a symbol. | |
4228 | ||
4229 | The builtin function @code{NEXT} is closely related to @code{ALIGN}. | |
4230 | ||
4231 | @item BLOCK(@var{exp}) | |
4232 | @kindex BLOCK(@var{exp}) | |
4233 | This is a synonym for @code{ALIGN}, for compatibility with older linker | |
4234 | scripts. It is most often seen when setting the address of an output | |
4235 | section. | |
4236 | ||
2d20f7bf JJ |
4237 | @item DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize}) |
4238 | @kindex DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize}) | |
4239 | This is equivalent to either | |
4240 | @smallexample | |
4241 | (ALIGN(@var{maxpagesize}) + (. & (@var{maxpagesize} - 1))) | |
4242 | @end smallexample | |
4243 | or | |
4244 | @smallexample | |
4245 | (ALIGN(@var{maxpagesize}) + (. & (@var{maxpagesize} - @var{commonpagesize}))) | |
4246 | @end smallexample | |
4247 | @noindent | |
4248 | depending on whether the latter uses fewer @var{commonpagesize} sized pages | |
4249 | for the data segment (area between the result of this expression and | |
4250 | @code{DATA_SEGMENT_END}) than the former or not. | |
4251 | If the latter form is used, it means @var{commonpagesize} bytes of runtime | |
4252 | memory will be saved at the expense of up to @var{commonpagesize} wasted | |
4253 | bytes in the on-disk file. | |
4254 | ||
4255 | This expression can only be used directly in @code{SECTIONS} commands, not in | |
4256 | any output section descriptions and only once in the linker script. | |
4257 | @var{commonpagesize} should be less or equal to @var{maxpagesize} and should | |
4258 | be the system page size the object wants to be optimized for (while still | |
4259 | working on system page sizes up to @var{maxpagesize}). | |
4260 | ||
4261 | @noindent | |
4262 | Example: | |
4263 | @smallexample | |
4264 | . = DATA_SEGMENT_ALIGN(0x10000, 0x2000); | |
4265 | @end smallexample | |
4266 | ||
4267 | @item DATA_SEGMENT_END(@var{exp}) | |
4268 | @kindex DATA_SEGMENT_END(@var{exp}) | |
4269 | This defines the end of data segment for @code{DATA_SEGMENT_ALIGN} | |
4270 | evaluation purposes. | |
4271 | ||
4272 | @smallexample | |
4273 | . = DATA_SEGMENT_END(.); | |
4274 | @end smallexample | |
4275 | ||
252b5132 RH |
4276 | @item DEFINED(@var{symbol}) |
4277 | @kindex DEFINED(@var{symbol}) | |
4278 | @cindex symbol defaults | |
4279 | Return 1 if @var{symbol} is in the linker global symbol table and is | |
4280 | defined, otherwise return 0. You can use this function to provide | |
4281 | default values for symbols. For example, the following script fragment | |
4282 | shows how to set a global symbol @samp{begin} to the first location in | |
4283 | the @samp{.text} section---but if a symbol called @samp{begin} already | |
4284 | existed, its value is preserved: | |
4285 | ||
4286 | @smallexample | |
4287 | @group | |
4288 | SECTIONS @{ @dots{} | |
4289 | .text : @{ | |
4290 | begin = DEFINED(begin) ? begin : . ; | |
4291 | @dots{} | |
4292 | @} | |
4293 | @dots{} | |
4294 | @} | |
4295 | @end group | |
4296 | @end smallexample | |
4297 | ||
4298 | @item LOADADDR(@var{section}) | |
4299 | @kindex LOADADDR(@var{section}) | |
4300 | @cindex section load address in expression | |
4301 | Return the absolute LMA of the named @var{section}. This is normally | |
4302 | the same as @code{ADDR}, but it may be different if the @code{AT} | |
4303 | attribute is used in the output section definition (@pxref{Output | |
4304 | Section LMA}). | |
4305 | ||
4306 | @kindex MAX | |
4307 | @item MAX(@var{exp1}, @var{exp2}) | |
4308 | Returns the maximum of @var{exp1} and @var{exp2}. | |
4309 | ||
4310 | @kindex MIN | |
4311 | @item MIN(@var{exp1}, @var{exp2}) | |
4312 | Returns the minimum of @var{exp1} and @var{exp2}. | |
4313 | ||
4314 | @item NEXT(@var{exp}) | |
4315 | @kindex NEXT(@var{exp}) | |
4316 | @cindex unallocated address, next | |
4317 | Return the next unallocated address that is a multiple of @var{exp}. | |
4318 | This function is closely related to @code{ALIGN(@var{exp})}; unless you | |
4319 | use the @code{MEMORY} command to define discontinuous memory for the | |
4320 | output file, the two functions are equivalent. | |
4321 | ||
4322 | @item SIZEOF(@var{section}) | |
4323 | @kindex SIZEOF(@var{section}) | |
4324 | @cindex section size | |
4325 | Return the size in bytes of the named @var{section}, if that section has | |
4326 | been allocated. If the section has not been allocated when this is | |
4327 | evaluated, the linker will report an error. In the following example, | |
4328 | @code{symbol_1} and @code{symbol_2} are assigned identical values: | |
4329 | @smallexample | |
4330 | @group | |
4331 | SECTIONS@{ @dots{} | |
4332 | .output @{ | |
4333 | .start = . ; | |
4334 | @dots{} | |
4335 | .end = . ; | |
4336 | @} | |
4337 | symbol_1 = .end - .start ; | |
4338 | symbol_2 = SIZEOF(.output); | |
4339 | @dots{} @} | |
4340 | @end group | |
4341 | @end smallexample | |
4342 | ||
4343 | @item SIZEOF_HEADERS | |
4344 | @itemx sizeof_headers | |
4345 | @kindex SIZEOF_HEADERS | |
4346 | @cindex header size | |
4347 | Return the size in bytes of the output file's headers. This is | |
4348 | information which appears at the start of the output file. You can use | |
4349 | this number when setting the start address of the first section, if you | |
4350 | choose, to facilitate paging. | |
4351 | ||
4352 | @cindex not enough room for program headers | |
4353 | @cindex program headers, not enough room | |
4354 | When producing an ELF output file, if the linker script uses the | |
4355 | @code{SIZEOF_HEADERS} builtin function, the linker must compute the | |
4356 | number of program headers before it has determined all the section | |
4357 | addresses and sizes. If the linker later discovers that it needs | |
4358 | additional program headers, it will report an error @samp{not enough | |
4359 | room for program headers}. To avoid this error, you must avoid using | |
4360 | the @code{SIZEOF_HEADERS} function, or you must rework your linker | |
4361 | script to avoid forcing the linker to use additional program headers, or | |
4362 | you must define the program headers yourself using the @code{PHDRS} | |
4363 | command (@pxref{PHDRS}). | |
4364 | @end table | |
4365 | ||
4366 | @node Implicit Linker Scripts | |
4367 | @section Implicit Linker Scripts | |
4368 | @cindex implicit linker scripts | |
4369 | If you specify a linker input file which the linker can not recognize as | |
4370 | an object file or an archive file, it will try to read the file as a | |
4371 | linker script. If the file can not be parsed as a linker script, the | |
4372 | linker will report an error. | |
4373 | ||
4374 | An implicit linker script will not replace the default linker script. | |
4375 | ||
4376 | Typically an implicit linker script would contain only symbol | |
4377 | assignments, or the @code{INPUT}, @code{GROUP}, or @code{VERSION} | |
4378 | commands. | |
4379 | ||
4380 | Any input files read because of an implicit linker script will be read | |
4381 | at the position in the command line where the implicit linker script was | |
4382 | read. This can affect archive searching. | |
4383 | ||
4384 | @ifset GENERIC | |
4385 | @node Machine Dependent | |
4386 | @chapter Machine Dependent Features | |
4387 | ||
4388 | @cindex machine dependencies | |
ff5dcc92 SC |
4389 | @command{ld} has additional features on some platforms; the following |
4390 | sections describe them. Machines where @command{ld} has no additional | |
252b5132 RH |
4391 | functionality are not listed. |
4392 | ||
4393 | @menu | |
4394 | * H8/300:: @code{ld} and the H8/300 | |
4395 | * i960:: @code{ld} and the Intel 960 family | |
4396 | * ARM:: @code{ld} and the ARM family | |
47d89dba | 4397 | * HPPA ELF32:: @code{ld} and HPPA 32-bit ELF |
3c3bdf30 NC |
4398 | @ifset MMIX |
4399 | * MMIX:: @code{ld} and MMIX | |
4400 | @end ifset | |
2469cfa2 NC |
4401 | @ifset MSP430 |
4402 | * MSP430:: @code{ld} and MSP430 | |
4403 | @end ifset | |
74459f0e | 4404 | @ifset TICOFF |
ff5dcc92 | 4405 | * TI COFF:: @command{ld} and TI COFF |
74459f0e | 4406 | @end ifset |
2ca22b03 NC |
4407 | @ifset WIN32 |
4408 | * WIN32:: @command{ld} and WIN32 (cygwin/mingw) | |
4409 | @end ifset | |
252b5132 RH |
4410 | @end menu |
4411 | @end ifset | |
4412 | ||
4413 | @c FIXME! This could use @raisesections/@lowersections, but there seems to be a conflict | |
4414 | @c between those and node-defaulting. | |
4415 | @ifset H8300 | |
4416 | @ifclear GENERIC | |
4417 | @raisesections | |
4418 | @end ifclear | |
4419 | ||
4420 | @node H8/300 | |
ff5dcc92 | 4421 | @section @command{ld} and the H8/300 |
252b5132 RH |
4422 | |
4423 | @cindex H8/300 support | |
ff5dcc92 | 4424 | For the H8/300, @command{ld} can perform these global optimizations when |
252b5132 RH |
4425 | you specify the @samp{--relax} command-line option. |
4426 | ||
4427 | @table @emph | |
4428 | @cindex relaxing on H8/300 | |
4429 | @item relaxing address modes | |
ff5dcc92 | 4430 | @command{ld} finds all @code{jsr} and @code{jmp} instructions whose |
252b5132 RH |
4431 | targets are within eight bits, and turns them into eight-bit |
4432 | program-counter relative @code{bsr} and @code{bra} instructions, | |
4433 | respectively. | |
4434 | ||
4435 | @cindex synthesizing on H8/300 | |
4436 | @item synthesizing instructions | |
4437 | @c FIXME: specifically mov.b, or any mov instructions really? | |
ff5dcc92 | 4438 | @command{ld} finds all @code{mov.b} instructions which use the |
252b5132 RH |
4439 | sixteen-bit absolute address form, but refer to the top |
4440 | page of memory, and changes them to use the eight-bit address form. | |
4441 | (That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into | |
4442 | @samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the | |
4443 | top page of memory). | |
4444 | @end table | |
4445 | ||
4446 | @ifclear GENERIC | |
4447 | @lowersections | |
4448 | @end ifclear | |
4449 | @end ifset | |
4450 | ||
2ca22b03 NC |
4451 | @ifset WIN32 |
4452 | @ifclear GENERIC | |
4453 | @raisesections | |
4454 | @end ifclear | |
4455 | ||
4456 | @node WIN32 | |
4457 | @section @command{ld} and WIN32 (cygwin/mingw) | |
4458 | ||
4459 | This section describes some of the win32 specific @command{ld} issues. | |
dc8465bf NC |
4460 | See @ref{Options,,Command Line Options} for detailed decription of the |
4461 | command line options mentioned here. | |
2ca22b03 NC |
4462 | |
4463 | @table @emph | |
4464 | @cindex import libraries | |
4465 | @item import libraries | |
69da35b5 | 4466 | The standard Windows linker creates and uses so-called import |
2ca22b03 | 4467 | libraries, which contains information for linking to dll's. They are |
69da35b5 NC |
4468 | regular static archives and are handled as any other static |
4469 | archive. The cygwin and mingw ports of @command{ld} have specific | |
2ca22b03 NC |
4470 | support for creating such libraries provided with the |
4471 | @samp{--out-implib} command line option. | |
4472 | ||
dc8465bf NC |
4473 | @item exporting DLL symbols |
4474 | @cindex exporting DLL symbols | |
4475 | The cygwin/mingw @command{ld} has several ways to export symbols for dll's. | |
4476 | ||
4477 | @table @emph | |
4478 | @item using auto-export functionality | |
4479 | @cindex using auto-export functionality | |
4480 | By default @command{ld} exports symbols with the auto-export functionality, | |
4481 | which is controlled by the following command line options: | |
4482 | ||
0a5d968e NC |
4483 | @itemize |
4484 | @item --export-all-symbols [This is the default] | |
4485 | @item --exclude-symbols | |
4486 | @item --exclude-libs | |
4487 | @end itemize | |
4488 | ||
4489 | If, however, @samp{--export-all-symbols} is not given explicitly on the | |
4490 | command line, then the default auto-export behavior will be @emph{disabled} | |
4491 | if either of the following are true: | |
4492 | ||
4493 | @itemize | |
4494 | @item A DEF file is used. | |
4495 | @item Any symbol in any object file was marked with the __declspec(dllexport) attribute. | |
4496 | @end itemize | |
dc8465bf NC |
4497 | |
4498 | @item using a DEF file | |
4499 | @cindex using a DEF file | |
4500 | Another way of exporting symbols is using a DEF file. A DEF file is | |
4501 | an ASCII file containing definitions of symbols which should be | |
4502 | exported when a dll is created. Usually it is named @samp{<dll | |
4503 | name>.def} and is added as any other object file to the linker's | |
0a5d968e | 4504 | command line. The file's name must end in @samp{.def} or @samp{.DEF}. |
dc8465bf NC |
4505 | |
4506 | @example | |
4507 | gcc -o <output> <objectfiles> <dll name>.def | |
4508 | @end example | |
4509 | ||
0a5d968e NC |
4510 | Using a DEF file turns off the normal auto-export behavior, unless the |
4511 | @samp{--export-all-symbols} option is also used. | |
4512 | ||
dc8465bf NC |
4513 | Here is an example of a DEF file for a shared library called @samp{xyz.dll}: |
4514 | ||
4515 | @example | |
4516 | LIBRARY "xyz.dll" BASE=0x10000000 | |
4517 | ||
4518 | EXPORTS | |
4519 | foo | |
4520 | bar | |
4521 | _bar = bar | |
4522 | @end example | |
4523 | ||
4524 | This example defines a base address and three symbols. The third | |
4525 | symbol is an alias for the second. For the complete format | |
4526 | specification see ld/deffilep.y in the binutils sources. | |
4527 | ||
4528 | @cindex creating a DEF file | |
4529 | While linking a shared dll, @command{ld} is able to create a DEF file | |
4530 | with the @samp{--output-def <file>} command line option. | |
0a5d968e NC |
4531 | |
4532 | @item Using decorations | |
4533 | @cindex Using decorations | |
4534 | Another way of marking symbols for export is to modify the source code | |
4535 | itself, so that when building the DLL each symbol to be exported is | |
4536 | declared as: | |
4537 | ||
4538 | @example | |
4539 | __declspec(dllexport) int a_variable | |
4540 | __declspec(dllexport) void a_function(int with_args) | |
4541 | @end example | |
4542 | ||
4543 | All such symbols will be exported from the DLL. If, however, | |
4544 | any of the object files in the DLL contain symbols decorated in | |
4545 | this way, then the normal auto-export behavior is disabled, unless | |
4546 | the @samp{--export-all-symbols} option is also used. | |
4547 | ||
4548 | Note that object files that wish to access these symbols must @emph{not} | |
4549 | decorate them with dllexport. Instead, they should use dllimport, | |
4550 | instead: | |
4551 | ||
4552 | @example | |
4553 | __declspec(dllimport) int a_variable | |
4554 | __declspec(dllimport) void a_function(int with_args) | |
4555 | @end example | |
4556 | ||
4557 | This complicates the structure of library header files, because | |
4558 | when included by the library itself the header must declare the | |
4559 | variables and functions as dllexport, but when included by client | |
4560 | code the header must declare them as dllimport. There are a number | |
4561 | of idioms that are typically used to do this; often client code can | |
4562 | omit the __declspec() declaration completely. See | |
4563 | @samp{--enable-auto-import} and @samp{automatic data imports} for more | |
4564 | imformation. | |
dc8465bf NC |
4565 | @end table |
4566 | ||
2ca22b03 NC |
4567 | @cindex automatic data imports |
4568 | @item automatic data imports | |
4569 | The standard Windows dll format supports data imports from dlls only | |
69da35b5 | 4570 | by adding special decorations (dllimport/dllexport), which let the |
2ca22b03 | 4571 | compiler produce specific assembler instructions to deal with this |
69da35b5 NC |
4572 | issue. This increases the effort necessary to port existing Un*x |
4573 | code to these platforms, especially for large | |
2ca22b03 | 4574 | c++ libraries and applications. The auto-import feature, which was |
69da35b5 NC |
4575 | initially provided by Paul Sokolovsky, allows one to omit the |
4576 | decorations to archieve a behavior that conforms to that on POSIX/Un*x | |
4577 | platforms. This feature is enabled with the @samp{--enable-auto-import} | |
4578 | command-line option, although it is enabled by default on cygwin/mingw. | |
4579 | The @samp{--enable-auto-import} option itself now serves mainly to | |
4580 | suppress any warnings that are ordinarily emitted when linked objects | |
4581 | trigger the feature's use. | |
4582 | ||
4583 | auto-import of variables does not always work flawlessly without | |
4584 | additional assistance. Sometimes, you will see this message | |
4585 | ||
4586 | "variable '<var>' can't be auto-imported. Please read the | |
4587 | documentation for ld's @code{--enable-auto-import} for details." | |
4588 | ||
4589 | The @samp{--enable-auto-import} documentation explains why this error | |
4590 | occurs, and several methods that can be used to overcome this difficulty. | |
4591 | One of these methods is the @emph{runtime pseudo-relocs} feature, described | |
4592 | below. | |
4593 | ||
4594 | @cindex runtime pseudo-relocation | |
4595 | For complex variables imported from DLLs (such as structs or classes), | |
4596 | object files typically contain a base address for the variable and an | |
4597 | offset (@emph{addend}) within the variable--to specify a particular | |
4598 | field or public member, for instance. Unfortunately, the runtime loader used | |
4599 | in win32 environments is incapable of fixing these references at runtime | |
4600 | without the additional information supplied by dllimport/dllexport decorations. | |
4601 | The standard auto-import feature described above is unable to resolve these | |
4602 | references. | |
4603 | ||
4604 | The @samp{--enable-runtime-pseudo-relocs} switch allows these references to | |
4605 | be resolved without error, while leaving the task of adjusting the references | |
4606 | themselves (with their non-zero addends) to specialized code provided by the | |
4607 | runtime environment. Recent versions of the cygwin and mingw environments and | |
4608 | compilers provide this runtime support; older versions do not. However, the | |
4609 | support is only necessary on the developer's platform; the compiled result will | |
4610 | run without error on an older system. | |
4611 | ||
4612 | @samp{--enable-runtime-pseudo-relocs} is not the default; it must be explicitly | |
4613 | enabled as needed. | |
2ca22b03 NC |
4614 | |
4615 | @cindex direct linking to a dll | |
4616 | @item direct linking to a dll | |
4617 | The cygwin/mingw ports of @command{ld} support the direct linking, | |
4618 | including data symbols, to a dll without the usage of any import | |
69da35b5 NC |
4619 | libraries. This is much faster and uses much less memory than does the |
4620 | traditional import library method, expecially when linking large | |
4621 | libraries or applications. When @command{ld} creates an import lib, each | |
4622 | function or variable exported from the dll is stored in its own bfd, even | |
4623 | though a single bfd could contain many exports. The overhead involved in | |
4624 | storing, loading, and processing so many bfd's is quite large, and explains the | |
4625 | tremendous time, memory, and storage needed to link against particularly | |
4626 | large or complex libraries when using import libs. | |
4627 | ||
4628 | Linking directly to a dll uses no extra command-line switches other than | |
4629 | @samp{-L} and @samp{-l}, because @command{ld} already searches for a number | |
4630 | of names to match each library. All that is needed from the developer's | |
4631 | perspective is an understanding of this search, in order to force ld to | |
4632 | select the dll instead of an import library. | |
4633 | ||
2ca22b03 | 4634 | |
69da35b5 NC |
4635 | For instance, when ld is called with the argument @samp{-lxxx} it will attempt |
4636 | to find, in the first directory of its search path, | |
2ca22b03 NC |
4637 | |
4638 | @example | |
4639 | libxxx.dll.a | |
4640 | xxx.dll.a | |
4641 | libxxx.a | |
69da35b5 | 4642 | cygxxx.dll (*) |
2ca22b03 NC |
4643 | libxxx.dll |
4644 | xxx.dll | |
4645 | @end example | |
4646 | ||
69da35b5 NC |
4647 | before moving on to the next directory in the search path. |
4648 | ||
4649 | (*) Actually, this is not @samp{cygxxx.dll} but in fact is @samp{<prefix>xxx.dll}, | |
4650 | where @samp{<prefix>} is set by the @command{ld} option | |
4651 | @samp{--dll-search-prefix=<prefix>}. In the case of cygwin, the standard gcc spec | |
4652 | file includes @samp{--dll-search-prefix=cyg}, so in effect we actually search for | |
4653 | @samp{cygxxx.dll}. | |
4654 | ||
4655 | Other win32-based unix environments, such as mingw or pw32, may use other | |
4656 | @samp{<prefix>}es, although at present only cygwin makes use of this feature. It | |
4657 | was originally intended to help avoid name conflicts among dll's built for the | |
4658 | various win32/un*x environments, so that (for example) two versions of a zlib dll | |
4659 | could coexist on the same machine. | |
4660 | ||
2ca22b03 NC |
4661 | The generic cygwin/mingw path layout uses a @samp{bin} directory for |
4662 | applications and dll's and a @samp{lib} directory for the import | |
69da35b5 | 4663 | libraries (using cygwin nomenclature): |
2ca22b03 NC |
4664 | |
4665 | @example | |
4666 | bin/ | |
4667 | cygxxx.dll | |
4668 | lib/ | |
4669 | libxxx.dll.a (in case of dll's) | |
4670 | libxxx.a (in case of static archive) | |
4671 | @end example | |
4672 | ||
69da35b5 NC |
4673 | Linking directly to a dll without using the import library can be |
4674 | done two ways: | |
2ca22b03 NC |
4675 | |
4676 | 1. Use the dll directly by adding the @samp{bin} path to the link line | |
4677 | @example | |
4678 | gcc -Wl,-verbose -o a.exe -L../bin/ -lxxx | |
4679 | @end example | |
4680 | ||
69da35b5 NC |
4681 | However, as the dll's often have version numbers appended to their names |
4682 | (@samp{cygncurses-5.dll}) this will often fail, unless one specifies | |
4683 | @samp{-L../bin -lncurses-5} to include the version. Import libs are generally | |
4684 | not versioned, and do not have this difficulty. | |
4685 | ||
2ca22b03 NC |
4686 | 2. Create a symbolic link from the dll to a file in the @samp{lib} |
4687 | directory according to the above mentioned search pattern. This | |
4688 | should be used to avoid unwanted changes in the tools needed for | |
4689 | making the app/dll. | |
4690 | ||
4691 | @example | |
4692 | ln -s bin/cygxxx.dll lib/[cyg|lib|]xxx.dll[.a] | |
4693 | @end example | |
4694 | ||
4695 | Then you can link without any make environment changes. | |
4696 | ||
4697 | @example | |
4698 | gcc -Wl,-verbose -o a.exe -L../lib/ -lxxx | |
4699 | @end example | |
69da35b5 NC |
4700 | |
4701 | This technique also avoids the version number problems, because the following is | |
4702 | perfectly legal | |
4703 | ||
4704 | @example | |
4705 | bin/ | |
4706 | cygxxx-5.dll | |
4707 | lib/ | |
4708 | libxxx.dll.a -> ../bin/cygxxx-5.dll | |
4709 | @end example | |
4710 | ||
dc8465bf | 4711 | Linking directly to a dll without using an import lib will work |
69da35b5 NC |
4712 | even when auto-import features are exercised, and even when |
4713 | @samp{--enable-runtime-pseudo-relocs} is used. | |
4714 | ||
4715 | Given the improvements in speed and memory usage, one might justifiably | |
dc8465bf | 4716 | wonder why import libraries are used at all. There are two reasons: |
69da35b5 NC |
4717 | |
4718 | 1. Until recently, the link-directly-to-dll functionality did @emph{not} | |
4719 | work with auto-imported data. | |
4720 | ||
dc8465bf NC |
4721 | 2. Sometimes it is necessary to include pure static objects within the |
4722 | import library (which otherwise contains only bfd's for indirection | |
4723 | symbols that point to the exports of a dll). Again, the import lib | |
4724 | for the cygwin kernel makes use of this ability, and it is not | |
4725 | possible to do this without an import lib. | |
69da35b5 NC |
4726 | |
4727 | So, import libs are not going away. But the ability to replace | |
4728 | true import libs with a simple symbolic link to (or a copy of) | |
4729 | a dll, in most cases, is a useful addition to the suite of tools | |
4730 | binutils makes available to the win32 developer. Given the | |
4731 | massive improvements in memory requirements during linking, storage | |
4732 | requirements, and linking speed, we expect that many developers | |
4733 | will soon begin to use this feature whenever possible. | |
dc8465bf NC |
4734 | |
4735 | @item symbol aliasing | |
4736 | @table @emph | |
4737 | @item adding additional names | |
4738 | Sometimes, it is useful to export symbols with additional names. | |
4739 | A symbol @samp{foo} will be exported as @samp{foo}, but it can also be | |
4740 | exported as @samp{_foo} by using special directives in the DEF file | |
4741 | when creating the dll. This will affect also the optional created | |
4742 | import library. Consider the following DEF file: | |
4743 | ||
4744 | @example | |
4745 | LIBRARY "xyz.dll" BASE=0x61000000 | |
4746 | ||
4747 | EXPORTS | |
4748 | foo | |
4749 | _foo = foo | |
4750 | @end example | |
4751 | ||
4752 | The line @samp{_foo = foo} maps the symbol @samp{foo} to @samp{_foo}. | |
4753 | ||
4754 | Another method for creating a symbol alias is to create it in the | |
4755 | source code using the "weak" attribute: | |
4756 | ||
4757 | @example | |
4758 | void foo () @{ /* Do something. */; @} | |
4759 | void _foo () __attribute__ ((weak, alias ("foo"))); | |
4760 | @end example | |
4761 | ||
4762 | See the gcc manual for more information about attributes and weak | |
4763 | symbols. | |
4764 | ||
4765 | @item renaming symbols | |
4766 | Sometimes it is useful to rename exports. For instance, the cygwin | |
4767 | kernel does this regularly. A symbol @samp{_foo} can be exported as | |
4768 | @samp{foo} but not as @samp{_foo} by using special directives in the | |
4769 | DEF file. (This will also affect the import library, if it is | |
4770 | created). In the following example: | |
4771 | ||
4772 | @example | |
4773 | LIBRARY "xyz.dll" BASE=0x61000000 | |
4774 | ||
4775 | EXPORTS | |
4776 | _foo = foo | |
4777 | @end example | |
4778 | ||
4779 | The line @samp{_foo = foo} maps the exported symbol @samp{foo} to | |
4780 | @samp{_foo}. | |
4781 | @end table | |
4782 | ||
0a5d968e NC |
4783 | Note: using a DEF file disables the default auto-export behavior, |
4784 | unless the @samp{--export-all-symbols} command line option is used. | |
4785 | If, however, you are trying to rename symbols, then you should list | |
4786 | @emph{all} desired exports in the DEF file, including the symbols | |
4787 | that are not being renamed, and do @emph{not} use the | |
4788 | @samp{--export-all-symbols} option. If you list only the | |
4789 | renamed symbols in the DEF file, and use @samp{--export-all-symbols} | |
4790 | to handle the other symbols, then the both the new names @emph{and} | |
4791 | the original names for the the renamed symbols will be exported. | |
4792 | In effect, you'd be aliasing those symbols, not renaming them, | |
4793 | which is probably not what you wanted. | |
2ca22b03 NC |
4794 | @end table |
4795 | ||
4796 | @ifclear GENERIC | |
4797 | @lowersections | |
4798 | @end ifclear | |
4799 | @end ifset | |
4800 | ||
252b5132 RH |
4801 | @ifclear GENERIC |
4802 | @ifset Hitachi | |
4803 | @c This stuff is pointless to say unless you're especially concerned | |
4804 | @c with Hitachi chips; don't enable it for generic case, please. | |
4805 | @node Hitachi | |
ff5dcc92 | 4806 | @chapter @command{ld} and other Hitachi chips |
252b5132 | 4807 | |
ff5dcc92 | 4808 | @command{ld} also supports the H8/300H, the H8/500, and the Hitachi SH. No |
252b5132 RH |
4809 | special features, commands, or command-line options are required for |
4810 | these chips. | |
4811 | @end ifset | |
4812 | @end ifclear | |
4813 | ||
4814 | @ifset I960 | |
4815 | @ifclear GENERIC | |
4816 | @raisesections | |
4817 | @end ifclear | |
4818 | ||
4819 | @node i960 | |
ff5dcc92 | 4820 | @section @command{ld} and the Intel 960 family |
252b5132 RH |
4821 | |
4822 | @cindex i960 support | |
4823 | ||
4824 | You can use the @samp{-A@var{architecture}} command line option to | |
4825 | specify one of the two-letter names identifying members of the 960 | |
4826 | family; the option specifies the desired output target, and warns of any | |
4827 | incompatible instructions in the input files. It also modifies the | |
4828 | linker's search strategy for archive libraries, to support the use of | |
4829 | libraries specific to each particular architecture, by including in the | |
4830 | search loop names suffixed with the string identifying the architecture. | |
4831 | ||
ff5dcc92 | 4832 | For example, if your @command{ld} command line included @w{@samp{-ACA}} as |
252b5132 RH |
4833 | well as @w{@samp{-ltry}}, the linker would look (in its built-in search |
4834 | paths, and in any paths you specify with @samp{-L}) for a library with | |
4835 | the names | |
4836 | ||
4837 | @smallexample | |
4838 | @group | |
4839 | try | |
4840 | libtry.a | |
4841 | tryca | |
4842 | libtryca.a | |
4843 | @end group | |
4844 | @end smallexample | |
4845 | ||
4846 | @noindent | |
4847 | The first two possibilities would be considered in any event; the last | |
4848 | two are due to the use of @w{@samp{-ACA}}. | |
4849 | ||
4850 | You can meaningfully use @samp{-A} more than once on a command line, since | |
4851 | the 960 architecture family allows combination of target architectures; each | |
4852 | use will add another pair of name variants to search for when @w{@samp{-l}} | |
4853 | specifies a library. | |
4854 | ||
ff5dcc92 | 4855 | @cindex @option{--relax} on i960 |
252b5132 | 4856 | @cindex relaxing on i960 |
ff5dcc92 SC |
4857 | @command{ld} supports the @samp{--relax} option for the i960 family. If |
4858 | you specify @samp{--relax}, @command{ld} finds all @code{balx} and | |
252b5132 RH |
4859 | @code{calx} instructions whose targets are within 24 bits, and turns |
4860 | them into 24-bit program-counter relative @code{bal} and @code{cal} | |
ff5dcc92 | 4861 | instructions, respectively. @command{ld} also turns @code{cal} |
252b5132 RH |
4862 | instructions into @code{bal} instructions when it determines that the |
4863 | target subroutine is a leaf routine (that is, the target subroutine does | |
4864 | not itself call any subroutines). | |
4865 | ||
4866 | @ifclear GENERIC | |
4867 | @lowersections | |
4868 | @end ifclear | |
4869 | @end ifset | |
4870 | ||
4871 | @ifclear GENERIC | |
4872 | @raisesections | |
4873 | @end ifclear | |
4874 | ||
4875 | @node ARM | |
ff5dcc92 | 4876 | @section @command{ld}'s support for interworking between ARM and Thumb code |
252b5132 RH |
4877 | |
4878 | @cindex ARM interworking support | |
6f798e5c | 4879 | @kindex --support-old-code |
ff5dcc92 | 4880 | For the ARM, @command{ld} will generate code stubs to allow functions calls |
252b5132 RH |
4881 | betweem ARM and Thumb code. These stubs only work with code that has |
4882 | been compiled and assembled with the @samp{-mthumb-interwork} command | |
4883 | line option. If it is necessary to link with old ARM object files or | |
4884 | libraries, which have not been compiled with the -mthumb-interwork | |
4885 | option then the @samp{--support-old-code} command line switch should be | |
4886 | given to the linker. This will make it generate larger stub functions | |
4887 | which will work with non-interworking aware ARM code. Note, however, | |
4888 | the linker does not support generating stubs for function calls to | |
4889 | non-interworking aware Thumb code. | |
4890 | ||
6f798e5c NC |
4891 | @cindex thumb entry point |
4892 | @cindex entry point, thumb | |
4893 | @kindex --thumb-entry=@var{entry} | |
4894 | The @samp{--thumb-entry} switch is a duplicate of the generic | |
a1ab1d2a | 4895 | @samp{--entry} switch, in that it sets the program's starting address. |
6f798e5c NC |
4896 | But it also sets the bottom bit of the address, so that it can be |
4897 | branched to using a BX instruction, and the program will start | |
4898 | executing in Thumb mode straight away. | |
4899 | ||
47d89dba | 4900 | @node HPPA ELF32 |
ff5dcc92 | 4901 | @section @command{ld} and HPPA 32-bit ELF support |
47d89dba AM |
4902 | @cindex HPPA multiple sub-space stubs |
4903 | @kindex --multi-subspace | |
ff5dcc92 | 4904 | When generating a shared library, @command{ld} will by default generate |
47d89dba | 4905 | import stubs suitable for use with a single sub-space application. |
ff5dcc92 | 4906 | The @samp{--multi-subspace} switch causes @command{ld} to generate export |
47d89dba AM |
4907 | stubs, and different (larger) import stubs suitable for use with |
4908 | multiple sub-spaces. | |
4909 | ||
4910 | @cindex HPPA stub grouping | |
4911 | @kindex --stub-group-size=@var{N} | |
ff5dcc92 | 4912 | Long branch stubs and import/export stubs are placed by @command{ld} in |
47d89dba AM |
4913 | stub sections located between groups of input sections. |
4914 | @samp{--stub-group-size} specifies the maximum size of a group of input | |
4915 | sections handled by one stub section. Since branch offsets are signed, | |
4916 | a stub section may serve two groups of input sections, one group before | |
4917 | the stub section, and one group after it. However, when using | |
4918 | conditional branches that require stubs, it may be better (for branch | |
4919 | prediction) that stub sections only serve one group of input sections. | |
4920 | A negative value for @samp{N} chooses this scheme, ensuring that | |
4921 | branches to stubs always use a negative offset. Two special values of | |
4922 | @samp{N} are recognized, @samp{1} and @samp{-1}. These both instruct | |
ff5dcc92 | 4923 | @command{ld} to automatically size input section groups for the branch types |
47d89dba AM |
4924 | detected, with the same behaviour regarding stub placement as other |
4925 | positive or negative values of @samp{N} respectively. | |
4926 | ||
4927 | Note that @samp{--stub-group-size} does not split input sections. A | |
4928 | single input section larger than the group size specified will of course | |
4929 | create a larger group (of one section). If input sections are too | |
4930 | large, it may not be possible for a branch to reach its stub. | |
4931 | ||
3c3bdf30 NC |
4932 | @ifset MMIX |
4933 | @node MMIX | |
4934 | @section @code{ld} and MMIX | |
4935 | For MMIX, there is choice of generating @code{ELF} object files or | |
4936 | @code{mmo} object files when linking. The simulator @code{mmix} | |
4937 | understands the @code{mmo} format. The binutils @code{objcopy} utility | |
4938 | can translate between the two formats. | |
4939 | ||
4940 | There is one special section, the @samp{.MMIX.reg_contents} section. | |
4941 | Contents in this section is assumed to correspond to that of global | |
4942 | registers, and symbols referring to it are translated to special symbols, | |
4943 | equal to registers. In a final link, the start address of the | |
4944 | @samp{.MMIX.reg_contents} section corresponds to the first allocated | |
4945 | global register multiplied by 8. Register @code{$255} is not included in | |
4946 | this section; it is always set to the program entry, which is at the | |
4947 | symbol @code{Main} for @code{mmo} files. | |
4948 | ||
4949 | Symbols with the prefix @code{__.MMIX.start.}, for example | |
4950 | @code{__.MMIX.start..text} and @code{__.MMIX.start..data} are special; | |
4951 | there must be only one each, even if they are local. The default linker | |
4952 | script uses these to set the default start address of a section. | |
4953 | ||
4954 | Initial and trailing multiples of zero-valued 32-bit words in a section, | |
4955 | are left out from an mmo file. | |
4956 | @end ifset | |
4957 | ||
2469cfa2 NC |
4958 | @ifset MSP430 |
4959 | @node MSP430 | |
4960 | @section @code{ld} and MSP430 | |
4961 | For the MSP430 it is possible to select the MPU architecture. The flag @samp{-m [mpu type]} | |
4962 | will select an appropriate linker script for selected MPU type. (To get a list of known MPUs | |
4963 | just pass @samp{-m help} option to the linker). | |
4964 | ||
4965 | @cindex MSP430 extra sections | |
4966 | The linker will recognize some extra sections which are MSP430 specific: | |
4967 | ||
4968 | @table @code | |
4969 | @item @samp{.vectors} | |
4970 | Defines a portion of ROM where interrupt vectors located. | |
4971 | ||
4972 | @item @samp{.bootloader} | |
4973 | Defines the bootloader portion of the ROM (if applicable). Any code | |
4974 | in this section will be uploaded to the MPU. | |
4975 | ||
4976 | @item @samp{.infomem} | |
4977 | Defines an information memory section (if applicable). Any code in | |
4978 | this section will be uploaded to the MPU. | |
4979 | ||
4980 | @item @samp{.infomemnobits} | |
4981 | This is the same as the @samp{.infomem} section except that any code | |
4982 | in this section will not be uploaded to the MPU. | |
4983 | ||
4984 | @item @samp{.noinit} | |
4985 | Denotes a portion of RAM located above @samp{.bss} section. | |
4986 | ||
4987 | The last two sections are used by gcc. | |
4988 | @end table | |
4989 | @end ifset | |
4990 | ||
74459f0e TW |
4991 | @ifset TICOFF |
4992 | @node TI COFF | |
ff5dcc92 | 4993 | @section @command{ld}'s support for various TI COFF versions |
74459f0e TW |
4994 | @cindex TI COFF versions |
4995 | @kindex --format=@var{version} | |
4996 | The @samp{--format} switch allows selection of one of the various | |
4997 | TI COFF versions. The latest of this writing is 2; versions 0 and 1 are | |
4998 | also supported. The TI COFF versions also vary in header byte-order | |
ff5dcc92 | 4999 | format; @command{ld} will read any version or byte order, but the output |
74459f0e TW |
5000 | header format depends on the default specified by the specific target. |
5001 | @end ifset | |
5002 | ||
252b5132 RH |
5003 | @ifclear GENERIC |
5004 | @lowersections | |
5005 | @end ifclear | |
5006 | ||
5007 | @ifclear SingleFormat | |
5008 | @node BFD | |
5009 | @chapter BFD | |
5010 | ||
5011 | @cindex back end | |
5012 | @cindex object file management | |
5013 | @cindex object formats available | |
5014 | @kindex objdump -i | |
5015 | The linker accesses object and archive files using the BFD libraries. | |
5016 | These libraries allow the linker to use the same routines to operate on | |
5017 | object files whatever the object file format. A different object file | |
5018 | format can be supported simply by creating a new BFD back end and adding | |
5019 | it to the library. To conserve runtime memory, however, the linker and | |
5020 | associated tools are usually configured to support only a subset of the | |
5021 | object file formats available. You can use @code{objdump -i} | |
5022 | (@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to | |
5023 | list all the formats available for your configuration. | |
5024 | ||
5025 | @cindex BFD requirements | |
5026 | @cindex requirements for BFD | |
5027 | As with most implementations, BFD is a compromise between | |
5028 | several conflicting requirements. The major factor influencing | |
5029 | BFD design was efficiency: any time used converting between | |
5030 | formats is time which would not have been spent had BFD not | |
5031 | been involved. This is partly offset by abstraction payback; since | |
5032 | BFD simplifies applications and back ends, more time and care | |
5033 | may be spent optimizing algorithms for a greater speed. | |
5034 | ||
5035 | One minor artifact of the BFD solution which you should bear in | |
5036 | mind is the potential for information loss. There are two places where | |
5037 | useful information can be lost using the BFD mechanism: during | |
5038 | conversion and during output. @xref{BFD information loss}. | |
5039 | ||
5040 | @menu | |
5041 | * BFD outline:: How it works: an outline of BFD | |
5042 | @end menu | |
5043 | ||
5044 | @node BFD outline | |
5045 | @section How it works: an outline of BFD | |
5046 | @cindex opening object files | |
5047 | @include bfdsumm.texi | |
5048 | @end ifclear | |
5049 | ||
5050 | @node Reporting Bugs | |
5051 | @chapter Reporting Bugs | |
ff5dcc92 SC |
5052 | @cindex bugs in @command{ld} |
5053 | @cindex reporting bugs in @command{ld} | |
252b5132 | 5054 | |
ff5dcc92 | 5055 | Your bug reports play an essential role in making @command{ld} reliable. |
252b5132 RH |
5056 | |
5057 | Reporting a bug may help you by bringing a solution to your problem, or | |
5058 | it may not. But in any case the principal function of a bug report is | |
ff5dcc92 | 5059 | to help the entire community by making the next version of @command{ld} |
252b5132 | 5060 | work better. Bug reports are your contribution to the maintenance of |
ff5dcc92 | 5061 | @command{ld}. |
252b5132 RH |
5062 | |
5063 | In order for a bug report to serve its purpose, you must include the | |
5064 | information that enables us to fix the bug. | |
5065 | ||
5066 | @menu | |
5067 | * Bug Criteria:: Have you found a bug? | |
5068 | * Bug Reporting:: How to report bugs | |
5069 | @end menu | |
5070 | ||
5071 | @node Bug Criteria | |
5072 | @section Have you found a bug? | |
5073 | @cindex bug criteria | |
5074 | ||
5075 | If you are not sure whether you have found a bug, here are some guidelines: | |
5076 | ||
5077 | @itemize @bullet | |
5078 | @cindex fatal signal | |
5079 | @cindex linker crash | |
5080 | @cindex crash of linker | |
5081 | @item | |
5082 | If the linker gets a fatal signal, for any input whatever, that is a | |
ff5dcc92 | 5083 | @command{ld} bug. Reliable linkers never crash. |
252b5132 RH |
5084 | |
5085 | @cindex error on valid input | |
5086 | @item | |
ff5dcc92 | 5087 | If @command{ld} produces an error message for valid input, that is a bug. |
252b5132 RH |
5088 | |
5089 | @cindex invalid input | |
5090 | @item | |
ff5dcc92 | 5091 | If @command{ld} does not produce an error message for invalid input, that |
252b5132 RH |
5092 | may be a bug. In the general case, the linker can not verify that |
5093 | object files are correct. | |
5094 | ||
5095 | @item | |
5096 | If you are an experienced user of linkers, your suggestions for | |
ff5dcc92 | 5097 | improvement of @command{ld} are welcome in any case. |
252b5132 RH |
5098 | @end itemize |
5099 | ||
5100 | @node Bug Reporting | |
5101 | @section How to report bugs | |
5102 | @cindex bug reports | |
ff5dcc92 | 5103 | @cindex @command{ld} bugs, reporting |
252b5132 RH |
5104 | |
5105 | A number of companies and individuals offer support for @sc{gnu} | |
ff5dcc92 | 5106 | products. If you obtained @command{ld} from a support organization, we |
252b5132 RH |
5107 | recommend you contact that organization first. |
5108 | ||
5109 | You can find contact information for many support companies and | |
5110 | individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs | |
5111 | distribution. | |
5112 | ||
ff5dcc92 | 5113 | Otherwise, send bug reports for @command{ld} to |
d7ed7ca6 | 5114 | @samp{bug-binutils@@gnu.org}. |
252b5132 RH |
5115 | |
5116 | The fundamental principle of reporting bugs usefully is this: | |
5117 | @strong{report all the facts}. If you are not sure whether to state a | |
5118 | fact or leave it out, state it! | |
5119 | ||
5120 | Often people omit facts because they think they know what causes the | |
5121 | problem and assume that some details do not matter. Thus, you might | |
b553b183 NC |
5122 | assume that the name of a symbol you use in an example does not |
5123 | matter. Well, probably it does not, but one cannot be sure. Perhaps | |
5124 | the bug is a stray memory reference which happens to fetch from the | |
5125 | location where that name is stored in memory; perhaps, if the name | |
5126 | were different, the contents of that location would fool the linker | |
5127 | into doing the right thing despite the bug. Play it safe and give a | |
5128 | specific, complete example. That is the easiest thing for you to do, | |
5129 | and the most helpful. | |
5130 | ||
5131 | Keep in mind that the purpose of a bug report is to enable us to fix | |
5132 | the bug if it is new to us. Therefore, always write your bug reports | |
5133 | on the assumption that the bug has not been reported previously. | |
252b5132 RH |
5134 | |
5135 | Sometimes people give a few sketchy facts and ask, ``Does this ring a | |
5136 | bell?'' Those bug reports are useless, and we urge everyone to | |
5137 | @emph{refuse to respond to them} except to chide the sender to report | |
5138 | bugs properly. | |
5139 | ||
5140 | To enable us to fix the bug, you should include all these things: | |
5141 | ||
5142 | @itemize @bullet | |
5143 | @item | |
ff5dcc92 | 5144 | The version of @command{ld}. @command{ld} announces it if you start it with |
252b5132 RH |
5145 | the @samp{--version} argument. |
5146 | ||
5147 | Without this, we will not know whether there is any point in looking for | |
ff5dcc92 | 5148 | the bug in the current version of @command{ld}. |
252b5132 RH |
5149 | |
5150 | @item | |
ff5dcc92 | 5151 | Any patches you may have applied to the @command{ld} source, including any |
252b5132 RH |
5152 | patches made to the @code{BFD} library. |
5153 | ||
5154 | @item | |
5155 | The type of machine you are using, and the operating system name and | |
5156 | version number. | |
5157 | ||
5158 | @item | |
ff5dcc92 | 5159 | What compiler (and its version) was used to compile @command{ld}---e.g. |
252b5132 RH |
5160 | ``@code{gcc-2.7}''. |
5161 | ||
5162 | @item | |
5163 | The command arguments you gave the linker to link your example and | |
5164 | observe the bug. To guarantee you will not omit something important, | |
5165 | list them all. A copy of the Makefile (or the output from make) is | |
5166 | sufficient. | |
5167 | ||
5168 | If we were to try to guess the arguments, we would probably guess wrong | |
5169 | and then we might not encounter the bug. | |
5170 | ||
5171 | @item | |
5172 | A complete input file, or set of input files, that will reproduce the | |
b553b183 NC |
5173 | bug. It is generally most helpful to send the actual object files |
5174 | provided that they are reasonably small. Say no more than 10K. For | |
5175 | bigger files you can either make them available by FTP or HTTP or else | |
5176 | state that you are willing to send the object file(s) to whomever | |
5177 | requests them. (Note - your email will be going to a mailing list, so | |
5178 | we do not want to clog it up with large attachments). But small | |
5179 | attachments are best. | |
252b5132 RH |
5180 | |
5181 | If the source files were assembled using @code{gas} or compiled using | |
5182 | @code{gcc}, then it may be OK to send the source files rather than the | |
5183 | object files. In this case, be sure to say exactly what version of | |
5184 | @code{gas} or @code{gcc} was used to produce the object files. Also say | |
5185 | how @code{gas} or @code{gcc} were configured. | |
5186 | ||
5187 | @item | |
5188 | A description of what behavior you observe that you believe is | |
5189 | incorrect. For example, ``It gets a fatal signal.'' | |
5190 | ||
ff5dcc92 | 5191 | Of course, if the bug is that @command{ld} gets a fatal signal, then we |
252b5132 RH |
5192 | will certainly notice it. But if the bug is incorrect output, we might |
5193 | not notice unless it is glaringly wrong. You might as well not give us | |
5194 | a chance to make a mistake. | |
5195 | ||
5196 | Even if the problem you experience is a fatal signal, you should still | |
5197 | say so explicitly. Suppose something strange is going on, such as, your | |
ff5dcc92 | 5198 | copy of @command{ld} is out of synch, or you have encountered a bug in the |
252b5132 RH |
5199 | C library on your system. (This has happened!) Your copy might crash |
5200 | and ours would not. If you told us to expect a crash, then when ours | |
5201 | fails to crash, we would know that the bug was not happening for us. If | |
5202 | you had not told us to expect a crash, then we would not be able to draw | |
5203 | any conclusion from our observations. | |
5204 | ||
5205 | @item | |
ff5dcc92 | 5206 | If you wish to suggest changes to the @command{ld} source, send us context |
252b5132 RH |
5207 | diffs, as generated by @code{diff} with the @samp{-u}, @samp{-c}, or |
5208 | @samp{-p} option. Always send diffs from the old file to the new file. | |
ff5dcc92 | 5209 | If you even discuss something in the @command{ld} source, refer to it by |
252b5132 RH |
5210 | context, not by line number. |
5211 | ||
5212 | The line numbers in our development sources will not match those in your | |
5213 | sources. Your line numbers would convey no useful information to us. | |
5214 | @end itemize | |
5215 | ||
5216 | Here are some things that are not necessary: | |
5217 | ||
5218 | @itemize @bullet | |
5219 | @item | |
5220 | A description of the envelope of the bug. | |
5221 | ||
5222 | Often people who encounter a bug spend a lot of time investigating | |
5223 | which changes to the input file will make the bug go away and which | |
5224 | changes will not affect it. | |
5225 | ||
5226 | This is often time consuming and not very useful, because the way we | |
5227 | will find the bug is by running a single example under the debugger | |
5228 | with breakpoints, not by pure deduction from a series of examples. | |
5229 | We recommend that you save your time for something else. | |
5230 | ||
5231 | Of course, if you can find a simpler example to report @emph{instead} | |
5232 | of the original one, that is a convenience for us. Errors in the | |
5233 | output will be easier to spot, running under the debugger will take | |
5234 | less time, and so on. | |
5235 | ||
5236 | However, simplification is not vital; if you do not want to do this, | |
5237 | report the bug anyway and send us the entire test case you used. | |
5238 | ||
5239 | @item | |
5240 | A patch for the bug. | |
5241 | ||
5242 | A patch for the bug does help us if it is a good one. But do not omit | |
5243 | the necessary information, such as the test case, on the assumption that | |
5244 | a patch is all we need. We might see problems with your patch and decide | |
5245 | to fix the problem another way, or we might not understand it at all. | |
5246 | ||
ff5dcc92 | 5247 | Sometimes with a program as complicated as @command{ld} it is very hard to |
252b5132 RH |
5248 | construct an example that will make the program follow a certain path |
5249 | through the code. If you do not send us the example, we will not be | |
5250 | able to construct one, so we will not be able to verify that the bug is | |
5251 | fixed. | |
5252 | ||
5253 | And if we cannot understand what bug you are trying to fix, or why your | |
5254 | patch should be an improvement, we will not install it. A test case will | |
5255 | help us to understand. | |
5256 | ||
5257 | @item | |
5258 | A guess about what the bug is or what it depends on. | |
5259 | ||
5260 | Such guesses are usually wrong. Even we cannot guess right about such | |
5261 | things without first using the debugger to find the facts. | |
5262 | @end itemize | |
5263 | ||
5264 | @node MRI | |
5265 | @appendix MRI Compatible Script Files | |
5266 | @cindex MRI compatibility | |
ff5dcc92 SC |
5267 | To aid users making the transition to @sc{gnu} @command{ld} from the MRI |
5268 | linker, @command{ld} can use MRI compatible linker scripts as an | |
252b5132 RH |
5269 | alternative to the more general-purpose linker scripting language |
5270 | described in @ref{Scripts}. MRI compatible linker scripts have a much | |
5271 | simpler command set than the scripting language otherwise used with | |
ff5dcc92 | 5272 | @command{ld}. @sc{gnu} @command{ld} supports the most commonly used MRI |
252b5132 RH |
5273 | linker commands; these commands are described here. |
5274 | ||
5275 | In general, MRI scripts aren't of much use with the @code{a.out} object | |
5276 | file format, since it only has three sections and MRI scripts lack some | |
5277 | features to make use of them. | |
5278 | ||
5279 | You can specify a file containing an MRI-compatible script using the | |
5280 | @samp{-c} command-line option. | |
5281 | ||
5282 | Each command in an MRI-compatible script occupies its own line; each | |
5283 | command line starts with the keyword that identifies the command (though | |
5284 | blank lines are also allowed for punctuation). If a line of an | |
ff5dcc92 | 5285 | MRI-compatible script begins with an unrecognized keyword, @command{ld} |
252b5132 RH |
5286 | issues a warning message, but continues processing the script. |
5287 | ||
5288 | Lines beginning with @samp{*} are comments. | |
5289 | ||
5290 | You can write these commands using all upper-case letters, or all | |
5291 | lower case; for example, @samp{chip} is the same as @samp{CHIP}. | |
5292 | The following list shows only the upper-case form of each command. | |
5293 | ||
5294 | @table @code | |
5295 | @cindex @code{ABSOLUTE} (MRI) | |
5296 | @item ABSOLUTE @var{secname} | |
5297 | @itemx ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname} | |
ff5dcc92 | 5298 | Normally, @command{ld} includes in the output file all sections from all |
252b5132 RH |
5299 | the input files. However, in an MRI-compatible script, you can use the |
5300 | @code{ABSOLUTE} command to restrict the sections that will be present in | |
5301 | your output program. If the @code{ABSOLUTE} command is used at all in a | |
5302 | script, then only the sections named explicitly in @code{ABSOLUTE} | |
5303 | commands will appear in the linker output. You can still use other | |
5304 | input sections (whatever you select on the command line, or using | |
5305 | @code{LOAD}) to resolve addresses in the output file. | |
5306 | ||
5307 | @cindex @code{ALIAS} (MRI) | |
5308 | @item ALIAS @var{out-secname}, @var{in-secname} | |
5309 | Use this command to place the data from input section @var{in-secname} | |
5310 | in a section called @var{out-secname} in the linker output file. | |
5311 | ||
5312 | @var{in-secname} may be an integer. | |
5313 | ||
5314 | @cindex @code{ALIGN} (MRI) | |
5315 | @item ALIGN @var{secname} = @var{expression} | |
5316 | Align the section called @var{secname} to @var{expression}. The | |
5317 | @var{expression} should be a power of two. | |
5318 | ||
5319 | @cindex @code{BASE} (MRI) | |
5320 | @item BASE @var{expression} | |
5321 | Use the value of @var{expression} as the lowest address (other than | |
5322 | absolute addresses) in the output file. | |
5323 | ||
5324 | @cindex @code{CHIP} (MRI) | |
5325 | @item CHIP @var{expression} | |
5326 | @itemx CHIP @var{expression}, @var{expression} | |
5327 | This command does nothing; it is accepted only for compatibility. | |
5328 | ||
5329 | @cindex @code{END} (MRI) | |
5330 | @item END | |
5331 | This command does nothing whatever; it's only accepted for compatibility. | |
5332 | ||
5333 | @cindex @code{FORMAT} (MRI) | |
5334 | @item FORMAT @var{output-format} | |
5335 | Similar to the @code{OUTPUT_FORMAT} command in the more general linker | |
a1ab1d2a | 5336 | language, but restricted to one of these output formats: |
252b5132 RH |
5337 | |
5338 | @enumerate | |
a1ab1d2a | 5339 | @item |
252b5132 RH |
5340 | S-records, if @var{output-format} is @samp{S} |
5341 | ||
5342 | @item | |
5343 | IEEE, if @var{output-format} is @samp{IEEE} | |
5344 | ||
5345 | @item | |
5346 | COFF (the @samp{coff-m68k} variant in BFD), if @var{output-format} is | |
5347 | @samp{COFF} | |
5348 | @end enumerate | |
5349 | ||
5350 | @cindex @code{LIST} (MRI) | |
5351 | @item LIST @var{anything}@dots{} | |
5352 | Print (to the standard output file) a link map, as produced by the | |
ff5dcc92 | 5353 | @command{ld} command-line option @samp{-M}. |
252b5132 RH |
5354 | |
5355 | The keyword @code{LIST} may be followed by anything on the | |
5356 | same line, with no change in its effect. | |
5357 | ||
5358 | @cindex @code{LOAD} (MRI) | |
5359 | @item LOAD @var{filename} | |
5360 | @itemx LOAD @var{filename}, @var{filename}, @dots{} @var{filename} | |
5361 | Include one or more object file @var{filename} in the link; this has the | |
ff5dcc92 | 5362 | same effect as specifying @var{filename} directly on the @command{ld} |
252b5132 RH |
5363 | command line. |
5364 | ||
5365 | @cindex @code{NAME} (MRI) | |
5366 | @item NAME @var{output-name} | |
ff5dcc92 | 5367 | @var{output-name} is the name for the program produced by @command{ld}; the |
252b5132 RH |
5368 | MRI-compatible command @code{NAME} is equivalent to the command-line |
5369 | option @samp{-o} or the general script language command @code{OUTPUT}. | |
5370 | ||
5371 | @cindex @code{ORDER} (MRI) | |
5372 | @item ORDER @var{secname}, @var{secname}, @dots{} @var{secname} | |
5373 | @itemx ORDER @var{secname} @var{secname} @var{secname} | |
ff5dcc92 | 5374 | Normally, @command{ld} orders the sections in its output file in the |
252b5132 RH |
5375 | order in which they first appear in the input files. In an MRI-compatible |
5376 | script, you can override this ordering with the @code{ORDER} command. The | |
5377 | sections you list with @code{ORDER} will appear first in your output | |
5378 | file, in the order specified. | |
5379 | ||
5380 | @cindex @code{PUBLIC} (MRI) | |
5381 | @item PUBLIC @var{name}=@var{expression} | |
5382 | @itemx PUBLIC @var{name},@var{expression} | |
5383 | @itemx PUBLIC @var{name} @var{expression} | |
5384 | Supply a value (@var{expression}) for external symbol | |
5385 | @var{name} used in the linker input files. | |
5386 | ||
5387 | @cindex @code{SECT} (MRI) | |
5388 | @item SECT @var{secname}, @var{expression} | |
5389 | @itemx SECT @var{secname}=@var{expression} | |
5390 | @itemx SECT @var{secname} @var{expression} | |
5391 | You can use any of these three forms of the @code{SECT} command to | |
5392 | specify the start address (@var{expression}) for section @var{secname}. | |
5393 | If you have more than one @code{SECT} statement for the same | |
5394 | @var{secname}, only the @emph{first} sets the start address. | |
5395 | @end table | |
5396 | ||
704c465c NC |
5397 | @node GNU Free Documentation License |
5398 | @appendix GNU Free Documentation License | |
5399 | @cindex GNU Free Documentation License | |
5400 | ||
5401 | GNU Free Documentation License | |
a1ab1d2a | 5402 | |
704c465c NC |
5403 | Version 1.1, March 2000 |
5404 | ||
5405 | Copyright (C) 2000 Free Software Foundation, Inc. | |
5406 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
a1ab1d2a | 5407 | |
704c465c NC |
5408 | Everyone is permitted to copy and distribute verbatim copies |
5409 | of this license document, but changing it is not allowed. | |
5410 | ||
5411 | ||
5412 | 0. PREAMBLE | |
5413 | ||
5414 | The purpose of this License is to make a manual, textbook, or other | |
5415 | written document "free" in the sense of freedom: to assure everyone | |
5416 | the effective freedom to copy and redistribute it, with or without | |
5417 | modifying it, either commercially or noncommercially. Secondarily, | |
5418 | this License preserves for the author and publisher a way to get | |
5419 | credit for their work, while not being considered responsible for | |
5420 | modifications made by others. | |
5421 | ||
5422 | This License is a kind of "copyleft", which means that derivative | |
5423 | works of the document must themselves be free in the same sense. It | |
5424 | complements the GNU General Public License, which is a copyleft | |
5425 | license designed for free software. | |
5426 | ||
5427 | We have designed this License in order to use it for manuals for free | |
5428 | software, because free software needs free documentation: a free | |
5429 | program should come with manuals providing the same freedoms that the | |
5430 | software does. But this License is not limited to software manuals; | |
5431 | it can be used for any textual work, regardless of subject matter or | |
5432 | whether it is published as a printed book. We recommend this License | |
5433 | principally for works whose purpose is instruction or reference. | |
5434 | ||
5435 | ||
5436 | 1. APPLICABILITY AND DEFINITIONS | |
5437 | ||
5438 | This License applies to any manual or other work that contains a | |
5439 | notice placed by the copyright holder saying it can be distributed | |
5440 | under the terms of this License. The "Document", below, refers to any | |
5441 | such manual or work. Any member of the public is a licensee, and is | |
5442 | addressed as "you". | |
5443 | ||
5444 | A "Modified Version" of the Document means any work containing the | |
5445 | Document or a portion of it, either copied verbatim, or with | |
5446 | modifications and/or translated into another language. | |
5447 | ||
5448 | A "Secondary Section" is a named appendix or a front-matter section of | |
5449 | the Document that deals exclusively with the relationship of the | |
5450 | publishers or authors of the Document to the Document's overall subject | |
5451 | (or to related matters) and contains nothing that could fall directly | |
5452 | within that overall subject. (For example, if the Document is in part a | |
5453 | textbook of mathematics, a Secondary Section may not explain any | |
5454 | mathematics.) The relationship could be a matter of historical | |
5455 | connection with the subject or with related matters, or of legal, | |
5456 | commercial, philosophical, ethical or political position regarding | |
5457 | them. | |
5458 | ||
5459 | The "Invariant Sections" are certain Secondary Sections whose titles | |
5460 | are designated, as being those of Invariant Sections, in the notice | |
5461 | that says that the Document is released under this License. | |
5462 | ||
5463 | The "Cover Texts" are certain short passages of text that are listed, | |
5464 | as Front-Cover Texts or Back-Cover Texts, in the notice that says that | |
5465 | the Document is released under this License. | |
5466 | ||
5467 | A "Transparent" copy of the Document means a machine-readable copy, | |
5468 | represented in a format whose specification is available to the | |
5469 | general public, whose contents can be viewed and edited directly and | |
5470 | straightforwardly with generic text editors or (for images composed of | |
5471 | pixels) generic paint programs or (for drawings) some widely available | |
5472 | drawing editor, and that is suitable for input to text formatters or | |
5473 | for automatic translation to a variety of formats suitable for input | |
5474 | to text formatters. A copy made in an otherwise Transparent file | |
5475 | format whose markup has been designed to thwart or discourage | |
5476 | subsequent modification by readers is not Transparent. A copy that is | |
5477 | not "Transparent" is called "Opaque". | |
5478 | ||
5479 | Examples of suitable formats for Transparent copies include plain | |
5480 | ASCII without markup, Texinfo input format, LaTeX input format, SGML | |
5481 | or XML using a publicly available DTD, and standard-conforming simple | |
5482 | HTML designed for human modification. Opaque formats include | |
5483 | PostScript, PDF, proprietary formats that can be read and edited only | |
5484 | by proprietary word processors, SGML or XML for which the DTD and/or | |
5485 | processing tools are not generally available, and the | |
5486 | machine-generated HTML produced by some word processors for output | |
5487 | purposes only. | |
5488 | ||
5489 | The "Title Page" means, for a printed book, the title page itself, | |
5490 | plus such following pages as are needed to hold, legibly, the material | |
5491 | this License requires to appear in the title page. For works in | |
5492 | formats which do not have any title page as such, "Title Page" means | |
5493 | the text near the most prominent appearance of the work's title, | |
5494 | preceding the beginning of the body of the text. | |
5495 | ||
5496 | ||
5497 | 2. VERBATIM COPYING | |
5498 | ||
5499 | You may copy and distribute the Document in any medium, either | |
5500 | commercially or noncommercially, provided that this License, the | |
5501 | copyright notices, and the license notice saying this License applies | |
5502 | to the Document are reproduced in all copies, and that you add no other | |
5503 | conditions whatsoever to those of this License. You may not use | |
5504 | technical measures to obstruct or control the reading or further | |
5505 | copying of the copies you make or distribute. However, you may accept | |
5506 | compensation in exchange for copies. If you distribute a large enough | |
5507 | number of copies you must also follow the conditions in section 3. | |
5508 | ||
5509 | You may also lend copies, under the same conditions stated above, and | |
5510 | you may publicly display copies. | |
5511 | ||
5512 | ||
5513 | 3. COPYING IN QUANTITY | |
5514 | ||
5515 | If you publish printed copies of the Document numbering more than 100, | |
5516 | and the Document's license notice requires Cover Texts, you must enclose | |
5517 | the copies in covers that carry, clearly and legibly, all these Cover | |
5518 | Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on | |
5519 | the back cover. Both covers must also clearly and legibly identify | |
5520 | you as the publisher of these copies. The front cover must present | |
5521 | the full title with all words of the title equally prominent and | |
5522 | visible. You may add other material on the covers in addition. | |
5523 | Copying with changes limited to the covers, as long as they preserve | |
5524 | the title of the Document and satisfy these conditions, can be treated | |
5525 | as verbatim copying in other respects. | |
5526 | ||
5527 | If the required texts for either cover are too voluminous to fit | |
5528 | legibly, you should put the first ones listed (as many as fit | |
5529 | reasonably) on the actual cover, and continue the rest onto adjacent | |
5530 | pages. | |
5531 | ||
5532 | If you publish or distribute Opaque copies of the Document numbering | |
5533 | more than 100, you must either include a machine-readable Transparent | |
5534 | copy along with each Opaque copy, or state in or with each Opaque copy | |
5535 | a publicly-accessible computer-network location containing a complete | |
5536 | Transparent copy of the Document, free of added material, which the | |
5537 | general network-using public has access to download anonymously at no | |
5538 | charge using public-standard network protocols. If you use the latter | |
5539 | option, you must take reasonably prudent steps, when you begin | |
5540 | distribution of Opaque copies in quantity, to ensure that this | |
5541 | Transparent copy will remain thus accessible at the stated location | |
5542 | until at least one year after the last time you distribute an Opaque | |
5543 | copy (directly or through your agents or retailers) of that edition to | |
5544 | the public. | |
5545 | ||
5546 | It is requested, but not required, that you contact the authors of the | |
5547 | Document well before redistributing any large number of copies, to give | |
5548 | them a chance to provide you with an updated version of the Document. | |
5549 | ||
5550 | ||
5551 | 4. MODIFICATIONS | |
5552 | ||
5553 | You may copy and distribute a Modified Version of the Document under | |
5554 | the conditions of sections 2 and 3 above, provided that you release | |
5555 | the Modified Version under precisely this License, with the Modified | |
5556 | Version filling the role of the Document, thus licensing distribution | |
5557 | and modification of the Modified Version to whoever possesses a copy | |
5558 | of it. In addition, you must do these things in the Modified Version: | |
5559 | ||
5560 | A. Use in the Title Page (and on the covers, if any) a title distinct | |
5561 | from that of the Document, and from those of previous versions | |
5562 | (which should, if there were any, be listed in the History section | |
5563 | of the Document). You may use the same title as a previous version | |
5564 | if the original publisher of that version gives permission. | |
5565 | B. List on the Title Page, as authors, one or more persons or entities | |
5566 | responsible for authorship of the modifications in the Modified | |
5567 | Version, together with at least five of the principal authors of the | |
5568 | Document (all of its principal authors, if it has less than five). | |
5569 | C. State on the Title page the name of the publisher of the | |
5570 | Modified Version, as the publisher. | |
5571 | D. Preserve all the copyright notices of the Document. | |
5572 | E. Add an appropriate copyright notice for your modifications | |
5573 | adjacent to the other copyright notices. | |
5574 | F. Include, immediately after the copyright notices, a license notice | |
5575 | giving the public permission to use the Modified Version under the | |
5576 | terms of this License, in the form shown in the Addendum below. | |
5577 | G. Preserve in that license notice the full lists of Invariant Sections | |
5578 | and required Cover Texts given in the Document's license notice. | |
5579 | H. Include an unaltered copy of this License. | |
5580 | I. Preserve the section entitled "History", and its title, and add to | |
5581 | it an item stating at least the title, year, new authors, and | |
5582 | publisher of the Modified Version as given on the Title Page. If | |
5583 | there is no section entitled "History" in the Document, create one | |
5584 | stating the title, year, authors, and publisher of the Document as | |
5585 | given on its Title Page, then add an item describing the Modified | |
5586 | Version as stated in the previous sentence. | |
5587 | J. Preserve the network location, if any, given in the Document for | |
5588 | public access to a Transparent copy of the Document, and likewise | |
5589 | the network locations given in the Document for previous versions | |
5590 | it was based on. These may be placed in the "History" section. | |
5591 | You may omit a network location for a work that was published at | |
5592 | least four years before the Document itself, or if the original | |
5593 | publisher of the version it refers to gives permission. | |
5594 | K. In any section entitled "Acknowledgements" or "Dedications", | |
5595 | preserve the section's title, and preserve in the section all the | |
5596 | substance and tone of each of the contributor acknowledgements | |
5597 | and/or dedications given therein. | |
5598 | L. Preserve all the Invariant Sections of the Document, | |
5599 | unaltered in their text and in their titles. Section numbers | |
5600 | or the equivalent are not considered part of the section titles. | |
5601 | M. Delete any section entitled "Endorsements". Such a section | |
5602 | may not be included in the Modified Version. | |
5603 | N. Do not retitle any existing section as "Endorsements" | |
5604 | or to conflict in title with any Invariant Section. | |
5605 | ||
5606 | If the Modified Version includes new front-matter sections or | |
5607 | appendices that qualify as Secondary Sections and contain no material | |
5608 | copied from the Document, you may at your option designate some or all | |
5609 | of these sections as invariant. To do this, add their titles to the | |
5610 | list of Invariant Sections in the Modified Version's license notice. | |
5611 | These titles must be distinct from any other section titles. | |
5612 | ||
5613 | You may add a section entitled "Endorsements", provided it contains | |
5614 | nothing but endorsements of your Modified Version by various | |
5615 | parties--for example, statements of peer review or that the text has | |
5616 | been approved by an organization as the authoritative definition of a | |
5617 | standard. | |
5618 | ||
5619 | You may add a passage of up to five words as a Front-Cover Text, and a | |
5620 | passage of up to 25 words as a Back-Cover Text, to the end of the list | |
5621 | of Cover Texts in the Modified Version. Only one passage of | |
5622 | Front-Cover Text and one of Back-Cover Text may be added by (or | |
5623 | through arrangements made by) any one entity. If the Document already | |
5624 | includes a cover text for the same cover, previously added by you or | |
5625 | by arrangement made by the same entity you are acting on behalf of, | |
5626 | you may not add another; but you may replace the old one, on explicit | |
5627 | permission from the previous publisher that added the old one. | |
5628 | ||
5629 | The author(s) and publisher(s) of the Document do not by this License | |
5630 | give permission to use their names for publicity for or to assert or | |
5631 | imply endorsement of any Modified Version. | |
5632 | ||
5633 | ||
5634 | 5. COMBINING DOCUMENTS | |
5635 | ||
5636 | You may combine the Document with other documents released under this | |
5637 | License, under the terms defined in section 4 above for modified | |
5638 | versions, provided that you include in the combination all of the | |
5639 | Invariant Sections of all of the original documents, unmodified, and | |
5640 | list them all as Invariant Sections of your combined work in its | |
5641 | license notice. | |
5642 | ||
5643 | The combined work need only contain one copy of this License, and | |
5644 | multiple identical Invariant Sections may be replaced with a single | |
5645 | copy. If there are multiple Invariant Sections with the same name but | |
5646 | different contents, make the title of each such section unique by | |
5647 | adding at the end of it, in parentheses, the name of the original | |
5648 | author or publisher of that section if known, or else a unique number. | |
5649 | Make the same adjustment to the section titles in the list of | |
5650 | Invariant Sections in the license notice of the combined work. | |
5651 | ||
5652 | In the combination, you must combine any sections entitled "History" | |
5653 | in the various original documents, forming one section entitled | |
5654 | "History"; likewise combine any sections entitled "Acknowledgements", | |
5655 | and any sections entitled "Dedications". You must delete all sections | |
5656 | entitled "Endorsements." | |
5657 | ||
5658 | ||
5659 | 6. COLLECTIONS OF DOCUMENTS | |
5660 | ||
5661 | You may make a collection consisting of the Document and other documents | |
5662 | released under this License, and replace the individual copies of this | |
5663 | License in the various documents with a single copy that is included in | |
5664 | the collection, provided that you follow the rules of this License for | |
5665 | verbatim copying of each of the documents in all other respects. | |
5666 | ||
5667 | You may extract a single document from such a collection, and distribute | |
5668 | it individually under this License, provided you insert a copy of this | |
5669 | License into the extracted document, and follow this License in all | |
5670 | other respects regarding verbatim copying of that document. | |
5671 | ||
5672 | ||
5673 | 7. AGGREGATION WITH INDEPENDENT WORKS | |
5674 | ||
5675 | A compilation of the Document or its derivatives with other separate | |
5676 | and independent documents or works, in or on a volume of a storage or | |
5677 | distribution medium, does not as a whole count as a Modified Version | |
5678 | of the Document, provided no compilation copyright is claimed for the | |
5679 | compilation. Such a compilation is called an "aggregate", and this | |
5680 | License does not apply to the other self-contained works thus compiled | |
5681 | with the Document, on account of their being thus compiled, if they | |
5682 | are not themselves derivative works of the Document. | |
5683 | ||
5684 | If the Cover Text requirement of section 3 is applicable to these | |
5685 | copies of the Document, then if the Document is less than one quarter | |
5686 | of the entire aggregate, the Document's Cover Texts may be placed on | |
5687 | covers that surround only the Document within the aggregate. | |
5688 | Otherwise they must appear on covers around the whole aggregate. | |
5689 | ||
5690 | ||
5691 | 8. TRANSLATION | |
5692 | ||
5693 | Translation is considered a kind of modification, so you may | |
5694 | distribute translations of the Document under the terms of section 4. | |
5695 | Replacing Invariant Sections with translations requires special | |
5696 | permission from their copyright holders, but you may include | |
5697 | translations of some or all Invariant Sections in addition to the | |
5698 | original versions of these Invariant Sections. You may include a | |
5699 | translation of this License provided that you also include the | |
5700 | original English version of this License. In case of a disagreement | |
5701 | between the translation and the original English version of this | |
5702 | License, the original English version will prevail. | |
5703 | ||
5704 | ||
5705 | 9. TERMINATION | |
5706 | ||
5707 | You may not copy, modify, sublicense, or distribute the Document except | |
5708 | as expressly provided for under this License. Any other attempt to | |
5709 | copy, modify, sublicense or distribute the Document is void, and will | |
5710 | automatically terminate your rights under this License. However, | |
5711 | parties who have received copies, or rights, from you under this | |
5712 | License will not have their licenses terminated so long as such | |
5713 | parties remain in full compliance. | |
5714 | ||
5715 | ||
5716 | 10. FUTURE REVISIONS OF THIS LICENSE | |
5717 | ||
5718 | The Free Software Foundation may publish new, revised versions | |
5719 | of the GNU Free Documentation License from time to time. Such new | |
5720 | versions will be similar in spirit to the present version, but may | |
5721 | differ in detail to address new problems or concerns. See | |
5722 | http://www.gnu.org/copyleft/. | |
5723 | ||
5724 | Each version of the License is given a distinguishing version number. | |
5725 | If the Document specifies that a particular numbered version of this | |
5726 | License "or any later version" applies to it, you have the option of | |
5727 | following the terms and conditions either of that specified version or | |
5728 | of any later version that has been published (not as a draft) by the | |
5729 | Free Software Foundation. If the Document does not specify a version | |
5730 | number of this License, you may choose any version ever published (not | |
5731 | as a draft) by the Free Software Foundation. | |
5732 | ||
5733 | ||
5734 | ADDENDUM: How to use this License for your documents | |
5735 | ||
5736 | To use this License in a document you have written, include a copy of | |
5737 | the License in the document and put the following copyright and | |
5738 | license notices just after the title page: | |
5739 | ||
5740 | @smallexample | |
5741 | Copyright (c) YEAR YOUR NAME. | |
5742 | Permission is granted to copy, distribute and/or modify this document | |
5743 | under the terms of the GNU Free Documentation License, Version 1.1 | |
5744 | or any later version published by the Free Software Foundation; | |
5745 | with the Invariant Sections being LIST THEIR TITLES, with the | |
5746 | Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. | |
5747 | A copy of the license is included in the section entitled "GNU | |
5748 | Free Documentation License". | |
5749 | @end smallexample | |
5750 | ||
5751 | If you have no Invariant Sections, write "with no Invariant Sections" | |
5752 | instead of saying which ones are invariant. If you have no | |
5753 | Front-Cover Texts, write "no Front-Cover Texts" instead of | |
5754 | "Front-Cover Texts being LIST"; likewise for Back-Cover Texts. | |
5755 | ||
5756 | If your document contains nontrivial examples of program code, we | |
5757 | recommend releasing these examples in parallel under your choice of | |
5758 | free software license, such as the GNU General Public License, | |
5759 | to permit their use in free software. | |
5760 | ||
252b5132 RH |
5761 | @node Index |
5762 | @unnumbered Index | |
5763 | ||
5764 | @printindex cp | |
5765 | ||
5766 | @tex | |
5767 | % I think something like @colophon should be in texinfo. In the | |
5768 | % meantime: | |
5769 | \long\def\colophon{\hbox to0pt{}\vfill | |
5770 | \centerline{The body of this manual is set in} | |
5771 | \centerline{\fontname\tenrm,} | |
5772 | \centerline{with headings in {\bf\fontname\tenbf}} | |
5773 | \centerline{and examples in {\tt\fontname\tentt}.} | |
5774 | \centerline{{\it\fontname\tenit\/} and} | |
5775 | \centerline{{\sl\fontname\tensl\/}} | |
5776 | \centerline{are used for emphasis.}\vfill} | |
5777 | \page\colophon | |
5778 | % Blame: doc@cygnus.com, 28mar91. | |
5779 | @end tex | |
5780 | ||
5781 | ||
5782 | @contents | |
5783 | @bye |