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