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