* config/ho-irix.h: New file; if not gcc, define BROKEN_ASSERT.
[deliverable/binutils-gdb.git] / ld / ld.texinfo
1 \input texinfo
2 @setfilename ld.info
3 @syncodeindex ky cp
4 @smallbook
5 @c @cropmarks
6
7 @ifinfo
8 @format
9 START-INFO-DIR-ENTRY
10 * Ld: (ld). The GNU linker.
11 END-INFO-DIR-ENTRY
12 @end format
13 @end ifinfo
14
15 @ifinfo
16 This file documents the GNU linker LD.
17
18 Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
19
20 Permission is granted to make and distribute verbatim copies of
21 this manual provided the copyright notice and this permission notice
22 are preserved on all copies.
23
24 Permission is granted to copy and distribute modified versions of this
25 manual under the conditions for verbatim copying, provided also that
26 the entire resulting derived work is distributed under the terms of a
27 permission notice identical to this one.
28
29 Permission is granted to copy and distribute translations of this manual
30 into another language, under the above conditions for modified versions.
31
32 @ignore
33 Permission is granted to process this file through Tex and print the
34 results, provided the printed document carries copying permission
35 notice identical to this one except for the removal of this paragraph
36 (this paragraph not being relevant to the printed manual).
37
38 @end ignore
39 @end ifinfo
40 @iftex
41 @finalout
42 @setchapternewpage odd
43 @settitle Using LD, the GNU linker
44 @titlepage
45 @title Using ld
46 @subtitle The GNU linker
47 @sp 1
48 @subtitle @code{ld} version 2
49 @subtitle March 1993
50 @author Steve Chamberlain and Roland Pesch
51 @author Cygnus Support
52 @page
53
54 @tex
55 \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
56 \xdef\manvers{\$Revision$} % For use in headers, footers too
57 {\parskip=0pt
58 \hfill Cygnus Support\par
59 \hfill steve\@cygnus.com, pesch\@cygnus.com\par
60 \hfill {\it Using LD, the GNU linker}, \manvers\par
61 \hfill \TeX{}info \texinfoversion\par
62 }
63 \global\parindent=0pt % Steve likes it this way.
64 @end tex
65 Edited by Jeffrey Osier (@code{jeffrey@@cygnus.com}), March 1993.
66
67 @vskip 0pt plus 1filll
68 Copyright @copyright{} 1991, 1992, 1993 Free Software Foundation, Inc.
69
70 Permission is granted to make and distribute verbatim copies of
71 this manual provided the copyright notice and this permission notice
72 are preserved on all copies.
73
74 Permission is granted to copy and distribute modified versions of this
75 manual under the conditions for verbatim copying, provided also that
76 the entire resulting derived work is distributed under the terms of a
77 permission notice identical to this one.
78
79 Permission is granted to copy and distribute translations of this manual
80 into another language, under the above conditions for modified versions.
81 @end titlepage
82 @end iftex
83 @c FIXME: Talk about importance of *order* of args, cmds to linker!
84
85 @node Top, Overview, (dir), (dir)
86 @ifinfo
87 This file documents the GNU linker ld.
88 @end ifinfo
89
90 @menu
91 * Overview:: Overview
92 * Invocation:: Invocation
93 * Commands:: Command Language
94 * Machine Dependent:: Machine Dependent Features
95 * BFD:: BFD
96 * MRI:: MRI Compatible Script Files
97 * Index:: Index
98
99 --- The Detailed Node Listing ---
100
101 Invocation
102
103 * Options:: Command Line Options
104 * Environment:: Environment Variables
105
106 Command Language
107
108 * Scripts:: Linker Scripts
109 * Expressions:: Expressions
110 * MEMORY:: MEMORY Command
111 * SECTIONS:: SECTIONS Command
112 * Entry Point:: The Entry Point
113 * Other Commands:: Other Commands
114
115 Expressions
116
117 * Integers:: Integers
118 * Symbols:: Symbol Names
119 * Location Counter:: The Location Counter
120 * Operators:: Operators
121 * Evaluation:: Evaluation
122 * Assignment:: Assignment: Defining Symbols
123 * Built-ins:: Built-In Functions
124
125 SECTIONS Command
126
127 * Section Definition:: Section Definitions
128 * Section Contents:: Section Contents
129 * Section Options:: Optional Section Attributes
130
131 Machine Dependent Features
132
133 * H8/300:: @code{ld} and the H8/300
134 * i960:: @code{ld} and the Intel 960 family
135
136 BFD
137
138 * BFD outline:: How it works: an outline of BFD
139 * BFD information loss:: Information Loss
140 * Mechanism:: Mechanism
141 @end menu
142
143 @node Overview, Invocation, Top, Top
144 @chapter Overview
145
146 @cindex GNU linker
147 @cindex what is this?
148 @code{ld} combines a number of object and archive files, relocates
149 their data and ties up symbol references. Often the last step in
150 building a new compiled program to run is a call to @code{ld}.
151
152 @code{ld} accepts Linker Command Language files written in
153 a superset of AT&T's Link Editor Command Language syntax,
154 to provide explicit and total control over the linking process.
155
156 This version of @code{ld} uses the general purpose BFD libraries
157 to operate on object files. This allows @code{ld} to read, combine, and
158 write object files in many different formats---for example, COFF or
159 @code{a.out}. Different formats may be linked together to produce any
160 available kind of object file. @xref{BFD} for a list of formats
161 supported on various architectures.
162
163 Aside from its flexibility, the GNU linker is more helpful than other
164 linkers in providing diagnostic information. Many linkers abandon
165 execution immediately upon encountering an error; whenever possible,
166 @code{ld} continues executing, allowing you to identify other errors
167 (or, in some cases, to get an output file in spite of the error).
168
169 @node Invocation, Commands, Overview, Top
170 @chapter Invocation
171
172 The GNU linker @code{ld} is meant to cover a broad range of situations,
173 and to be as compatible as possible with other linkers. As a result,
174 you have many choices to control its behavior through the command line,
175 and through environment variables.
176
177 @menu
178 * Options:: Command Line Options
179 * Environment:: Environment Variables
180 @end menu
181
182 @node Options, Environment, Invocation, Invocation
183 @section Command Line Options
184
185 @cindex command line
186 @cindex options
187 Here is a sketch of the options you can use on the @code{ld} command
188 line:
189
190 @smallexample
191 ld [-o @var{output} ] @var{objfiles}@dots{}
192 [ -A@var{architecture} ] [ -b @var{input-format} ] [ -Bstatic ]
193 [ -c @var{MRI-commandfile} ] [ -d | -dc | -dp ]
194 [ -defsym @var{symbol}=@var{expression} ]
195 [ -e @var{entry} ] [ -F ] [ -F @var{format} ]
196 [ -format @var{input-format} ] [ -g ] [ -i ]
197 [ -l@var{ar} ] [ -L@var{searchdir} ] [ -M | -m ]
198 [ -n | -N ] [ -noinhibit-exec ] [ -R @var{filename} ]
199 [ -relax ] [ -r | -Ur ] [ -S ] [ -s ] [ -T @var{commandfile} ]
200 [ -Ttext @var{textorg} ] [ -Tdata @var{dataorg} ] [ -Tbss @var{bssorg} ]
201 [ -t ] [ -u @var{sym}] [-v] [ -X ] [ -x ] [ -y@var{symbol} ]
202 [ @{ @var{script} @} ]
203 @end smallexample
204
205 This plethora of command-line options may seem intimidating, but in
206 actual practice few of them are used in any particular context.
207 @cindex standard Unix system
208 For instance, a frequent use of @code{ld} is to link standard Unix
209 object files on a standard, supported Unix system. On such a system, to
210 link a file @code{hello.o}:
211 @example
212 $ ld -o @var{output} /lib/crt0.o hello.o -lc
213 @end example
214 This tells @code{ld} to produce a file called @var{output} as the
215 result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
216 the library @code{libc.a} which will come from the standard search
217 directories. (See the discussion of the @samp{-l} flag below.)
218
219 The command-line options to @code{ld} may be specified in any order, and
220 may be repeated at will. For the most part, repeating an option with a
221 different argument will either have no further effect, or override prior
222 occurrences (those further to the left on the command line) of an
223 option.
224
225 The exceptions---which may meaningfully be used more than once---are
226 @code{-A}, @code{-b} (or its synonym @code{-format}), @code{-defsym},
227 @code{-L}, @code{-l}, @code{-R}, and @code{-u}.
228
229 @cindex object files
230 The list of object files to be linked together, shown as @var{objfiles},
231 may follow, precede, or be mixed in with command-line options; save that
232 an @var{objfiles} argument may not be placed between an option flag and
233 its argument.
234
235 Usually the linker is invoked with at least one object file, but other
236 forms of binary input files can also be specified with @code{-l},
237 @code{-R}, and the script command language. If @emph{no} binary input
238 files at all are specified, the linker does not produce any output, and
239 issues the message @samp{No input files}.
240
241 Option arguments must either follow the option letter without intervening
242 whitespace, or be given as separate arguments immediately following the
243 option that requires them.
244
245 @table @code
246 @item @var{objfiles}@dots{}
247 The object files @var{objfiles} to be linked.
248
249 @cindex architectures
250 @kindex -A@var{arch}
251 @item -A@var{architecture}
252 In the current release of @code{ld}, this option is useful only for the
253 Intel 960 family of architectures. In that @code{ld} configuration, the
254 @var{architecture} argument identifies the particular architecture in
255 the 960 family, enabling some safeguards and modifying the
256 archive-library search path. @xref{i960,,@code{ld} and the Intel 960
257 family}, for details.
258
259 Future releases of @code{ld} may support similar functionality for
260 other architecture families.
261
262 @cindex binary input format
263 @kindex -b @var{format}
264 @cindex input format
265 @item -b @var{input-format}
266 @cindex input format
267 Specify the binary format for input object files that follow this option
268 on the command line. You don't usually need to specify this, as
269 @code{ld} is configured to expect as a default input format the most
270 usual format on each machine. @var{input-format} is a text string, the
271 name of a particular format supported by the BFD libraries.
272 @w{@code{-format @var{input-format}}} has the same effect. @xref{BFD}.
273
274 You may want to use this option if you are linking files with an unusual
275 binary format. You can also use @code{-b} to switch formats explicitly (when
276 linking object files of different formats), by including
277 @code{-b @var{input-format}} before each group of object files in a
278 particular format.
279
280 The default format is taken from the environment variable
281 @code{GNUTARGET}. @xref{Environment}. You can also define the input
282 format from a script, using the command @code{TARGET}; see @ref{Other
283 Commands}.
284
285 @kindex -Bstatic
286 @item -Bstatic
287 This flag is accepted for command-line compatibility with the SunOS linker,
288 but has no effect on @code{ld}.
289
290 @kindex -c @var{MRI-cmdfile}
291 @cindex compatibility, MRI
292 @item -c @var{MRI-commandfile}
293 For compatibility with linkers produced by MRI, @code{ld} accepts script
294 files written in an alternate, restricted command language, described in
295 @ref{MRI,,MRI Compatible Script Files}. Introduce MRI script files with
296 the option flag @samp{-c}; use the @samp{-T} option to run linker
297 scripts written in the general-purpose @code{ld} scripting language.
298
299 @cindex common allocation
300 @kindex -d
301 @item -d
302 @kindex -dc
303 @itemx -dc
304 @kindex -dp
305 @itemx -dp
306 These three options are equivalent; multiple forms are supported for
307 compatibility with other linkers. Use any of them to make @code{ld}
308 assign space to common symbols even if a relocatable output file is
309 specified (@code{-r}). The script command
310 @code{FORCE_COMMON_ALLOCATION} has the same effect. @xref{Other
311 Commands}.
312
313 @cindex symbols, from command line
314 @kindex -defsym @var{symbol}=@var{exp}
315 @item -defsym @var{symbol}=@var{expression}
316 Create a global symbol in the output file, containing the absolute
317 address given by @var{expression}. You may use this option as many
318 times as necessary to define multiple symbols in the command line. A
319 limited form of arithmetic is supported for the @var{expression} in this
320 context: you may give a hexadecimal constant or the name of an existing
321 symbol, or use @code{+} and @code{-} to add or subtract hexadecimal
322 constants or symbols. If you need more elaborate expressions, consider
323 using the linker command language from a script (@pxref{Assignment, ,
324 Assignment: Symbol Definitions}). @emph{Note:} there should be no
325 white space between @var{symbol}, the equals sign (``@key{=}''), and
326 @var{expression}.
327
328 @cindex entry point, from command line
329 @kindex -e @var{entry}
330 @item -e @var{entry}
331 Use @var{entry} as the explicit symbol for beginning execution of your
332 program, rather than the default entry point. @xref{Entry Point}, for a
333 discussion of defaults and other ways of specifying the
334 entry point.
335
336 @ignore
337 @cindex fill, from command line
338 @kindex -f @var{fill}
339 @c -f in older GNU linker, not in new
340 @item -f @var{fill}
341 Sets the default fill pattern for ``holes'' in the output file to
342 the lowest two bytes of the expression specified. Holes are created
343 when you advance the location counter (@xref{Location Counter}), or when
344 there is a gap between explicitly specified section addresses
345 (@xref{Section Options}).
346 @end ignore
347
348 @kindex -F
349 @item -F
350 @itemx -F@var{format}
351 Some older linkers used this option throughout a compilation toolchain
352 for specifying object-file format for both input and output object
353 files. The mechanisms @code{ld} uses for this purpose (the @code{-b} or
354 @code{-format} options for input files, the @code{TARGET} command in
355 linker scripts for output files, the @code{GNUTARGET} environment
356 variable) are more flexible, but @code{ld} accepts (and ignores) the
357 @code{-F} option flag for compatibility with scripts written to call the
358 old linker.
359
360 @kindex -format
361 @item -format @var{input-format}
362 Synonym for @code{-b} @var{input-format}.
363
364 @kindex -g
365 @item -g
366 Accepted, but ignored; provided for compatibility with other tools.
367
368 @kindex -i
369 @cindex incremental link
370 @item -i
371 Perform an incremental link (same as option @code{-r}).
372
373
374 @cindex archive files, from cmd line
375 @kindex -l@var{ar}
376 @item -l@var{ar}
377 Add an archive file @var{ar} to the list of files to link. This
378 option may be used any number of times. @code{ld} will search its
379 path-list for occurrences of @code{lib@var{ar}.a} for every @var{ar}
380 specified.
381
382 @cindex search directory, from cmd line
383 @kindex -L@var{dir}
384 @item -L@var{searchdir}
385 This command adds path @var{searchdir} to the list of paths that
386 @code{ld} will search for archive libraries. You may use this option
387 any number of times.
388
389 The default set of paths searched (without being specified with
390 @code{-L}) depends on what emulation mode @code{ld} is using, and in
391 some cases also on how it was configured. @xref{Environment}. The
392 paths can also be specified in a link script with the @code{SEARCH_DIR}
393 command.
394
395 @cindex link map
396 @kindex -M
397 @item -M
398 @kindex -m
399 @itemx -m
400 Print (to the standard output file) a link map---diagnostic information
401 about where symbols are mapped by @code{ld}, and information on global
402 common storage allocation.
403
404 @kindex -N
405 @cindex read/write from cmd line
406 @kindex OMAGIC
407 @item -N
408 Specifies readable and writable @code{text} and @code{data} sections. If
409 the output format supports Unix style magic numbers, the output is
410 marked as @code{OMAGIC}.
411
412 When you use the @samp{-N} option, the linker does not page-align the
413 data segment.
414
415 @item -n
416 @kindex -n
417 @cindex read-only text
418 @kindex NMAGIC
419 Sets the text segment to be read only, and @code{NMAGIC} is written
420 if possible.
421
422 @item -noinhibit-exec
423 @cindex output file after errors
424 @kindex -noinhibit-exec
425 Normally, the linker will not produce an output file if it encounters
426 errors during the link process. With this flag, you can specify that
427 you wish the output file retained whenever the executable output file is
428 still usable. (Otherwise, @code{ld} exits without writing an output
429 file when it issues any error whatsoever.)
430
431 @item -o @var{output}
432 @kindex -o @var{output}
433 @cindex naming the output file
434 @var{output} is a name for the program produced by @code{ld}; if this
435 option is not specified, the name @samp{a.out} is used by default. The
436 script command @code{OUTPUT} can also specify the output file name.
437
438 @item -R @var{filename}
439 @kindex -R @var{file}
440 @cindex symbol-only input
441 Read symbol names and their addresses from @var{filename}, but do not
442 relocate it or include it in the output. This allows your output file
443 to refer symbolically to absolute locations of memory defined in other
444 programs.
445
446 @item -relax
447 @kindex -relax
448 @cindex synthesizing linker
449 @cindex relaxing addressing modes
450 An option with machine dependent effects. Currently this option is only
451 supported on the H8/300; see @ref{H8/300,,@code{ld} and the H8/300}.
452
453 On some platforms, use this option to perform global optimizations that
454 become possible when the linker resolves addressing in your program, such
455 as relaxing address modes and synthesizing new instructions in the
456 output object file.
457
458 On platforms where this is not supported, @samp{-relax} is accepted, but
459 has no effect.
460
461 @item -r
462 @cindex partial link
463 @cindex relocatable output
464 @kindex -r
465 Generates relocatable output---i.e., generate an output file that can in
466 turn serve as input to @code{ld}. This is often called @dfn{partial
467 linking}. As a side effect, in environments that support standard Unix
468 magic numbers, this option also sets the output file's magic number to
469 @code{OMAGIC}.
470 @c ; see @code{-N}.
471 If this option is not specified, an absolute file is produced. When
472 linking C++ programs, this option @emph{will not} resolve references to
473 constructors; @code{-Ur} is an alternative. @refill
474
475 This option does the same as @code{-i}.
476
477 @item -S
478 @kindex -S
479 @cindex strip debugger symbols
480 Omits debugger symbol information (but not all symbols) from the output file.
481
482 @item -s
483 @kindex -s
484 @cindex strip all symbols
485 Omits all symbol information from the output file.
486
487 @item @{ @var{script} @}
488 @kindex @{ @var{script} @}
489 @cindex scripts on command line
490 You can, if you wish, include a script of linker commands directly in
491 the command line instead of referring to it via an input file. When the
492 character @samp{@{} occurs on the command line, the linker switches to
493 interpreting the command language until the end of the list of commands
494 is reached; the end is indicated with a closing brace @samp{@}}.
495 @code{ld} does not recognize other command-line options while parsing
496 the script. @xref{Commands}, for a description of the command language.
497
498 @item -Tbss @var{bssorg}
499 @kindex -Tbss @var{bssorg}
500 @itemx -Tdata @var{dataorg}
501 @kindex -Tdata @var{dataorg}
502 @itemx -Ttext @var{textorg}
503 @kindex -Ttext @var{textorg}
504 @cindex segment origins, cmd line
505 Use @var{org} as the starting address for---respectively---the
506 @code{bss}, @code{data}, or the @code{text} segment of the output file.
507 Any @var{org} value must be a single hexadecimal integer; in this case
508 (for compatibility with other linkers), you may omit the leading
509 @samp{0x} usually associated with hexadecimal values.
510
511 @item -T @var{commandfile}
512 @itemx -T@var{commandfile}
513 @kindex -T @var{script}
514 @cindex script files
515 Directs @code{ld} to read link commands from the file
516 @var{commandfile}. These commands will completely override @code{ld}'s
517 default link format (rather than adding to it); @var{commandfile} must
518 specify everything necessary to describe the target format.
519 @xref{Commands}.
520
521 You may also include a script of link commands directly in the command
522 line by bracketing it between @samp{@{} and @samp{@}}.
523
524 @item -t
525 @kindex -t
526 @cindex verbose
527 @cindex input files, displaying
528 Prints names of input files as @code{ld} processes them.
529
530 @item -u @var{sym}
531 @kindex -u @var{sym}
532 @cindex undefined symbol
533 Forces @var{sym} to be entered in the output file as an undefined symbol.
534 This may, for example, trigger linking of additional modules from
535 standard libraries. @code{-u} may be repeated with different option
536 arguments to enter additional undefined symbols.
537 @c Nice idea, but no such command: This option is equivalent
538 @c to the @code{EXTERN} linker command.
539
540 @item -Ur
541 @kindex -Ur
542 @cindex constructors
543 For anything other than C++ programs, this option is equivalent to
544 @code{-r}: it generates relocatable output---i.e., an output file that can in
545 turn serve as input to @code{ld}. When linking C++ programs, @code{-Ur}
546 @emph{will} resolve references to constructors, unlike @code{-r}.
547
548 @item -v
549 @kindex -v
550 @cindex version
551 Display the version number for @code{ld}.
552
553 @item -X
554 @kindex -X
555 @cindex local symbols, deleting
556 @cindex L, deleting symbols beginning
557 If @code{-s} or @code{-S} is also specified, delete only local symbols
558 beginning with @samp{L}.
559
560 @item -x
561 @kindex -x
562 @cindex deleting local symbols
563 If @code{-s} or @code{-S} is also specified, delete all local symbols,
564 not just those beginning with @samp{L}.
565
566 @item -y
567 @kindex -y@var{symbol}
568 @cindex symbol tracing
569 Prints the name of each linked file in which @var{symbol} appears. The
570 option may be given any number of times. On many systems it is necessary
571 to prepend an underscore.
572
573 This option is useful when you have an undefined symbol in your link but
574 don't know where the reference is coming from.
575
576 @ignore
577 @c -z in older GNU linker, not in new
578 @item -z
579 @kindex -z
580 @cindex read-only text
581 Specifies a read-only, demand pageable, and shared @code{text} segment.
582 If the output format supports Unix-style magic numbers, @code{-z} also
583 marks the output as @code{ZMAGIC}, the default.
584
585 @c why was following here?. Is it useful to say '-z -r' for
586 @c instance, or is this just a ref to other ways of setting
587 @c magic no?
588 Specifying a relocatable output file (@code{-r}) will also set the magic
589 number to @code{OMAGIC}.
590
591 See description of @code{-N}.
592 @end ignore
593
594 @end table
595
596 @node Environment, , Options, Invocation
597 @section Environment Variables
598
599 You can change the behavior of @code{ld} with the environment
600 variable @code{GNUTARGET}.
601 @ignore
602 and @code{LDEMULATION}. Depending on the
603 setting of the latter, other environment variables may be used as well.
604 @end ignore
605
606 @kindex GNUTARGET
607 @cindex default input format
608 @code{GNUTARGET} determines the input-file object format if you don't
609 use @code{-b} (or its synonym @code{-format}). Its value should be one
610 of the BFD names for an input format (@pxref{BFD}). If there is no
611 @code{GNUTARGET} in the environment, @code{ld} uses the natural format
612 of the host. If @code{GNUTARGET} is set to @code{default} then BFD attempts to discover the
613 input format by examining binary input files; this method often
614 succeeds, but there are potential ambiguities, since there is no method
615 of ensuring that the magic number used to flag object-file formats is
616 unique. However, the configuration procedure for BFD on each system
617 places the conventional format for that system first in the search-list,
618 so ambiguities are resolved in favor of convention.
619
620 @ignore
621 @kindex LDEMULATION
622 @cindex emulation
623 @cindex environment vars
624 @code{LDEMULATION} controls some aspects of @code{ld}'s dominant
625 personality. Although @code{ld} is flexible enough to permit its use
626 in many contexts regardless of configuration, you can use this variable
627 to make it act more like one or another older linker by default.
628
629 @cindex defaults
630 @cindex library paths, default
631 In particular, the value of @code{LDEMULATION} controls what default
632 linker script is used (thereby controlling the default input and output
633 formats; @pxref{BFD}); what default paths are searched for
634 archive libraries; and in some cases whether additional linker script
635 commands are available.
636
637 Here is the current set of emulations available:
638 @table @code
639
640 @item LDEMULATION=gld
641 @kindex gld
642 @cindex emulating old GNU linker
643 Emulate the older GNU linker. When this emulation is selected, the
644 default library search paths are
645 @example
646 /lib
647 /usr/lib
648 /usr/local/lib/lib
649 @end example
650 @noindent
651 The default output format is set to @code{a.out-generic-big}, and the
652 default machine is the system's configured BFD default.
653
654 @item LDEMULATION=gld68k
655 @kindex gld68k
656 @cindex m68k
657 A variant of the @code{gld} emulation; only differs in specifically
658 setting the default BFD machine as @code{m68k}.
659
660 @item LDEMULATION=gld960
661 @itemx LDEMULATION=lnk960
662 Emulate older linkers for the i960 family; see @ref{i960,,@code{ld} and
663 the Intel 960 family}, for details.
664
665 @item LDEMULATION=gldm88kbcs
666 Configure the linker for the Motorola 88K family.
667 @xref{m88k,,@code{gld} and the Motorola 880x0 family}, for details.
668
669 @item LDEMULATION=vanilla
670 @kindex vanilla
671 @cindex emulation, disabling
672 @cindex disabling emulation
673 This is the least specific setting for @code{ld}. You can set
674 @code{LDEMULATION=vanilla} to disable emulation of other linkers. This
675 setting makes @code{ld} take the default machine from the BFD
676 configuration on your system; @code{a.out-generic-big} is the default
677 target. No other defaults are specified.
678 @end table
679 @end ignore
680
681 @node Commands, Machine Dependent, Invocation, Top
682 @chapter Command Language
683
684 @cindex command files
685 The command language allows explicit control over the link process,
686 allowing complete specification of the mapping between the linker's
687 input files and its output. This includes:
688 @itemize @bullet
689 @item
690 input files
691 @item
692 file formats
693 @item
694 output file format
695 @item
696 addresses of sections
697 @item
698 placement of common blocks
699 @end itemize
700
701 You may supply a command file (also known as a link script) to the
702 linker either explicitly through the @code{-T} option, or implicitly as
703 an ordinary file. If the linker opens a file which it cannot recognize
704 as a supported object or archive format, it tries to interpret the file
705 as a command file.
706
707 You can also include a script directly on the @code{ld} command line,
708 delimited by the characters @samp{@{} and @samp{@}}.
709
710 @menu
711 * Scripts:: Linker Scripts
712 * Expressions:: Expressions
713 * MEMORY:: MEMORY Command
714 * SECTIONS:: SECTIONS Command
715 * Entry Point:: The Entry Point
716 * Other Commands:: Other Commands
717 @end menu
718
719 @node Scripts, Expressions, Commands, Commands
720 @section Linker Scripts
721 The @code{ld} command language is a collection of statements; some are
722 simple keywords setting a particular flag, some are used to select and
723 group input files or name output files; and two particular statement
724 types have a fundamental and pervasive impact on the linking process.
725
726 @cindex fundamental script commands
727 @cindex commands, fundamental
728 @cindex output file layout
729 @cindex layout of output file
730 The most fundamental command of the @code{ld} command language is the
731 @code{SECTIONS} command (@pxref{SECTIONS}). Every meaningful command
732 script must have a @code{SECTIONS} command: it specifies a
733 ``picture'' of the output file's layout, in varying degrees of detail.
734 No other command is required in all cases.
735
736 The @code{MEMORY} command complements @code{SECTIONS} by describing the
737 available memory in the target architecture. This command is optional;
738 if you don't use a @code{MEMORY} command, @code{ld} assumes sufficient
739 memory is available in a contiguous block for all output.
740 @xref{MEMORY}.
741
742 @cindex comments
743 You may include comments in linker scripts just as in C: delimited
744 by @samp{/*} and @samp{*/}. As in C, comments are syntactically
745 equivalent to whitespace.
746
747 @node Expressions, MEMORY, Scripts, Commands
748 @section Expressions
749 @cindex expression syntax
750 @cindex arithmetic
751 Many useful commands involve arithmetic expressions. The syntax for
752 expressions in the command language is identical to that of C
753 expressions, with the following features:
754 @itemize @bullet
755 @item
756 All expressions evaluated as integers and
757 are of ``long'' or ``unsigned long'' type.
758 @item
759 All constants are integers.
760 @item
761 All of the C arithmetic operators are provided.
762 @item
763 You may reference, define, and create global variables.
764 @item
765 You may call special purpose built-in functions.
766 @end itemize
767
768 @menu
769 * Integers:: Integers
770 * Symbols:: Symbol Names
771 * Location Counter:: The Location Counter
772 * Operators:: Operators
773 * Evaluation:: Evaluation
774 * Assignment:: Assignment: Defining Symbols
775 * Built-ins:: Built-In Functions
776 @end menu
777
778 @node Integers, Symbols, Expressions, Expressions
779 @subsection Integers
780 @cindex integer notation
781 @cindex octal integers
782 An octal integer is @samp{0} followed by zero or more of the octal
783 digits (@samp{01234567}).
784 @example
785 _as_octal = 0157255;
786 @end example
787
788 @cindex decimal integers
789 A decimal integer starts with a non-zero digit followed by zero or
790 more digits (@samp{0123456789}).
791 @example
792 _as_decimal = 57005;
793 @end example
794
795 @cindex hexadecimal integers
796 @kindex 0x
797 A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or
798 more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}.
799 @example
800 _as_hex = 0xdead;
801 @end example
802
803 @cindex negative integers
804 Decimal integers have the usual values. To write a negative integer, use
805 the prefix operator @samp{-}; @pxref{Operators}.
806 @example
807 _as_neg = -57005;
808 @end example
809
810 @cindex scaled integers
811 @cindex K and M integer suffixes
812 @cindex M and K integer suffixes
813 @cindex suffixes for integers
814 @cindex integer suffixes
815 Additionally the suffixes @code{K} and @code{M} may be used to scale a
816 constant by
817 @c TEXI2ROFF-KILL
818 @ifinfo
819 @c END TEXI2ROFF-KILL
820 @code{1024} or @code{1024*1024}
821 @c TEXI2ROFF-KILL
822 @end ifinfo
823 @tex
824 ${\rm 1024}$ or ${\rm 1024}^2$
825 @end tex
826 @c END TEXI2ROFF-KILL
827 respectively. For example, the following all refer to the same quantity:@refill
828
829 @example
830 _fourk_1 = 4K;
831 _fourk_2 = 4096;
832 _fourk_3 = 0x1000;
833 @end example
834
835 @node Symbols, Location Counter, Integers, Expressions
836 @subsection Symbol Names
837 @cindex symbol names
838 @cindex names
839 @cindex quoted symbol names
840 @kindex "
841 Unless quoted, symbol names start with a letter, underscore, point or
842 hyphen and may include any letters, underscores, digits, points,
843 and minus signs. Unquoted symbol names must not conflict with any
844 keywords. You can specify a symbol which contains odd characters or has
845 the same name as a keyword, by surrounding the symbol name in double quotes:
846 @example
847 "SECTION" = 9;
848 "with a space" = "also with a space" + 10;
849 @end example
850
851 @node Location Counter, Operators, Symbols, Expressions
852 @subsection The Location Counter
853 @kindex .
854 @cindex dot
855 @cindex location counter
856 @cindex current output location
857 The special linker variable @dfn{dot} @samp{.} always contains the
858 current output location counter. Since the @code{.} always refers to
859 a location in an output section, it must always appear in an
860 expression within a @code{SECTIONS} command. The @code{.} symbol
861 may appear anywhere that an ordinary symbol is allowed in an
862 expression, but its assignments have a side effect. Assigning a value
863 to the @code{.} symbol will cause the location counter to be moved.
864 @cindex holes
865 This may be used to create holes in the output section. The location
866 counter may never be moved backwards.
867 @example
868 SECTIONS
869 @{
870 output :
871 @{
872 file1(.text)
873 . = . + 1000;
874 file2(.text)
875 . += 1000;
876 file3(.text)
877 @} = 0x1234;
878 @}
879 @end example
880 @noindent
881 In the previous example, @code{file1} is located at the beginning of the
882 output section, then there is a 1000 byte gap. Then @code{file2}
883 appears, also with a 1000 byte gap following before @code{file3} is
884 loaded. The notation @samp{= 0x1234} specifies what data to write in
885 the gaps (@pxref{Section Options}).
886
887 @node Operators, Evaluation, Location Counter, Expressions
888 @subsection Operators
889 @cindex Operators for arithmetic
890 @cindex arithmetic operators
891 @cindex precedence in expressions
892 The linker recognizes the standard C set of arithmetic operators, with
893 the standard bindings and precedence levels:
894 @c TEXI2ROFF-KILL
895 @ifinfo
896 @c END TEXI2ROFF-KILL
897 @example
898 precedence associativity Operators Notes
899 (highest)
900 1 left ! - ~ (1)
901 2 left * / %
902 3 left + -
903 4 left >> <<
904 5 left == != > < <= >=
905 6 left &
906 7 left |
907 8 left &&
908 9 left ||
909 10 right ? :
910 11 right &= += -= *= /= (2)
911 (lowest)
912 @end example
913 Notes:
914 (1) Prefix operators
915 (2) @xref{Assignment}
916 @c TEXI2ROFF-KILL
917 @end ifinfo
918 @tex
919 \vskip \baselineskip
920 %"lispnarrowing" is the extra indent used generally for @example
921 \hskip\lispnarrowing\vbox{\offinterlineskip
922 \hrule
923 \halign
924 {\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr
925 height2pt&\omit&&\omit&&\omit&\cr
926 &Precedence&& Associativity &&{\rm Operators}&\cr
927 height2pt&\omit&&\omit&&\omit&\cr
928 \noalign{\hrule}
929 height2pt&\omit&&\omit&&\omit&\cr
930 &highest&&&&&\cr
931 % '176 is tilde, '~' in tt font
932 &1&&left&&\qquad- \char'176\ !\qquad\dag&\cr
933 &2&&left&&* / \%&\cr
934 &3&&left&&+ -&\cr
935 &4&&left&&>> <<&\cr
936 &5&&left&&== != > < <= >=&\cr
937 &6&&left&&\&&\cr
938 &7&&left&&|&\cr
939 &8&&left&&{\&\&}&\cr
940 &9&&left&&||&\cr
941 &10&&right&&? :&\cr
942 &11&&right&&\qquad\&= += -= *= /=\qquad\ddag&\cr
943 &lowest&&&&&\cr
944 height2pt&\omit&&\omit&&\omit&\cr}
945 \hrule}
946 @end tex
947 @iftex
948 {
949 @obeylines@parskip=0pt@parindent=0pt
950 @dag@quad Prefix operators.
951 @ddag@quad @xref{Assignment}.
952 }
953 @end iftex
954 @c END TEXI2ROFF-KILL
955
956 @node Evaluation, Assignment, Operators, Expressions
957 @subsection Evaluation
958
959 @cindex lazy evaluation
960 @cindex expression evaluation order
961 The linker uses ``lazy evaluation'' for expressions; it only calculates
962 an expression when absolutely necessary. The linker needs the value of
963 the start address, and the lengths of memory regions, in order to do any
964 linking at all; these values are computed as soon as possible when the
965 linker reads in the command file. However, other values (such as symbol
966 values) are not known or needed until after storage allocation. Such
967 values are evaluated later, when other information (such as the sizes of
968 output sections) is available for use in the symbol assignment
969 expression.
970
971 @node Assignment, Built-ins, Evaluation, Expressions
972 @subsection Assignment: Defining Symbols
973 @cindex assignment in scripts
974 @cindex symbol definition, scripts
975 @cindex variables, defining
976 You may create global symbols, and assign values (addresses) to global
977 symbols, using any of the C assignment operators:
978
979 @table @code
980 @item @var{symbol} = @var{expression} ;
981 @itemx @var{symbol} &= @var{expression} ;
982 @itemx @var{symbol} += @var{expression} ;
983 @itemx @var{symbol} -= @var{expression} ;
984 @itemx @var{symbol} *= @var{expression} ;
985 @itemx @var{symbol} /= @var{expression} ;
986 @end table
987
988 Two things distinguish assignment from other operators in @code{ld}
989 expressions.
990 @itemize @bullet
991 @item
992 Assignment may only be used at the root of an expression;
993 @samp{a=b+3;} is allowed, but @samp{a+b=3;} is an error.
994
995 @kindex ;
996 @cindex semicolon
997 @item
998 You must place a trailing semicolon (``@key{;}'') at the end of an
999 assignment statement.
1000 @end itemize
1001
1002 Assignment statements may appear:
1003 @itemize @bullet
1004 @item
1005 as commands in their own right in an @code{ld} script; or
1006 @item
1007 as independent statements within a @code{SECTIONS} command; or
1008 @item
1009 as part of the contents of a section definition in a
1010 @code{SECTIONS} command.
1011 @end itemize
1012
1013 The first two cases are equivalent in effect---both define a symbol with
1014 an absolute address; the last case defines a symbol whose address is
1015 relative to a particular section (@pxref{SECTIONS}).
1016
1017 @cindex absolute and relocatable symbols
1018 @cindex relocatable and absolute symbols
1019 @cindex symbols, relocatable and absolute
1020 When a linker expression is evaluated and assigned to a variable, it is
1021 given either an absolute or a relocatable type. An absolute expression
1022 type is one in which the symbol contains the value that it will have in
1023 the output file, a relocateable expression type is one in which the
1024 value is expressed as a fixed offset from the base of a section.
1025
1026 The type of the expression is controlled by its position in the script
1027 file. A symbol assigned within a section definition is created relative
1028 to the base of the section; a symbol assigned in any other place is
1029 created as an absolute symbol. Since a symbol created within a
1030 section definition is relative to the base of the section, it
1031 will remain relocatable if relocatable output is requested. A symbol
1032 may be created with an absolute value even when assigned to within a
1033 section definition by using the absolute assignment function
1034 @code{ABSOLUTE}. For example, to create an absolute symbol whose address
1035 is the last byte of an output section named @code{.data}:
1036 @example
1037 SECTIONS@{ @dots{}
1038 .data :
1039 @{
1040 *(.data)
1041 _edata = ABSOLUTE(.) ;
1042 @}
1043 @dots{} @}
1044 @end example
1045
1046 The linker tries to put off the evaluation of an assignment until all
1047 the terms in the source expression are known (@pxref{Evaluation}). For
1048 instance the sizes of sections cannot be known until after allocation,
1049 so assignments dependent upon these are not performed until after
1050 allocation. Some expressions, such as those depending upon the location
1051 counter @dfn{dot}, @samp{.} must be evaluated during allocation. If the
1052 result of an expression is required, but the value is not available,
1053 then an error results. For example, a script like the following
1054 @example
1055 SECTIONS @{ @dots{}
1056 text 9+this_isnt_constant :
1057 @{ @dots{}
1058 @}
1059 @dots{} @}
1060 @end example
1061 @kindex Non constant expression
1062 @noindent
1063 will cause the error message ``@code{Non constant expression for initial
1064 address}''.
1065
1066 @node Built-ins, , Assignment, Expressions
1067 @subsection Built-In Functions
1068 @cindex functions in expression language
1069 The command language includes a number of special purpose built-in
1070 functions for use in link script expressions.
1071 @table @code
1072 @item ABSOLUTE(@var{exp})
1073 @kindex ABSOLUTE(@var{exp})
1074 @cindex expression, absolute
1075 returns the absolute value of the expression @var{exp}. Primarily
1076 useful to assign an absolute value to a symbol within a section
1077 definition, where symbol values are normally section-relative.
1078
1079 @item ADDR(@var{section})
1080 @kindex ADDR(@var{section})
1081 @cindex section address
1082 returns the absolute address of the named @var{section}. Your script must
1083 previously have defined the location of that section. In the following
1084 example the @code{symbol_1} and @code{symbol_2} are assigned identical
1085 values:
1086 @example
1087 SECTIONS@{ @dots{}
1088 .output1 :
1089 @{
1090 start_of_output_1 = ABSOLUTE(.);
1091 @dots{}
1092 @}
1093 .output :
1094 @{
1095 symbol_1 = ADDR(.output1);
1096 symbol_2 = start_of_output_1;
1097 @}
1098 @dots{} @}
1099 @end example
1100
1101 @item ALIGN(@var{exp})
1102 @kindex ALIGN(@var{exp})
1103 @cindex rounding up location counter
1104 returns the result of the current location counter (@code{.}) aligned to
1105 the next @var{exp} boundary. @var{exp} must be an expression whose
1106 value is a power of two. This is equivalent to
1107 @example
1108 (. + @var{exp} - 1) & ~(@var{exp} - 1)
1109 @end example
1110
1111 @code{ALIGN} doesn't change the value of the location counter---it just
1112 does arithmetic on it. As an example, to align the output @code{.data}
1113 section to the next @code{0x2000} byte boundary after the preceding
1114 section and to set a variable within the section to the next
1115 @code{0x8000} boundary after the input sections:
1116 @example
1117 SECTIONS@{ @dots{}
1118 .data ALIGN(0x2000): @{
1119 *(.data)
1120 variable = ALIGN(0x8000);
1121 @}
1122 @dots{} @}
1123 @end example
1124 @noindent
1125 The first use of @code{ALIGN} in this example specifies the location of
1126 a section because it is used as the optional @var{start} attribute of a
1127 section definition (@pxref{Section Options}). The second use simply
1128 defines the value of a variable.
1129
1130 The built-in @code{NEXT} is closely related to @code{ALIGN}.
1131
1132 @item DEFINED(@var{symbol})
1133 @kindex DEFINED(@var{symbol})
1134 @cindex symbol defaults
1135 Returns @code{1} if @var{symbol} is in the linker global symbol table and is
1136 defined, otherwise it returns @code{0}. You can use this to provide default
1137 values for symbols. For example, this command-file fragment shows how
1138 to set a global symbol @code{begin} to the first location in the
1139 @code{.text} section---but if a symbol called @code{begin} already
1140 existed, its value is preserved:
1141 @smallexample
1142 SECTIONS@{ @dots{}
1143 .text : @{
1144 begin = DEFINED(begin) ? begin : . ;
1145 @dots{}
1146 @}
1147 @dots{} @}
1148 @end smallexample
1149
1150 @item NEXT(@var{exp})
1151 @kindex NEXT(@var{exp})
1152 @cindex unallocated address, next
1153 Returns the next unallocated address that is a multiple of @var{exp}.
1154 This command is closely related to @code{ALIGN(@var{exp})}; unless you
1155 use the @code{MEMORY} command to define discontinuous memory for the
1156 output file, the two commands are equivalent.
1157
1158 @item SIZEOF(@var{section})
1159 @kindex SIZEOF(@var{section})
1160 @cindex section size
1161 returns the size in bytes of the named @var{section}, if the section has
1162 been allocated. In the following example the @code{symbol_1} and
1163 @code{symbol_2} are assigned identical values:
1164 @example
1165 SECTIONS@{ @dots{}
1166 .output @{
1167 .start = . ;
1168 @dots{}
1169 .end = . ;
1170 @}
1171 symbol_1 = .end - .start ;
1172 symbol_2 = SIZEOF(.output);
1173 @dots{} @}
1174
1175 @end example
1176
1177 @item SIZEOF_HEADERS
1178 @kindex SIZEOF_HEADERS
1179 @cindex header size
1180 @itemx sizeof_headers
1181 @kindex sizeof_headers
1182 the size in bytes of the output file's headers. You can use this number
1183 as the start address of the first section, if you choose, to facilitate
1184 paging.
1185
1186 @end table
1187
1188 @node MEMORY, SECTIONS, Expressions, Commands
1189 @section MEMORY Command
1190 @kindex MEMORY
1191 @cindex regions of memory
1192 @cindex discontinuous memory
1193 @cindex allocating memory
1194 The linker's default configuration permits allocation of all memory.
1195 You can override this by using the @code{MEMORY} command. The
1196 @code{MEMORY} command describes the location and size of blocks of
1197 memory in the target. By using it carefully, you can describe which
1198 memory regions may be used by the linker, and which memory regions it
1199 must avoid. The linker does not shuffle sections to fit into the
1200 available regions, but does move the requested sections into the correct
1201 regions and issue errors when the regions become too full.
1202
1203 Command files may contain at most one use of the @code{MEMORY}
1204 command; however, you can define as many blocks of memory within it as
1205 you wish. The syntax is:
1206
1207 @example
1208 MEMORY
1209 @{
1210 @var{name} (@var{attr}) : ORIGIN = @var{origin}, LENGTH = @var{len}
1211 @dots{}
1212 @}
1213 @end example
1214 @table @code
1215 @item @var{name}
1216 @cindex naming memory regions
1217 is a name used internally by the linker to refer to the region. Any
1218 symbol name may be used. The region names are stored in a separate
1219 name space, and will not conflict with symbols, filenames or section
1220 names. Use distinct names to specify multiple regions.
1221 @item (@var{attr})
1222 @cindex memory region attributes
1223 is an optional list of attributes, permitted for compatibility with the
1224 AT&T linker but not used by @code{ld} beyond checking that the
1225 attribute list is valid. Valid attribute lists must be made up of the
1226 characters ``@code{LIRWX}''. If you omit the attribute list, you may
1227 omit the parentheses around it as well.
1228 @item @var{origin}
1229 @kindex ORIGIN =
1230 @kindex o =
1231 @kindex org =
1232 is the start address of the region in physical memory. It is expressed as
1233 an expression, which must evaluate to a constant before
1234 memory allocation is performed. The keyword @code{ORIGIN} may be
1235 abbreviated to @code{org} or @code{o}.
1236 @item @var{len}
1237 @kindex LENGTH =
1238 @kindex len =
1239 @kindex l =
1240 is the size in bytes of the region (an expression).
1241 The keyword @code{LENGTH} may be abbreviated to @code{len} or @code{l}.
1242 @end table
1243
1244 For example, to specify that memory has two regions available for
1245 allocation---one starting at @code{0} for 256 kilobytes, and the other
1246 starting at @code{0x40000000} for four megabytes:
1247
1248 @example
1249 MEMORY
1250 @{
1251 rom : ORIGIN = 0, LENGTH = 256K
1252 ram : org = 0x40000000, l = 4M
1253 @}
1254 @end example
1255
1256 Once you have defined a region of memory named @var{mem}, you can direct
1257 specific output sections there by using a command ending in
1258 @samp{>@var{mem}} within the @code{SECTIONS} command (@pxref{Section
1259 Options}). If the combined output sections directed to a region are too
1260 big for the region, the linker will issue an error message.
1261
1262 @node SECTIONS, Entry Point, MEMORY, Commands
1263 @section SECTIONS Command
1264 @kindex SECTIONS
1265 The @code{SECTIONS} command controls exactly where input sections are
1266 placed into output sections, their order and to which output sections
1267 they are allocated.
1268
1269 You may use at most one @code{SECTIONS} command in a commands file,
1270 but you can have as many statements within it as you wish. Statements
1271 within the @code{SECTIONS} command can do one of three things:
1272 @itemize @bullet
1273 @item
1274 define the entry point;
1275 @item
1276 assign a value to a symbol;
1277 @item
1278 describe the placement of a named output section, and what input
1279 sections make it up.
1280 @end itemize
1281
1282 The first two possibilities---defining the entry point, and defining
1283 symbols---can also be done outside the @code{SECTIONS} command:
1284 @pxref{Entry Point}, @pxref{Assignment}. They are permitted here as
1285 well for your convenience in reading the script, so that symbols or the
1286 entry point can be defined at meaningful points in your output-file
1287 layout.
1288
1289 When no @code{SECTIONS} command is specified, the default action
1290 of the linker is to place each input section into an identically named
1291 output section in the order that the sections are first encountered in
1292 the input files; if all input sections are present in the first file,
1293 for example, the order of sections in the output file will match the
1294 order in the first input file.
1295
1296 @menu
1297 * Section Definition:: Section Definitions
1298 * Section Contents:: Section Contents
1299 * Section Options:: Optional Section Attributes
1300 @end menu
1301
1302 @node Section Definition, Section Contents, SECTIONS, SECTIONS
1303 @subsection Section Definitions
1304 @cindex section definition
1305 The most frequently used statement in the @code{SECTIONS} command is
1306 the @dfn{section definition}, which you can use to specify the
1307 properties of an output section: its location, alignment, contents,
1308 fill pattern, and target memory region can all be specified. Most of
1309 these specifications are optional; the simplest form of a section
1310 definition is
1311 @example
1312 SECTIONS @{ @dots{}
1313 @var{secname} : @{
1314 @var{contents}
1315 @}
1316 @dots{} @}
1317 @end example
1318 @cindex naming output sections
1319 @noindent
1320 @var{secname} is the name of the output section, and @var{contents} a
1321 specification of what goes there---for example a list of input files or
1322 sections of input files. As you might assume, the whitespace shown is
1323 optional; you do need the colon @samp{:} and the braces @samp{@{@}},
1324 however.
1325
1326 @var{secname} must meet the constraints of your output format. In
1327 formats which only support a limited number of sections, such as
1328 @code{a.out}, the name must be one of the names supported by the format
1329 (@code{a.out}, for example, allows only @code{.text}, @code{.data} or
1330 @code{.bss}). If the output format supports any number of sections, but
1331 with numbers and not names (as is the case for Oasys), the name should be
1332 supplied as a quoted numeric string. A section name may consist of any
1333 sequence characters, but any name which does not conform to the standard
1334 @code{ld} symbol name syntax must be quoted.
1335
1336 @node Section Contents, Section Options, Section Definition, SECTIONS
1337 @subsection Section Contents
1338 @cindex contents of a section
1339 In a section definition, you can specify the contents of an output section by
1340 listing particular object files; by listing particular input-file
1341 sections; or a combination of the two. You can also place arbitrary
1342 data in the section, and define symbols relative to the beginning of the
1343 section.
1344
1345 The @var{contents} of a section definition may include any of the
1346 following kinds of statement. You can include as many of these as you
1347 like in a single section definition, separated from one another by
1348 whitespace.
1349
1350 @table @code
1351 @item @var{filename}
1352 @kindex @var{filename}
1353 @cindex input files, section defn
1354 @cindex files, including in output sections
1355 You may simply name a particular input file to be placed in the current
1356 output section; @emph{all} sections from that file are placed in the
1357 current section definition. To specify a list of particular files by
1358 name:
1359 @example
1360 .data : @{ afile.o bfile.o cfile.o @}
1361 @end example
1362 @noindent
1363 The example also illustrates that multiple statements can be included in
1364 the contents of a section definition, since each filename is a separate
1365 statement.
1366
1367 If the file name has already been mentioned in another section
1368 definition, with an explicit section name list, then only those sections
1369 which have not yet been allocated are used.
1370
1371 @item @var{filename}( @var{section} )
1372 @itemx @var{filename}( @var{section}, @var{section}, @dots{} )
1373 @itemx @var{filename}( @var{section} @var{section} @dots{} )
1374 @kindex @var{filename}(@var{section})
1375 @cindex files and sections, section defn
1376 You can name one or more sections from your input files, for
1377 insertion in the current output section. If you wish to specify a list
1378 of input-file sections inside the parentheses, you may separate the
1379 section names by either commas or whitespace.
1380
1381 @item * (@var{section})
1382 @itemx * (@var{section}, @var{section}, @dots{})
1383 @itemx * (@var{section} @var{section} @dots{}
1384 @cindex input sections to output section
1385 @kindex *(@var{section})
1386 Instead of explicitly naming particular input files in a link control
1387 script, you can refer to @emph{all} files from the @code{ld} command
1388 line: use @samp{*} instead of a particular filename before the
1389 parenthesized input-file section list.
1390
1391 For example, to copy sections @code{1} through @code{4} from a Oasys file
1392 into the @code{.text} section of an @code{a.out} file, and sections @code{13}
1393 and @code{14} into the @code{.data} section:
1394 @example
1395 SECTIONS @{
1396 .text :@{
1397 *("1" "2" "3" "4")
1398 @}
1399
1400 .data :@{
1401 *("13" "14")
1402 @}
1403 @}
1404 @end example
1405
1406 If you have already explicitly included some files by name, @samp{*}
1407 refers to all @emph{remaining} files---those whose places in the output
1408 file have not yet been defined.
1409
1410 @item [ @var{section} ]
1411 @itemx [ @var{section}, @var{section}, @dots{} ]
1412 @itemx [ @var{section} @var{section} @dots{} ]
1413 @kindex [ @var{sections} ]
1414 This is an alternate notation to specify named sections from all
1415 unallocated input files; its effect is exactly the same as that of
1416 @samp{* (@var{section}@dots{})}
1417
1418 @item @var{filename}@code{( COMMON )}
1419 @itemx ( COMMON )
1420 @kindex ( COMMON )
1421 @cindex uninitialized data
1422 @cindex commons in output
1423 Specify where in your output file to place uninitialized data
1424 with this notation. @code{*(COMMON)} by itself refers to all
1425 uninitialized data from all input files (so far as it is not yet
1426 allocated); @var{filename}@code{(COMMON)} refers to uninitialized data
1427 from a particular file. Both are special cases of the general
1428 mechanisms for specifying where to place input-file sections:
1429 @code{ld} permits you to refer to uninitialized data as if it
1430 were in an input-file section named @code{COMMON}, regardless of the
1431 input file's format.
1432 @end table
1433
1434 For example, the following command script arranges the output file into
1435 three consecutive sections, named @code{.text}, @code{.data}, and
1436 @code{.bss}, taking the input for each from the correspondingly named
1437 sections of all the input files:
1438 @example
1439 SECTIONS @{
1440 .text : @{ *(.text) @}
1441 .data : @{ *(.data) @}
1442 .bss : @{ *(.bss) *(COMMON) @}
1443 @}
1444 @end example
1445
1446 The following example reads all of the sections from file @code{all.o}
1447 and places them at the start of output section @code{outputa} which
1448 starts at location @code{0x10000}. All of section @code{.input1} from
1449 file @code{foo.o} follows immediately, in the same output section. All
1450 of section @code{.input2} from @code{foo.o} goes into output section
1451 @code{outputb}, followed by section @code{.input1} from @code{foo1.o}.
1452 All of the remaining @code{.input1} and @code{.input2} sections from any
1453 files are written to output section @code{outputc}.
1454
1455 @example
1456 SECTIONS @{
1457 outputa 0x10000 :
1458 @{
1459 all.o
1460 foo.o (.input1)
1461 @}
1462 outputb :
1463 @{
1464 foo.o (.input2)
1465 foo1.o (.input1)
1466 @}
1467 outputc :
1468 @{
1469 *(.input1)
1470 *(.input2)
1471 @}
1472 @}
1473 @end example
1474
1475 There are still more kinds of statements permitted in the contents of
1476 output section definitions. The foregoing statements permitted you to
1477 arrange, in your output file, data originating from your input files.
1478 You can also place data directly in an output section from the link
1479 command script. Most of these additional statements involve
1480 expressions; @pxref{Expressions}. Although these statements are shown
1481 separately here for ease of presentation, no such segregation is needed
1482 within a section definition in the @code{SECTIONS} command; you can
1483 intermix them freely with any of the statements we've just described.
1484
1485 @table @code
1486 @item CREATE_OBJECT_SYMBOLS
1487 @kindex CREATE_OBJECT_SYMBOLS
1488 @cindex input filename symbols
1489 @cindex filename symbols
1490 instructs the linker to create a symbol for each input file
1491 in the current section, set with the address of the first byte of
1492 data written from the input file. For instance, with @code{a.out}
1493 files it is conventional to have a symbol for each input file. You can
1494 accomplish this by defining the output @code{.text} section as follows:
1495 @example
1496 SECTIONS @{
1497 .text 0x2020 :
1498 @{
1499 CREATE_OBJECT_SYMBOLS
1500 *(.text)
1501 _etext = ALIGN(0x2000);
1502 @}
1503 @dots{}
1504 @}
1505 @end example
1506
1507 If @code{objsym} is a file containing this script, and @code{a.o},
1508 @code{b.o}, @code{c.o}, and @code{d.o} are four input files with
1509 contents like the following---
1510 @example
1511 /* a.c */
1512
1513 afunction() @{ @}
1514 int adata=1;
1515 int abss;
1516 @end example
1517
1518 @noindent
1519 @samp{ld -M sample a.o b.o c.o d.o} would create a map like this,
1520 containing symbols matching the object file names:
1521 @example
1522 00000000 A __DYNAMIC
1523 00004020 B _abss
1524 00004000 D _adata
1525 00002020 T _afunction
1526 00004024 B _bbss
1527 00004008 D _bdata
1528 00002038 T _bfunction
1529 00004028 B _cbss
1530 00004010 D _cdata
1531 00002050 T _cfunction
1532 0000402c B _dbss
1533 00004018 D _ddata
1534 00002068 T _dfunction
1535 00004020 D _edata
1536 00004030 B _end
1537 00004000 T _etext
1538 00002020 t a.o
1539 00002038 t b.o
1540 00002050 t c.o
1541 00002068 t d.o
1542 @end example
1543
1544 @item @var{symbol} = @var{expression} ;
1545 @kindex @var{symbol} = @var{expression} ;
1546 @itemx @var{symbol} @var{f}= @var{expression} ;
1547 @kindex @var{symbol} @var{f}= @var{expression} ;
1548 @var{symbol} is any symbol name (@pxref{Symbols}). ``@var{f}=''
1549 refers to any of the operators @code{&= += -= *= /=} which combine
1550 arithmetic and assignment.
1551
1552 @cindex assignment, in section defn
1553 When you assign a value to a symbol within a particular section
1554 definition, the value is relative to the beginning of the section
1555 (@pxref{Assignment}). If you write
1556 @example
1557 SECTIONS @{
1558 abs = 14 ;
1559 @dots{}
1560 .data : @{ @dots{} rel = 14 ; @dots{} @}
1561 abs2 = 14 + ADDR(.data);
1562 @dots{}
1563 @}
1564 @end example
1565 @c FIXME: Try above example!
1566 @noindent
1567 @code{abs} and @var{rel} do not have the same value; @code{rel} has the
1568 same value as @code{abs2}.
1569
1570 @item BYTE(@var{expression})
1571 @kindex BYTE(@var{expression})
1572 @itemx SHORT(@var{expression})
1573 @kindex SHORT(@var{expression})
1574 @itemx LONG(@var{expression})
1575 @kindex LONG(@var{expression})
1576 @cindex direct output
1577 By including one of these three statements in a section definition, you
1578 can explicitly place one, two, or four bytes (respectively) at the
1579 current address of that section. Multiple-byte quantities are
1580 represented in whatever byte order is appropriate for the output file
1581 format (@pxref{BFD}).
1582
1583 @item FILL(@var{expression})
1584 @kindex FILL(@var{expression})
1585 @cindex holes, filling
1586 @cindex unspecified memory
1587 Specifies the ``fill pattern'' for the current section. Any otherwise
1588 unspecified regions of memory within the section (for example, regions
1589 you skip over by assigning a new value to the location counter @samp{.})
1590 are filled with the two least significant bytes from the
1591 @var{expression} argument. A @code{FILL} statement covers memory
1592 locations @emph{after} the point it occurs in the section definition; by
1593 including more than one @code{FILL} statement, you can have different
1594 fill patterns in different parts of an output section.
1595 @end table
1596
1597 @node Section Options, , Section Contents, SECTIONS
1598 @subsection Optional Section Attributes
1599 @cindex section defn, full syntax
1600 Here is the full syntax of a section definition, including all the
1601 optional portions:
1602
1603 @smallexample
1604 SECTIONS @{
1605 @dots{}
1606 @var{secname} @var{start} BLOCK(@var{align}) (NOLOAD) : @{ @var{contents} @} =@var{fill} >@var{region}
1607 @dots{}
1608 @}
1609 @end smallexample
1610
1611 @var{secname} and @var{contents} are required. @xref{Section
1612 Definition}, and @pxref{Section Contents} for details on @var{contents}.
1613 The remaining elements---@var{start}, @code{BLOCK(@var{align)}},
1614 @code{(NOLOAD)} @code{=@var{fill}}, and @code{>@var{region}}---are all
1615 optional.
1616
1617 @table @code
1618 @item @var{start}
1619 @cindex start address, section
1620 @cindex section start
1621 @cindex section address
1622 You can force the output section to be loaded at a specified address by
1623 specifying @var{start} immediately following the section name.
1624 @var{start} can be represented as any expression. The following
1625 example generates section @var{output} at location
1626 @code{0x40000000}:
1627 @example
1628 SECTIONS @{
1629 @dots{}
1630 output 0x40000000: @{
1631 @dots{}
1632 @}
1633 @dots{}
1634 @}
1635 @end example
1636
1637 @item BLOCK(@var{align})
1638 @kindex BLOCK(@var{align})
1639 @cindex section alignment
1640 @cindex aligning sections
1641 You can include @code{BLOCK()} specification to advance the location of
1642 the location counter @code{.} prior to the beginning of the section, so
1643 that the section will begin at the specified alignment. @var{align} is
1644 an expression.
1645
1646 @item (NOLOAD)
1647 @kindex NOLOAD
1648 @cindex prevent unnecessary loading
1649 Use @samp{(NOLOAD)} to prevent a section from being loaded into memory
1650 each time it is accessed. For example, in the script sample below, the
1651 @code{ROM} segment is addressed at memory location @samp{0} and does not
1652 need to be loaded into each object file:
1653 @example
1654 SECTIONS @{
1655 ROM 0 (NOLOAD) : @{ @dots{} @}
1656 @dots{}
1657 @}
1658 @end example
1659
1660 @item =@var{fill}
1661 @kindex =@var{fill}
1662 @cindex section fill pattern
1663 @cindex fill pattern, entire section
1664 You may use any expression to specify @var{fill}. Including
1665 @code{=@var{fill}} in a section definition specifies the initial fill
1666 value for that section. Any unallocated holes in the current output
1667 section when written to the output file will be filled with the two
1668 least significant bytes of the value, repeated as necessary. You can
1669 also change the fill value with a @code{FILL} statement in the
1670 @var{contents} of a section definition.
1671
1672 @item >@var{region}
1673 @kindex >@var{region}
1674 @cindex section, assigning to memory region
1675 @cindex memory regions and sections
1676 Assign this section to a previously defined region of memory.
1677 @xref{MEMORY}.
1678
1679 @end table
1680
1681 @node Entry Point, Other Commands, SECTIONS, Commands
1682 @section The Entry Point
1683 @kindex ENTRY(@var{symbol})
1684 @cindex start of execution
1685 @cindex first instruction
1686 The linker command language includes a command specifically for
1687 defining the first executable instruction in an output file (its
1688 @dfn{entry point}). Its argument is a symbol name:
1689 @example
1690 ENTRY(@var{symbol})
1691 @end example
1692
1693 Like symbol assignments, the @code{ENTRY} command may be placed either
1694 as an independent command in the command file, or among the section
1695 definitions within the @code{SECTIONS} command---whatever makes the most
1696 sense for your layout.
1697
1698 @cindex entry point, defaults
1699 @code{ENTRY} is only one of several ways of choosing the entry point.
1700 You may indicate it in any of the following ways (shown in descending
1701 order of priority: methods higher in the list override methods lower down).
1702 @itemize @bullet
1703 @item
1704 the @code{-e} @var{entry} command-line option;
1705 @item
1706 the @code{ENTRY(@var{symbol}} command in a linker control script;
1707 @item
1708 the value of the symbol @code{start}, if present;
1709 @item
1710 the value of the symbol @code{_main}, if present;
1711 @item
1712 the address of the first byte of the @code{.text} section, if present;
1713 @item
1714 The address @code{0}.
1715 @end itemize
1716
1717 For example, you can use these rules to generate an entry point with an
1718 assignment statement: if no symbol @code{start} is defined within your
1719 input files, you can simply define it, assigning it an appropriate
1720 value---
1721 @example
1722 start = 0x2020;
1723 @end example
1724
1725 @noindent
1726 The example shows an absolute address, but you can use any expression.
1727 For example, if your input object files use some other symbol-name
1728 convention for the entry point, you can just assign the value of
1729 whatever symbol contains the start address to @code{start}:
1730 @example
1731 start = other_symbol ;
1732 @end example
1733
1734 @node Other Commands, , Entry Point, Commands
1735 @section Other Commands
1736 The command language includes a number of other commands that you can
1737 use for specialized purposes. They are similar in purpose to
1738 command-line options.
1739
1740 @table @code
1741 @item FLOAT
1742 @kindex FLOAT
1743 @itemx NOFLOAT
1744 @kindex NOFLOAT
1745 These keywords were used in some older linkers to request a particular
1746 math subroutine library. @code{ld} doesn't use the keywords, assuming
1747 instead that any necessary subroutines are in libraries specified using
1748 the general mechanisms for linking to archives; but to permit the use of
1749 scripts that were written for the older linkers, the keywords
1750 @code{FLOAT} and @code{NOFLOAT} are accepted and ignored.
1751
1752 @item FORCE_COMMON_ALLOCATION
1753 @kindex FORCE_COMMON_ALLOCATION
1754 @cindex common allocation
1755 This command has the same effect as the @code{-d} command-line option:
1756 to make @code{ld} assign space to common symbols even if a relocatable
1757 output file is specified (@code{-r}).
1758
1759 @item INPUT ( @var{file}, @var{file}, @dots{} )
1760 @kindex INPUT ( @var{files} )
1761 @itemx INPUT ( @var{file} @var{file} @dots{} )
1762 @cindex binary input files
1763 Use this command to include binary input files in the link, without
1764 including them in a particular section definition. Files specified this
1765 way are treated identically to object files listed on the command line.
1766
1767 @ignore
1768 @item MAP ( @var{name} )
1769 @kindex MAP ( @var{name} )
1770 @c MAP(...) appears to look for an F in the arg, ignoring all other
1771 @c chars; if it finds one, it sets "map_option_f" to true. But nothing
1772 @c checks map_option_f. Apparently a stub for the future...
1773 @end ignore
1774
1775 @item OUTPUT ( @var{filename} )
1776 @kindex OUTPUT ( @var{filename} )
1777 @cindex naming the output file
1778 Use this command to name the link output file @var{filename}. The
1779 effect of @code{OUTPUT(@var{filename})} is identical to the effect of
1780 @w{@code{-o @var{filename}}}, and whichever is encountered last will
1781 control the name actually used to name the output file. In particular,
1782 you can use this command to supply a default output-file name other than
1783 @code{a.out}.
1784
1785 @item OUTPUT_ARCH ( @var{bfdname} )
1786 @kindex OUTPUT_ARCH ( @var{bfdname} )
1787 @cindex machine architecture, output
1788 Specify a particular output machine architecture, with one of the names
1789 used by the BFD back-end routines (@pxref{BFD}). This command is often
1790 unnecessary; the architecture is most often set implicitly by either the
1791 system BFD configuration or as a side effect of the @code{OUTPUT_FORMAT}
1792 command. @refill
1793
1794 @item OUTPUT_FORMAT ( @var{bfdname} )
1795 @kindex OUTPUT_FORMAT ( @var{bfdname} )
1796 @cindex format, output file
1797 Specify a particular output format, with one of the names used by the
1798 BFD back-end routines (@pxref{BFD}). This selection will only affect
1799 the output file; the related command @code{TARGET} affects primarily
1800 input files.@refill
1801
1802 @item SEARCH_DIR ( @var{path} )
1803 @kindex SEARCH_DIR ( @var{path} )
1804 @cindex path for libraries
1805 @cindex search path, libraries
1806 Add @var{path} to the list of paths where @code{ld} looks for
1807 archive libraries. @code{SEARCH_DIR(@var{path})} has the same
1808 effect as @code{-L@var{path})} on the command line.
1809
1810 @item STARTUP ( @var{filename} )
1811 @kindex STARTUP ( @var{filename} )
1812 @cindex first input file
1813 Ensure that @var{filename} is the first input file used in the link
1814 process.
1815
1816 @item TARGET ( @var{format} )
1817 @cindex input file format
1818 @kindex TARGET ( @var{format} )
1819 Change the input-file object code format (like the command-line option
1820 @code{-b} or its synonym @code{-format}). The argument @var{format} is
1821 one of the strings used by BFD to name binary formats. In the current
1822 @code{ld} implementation, if @code{TARGET} is specified but
1823 @code{OUTPUT_FORMAT} is not, the last @code{TARGET} argument is also
1824 used as the default format for the @code{ld} output file.
1825 @xref{BFD}.@refill
1826
1827 @kindex GNUTARGET
1828 If you don't use the @code{TARGET} command, @code{ld} uses the value of
1829 the environment variable @code{GNUTARGET}, if available, to select the
1830 output file format. If that variable is also absent, @code{ld} uses
1831 the default format configured for your machine in the BFD libraries.
1832
1833 @end table
1834
1835 @node Machine Dependent, BFD, Commands, Top
1836 @chapter Machine Dependent Features
1837
1838 @cindex machine dependencies
1839 @code{ld} has additional features on some platforms; the following
1840 sections describe them. Machines where @code{ld} has no additional
1841 functionality are not listed.
1842
1843 @menu
1844 * H8/300:: @code{ld} and the H8/300
1845 * i960:: @code{ld} and the Intel 960 family
1846 @end menu
1847
1848 @node H8/300, i960, Machine Dependent, Machine Dependent
1849 @section @code{ld} and the H8/300
1850
1851 @cindex H8/300 support
1852 For the H8/300, @code{ld} can perform these global optimizations when
1853 you specify the @samp{-relax} command-line option.
1854
1855 @table @emph
1856 @item relaxing address modes
1857 @cindex relaxing on H8/300
1858 @code{ld} finds all @code{jsr} and @code{jmp} instructions whose
1859 targets are within eight bits, and turns them into eight-bit
1860 program-counter relative @code{bsr} and @code{bra} instructions,
1861 respectively.
1862
1863 @item synthesizing instructions
1864 @cindex synthesizing on H8/300
1865 @c FIXME: specifically mov.b, or any mov instructions really?
1866 @code{ld} finds all @code{mov.b} instructions which use the
1867 sixteen-bit absolute address form, but refer to the top
1868 page of memory, and changes them to use the eight-bit address form.
1869 (That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into
1870 @samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the
1871 top page of memory).
1872 @end table
1873
1874 @node i960, , H8/300, Machine Dependent
1875 @section @code{ld} and the Intel 960 family
1876
1877 @cindex i960 support
1878
1879 @ignore
1880 @menu
1881 * i960-arch:: Linking for a Specific i960 Architecture
1882 * i960-emulation:: Emulating Other i960 Linkers
1883 * i960-commands:: Command Language Extensions for i960
1884 @end menu
1885
1886 @node i960-arch, i960-emulation, i960, i960
1887 @subsection Linking for a Specific i960 Architecture
1888 @end ignore
1889
1890 You can use the @samp{-A@var{architecture}} command line option to
1891 specify one of the two-letter names identifying members of the 960
1892 family; the option specifies the desired output target, and warns of any
1893 incompatible instructions in the input files. It also modifies the
1894 linker's search strategy for archive libraries, to support the use of
1895 libraries specific to each particular architecture, by including in the
1896 search loop names suffixed with the string identifying the architecture.
1897
1898 For example, if your @code{ld} command line included @w{@samp{-ACA}} as
1899 well as @w{@samp{-ltry}}, the linker would look (in its built-in search
1900 paths, and in any paths you specify with @code{-L}) for a library with
1901 the names
1902 @example
1903 try
1904 libtry.a
1905 tryca
1906 libtryca.a
1907 @end example
1908 @noindent
1909 The first two possibilities would be considered in any event; the last
1910 two are due to the use of @w{@samp{-ACA}}.
1911
1912 You can meaningfully use @code{-A} more than once on a command line, since
1913 the 960 architecture family allows combination of target architectures; each
1914 use will add another pair of name variants to search for when @w{@code{-l}}
1915 specifies a library.
1916
1917 @ignore
1918 @node i960-emulation, i960-commands, i960-arch, i960
1919 @subsection Emulating Other i960 Linkers
1920 You can set the @code{LDEMULATION} environment variable
1921 (@pxref{Environment,,Environment Variables}) to make
1922 @code{ld} more compatible with two older Intel 960 linkers:
1923
1924 @table @code
1925 @item LDEMULATION=gld960
1926 @kindex gld960
1927 @kindex G960LIB
1928 @kindex G960BASE
1929 @cindex i960
1930 Emulate the Intel port of the older @code{gld} for the i960
1931 architectures. The default library search paths are taken from two
1932 other environment variables, @code{G960LIB} and @code{G960BASE}. The
1933 default architecture is @code{i960}. The default output format is set
1934 to @code{b.out.big}, and in fact the default output file name (if
1935 @code{-o} is not specified) is @code{b.out}, to reflect this variant
1936 format, for this emulation.
1937
1938 @kindex GNU960
1939 This emulation can behave slightly differently depending on the setting
1940 of the @code{ld} compile-time switch @code{GNU960}. If @code{ld} is
1941 compiled with @code{GNU960} defined, then an additional environment
1942 variable---@code{GNUTARGET}---is available; its value, if available,
1943 specifies some other default output format than @code{b.out.big}.
1944
1945 @item LDEMULATION=lnk960
1946 @kindex lnk960
1947 @cindex i960
1948 @cindex Architectures, i960 family
1949 Emulate the Intel linker @code{lnk960}. The default output format is
1950 @code{coff-Intel-big}. With this emulation, @code{ld}
1951 supports the additional script commands @code{HLL} and @code{SYSLIB} for
1952 specification of library archives. This is the only emulation with
1953 extensive support for the @code{-A} (architecture) command-line option.
1954 By default, the architecture @code{CORE} is assumed, but you can choose
1955 additional features from the i960 architecture family by using one of
1956 the following with @code{-A} (or by using the @code{OUTPUT_ARCH} command
1957 from a script):
1958 @example
1959 CORE
1960 KB
1961 SB
1962 MC
1963 XA
1964 CA
1965 KA
1966 SA
1967 @end example
1968
1969 The default libraries are chosen with some attention to the architecture
1970 selected; the core library @file{cg} is always included, but the library
1971 @code{fpg} is also used if you've specified any of the architectures
1972 @code{KA}, @code{SA}, or @code{CA}.
1973
1974 @kindex GNU960
1975 Like @code{gld960}, this emulation uses additional environment variables
1976 to set the default library search paths. Also like @code{gld960}, the
1977 behavior of this emulation is slightly different depending on whether
1978 @code{ld} itself was compiled with @code{GNU960} defined.
1979
1980 @kindex G960BASE
1981 @kindex G960LIB
1982 @kindex I960BASE
1983 If your @code{ld} was compiled with @code{GNU960} defined, the default
1984 paths are taken from all three of @code{G960LIB}, @code{G960BASE}, and
1985 @code{I960BASE}. For the first two, paths you supply are automatically
1986 suffixed with @samp{/lib/libcoff}; for the last, your path is
1987 automatically suffixed with @samp{/lib}.
1988
1989 If your @code{ld} was @emph{not} compiled with @code{GNU960} defined,
1990 the default paths are taken from @code{I960BASE}, and @code{G960BASE} is
1991 only consulted if @code{I960BASE} is undefined. In this case
1992 @code{G960LIB} is not used at all.
1993 @end table
1994
1995 @node i960-commands, , i960-emulation, i960
1996 @subsection Command Language Extensions for i960
1997
1998 @code{ld} understands the following additional commands when
1999 @code{LDEMULATION} is set to @samp{lnk960}:
2000
2001 @table @code
2002 @item HLL ( @var{file}, @var{file}, @dots{} )
2003 @itemx HLL ( @var{file} @var{file} @dots{} )
2004 @itemx HLL ( )
2005 @kindex HLL ( @var{files} )
2006 Include ``high-level libraries'' or archives as input files in the link.
2007 Using @code{HLL(@var{file}} in a linker script is equivalent to
2008 including @code{-l}@var{file} on the command line.
2009
2010 @cindex @code{lnk960} command @code{HLL}
2011 The @code{HLL} command is only supported when @code{ld} emulates
2012 @code{lnk960}, as specified by the @code{LDEMULATION} environment
2013 variable.
2014
2015 @item SYSLIB ( @var{file}, @var{file}, @dots{} )
2016 @itemx SYSLIB ( @var{file} @var{file} @dots{} )
2017 @kindex SYSLIB ( @var{file}, @var{file}, @dots{} )
2018 Use the named @var{file}s as binary input files, searching for them in
2019 the same list of paths as archives.
2020
2021 @cindex @code{lnk960} command @code{SYSLIB}
2022 The @code{SYSLIB} command is only supported when @code{ld} emulates
2023 @code{lnk960}, as specified by the @code{LDEMULATION} environment
2024 variable.
2025
2026 @end table
2027
2028 @node m68k, m88k, i960, Machine Dependent
2029 @section @code{ld} and the Motorola 680x0 family
2030
2031 @cindex m68k support
2032 You can set the environment variable @code{LDEMULATION} to @samp{gld68k}
2033 for closer compatibility with the older GNU linker on Motorola 680x0
2034 platforms. This emulation is a variant of the @code{gld} emulation; it
2035 only differs in specifically setting the default BFD machine as
2036 @code{m68k}. @xref{Environment,,Environment Variables}.
2037
2038 @node m88k, , m68k, Machine Dependent
2039 @section @code{ld} and the Motorola 880x0 family
2040
2041 @cindex m88k support
2042 @kindex gldm88kbcs
2043 You can configure the linker to conform to the Motorola 88K BCS by
2044 setting the environment variable @code{LDEMULATION} to @samp{gldm88kbcs}.
2045 This sets the output format to @code{m88kbcs} and the architecture to
2046 @code{m88k}. Default library search paths are
2047 @example
2048 /lib
2049 /usr/lib
2050 /usr/local/lib
2051 @end example
2052
2053 For other settings of @code{LDEMULATION}, consult
2054 @ref{Environment,,Environment Variables}.
2055
2056 @end ignore
2057
2058 @node BFD, MRI, Machine Dependent, Top
2059 @chapter BFD
2060
2061 @cindex back end
2062 @cindex object file management
2063 The linker accesses object and archive files using the BFD libraries.
2064 These libraries allow the linker to use the same routines to operate on
2065 object files whatever the object file format. A different object file
2066 format can be supported simply by creating a new BFD back end and adding
2067 it to the library. You can use @code{objdump -i}
2068 (@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to
2069 list all the formats available for each architecture under BFD. This
2070 was the list of formats, and of architectures supported for each format,
2071 as of the time this manual was prepared:
2072 @cindex formats available
2073 @cindex architectures available
2074 @example
2075 BFD header file version 0.18
2076 a.out-i386
2077 (header big endian, data big endian)
2078 m68k:68020
2079 a29k
2080 sparc
2081 i386
2082 a.out-sunos-big
2083 (header big endian, data big endian)
2084 m68k:68020
2085 a29k
2086 sparc
2087 i386
2088 b.out.big
2089 (header big endian, data little endian)
2090 i960:core
2091 b.out.little
2092 (header little endian, data little endian)
2093 i960:core
2094 coff-a29k-big
2095 (header big endian, data big endian)
2096 a29k
2097 coff-h8300
2098 (header big endian, data big endian)
2099 H8/300
2100 coff-i386
2101 (header little endian, data little endian)
2102 i386
2103 coff-Intel-big
2104 (header big endian, data little endian)
2105 i960:core
2106 coff-Intel-little
2107 (header little endian, data little endian)
2108 i960:core
2109 coff-m68k
2110 (header big endian, data big endian)
2111 m68k:68020
2112 coff-m88kbcs
2113 (header big endian, data big endian)
2114 m88k:88100
2115 ecoff-bigmips
2116 (header big endian, data big endian)
2117 mips
2118 ecoff-littlemips
2119 (header little endian, data little endian)
2120 mips
2121 elf-big
2122 (header big endian, data big endian)
2123 m68k:68020
2124 vax
2125 i960:core
2126 a29k
2127 sparc
2128 mips
2129 i386
2130 m88k:88100
2131 H8/300
2132 rs6000:6000
2133 elf-little
2134 (header little endian, data little endian)
2135 m68k:68020
2136 vax
2137 i960:core
2138 a29k
2139 sparc
2140 mips
2141 i386
2142 m88k:88100
2143 H8/300
2144 rs6000:6000
2145 ieee
2146 (header big endian, data big endian)
2147 m68k:68020
2148 vax
2149 i960:core
2150 a29k
2151 sparc
2152 mips
2153 i386
2154 m88k:88100
2155 H8/300
2156 rs6000:6000
2157 srec
2158 (header big endian, data big endian)
2159 m68k:68020
2160 vax
2161 i960:core
2162 a29k
2163 sparc
2164 mips
2165 i386
2166 m88k:88100
2167 H8/300
2168 rs6000:6000
2169 @end example
2170
2171 @cindex BFD requirements
2172 @cindex requirements for BFD
2173 As with most implementations, BFD is a compromise between
2174 several conflicting requirements. The major factor influencing
2175 BFD design was efficiency: any time used converting between
2176 formats is time which would not have been spent had BFD not
2177 been involved. This is partly offset by abstraction payback; since
2178 BFD simplifies applications and back ends, more time and care
2179 may be spent optimizing algorithms for a greater speed.
2180
2181 One minor artifact of the BFD solution which you should bear in
2182 mind is the potential for information loss. There are two places where
2183 useful information can be lost using the BFD mechanism; during
2184 conversion and during output. @xref{BFD information loss}.
2185
2186 @menu
2187 * BFD outline:: How it works: an outline of BFD
2188 * BFD information loss:: Information Loss
2189 * Mechanism:: Mechanism
2190 @end menu
2191
2192 @node BFD outline, BFD information loss, BFD, BFD
2193 @section How it works: an outline of BFD
2194 @cindex opening object files
2195 When an object file is opened, BFD subroutines automatically
2196 determine the format of the input object file, and build a descriptor in
2197 memory with pointers to routines that will be used to access elements of
2198 the object file's data structures.
2199
2200 As different information from the the object files is required
2201 BFD reads from different sections of the file and processes them.
2202 For example a very common operation for the linker is processing symbol
2203 tables. Each BFD back end provides a routine for converting
2204 between the object file's representation of symbols and an internal
2205 canonical format. When the linker asks for the symbol table of an object
2206 file, it calls through the memory pointer to the relevant BFD
2207 back end routine which reads and converts the table into a canonical
2208 form. The linker then operates upon the common form. When the link is
2209 finished and the linker writes the symbol table of the output file,
2210 another BFD back end routine is called which takes the newly
2211 created symbol table and converts it into the chosen output format.
2212
2213 @node BFD information loss, Mechanism, BFD outline, BFD
2214 @section Information Loss
2215 @emph{Information can be lost during output.} The output formats
2216 supported by BFD do not provide identical facilities, and
2217 information which may be described in one form has nowhere to go in
2218 another format. One example of this is alignment information in
2219 @code{b.out}. There is nowhere in an @code{a.out} format file to store
2220 alignment information on the contained data, so when a file is linked
2221 from @code{b.out} and an @code{a.out} image is produced, alignment
2222 information will not propagate to the output file. (The linker will
2223 still use the alignment information internally, so the link is performed
2224 correctly).
2225
2226 Another example is COFF section names. COFF files may contain an
2227 unlimited number of sections, each one with a textual section name. If
2228 the target of the link is a format which does not have many sections (eg
2229 @code{a.out}) or has sections without names (eg the Oasys format) the
2230 link cannot be done simply. You can circumvent this problem by
2231 describing the desired input-to-output section mapping with the command
2232 language.
2233
2234 @emph{Information can be lost during canonicalization.} The BFD
2235 internal canonical form of the external formats is not exhaustive; there
2236 are structures in input formats for which there is no direct
2237 representation internally. This means that the BFD back ends
2238 cannot maintain all possible data richness through the transformation
2239 between external to internal and back to external formats.
2240
2241 This limitation is only a problem when using the linker to read one
2242 format and write another. Each BFD back end is responsible for
2243 maintaining as much data as possible, and the internal BFD
2244 canonical form has structures which are opaque to the BFD core,
2245 and exported only to the back ends. When a file is read in one format,
2246 the canonical form is generated for BFD and the linker. At the
2247 same time, the back end saves away any information which may otherwise
2248 be lost. If the data is then written back in the same format, the back
2249 end routine will be able to use the canonical form provided by the
2250 BFD core as well as the information it prepared earlier. Since
2251 there is a great deal of commonality between back ends, this mechanism
2252 is very useful. There is no information lost for this reason when
2253 linking big endian COFF to little endian COFF, or from @code{a.out} to
2254 @code{b.out}. When a mixture of formats is linked, the information is
2255 only lost from the files whose format differs from the destination.
2256
2257 @node Mechanism, , BFD information loss, BFD
2258 @section Mechanism
2259 The greatest potential for loss of information is when there is least
2260 overlap between the information provided by the source format, that
2261 stored by the canonical format, and the information needed by the
2262 destination format. A brief description of the canonical form may help
2263 you appreciate what kinds of data you can count on preserving across
2264 conversions.
2265 @cindex BFD canonical format
2266 @cindex internal object-file format
2267
2268 @table @emph
2269 @item files
2270 Information on target machine architecture, particular implementation
2271 and format type are stored on a per-file basis. Other information
2272 includes a demand pageable bit and a write protected bit. Note that
2273 information like Unix magic numbers is not stored here---only the magic
2274 numbers' meaning, so a @code{ZMAGIC} file would have both the demand pageable
2275 bit and the write protected text bit set.
2276
2277 The byte order of the target is stored on a per-file basis, so that big-
2278 and little-endian object files may be linked with one another.
2279
2280 @item sections
2281 Each section in the input file contains the name of the section, the
2282 original address in the object file, various flags, size and alignment
2283 information and pointers into other BFD data structures.
2284
2285 @item symbols
2286 Each symbol contains a pointer to the object file which originally
2287 defined it, its name, its value, and various flag bits. When a
2288 BFD back end reads in a symbol table, the back end relocates all
2289 symbols to make them relative to the base of the section where they were
2290 defined. This ensures that each symbol points to its containing
2291 section. Each symbol also has a varying amount of hidden data to contain
2292 private data for the BFD back end. Since the symbol points to the
2293 original file, the private data format for that symbol is accessible.
2294 @code{ld} can operate on a collection of symbols of wildly different
2295 formats without problems.
2296
2297 Normal global and simple local symbols are maintained on output, so an
2298 output file (no matter its format) will retain symbols pointing to
2299 functions and to global, static, and common variables. Some symbol
2300 information is not worth retaining; in @code{a.out} type information is
2301 stored in the symbol table as long symbol names. This information would
2302 be useless to most COFF debuggers and may be thrown away with
2303 appropriate command line switches. (The GNU debugger @code{gdb} does
2304 support @code{a.out} style debugging information in COFF).
2305
2306 There is one word of type information within the symbol, so if the
2307 format supports symbol type information within symbols (for example COFF,
2308 IEEE, Oasys) and the type is simple enough to fit within one word
2309 (nearly everything but aggregates) the information will be preserved.
2310
2311 @item relocation level
2312 Each canonical BFD relocation record contains a pointer to the symbol to
2313 relocate to, the offset of the data to relocate, the section the data
2314 is in and a pointer to a relocation type descriptor. Relocation is
2315 performed effectively by message passing through the relocation type
2316 descriptor and symbol pointer. It allows relocations to be performed
2317 on output data using a relocation method only available in one of the
2318 input formats. For instance, Oasys provides a byte relocation format.
2319 A relocation record requesting this relocation type would point
2320 indirectly to a routine to perform this, so the relocation may be
2321 performed on a byte being written to a COFF file, even though 68k COFF
2322 has no such relocation type.
2323 @c FIXME why specific reference to 68K above?
2324
2325 @item line numbers
2326 Object formats can contain, for debugging purposes, some form of mapping
2327 between symbols, source line numbers, and addresses in the output file.
2328 These addresses have to be relocated along with the symbol information.
2329 Each symbol with an associated list of line number records points to the
2330 first record of the list. The head of a line number list consists of a
2331 pointer to the symbol, which allows divination of the address of the
2332 function whose line number is being described. The rest of the list is
2333 made up of pairs: offsets into the section and line numbers. Any format
2334 which can simply derive this information can pass it successfully
2335 between formats (COFF, IEEE and Oasys).
2336 @end table
2337
2338 @node MRI, Index, BFD, Top
2339 @appendix MRI Compatible Script Files
2340 @cindex MRI compatibility
2341 To aid users making the transition to @sc{gnu} @code{ld} from the MRI
2342 linker, @code{ld} can use MRI compatible linker scripts as an
2343 alternative to the more general-purpose linker scripting language
2344 described in @ref{Commands,,Command Language}. MRI compatible linker
2345 scripts have a much simpler command set than the scripting language
2346 otherwise used with @code{ld}. @sc{gnu} @code{ld} supports the most
2347 commonly used MRI linker commands; these commands are described here.
2348
2349 You can specify a file containing an MRI-compatible script using the
2350 @samp{-c} command-line option.
2351
2352 Each command in an MRI-compatible script occupies its own line; each
2353 command line starts with the keyword that identifies the command (though
2354 blank lines are also allowed for punctuation). If a line of an
2355 MRI-compatible script begins with an unrecognized keyword, @code{ld}
2356 issues a warning message, but continues processing the script.
2357
2358 Lines beginning with @samp{*} are comments.
2359
2360 You can write these commands using all upper-case letters, or all
2361 lower case; for example, @samp{chip} is the same as @samp{CHIP}.
2362 The following list shows only the upper-case form of each command.
2363
2364 @table @code
2365 @item ABSOLUTE @var{secname}
2366 @item ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
2367 @cindex @code{ABSOLUTE} (MRI)
2368 Normally, @code{ld} includes in the output file all sections from all
2369 the input files. However, in an MRI-compatible script, you can use the
2370 @code{ABSOLUTE} command to restrict the sections that will be present in
2371 your output program. If the @code{ABSOLUTE} command is used at all in a
2372 script, then only the sections named explicitly in @code{ABSOLUTE}
2373 commands will appear in the linker output. You can still use other
2374 input sections (whatever you select on the command line, or using
2375 @code{LOAD}) to resolve addresses in the output file.
2376
2377 @item ALIAS @var{out-secname}, @var{in-secname}
2378 @cindex @code{ALIAS} (MRI)
2379 Use this command to place the data from input section @var{in-secname}
2380 in a section called @var{out-secname} in the linker output file.
2381
2382 @var{in-secname} may be an integer.
2383
2384 @item BASE @var{expression}
2385 @cindex @code{BASE} (MRI)
2386 Use the value of @var{expression} as the lowest address (other than
2387 absolute addresses) in the output file.
2388
2389 @item CHIP @var{expression}
2390 @itemx CHIP @var{expression}, @var{expression}
2391 @cindex @code{CHIP} (MRI)
2392 This command does nothing whatever; it's only accepted for compatibility.
2393
2394 @item END
2395 @cindex @code{END} (MRI)
2396 This command does nothing whatever; it's only accepted for compatibility.
2397
2398 @item FORMAT @var{output-format}
2399 @cindex @code{FORMAT} (MRI)
2400 Similar to the @code{OUTPUT_FORMAT} command in the more general linker
2401 language, but restricted to one of these output formats:
2402 @enumerate
2403 @item
2404 S-records, if @var{output-format} is @samp{S}
2405
2406 @item
2407 IEEE, if @var{output-format} is @samp{IEEE}
2408
2409 @item
2410 COFF (the @samp{coff-m68k} variant in BFD), if @var{output-format} is
2411 @samp{COFF}
2412 @end enumerate
2413
2414 @item LIST @var{@dots{}}
2415 @cindex @code{LIST} (MRI)
2416 Print (to the standard output file) a link map, as produced by the
2417 @code{ld} command-line option @samp{-M}.
2418
2419 (The keyword @code{LIST} may be followed by anything whatsoever on the
2420 same line, with no change in its effect.)
2421
2422 @item LOAD @var{filename}
2423 @item LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
2424 @cindex @code{LOAD} (MRI)
2425 Include one or more object file @var{filename} in the link; this has the
2426 same effect as specifying @var{filename} directly on the @code{ld}
2427 command line.
2428
2429 @item NAME @var{output-name}
2430 @cindex @code{NAME} (MRI)
2431 @var{output-name} is the name for the program produced by @code{ld}; the
2432 MRI-compatible command @code{NAME} is equivalent to the command-line
2433 option @samp{-o} or the general script language command @code{OUTPUT}.
2434
2435 @item ORDER @var{secname}, @var{secname}, @dots{} @var{secname}
2436 @itemx ORDER @var{secname} @var{secname} @var{secname}
2437 @cindex @code{ORDER} (MRI)
2438 Normally, @code{ld} orders the sections in its output file in whatever
2439 order they first appear in the input files. In an MRI-compatible
2440 script, you can override this with the @code{ORDER} command. The
2441 sections you list with @code{ORDER} will appear first in your output
2442 file, in the order specified.
2443
2444 @item PUBLIC @var{name}=@var{expression}
2445 @itemx PUBLIC @var{name},@var{expression}
2446 @itemx PUBLIC @var{name} @var{expression}
2447 @cindex @code{PUBLIC} (MRI)
2448 This command supplies a value (@var{expression}) for an external symbol
2449 @var{name} used in the linker input files.
2450
2451 @item SECT @var{secname}, @var{expression}
2452 @itemx SECT @var{secname}=@var{expression}
2453 @itemx SECT @var{secname} @var{expression}
2454 @cindex @code{SECT} (MRI)
2455 You can use any of these three forms of the @code{SECT} command to
2456 specify the start address (@var{expression}) for section @var{secname}.
2457 If you have more than one @code{SECT} statement for the same
2458 @var{secname}, only the @emph{first} sets the start address.
2459 @end table
2460
2461
2462 @node Index, , MRI, Top
2463 @unnumbered Index
2464
2465 @printindex cp
2466
2467 @tex
2468 % I think something like @colophon should be in texinfo. In the
2469 % meantime:
2470 \long\def\colophon{\hbox to0pt{}\vfill
2471 \centerline{The body of this manual is set in}
2472 \centerline{\fontname\tenrm,}
2473 \centerline{with headings in {\bf\fontname\tenbf}}
2474 \centerline{and examples in {\tt\fontname\tentt}.}
2475 \centerline{{\it\fontname\tenit\/} and}
2476 \centerline{{\sl\fontname\tensl\/}}
2477 \centerline{are used for emphasis.}\vfill}
2478 \page\colophon
2479 % Blame: pesch@cygnus.com, 28mar91.
2480 @end tex
2481
2482
2483 @contents
2484 @bye
2485
2486
This page took 0.086558 seconds and 4 git commands to generate.