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