Initial revision
[deliverable/binutils-gdb.git] / ld / ld.texinfo
CommitLineData
f22eee08 1\input texinfo
b4d4e8e3
RP
2@setfilename gld.info
3@c $Id$
4@syncodeindex ky cp
5@ifinfo
6This file documents the GNU linker GLD.
7
8Copyright (C) 1991 Free Software Foundation, Inc.
9
10Permission is granted to make and distribute verbatim copies of
11this manual provided the copyright notice and this permission notice
12are preserved on all copies.
13
14@ignore
15Permission is granted to process this file through Tex and print the
16results, provided the printed document carries copying permission
17notice 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
21Permission is granted to copy and distribute modified versions of this
22manual under the conditions for verbatim copying, provided also that the
23section entitled ``GNU General Public License'' is included exactly as
24in the original, and provided that the entire resulting derived work is
25distributed under the terms of a permission notice identical to this
26one.
27
28Permission is granted to copy and distribute translations of this manual
29into another language, under the above conditions for modified versions,
30except that the section entitled ``GNU General Public License'' may be
31included in a translation approved by the author instead of in the
32original English.
33@end ifinfo
34@setchapternewpage odd
35@settitle GLD, the GNU linker
f22eee08
RP
36@titlepage
37@title{gld}
b4d4e8e3 38@subtitle{The GNU linker}
f22eee08 39@sp 1
b4d4e8e3
RP
40@subtitle Second Edition---@code{gld} version 2.0
41@subtitle April 1991
42@author {Steve Chamberlain, Roland Pesch}
43@author {Cygnus Support}
44@page
45
46@tex
47\def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
48\xdef\manvers{\$Revision$} % For use in headers, footers too
49{\parskip=0pt
50\hfill Cygnus Support\par
51\hfill {\it GLD, the GNU linker}, \manvers\par
52\hfill \TeX{}info \texinfoversion\par
53\hfill steve\@cygnus.com, pesch\@cygnus.com\par
54}
55\global\parindent=0pt % Steve likes it this way.
56@end tex
57
f22eee08
RP
58@vskip 0pt plus 1filll
59Copyright @copyright{} 1991 Free Software Foundation, Inc.
60
61Permission is granted to make and distribute verbatim copies of
62this manual provided the copyright notice and this permission notice
63are preserved on all copies.
64
65Permission is granted to copy and distribute modified versions of this
66manual under the conditions for verbatim copying, provided also that
67the entire resulting derived work is distributed under the terms of a
68permission notice identical to this one.
69
70Permission is granted to copy and distribute translations of this manual
71into another language, under the above conditions for modified versions.
f22eee08 72@end titlepage
b4d4e8e3 73@c FIXME: Talk about importance of *order* of args, cmds to linker!
f22eee08
RP
74
75@node Top,,,
f22eee08
RP
76@ifinfo
77This file documents the GNU linker gld.
78@end ifinfo
79
b4d4e8e3 80@node Overview,,,
f22eee08
RP
81@chapter Overview
82
b4d4e8e3
RP
83@code{gld} combines a number of object and archive files, relocates
84their data and ties up symbol references. Often the last step in
85building a new compiled program to run is a call to @code{gld}.
f22eee08 86
b4d4e8e3
RP
87@code{gld} accepts Linker Command Language files written in
88a superset of AT@&T's Link Editor Command Language syntax,
89to provide explicit and total control over the linking process.
f22eee08
RP
90
91This version of @code{gld} uses the general purpose @code{bfd} libraries
b4d4e8e3
RP
92to operate on object files. This allows @code{gld} to read, combine, and
93write object files in many different formats---for example, COFF or
94@code{a.out}. Different formats may be linked together to produce any
95available kind of object file. @xref{BFD} for a list of formats
96supported on various architectures.
f22eee08 97
b4d4e8e3
RP
98When linking formats with equivalent representations of debugging
99information (typically variations on one format), @code{gld} maintains
100all debugging information.
f22eee08 101
b4d4e8e3 102@node Invocation,,,
f22eee08
RP
103@chapter Command line options
104
b4d4e8e3
RP
105@c FIXME: -D, -N, -z, -f from older GNU linker, but not currently in new;
106@c FIXME...steve is currently thinking about whether to add them. Maybe
107@c FIXME...remove from document.
108@example
109gld [-o @var{output} ] @var{objfiles}@dots{}
110 [ -A@var{architecture} ] [ -b @var{output-format} ] [ -Bstatic ]
111 [ -c @var{commandfile} ] [ -D @var{datasize} ]
112 [ -d | -dc | -dp ] [ -defsym @var{symbol} = @var{expression} ]
113 [ -e @var{entry} ] [ -f @var{fill} ] [ -F ] [ -F @var{format} ]
114 [ -format @var{output-format} ] [ -g ] [ -i ]
115 [ -l@var{ar} ] [ -L@var{searchdir} ] [ -M | -m ]
116 [ -N | -n | -z ] [ -noinhibit-exec ] [ -R @var{filename} ]
117 [ -r | -Ur ] [ -S ] [ -s ]
118 [ SCRIPT @dots{} ENDSCRIPT ] [ SCRIPT @dots{} @@ ]
119 [ -T @var{commandfile} ]
120 [ -Ttext @var{textorg} ] [ -Tdata @var{dataorg} ] [ -Tbss @var{bssorg} ]
121 [ -t ] [ -u @var{sym}] [-v] [ -X ] [ -x ]
122@end example
123
124This plethora of command-line options may seem intimidating, but in
125actual practice few of them are used in any particular context.
126For instance, a frequent use of @code{gld} is to link standard Unix
127object files on a standard, supported Unix system. On such a system, to
128link a file @code{hello.o}:
f22eee08 129@example
b4d4e8e3 130$ gld -o output /lib/crt0.o hello.o -lc
f22eee08 131@end example
b4d4e8e3
RP
132This tells @code{gld} to produce a file called @code{output} as the
133result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
134the library @code{libc.a} which will come from the standard search
135directories.
f22eee08 136
b4d4e8e3 137The command-line options to @code{gld} may be specified in any order, and
f22eee08
RP
138may be repeated at will. For the most part, repeating an option with a
139different argument will either have no further effect, or override prior
140occurrences (those further to the left on the command line) of an
141option.
142
b4d4e8e3 143The exceptions---which may meaningfully be used more than once---
f22eee08 144are @code{-L}, @code{-l}, and @code{-u}.
b4d4e8e3 145@c FIXME: probably some new opts can be repeated meaningfully too.
f22eee08 146
b4d4e8e3
RP
147The list of object files to be linked together, shown as @var{objfiles},
148may follow, precede, or be mixed in with command-line options; save that
149an @var{objfiles} argument may not be placed between an option flag and
150its argument.
f22eee08
RP
151
152Option arguments must follow the option letter without intervening
153whitespace, or be given as separate arguments immediately following the
154option that requires them.
155
156@table @code
157@item @var{objfiles}@dots{}
158The object files @var{objfiles} to be linked; at least one must be specified.
159
b4d4e8e3
RP
160@item -A@var{architecture}
161In the current release of @code{gld}, this option is useful only for the
162Intel 960 family of architectures. In that context, the
163@var{architecture} argument is one of the two-letter names identifying
164members of the 960 family; the option specifies the desired output
165target, and warns of any incompatible instructions in the input files.
166It also selects archive libraries supporting the particular
167architecture; its effect in this regard is similar to that of @code{-l}, save
168that @code{-A}@var{architecture} triggers a two-level search; first for a
169library with exactly the name you specify as @var{architecture}, and if
170that fails, for a library named with the @code{-l} convention---i.e.,
171@samp{lib@var{architecture}.a}.
172
173Future releases of @code{gld} may support similar functionality for
174other architecture families.
175
176@item -b @var{output-format}
177Specify the desired output-file binary format. You don't usually need
178to specify this. @code{gld} can determine
179the format of @emph{input} files by inspection, and---in the most frequent
180case, when all input files have the same format, @code{gld} selects the
181same format for output files by default.
182
183You can use this option if you need to link a variety of object formats
184together, or if you wish to force a different output format even though
185you have homogeneous input files.
186
187@var{output-format} is a text string, the name of a particular format
188supported by the BFD libraries. @xref{BFD}.
189
190@code{-format @var{output-format}} has the same effect.
191
f22eee08
RP
192@item -Bstatic
193This flag is accepted for command-line compatibility with the SunOS linker,
194but has no effect on @code{gld}.
195
196@item -c @var{commandfile}
b4d4e8e3
RP
197Directs @code{gld} to read link commands from the file
198@var{commandfile}. These commands will override @code{gld}'s
199default link format in its entirety; @var{commandfile} must specify
200everything necessary to specify the target format. @xref{Commands}.
f22eee08 201
b4d4e8e3
RP
202You may also include a script of link commands directly in the command
203line by using the @code{SCRIPT} @dots{} @code{ENDSCRIPT} keywords.
204
205@c FIXME: -D in older GNU linker, not necessarily in new
f22eee08
RP
206@item -D @var{datasize}
207Use this option to specify a target size for the @code{data} segment of
208your linked program. The option is only obeyed if @var{datasize} is
209larger than the natural size of the program's @code{data} segment.
210
211@var{datasize} must be an integer specified in hexadecimal.
212
213@code{ld} will simply increase the size of the @code{data} segment,
b4d4e8e3
RP
214padding the created gap with zeros (or a fill pattern specified with
215@samp{-f}, or using the command language), and reduce the size of the
216@code{bss} segment by the same amount.
217@c FIXME: double-check this w/Steve. Open questions: order? Does it
218@c FIXME...matter whether -f before or after -D? What about -c relative
219@c FIXME...position? fill cmd in default script? Apparently
220@c FIXME...can have multiple fill patterns; which used here?
221
222
223@item -d
224@itemx -dc
225@itemx -dp
226These three options are equivalent; multiple forms are supported for
227compatibility with other linkers. Any of them options will force
228@code{ld} to assign space to common symbols even if a relocatable output
229file is specified (@code{-r}).
230
231@item -defsym @var{symbol} = @var{expression}
232Create a global symbol, in the output file, set to the absolute address
233given by @var{expression}. A limited form of arithmetic is supported
234for the @var{expression} in this context: you may give a hexadecimal
235constant, or use @code{+} and @code{-} to add or subtract hexacedimal
236constants. If you need more elaborate expressions, consider using the
237linker command language from a script.
f22eee08
RP
238
239@item -e @var{entry}
240Use @var{entry} as the explicit symbol for beginning execution of your
b4d4e8e3
RP
241program, rather than the default entry point. @xref{Entry Point}, for a
242discussion of defaults and other ways of specifying the
243entry point.
f22eee08 244
b4d4e8e3 245@c FIXME: -f in older GNU linker, not necessarily in new
f22eee08
RP
246@item -f @var{fill}
247Sets the default fill pattern for ``holes'' in the output file to
248the lowest two bytes of the expression specified.
249
b4d4e8e3
RP
250@item -F
251@itemx -F{format}
252Some older linkers required the specification of object-file format,
253even when all input files were homogeneous, and used this option for
254that purpose. @code{gld} doesn't usually require this information---it
255automatically recognizes input-file object format---but it accepts the
256option flag for compatibility with old scripts.
257
258@item -format @var{output-format}
259Synonym for @code{-b} @var{output-format}.
260
261@item -g
262Accepted, but ignored; provided for compatibility with other tools.
263
f22eee08
RP
264@item -i
265Produce an incremental link (same as option @code{-r}).
266
b4d4e8e3
RP
267@item -l@var{ar}
268Add an archive file @var{ar} to the list of files to link. This
f22eee08 269option may be used any number of times. @code{ld} will search its
b4d4e8e3 270path-list for occurrences of @code{lib@var{ar}.a} for every @var{ar}
f22eee08
RP
271specified.
272
b4d4e8e3
RP
273@c FIXME: -l also has a side effect of using the "c++ demangler" if we happen
274@c FIXME...to specify -llibg++. Document? pesch@@cygnus.com, 24jan91
f22eee08 275
b4d4e8e3
RP
276@item -L@var{searchdir}
277This command adds path @var{searchdir} to the list of paths that
278@code{gld} will search for archive libraries. You may use this option
279any number of times.
f22eee08
RP
280
281@c Should we make any attempt to list the standard paths searched
282@c without listing? When hacking on a new system I often want to know
283@c this, but this may not be the place... it's not constant across
284@c systems, of course, which is what makes it interesting.
285@c pesch@@cygnus.com, 24jan91.
286
287@item -M
288@itemx -m
289Print (to the standard output file) a link map---diagnostic information
290about where symbols are mapped by @code{ld}, and information on global
291common storage allocation.
292
b4d4e8e3 293@c FIXME: -N in older GNU linker, not necessarily in new
f22eee08 294@item -N
b4d4e8e3
RP
295specifies readable and writable @code{text} and @code{data} sections. If
296the output format supports Unix style magic numbers, the output is
297marked as @code{OMAGIC}.
f22eee08
RP
298
299@item -n
300sets the text segment to be read only, and @code{NMAGIC} is written
301if possible.
302
b4d4e8e3
RP
303@item -noinhibit-exec
304Normally, the linker will not produce an output file if it encounters
305errors during the link process. With this flag, you can specify that
306you wish the output file retained for even after non-fatal errors.
307
f22eee08
RP
308@item -o @var{output}
309@var{output} is a name for the program produced by @code{ld}; if this
310option is not specified, the name @samp{a.out} is used by default.
311
b4d4e8e3
RP
312@item -R @var{filename}
313Read symbol names and their addresses from @var{filename}, but do not
314relocate it or include it in the output. This allows your output file
315to refer symbolically to absolute locations of memory defined in other
316programs.
317@c FIXME: -R accurate? Motivation? Kernel memory, shared mem?
318
f22eee08 319@item -r
b4d4e8e3 320@cindex partial link
f22eee08 321Generates relocatable output---i.e., generate an output file that can in
b4d4e8e3
RP
322turn serve as input to @code{gld}. This is often called @dfn{partial
323linking}. As a side effect, this option also sets the output file's
324magic number to @code{OMAGIC}; see @samp{-N}. If this option is not
325specified, an absolute file is produced. When linking C++ programs,
326this option @emph{will not} resolve references to constructors;
327@samp{-Ur} is an alternative.
f22eee08
RP
328
329@item -S
330Omits debugger symbol information (but not all symbols) from the output file.
331
332@item -s
333Omits all symbol information from the output file.
334
b4d4e8e3
RP
335@item SCRIPT @dots @@
336@itemx SCRIPT @dots ENDSCRIPT
337You can, if you wish, include a script of linker commands directly in
338the command line instead of referring to it via an input file. When the
339keyword @code{SCRIPT} occurs on the command line, the linker switches to
340interpreting the command language until the end of the list of commands
341is reached---flagged with either an at sign @samp{@@} or with the
342keyword @code{ENDSCRIPT}. Other command-line options will not be
343recognized while parsing the script. @xref{Commands} for a description
344of the command language.
345
346@item -Tbss @var{bssorg}
347@itemx -Tdata @var{dataorg}
f22eee08 348@itemx -Ttext @var{textorg}
b4d4e8e3
RP
349Use @var{textorg} as the starting address for---respectively---the
350@code{bss}, @code{data}, or the @code{text} segment of the output file.
351@var{textorg} must be a hexadecimal integer.
f22eee08 352
b4d4e8e3
RP
353@item -T @var{commandfile}
354@itemx -T@var{commandfile}
355Equivalent to @code{-c @var{commandfile}}; supported for compatibility with
356other tools.
f22eee08
RP
357
358@item -t
359Prints names of input files as @code{ld} processes them.
360
361@item -u @var{sym}
362Forces @var{sym} to be entered in the output file as an undefined symbol.
363This may, for example, trigger linking of additional modules from
364standard libraries. @code{-u} may be repeated with different option
365arguments to enter additional undefined symbols. This option is equivalent
366to the @code{EXTERN} linker command.
367
b4d4e8e3
RP
368@item -Ur
369@cindex constructors
370For anything other than C++ programs, this option is equivalent to
371@samp{-r}: it generates relocatable output---i.e., an output file that can in
372turn serve as input to @code{gld}. When linking C++ programs, @samp{-Ur}
373@emph{will} resolve references to constructors, unlike @samp{-r}.
374
375@item -v
376@cindex version
377@cindex verbose
378``Verbose'' switch: display informative messages, including the version
379numbers for @code{gld} and BFD, information on files opened, and BFD
380subroutine calls.
381
f22eee08
RP
382@item -X
383If @code{-s} or @code{-S} is also specified, delete only local symbols
384beginning with @samp{L}.
385
b4d4e8e3
RP
386@item -x
387If @code{-s} or @code{-S} is also specified, delete all local symbols,
388not just those beginning with @samp{L}.
389
390@c FIXME: -z in older GNU linker, not necessarily in new
f22eee08 391@item -z
b4d4e8e3
RP
392Specifies a read-only, demand pageable, and shared @code{text} segment.
393If the output format supports Unix-style magic numbers, @code{-z} also
394marks the output as @code{ZMAGIC}, the default.
f22eee08 395
b4d4e8e3
RP
396@c FIXME: why is following here?. Is it useful to say '-z -r' for
397@c FIXME...instance, or is this just a ref to other ways of setting
398@c FIXME...magic no?
f22eee08
RP
399Specifying a relocatable output file (@code{-r}) will also set the magic
400number to @code{OMAGIC}.
401
402See description of @samp{-N}.
403
f22eee08 404@end table
b4d4e8e3
RP
405
406@node Commands,,,
f22eee08 407@chapter Command Language
b4d4e8e3
RP
408@c FIXME: is this a good place to talk about LDEMULATION env var?
409@c FIXME...Apparently some commands "subtly different" depending on
410@c FIXME...whether this set to eg "link960", "gld960", "gld". What is
411@c FIXME...full set of possibilities, what is default? Config-dep?
f22eee08
RP
412
413
b4d4e8e3
RP
414The command language allows explicit control over the link process,
415allowing complete specification of the mapping between the linker's
416input files and its output. This includes:
417@itemize @bullet
f22eee08
RP
418@item input files
419@item file formats
420@item output file format
421@item addresses of sections
422@item placement of common blocks
b4d4e8e3 423@end itemize
f22eee08 424
b4d4e8e3
RP
425A command file may be supplied to the linker, either explicitly through
426the @code{-c} option, or implicitly as an ordinary file. If the linker
427opens a file which it cannot recognize as a supported object or archive
428format, it tries to interpret the file as a command file.
429
430@node Scripts,,,
431@section Linker Scripts
432The @code{gld} command language is a collection of statements; some are
433simple keywords setting a particular flag, some are used to select and
434group input files or name output files; and two particular statement
435types have a fundamental and pervasive impact on the linking process.
436
437The most fundamental command of the @code{gld} command language is the
438@code{SECTIONS} command (@pxref{SECTIONS}). Every meaningful command
439script must have a @code{SECTIONS} command: it specifies a
440``picture'' of the output file's layout, in varying degrees of detail.
441No other command is required in all cases.
442
443The @code{MEMORY} command complements @code{SECTIONS} by describing the
444available memory in the target architecture; if it is not present,
445sufficient memory is assumed to be available in a contiguous block for
446all output. @xref{MEMORY}.
447
448@node Expressions,,,
f22eee08 449@section Expressions
b4d4e8e3
RP
450Many useful commands involve arithmetic expressions. The syntax for
451expressions in the command language is identical to that of C
452expressions, with the following features:
453@itemize @bullet
f22eee08
RP
454@item All expressions evaluated as integers and
455are of ``long'' or ``unsigned long'' type.
456@item All constants are integers.
457@item All of the C arithmetic operators are provided.
458@item Global variables may be referenced, defined and created.
b4d4e8e3
RP
459@item Built in functions may be called.
460@end itemize
f22eee08 461
b4d4e8e3 462@node Integers,,,
f22eee08
RP
463@subsection Integers
464An octal integer is @samp{0} followed by zero or more of the octal
465digits (@samp{01234567}).
b4d4e8e3
RP
466@example
467@end example
f22eee08
RP
468
469A decimal integer starts with a non-zero digit followed by zero or
470more digits (@samp{0123456789}).
b4d4e8e3
RP
471@example
472_as_octal = 0157255;
473@end example
f22eee08
RP
474
475A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or
476more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}.
b4d4e8e3
RP
477@example
478_as_hex = 0xdead;
479@end example
f22eee08 480
b4d4e8e3
RP
481Decimal integers have the usual values. To denote a negative integer, use
482the prefix operator @samp{-}; @pxref{Operators}.
483@example
484_as_decimal = 57005;
485_as_neg = -57005;
486@end example
f22eee08 487
b4d4e8e3
RP
488Additionally the suffixes @code{K} and @code{M} may be used to scale a
489constant by
f22eee08 490@tex
b4d4e8e3 491${\rm 1024}$ or ${\rm 1024}^2$
f22eee08 492@end tex
b4d4e8e3
RP
493@ifinfo
4941024 or 1024*1024
495@end ifinfo
496respectively. For example, the following all refer to the same quantity:@refill
f22eee08
RP
497
498@example
f22eee08
RP
499 _4k_1 = 4K;
500 _4k_2 = 4096;
501 _4k_3 = 0x1000;
502@end example
b4d4e8e3
RP
503
504@node Symbols,,,
505@subsection Symbol Names
506Unless quoted, symbol names start with a letter, underscore, point or
507minus sign and may include any letters, underscores, digits, points,
508and minus signs. Unquoted symbol names must not conflict with any
509keywords. You can specify a symbol which contains odd characters or has
510the same name as a keyword, by surrounding the symbol name in double quotes:
511@example
512 "SECTION" = 9;
513 "with a space" = "also with a space" + 10;
514@end example
515
516@subsection The Location Counter
517The special linker variable @dfn{dot} @samp{.} always contains the
518current output location counter. Since the @code{.} always refers to
519a location in an output section, it must always appear in an
520expression within a @code{SECTIONS} command. The @code{.} symbol
521may appear anywhere that an ordinary symbol is allowed in an
522expression, but its assignments have a side effect. Assigning a value
523to the @code{.} symbol will cause the location counter to be moved.
524This may be used to create holes in the output section. The location
525counter may never be moved backwards.
526@example
527 SECTIONS
528 @{
529 output :
530 @{
531 file1(.text)
532 . = . + 1000;
533 file2(.text)
534 . += 1000;
535 file3(.text)
536 . -= 32;
537 file4(.text)
538 @} = 0x1234;
539 @}
540@end example
541In the previous example, @code{file1} is located at the beginning of
542the output section, then there is a 1000 byte gap, filled with 0x1234.
543Then @code{file2} appears, also with a 1000 byte gap following before
544@code{file3} is loaded. Then the first 32 bytes of @code{file4} are
545placed over the last 32 bytes of @code{file3}.
546
547@node Operators,,,
f22eee08 548@subsection Operators
b4d4e8e3 549The linker recognizes the standard C set of arithmetic operators, with
f22eee08 550the standard bindings and precedence levels:
b4d4e8e3
RP
551@c FIXME: distinguish somehow between prefix, infix in operator table!
552@c FIXME: is it fair to include assignments below? Don't they
553@c FIXME...require trailing ; when no other exprs do?
554@ifinfo
f22eee08 555@example
b4d4e8e3
RP
556precedence associativity Operators
557(highest)
5581 left ! - ~
5592 left * / %
5603 left + -
5614 left >> <<
5625 left == != > < <= >=
5636 left &
5647 left |
5658 left &&
5669 left ||
56710 right ? :
56811 right &= += -= *= /=
569(lowest)
f22eee08 570@end example
b4d4e8e3
RP
571@end ifinfo
572@c FIXME: simplify, debug TeX form of this table!
f22eee08
RP
573@tex
574
575\vbox{\offinterlineskip
576\hrule
577\halign
578{\vrule#&\hfil#\hfil&\vrule#&\hfil#\hfil&\vrule#&\hfil#\hfil&\vrule#\cr
579height2pt&&&&&\cr
580&Level&& associativity &&Operators&\cr
581height2pt&&&&&\cr
582\noalign{\hrule}
583height2pt&&&&&\cr
b4d4e8e3 584&highest&&&&&\cr
f22eee08
RP
585&1&&left&&$ ! - ~$&\cr
586height2pt&&&&&\cr
587&2&&left&&* / \%&\cr
588height2pt&&&&&\cr
589&3&&left&&+ -&\cr
590height2pt&&&&&\cr
591&4&&left&&$>> <<$&\cr
592height2pt&&&&&\cr
593&5&&left&&$== != > < <= >=$&\cr
594height2pt&&&&&\cr
595&6&&left&&\&&\cr
596height2pt&&&&&\cr
597&7&&left&&|&\cr
598height2pt&&&&&\cr
599&8&&left&&{\&\&}&\cr
600height2pt&&&&&\cr
601&9&&left&&||&\cr
602height2pt&&&&&\cr
603&10&&right&&? :&\cr
604height2pt&&&&&\cr
605&11&&right&&$${\&= += -= *= /=}&\cr
b4d4e8e3 606&lowest&&&&&\cr
f22eee08
RP
607height2pt&&&&&\cr}
608\hrule}
609@end tex
610
b4d4e8e3
RP
611@node Evaluation,,,
612@subsection Evaluation
613
614The linker uses ``lazy evaluation'' for expressions; it only calculates
615an expression when absolutely necessary. The linker needs the value of
616the start address, and the lengths of memory regions, in order to do any
617linking at all; these values are computed as soon as possible when the
618linker reads in the command file. However, other values (such as symbol
619values) are not known or needed until after storage allocation. Such
620values are evaluated later, when other information (such as the sizes of
621output sections) is available for use in the symbol assignment
622expression.
623
624@node Assignment,,,
625@subsection Assignment: Defining Symbols
626
627You may create global symbols, and assign values (addresses) to global
628symbols, using any of the C assignment operators:
629
630@table @code
631@item @var{symbol} = @var{expression} ;
632@itemx @var{symbol} += @var{expression} ;
633@itemx @var{symbol} -= @var{expression} ;
634@itemx @var{symbol} *= @var{expression} ;
635@itemx @var{symbol} /= @var{expression} ;
636@end table
637
638Two things distinguish assignment from other operators in @code{gld}
639expressions.
640@itemize @bullet
641@item Assignment may only be used at the root of an expression;
642@samp{a=b+3;} is allowed, but @samp{a+b=3;} is an error.
643@item A trailing semicolon is required at the end of an assignment
644statement.
645@end itemize
646
647Assignment statements may appear:
648@itemize @bullet
649@item as commands in their own right in a @code{gld} script; or
650@item as independent statements within a @code{SECTIONS} command; or
651@item as part of the contents of a section definition in a
652@code{SECTIONS} command.
653@end itemize
654
655The first two cases are equivalent in effect---both define a symbol with
656an absolute address; the last case defines a symbol whose address is
657relative to a particular section (@pxref{SECTIONS}).
658
659When a linker expression is evaluated and assigned to a variable it is given
660either an absolute or a relocatable type. An absolute expression type
661is one in which the symbol contains the value that it will have in the
662output file, a relocateable expression type is one in which the value
663is expressed as a fixed offset from the base of a section.
664
665The type of the expression is controlled by its position in the script
666file. A symbol assigned within a @code{SECTION} specification is
667created relative to the base of the section, a symbol assigned in any
668other place is created as an absolute symbol. Since a symbol created
669within a @code{SECTION} specification is relative to the base of the
670section it will remain relocatable if relocatable output is requested.
671A symbol may be created with an absolute value even when assigned to
672within a @code{SECTION} specification by using the absolute assignment
673function @code{ABSOLUTE} For example, to create an absolute symbol
674whose address is the last byte of the output section @code{.data}:
675@example
676.data :
677 @{
678 *(.data)
679 _edata = ABSOLUTE(.) ;
680 @}
681@end example
682
683The linker tries to put off the evaluation of an assignment until
684all the terms in the source expression are known (@pxref{Evaluation}).
685For instance the sizes of sections cannot be known until after
686allocation, so assignments dependent upon these are not performed until
687after allocation. Some expressions, such as those depending upon the
688location counter @dfn{dot}, @samp{.} must be evaluated during
689allocation. If the result of an expression is required, but the value is
690not available, then an error results. For example, attempting to use a
691script like the following
692@example
693SECTIONS @{
694 text 9+this_isnt_constant:
695 @{ @dots{}
696 @}
697 @}
698@end example
699will get the error message ``@code{Non constant expression for initial
700address}''.
701
702@node Builtins,,,
703@subsection Built in Functions
f22eee08 704The command language provides built in functions for use in
b4d4e8e3
RP
705expressions in link scripts.
706@itemize @bullet
f22eee08 707@item @code{ALIGN(@var{exp})}
b4d4e8e3
RP
708returns the result of the current location counter (@code{.}) aligned to
709the next @var{exp} boundary. @var{exp} must be an expression whose
710value is a power of two. This is equivalent to @samp{(. + @var{exp} -1)
711& ~(@var{exp}-1)}. As an example, to align the output @code{.data}
712section to the next 0x2000 byte boundary after the preceding section and
713to set a variable within the section to the next 0x8000 boundary after
714the input sections:
f22eee08
RP
715@example
716 .data ALIGN(0x2000) :@{
717 *(.data)
718 variable = ALIGN(0x8000);
719 @}
720@end example
721
722@item @code{ADDR(@var{section name})}
b4d4e8e3
RP
723returns the absolute address of the named section. Your script must
724previously have defined the location of that section. In the following
725example the @code{symbol_1} and @code{symbol_2} are assigned identical
726values:
f22eee08
RP
727@example
728 .output1:
729 @{
730 start_of_output_1 $= .;
731 ...
732 @}
733 .output:
734 @{
735 symbol_1 = ADDR(.output1);
736 symbol_2 = start_of_output_1;
737 @}
738@end example
739
740@item @code{SIZEOF(@var{section name})}
741returns the size in bytes of the named section, if the section has
742been allocated. In the following example the @code{symbol_1} and
743@code{symbol_2} are assigned identical values:
744@example
745 .output @{
746 .start = . ;
747 ...
748 .end = .;
749 @}
750 symbol_1 = .end - .start;
751 symbol_2 = SIZEOF(.output);
752@end example
753
754@item @code{DEFINED(@var{symbol name})}
755Returns 1 if the symbol is in the linker global symbol table and is
b4d4e8e3
RP
756defined, otherwise it returns 0. For example, this command-file fragment
757shows how to set a global symbol @code{begin} to the first location in
758the @code{.text} section---but only if no symbol called @code{begin}
759existed:
f22eee08
RP
760@example
761 .text: @{
762 begin = DEFINED(begin) ? begin : . ;
763 ...
764 @}
765@end example
b4d4e8e3
RP
766@end itemize
767
768@node MEMORY,,,
769@section MEMORY Command
770The linker's default configuration permits allocation of all memory.
771You can override this by using the @code{MEMORY} command. The
772@code{MEMORY} command describes the location and size of blocks of
773memory in the target. By using it carefully, you can describe which
774memory regions may be used by the linker, and which memory regions it
775must avoid. The linker does not shuffle sections to fit into the
776available regions, but does move the requested sections into the correct
777regions and issue errors when the regions become too full.
778
779Command files may contain at most one use of the @code{MEMORY}
780command; however, you can define as many blocks of memory within it as
781you wish. The syntax is:
f22eee08
RP
782
783@example
b4d4e8e3
RP
784MEMORY
785 @{
786 @var{name} (@var{attr}): ORIGIN = @var{origin}, LENGTH = @var{len}
787 .
788 .
789 .
790 @}
f22eee08
RP
791@end example
792@table @code
793@item @var{name}
794is a name used internally by the linker to refer to the region. Any
795symbol name may be used. The region names are stored in a separate
796name space, and will not conflict with symbols, filenames or section
b4d4e8e3
RP
797names. Use distinct names to specify multiple regions.
798@item (@var{attr})
f22eee08 799is an optional list of attributes, parsed for compatibility with the
b4d4e8e3
RP
800AT@&T linker but ignored by the both the AT@&T and the GNU linker.
801Valid attribute lists must be made up of the characters ``@code{RWXL}''.
802If you omit the attribute list, you may omit the parentheses around it
803as well.
f22eee08 804@item @var{origin}
b4d4e8e3
RP
805is the start address of the region in physical memory. It is expressed as
806an expression, which must evaluate to a constant before
f22eee08
RP
807memory allocation is performed. The keyword @code{ORIGIN} may be
808abbreviated to @code{org} or @code{o}.
809@item @var{len}
b4d4e8e3 810is the size in bytes of the region (an expression).
f22eee08
RP
811The keyword @code{LENGTH} may be abbreviated to @code{len} or @code{l}
812@end table
813
814For example, to specify that memory has two regions available for
815allocation; one starting at 0 for 256k, and the other starting at
8160x40000000 for four megabytes:
817
818@example
b4d4e8e3
RP
819MEMORY
820 @{
821 rom : ORIGIN= 0, LENGTH = 256K
822 ram : org= 0x40000000, l = 4M
823 @}
f22eee08
RP
824@end example
825
b4d4e8e3
RP
826Once you have defined a region of memory named @var{mem}, you can direct
827specific output sections there by using a command ending in @samp{>@var{mem}}
828within the @code{SECTIONS} command. If the combined output
829sections directed to a region are too big for the region, the linker will
830issue an error message.
831
832@node SECTIONS,,,
833@section SECTIONS Command
834The @code{SECTIONS} command controls exactly where input sections are
835placed into output sections, their order and to which output sections
836they are allocated.
837
838You may use at most one @code{SECTIONS} command in a commands file,
839but you can have as many statements within it as you wish. Statements
840within the @code{SECTIONS} command can do one of three things:
841@itemize @bullet
842@item
843define the entry point;
844@item
845assign a value to a symbol;
846@item
847describe the placement of a named output section, and what input
848sections make it up.
849@end itemize
850
851The first two possibilities---defining the entry point, and defining
852symbols---can also be done outside the @samp{SECTIONS} command:
853@pxref{Entry Point}, @pxref{Assignment}. They are permitted here as
854well for your convenience in reading the script, so that symbols or the
855entry point can be defined at meaningful points in your output-file
856layout.
f22eee08 857
b4d4e8e3 858When no @code{SECTIONS} command is specified, the default action
f22eee08 859of the linker is to place each input section into an identically named
b4d4e8e3
RP
860output section in the order that the sections are first encountered in
861the input files; if all input sections are present in the first file,
862for example, the order of sections in the output file will match the
863order in the first input file.
864
865@node Section Definition,,,
866@subsection Section Definitions
867The most frequently used statement in the @code{SECTIONS} command is
868the @dfn{section definition}, which you can use to specify the
869properties of an output section: its location, alignment, contents,
870fill pattern, and target memory region can all be specified. Most of
871these specifications are optional; the simplest form of a section
872definition is
873@example
874SECTIONS
875@{
876.
877.
878.
879@var{secname} : @{
880 @var{contents}
881 @}
882.
883.
884.
885@}
886@end example
887@noindent
888@var{secname} is the name of the output section, and @var{contents} a
889specification of what goes there---for example a list of input files or
890sections of input files. As you might assume, the whitespace shown is
891optional; you do need the colon @samp{:} and the braces @samp{@{@}},
892however.
893
894@var{secname} must meet the constraints of your output format. In
895formats which only support a limited number of sections, such as
896@code{a.out}, the name must be one of the names supported by the format
897(in the case of @code{a.out}, @code{.text}, @code{.data} or @code{.bss}). If
898the output format supports any number of sections, but with numbers and
899not names (in the case of IEEE), the name should be supplied as a quoted
900numeric string. A section name may consist of any sequence characters,
901but any name which does not conform to the standard @code{gld} symbol
902name syntax must be quoted.
903
904@node Section Contents,,,
905@subsection Section Contents
906In a section definition, you can specify the contents of an output section by
907listing particular object files; by listing particular input-file
908sections; or a combination of the two. You can also place arbitrary
909data in the section, and define symbols relative to the beginning of the
910section.
911
912The @var{contents} of a section definition may include any of the
913following kinds of statement. You can include as many of these as you
914like in a single section definition, separated from one another by
915whitespace.
f22eee08 916
b4d4e8e3
RP
917@table @code
918@item @var{filename}( @var{section} )
919@itemx @var{filename}( @var{section}, @var{section}, @dots{} )
920@itemx @var{filename}( @var{section} @var{section} @dots{} )
921You can name one or more sections from your input files, for
922insertion in the current output section. If you wish to specify a list
923of input-file sections inside the parentheses, you may separate the
924section names by either commas or whitespace.
f22eee08 925
b4d4e8e3
RP
926@item @var{filename}
927You may simply name a particular input file to be placed in the current
928output section; @emph{all} sections from that file are placed in
929the current section definition. Since multiple statements may be
930present in the contents of a section definition, you can specify a list
931of particular files by name:
f22eee08 932@example
b4d4e8e3 933.data: @{ afile.o bfile.o cfile.o @}
f22eee08
RP
934@end example
935
b4d4e8e3
RP
936If the file name has already been mentioned in another section
937definition, with an explicit section name list, then only those sections
938which have not yet been allocated are used.
939
940@item * (@var{section})
941@itemx * (@var{section}, @var{section}, @dots{})
942@itemx * (@var{section} @var{section} @dots{})
943Instead of explicitly naming particular input files in a link control
944script, you can refer to @emph{all} files from the @code{gld} command
945line: use @samp{*} instead of a particular filename before the
946parenthesized input-file section list.
947
948For example, to copy sections @code{1} through @code{4} from a Oasys file
949into the @code{.text} section of an @code{a.out} file, and sections @code{13}
950and @code{14} into the @code{.data} section:
951@example
952SECTION @{
953 .text :@{
954 *("1" "2" "3" "4")
955 @}
f22eee08 956
b4d4e8e3
RP
957 .data :@{
958 *("13" "14")
f22eee08 959 @}
b4d4e8e3 960@}
f22eee08
RP
961@end example
962
b4d4e8e3
RP
963If you have already explicitly included some files by name, @samp{*}
964refers to all @emph{remaining} files---those whose places in the output
965file have not yet been defined.
966
967@item [ @var{section} ]
968@itemx [ @var{section}, @var{section}, @dots{} ]
969@itemx [ @var{section} @var{section} @dots{} ]
970This is an alternate notation to specify named sections from all
971unallocated input files; its effect is exactly the same as that of
972@samp{* (@var{section}@dots{})}
973
974@item @var{filename}@code{( COMMON )}
975@itemx [ COMMON ]
976Specify where in your output file to place uninitialized data
977with this notation. @code{[COMMON]} by itself refers to all
978uninitialized data from all input files (so far as it is not yet
979allocated); @var{filename}@code{(COMMON)} refers to uninitialized data
980from a particular file. Both are special cases of the general
981mechanisms for specifying where to place input-file sections:
982@code{gld} permits you to refer to uninitialized data as if it
983were in an input-file section named @code{COMMON}, regardless of the
984input file's format.
985@end table
986
987For example, the following command script arranges its output file into
988three consecutive sections, named @code{.text}, @code{.data}, and
989@code{.bss}, taking the input for each from the correspondingly named
990sections of all the input files:
f22eee08 991@example
b4d4e8e3
RP
992SECTIONS
993{
994 .text: { *(.text) }
995 .data: { *(.data) }
996 .bss: { *(.bss) [COMMON] }
997}
f22eee08 998@end example
b4d4e8e3
RP
999
1000The following example reads all of the sections from file @code{all.o}
1001and places them at the start of output section @code{outputa} which
1002starts at location @code{0x10000}. All of section @code{.input1} from
1003file @code{foo.o} follows immediately, in the same output section. All
1004of section @code{.input2} from @code{foo.o} goes into output section
1005@code{outputb}, followed by section @code{.input1} from @code{foo1.o}.
1006All of the remaining @code{.input1} and @code{.input2} sections from any
1007files are written to output section @code{outputc}.
1008
1009@example
1010SECTIONS
1011 @{
1012 outputa 0x10000 :
1013 @{
1014 all.o
1015 foo.o (.input1)
f22eee08 1016 @}
b4d4e8e3
RP
1017 outputb :
1018 @{
1019 foo.o (.input2)
1020 foo1.o (.input1)
f22eee08 1021 @}
b4d4e8e3
RP
1022 outputc :
1023 @{
1024 *(.input1)
1025 *(.input2)
f22eee08 1026 @}
b4d4e8e3
RP
1027 @}
1028@end example
1029
1030There are still more kinds of statements permitted in the contents of
1031output section definitions! The foregoing statements permitted you to
1032arrange, in your output file, data originating from your input files.
1033You can also place data directly in an output section from the link
1034command script. Most of these additional statements involve
1035expressions; @pxref{Expressions}. Although these statements are shown
1036separately here for ease of presentation, no such segregation is needed
1037within a section definition in the @code{SECTIONS} command; you can
1038intermix them freely with any of the statements we've just described.
f22eee08 1039
b4d4e8e3
RP
1040@table @code
1041@item CREATE_OBJECT_SYMBOLS
1042instructs the linker to create a symbol for each input file and place it
1043into the current section, set with the address of the first byte of
f22eee08 1044data written from the input file. For instance, with @code{a.out}
b4d4e8e3
RP
1045files it is conventional to have a symbol for each input file. You can
1046accomplish this by defining the output @code{.text} section as follows:
1047@example
1048SECTIONS @{
1049 .text 0x2020 :
1050 @{
1051 CREATE_OBJECT_SYMBOLS
1052 *(.text)
1053 _etext = ALIGN(0x2000);
f22eee08 1054 @}
b4d4e8e3
RP
1055 .
1056 .
1057 .
1058 @}
f22eee08 1059@end example
b4d4e8e3
RP
1060
1061If @code{objsym} is a file containing this script, and @code{a.o},
1062@code{b.o}, @code{c.o}, and @code{d.o} are four input files with
1063contents like the following---
f22eee08 1064@example
b4d4e8e3
RP
1065/* a.c */
1066
1067afunction() { }
1068int adata=1;
1069int abss;
1070@end example
f22eee08 1071
b4d4e8e3
RP
1072@noindent
1073@samp{gld -M sample a.o b.o c.o d.o} would create a map like this,
1074containing symbols matching the object file names:
1075@example
f22eee08
RP
107600000000 A __DYNAMIC
107700004020 B _abss
107800004000 D _adata
107900002020 T _afunction
108000004024 B _bbss
108100004008 D _bdata
108200002038 T _bfunction
108300004028 B _cbss
108400004010 D _cdata
108500002050 T _cfunction
10860000402c B _dbss
108700004018 D _ddata
108800002068 T _dfunction
108900004020 D _edata
109000004030 B _end
109100004000 T _etext
109200002020 t a.o
109300002038 t b.o
109400002050 t c.o
109500002068 t d.o
f22eee08
RP
1096@end example
1097
b4d4e8e3
RP
1098@item FORCE_COMMON_ALLOCATION
1099@c FIXME! I don't know what this does.
1100
1101@item @var{symbol} = @var{expression} ;
1102@itemx @var{symbol} @var{f}= @var{expression} ;
1103@var{symbol} is any symbol name (@pxref{Symbols}). When you assign a
1104value to a symbol within a particular section definition, the value is
1105relative to the beginning of the section (@pxref{Assignment}). If you write
1106@example
1107SECTIONS
1108{
1109 abs = 14 ;
1110.
1111.
1112.
1113 .data: { @dots{} rel = 14 ; @dots{} }
1114 abs2 = 14 + ADDR(.data);
1115.
1116.
1117.
1118}
f22eee08 1119@end example
b4d4e8e3
RP
1120@c FIXME! Try above example!
1121@noindent
1122@code{abs} and @var{rel} do not have the same value; @code{rel} has the
1123same value as @code{abs2}.
1124
1125``@var{f}='' here refers to any of the operators @code{&= += -= *=
1126/=} which combine arithmetic and assignment.
1127
1128@item BYTE(@var{expression})
1129@itemx SHORT(@var{expression})
1130@itemx LONG(@var{expression})
1131By including one of these three statements in a section definition, you
1132can explicitly place one, two, or four bytes (respectively) at the
1133current address of that section. Multiple-byte quantities are
1134represented in whatever byte order is appropriate for the output file
1135format (@pxref{BFD}).
1136
1137@item FILL(@var{expression})
1138Specifies the ``fill pattern'' for the current section. Any otherwise
1139unspecified regions of memory within the section (for example, regions
1140you skip over by assigning a new value to the location counter @samp{.})
1141are filled with the two least significant bytes from the
1142@var{expression} argument. A @code{FILL} statement covers memory
1143locations @emph{after} the point it occurs in the section definition; by
1144including more than one @code{FILL} statement, you can have different
1145fill patterns in different parts of an output section.
1146@end table
1147
1148@node Section Options,,,
1149@subsection Optional Section Attributes
1150Here is the full syntax of a section definition, including all the
1151optional portions:
1152
f22eee08 1153@example
b4d4e8e3
RP
1154SECTIONS
1155@{
1156.
1157.
1158.
1159@var{secname} @var{start} BLOCK(@var{align}) : @var{contents} =@var{fill} >@var{region}
1160.
1161.
1162.
1163@}
1164@end example
1165
1166@var{secname} and @var{contents} are required. @xref{Section
1167Definition}, and @pxref{Section Contents} for the details of
1168@var{contents}. @var{start}, @code{BLOCK(@var{align)}},
1169@code{=@var{fill}}, and @code{>@var{region}} are all optional.
f22eee08 1170
b4d4e8e3
RP
1171@table @code
1172@item @var{start}
1173You can force the output section to be loaded at a specified address by
1174specifying @var{start} immediately following the section name.
1175@var{start} can be represented as any expression. The following
1176example generates section @var{output} at location
1177@code{0x40000000}:
1178@example
1179SECTIONS @{
1180 .
1181 .
1182 .
1183 output 0x40000000: @{
1184 @dots{}
1185 @}
1186 .
1187 .
1188 .
1189@}
f22eee08 1190@end example
f22eee08 1191
b4d4e8e3
RP
1192@item BLOCK(@var{align})
1193@c FIXME! Fill in BLOCK(align) description
f22eee08 1194
b4d4e8e3
RP
1195@item =@var{fill}
1196You may use any expression to specify @var{fill}. Including
1197@code{=@var{fill}} in a section definition specifies the initial fill
1198value for that section. Any unallocated holes in the current output
1199section when written to the output file will be filled with the two
1200least significant bytes of the value, repeated as necessary. You can
1201also change the fill value with a @code{FILL} statement in the
1202@var{contents} of a section definition.
f22eee08 1203
b4d4e8e3
RP
1204@item >@var{region}
1205@c FIXME! Fill in >region description
f22eee08 1206
f22eee08 1207@end table
b4d4e8e3
RP
1208
1209@node Entry Point,,,
1210@section The Entry Point
1211The linker command language includes a command specifically for
1212defining the first executable instruction in an output file (its
1213@dfn{entry point}). Its argument is a symbol name:
f22eee08 1214@example
b4d4e8e3 1215ENTRY(@var{symbol})
f22eee08 1216@end example
b4d4e8e3
RP
1217
1218Like symbol assignments, the @code{ENTRY} command may be placed either
1219as an independent command in the command file, or among the section
1220definitions within the @code{SECTIONS} command---whatever makes the most
1221sense for your layout.
1222
1223@code{ENTRY} is only one of several ways of choosing the entry point.
1224You may indicate it in any of the following ways (shown in descending
1225order of priority: methods higher in the list override methods lower down).
f22eee08
RP
1226@itemize @bullet
1227@item
b4d4e8e3 1228the @code{-e} @var{entry} command-line option;
f22eee08 1229@item
b4d4e8e3 1230the @code{ENTRY} @var{symbol} command in a linker control script;
f22eee08 1231@item
b4d4e8e3 1232the value of the symbol @code{start}, if present;
f22eee08 1233@item
b4d4e8e3 1234the value of the symbol @code{_main}, if present;
f22eee08 1235@item
b4d4e8e3 1236the address of the first byte of the @code{.text} section, if present;
f22eee08 1237@item
b4d4e8e3 1238The address @code{0}.
f22eee08 1239@end itemize
b4d4e8e3
RP
1240
1241For example, you can also generate an entry point with an assignment statement:
1242if no symbol @code{start} is defined within your input files, you can
1243simply assign it an appropriate value---
f22eee08 1244@example
b4d4e8e3 1245start = 0x2020;
f22eee08 1246@end example
b4d4e8e3
RP
1247
1248@noindent
1249The example shows an absolute address, but you can use any expression.
1250For example, if your input object files use some other symbol-name
1251convention for the entry point, you can just assign the value of
1252whatever symbol contains the start address to @code{start}:
f22eee08 1253@example
b4d4e8e3 1254start = other_symbol;
f22eee08 1255@end example
f22eee08 1256
b4d4e8e3
RP
1257@node Other Commands,,,
1258@section Other Commands
1259The command language includes a number of other commands that you can
1260use for specialized purposes. They are similar in purpose to
1261command-line options.
1262
1263@table @code
1264@item FLOAT
1265@itemx NOFLOAT
1266Declare to the linker whether or not floating point support is
1267available. The default assumption is @code{NOFLOAT}.
1268@c FIXME: So what? What does it do once it knows FLOAT or NOFLOAT?
1269
1270@item HLL ( @var{file}, @var{file}, @dots{} )
1271@itemx HLL ( @var{file} @var{file} @dots{} )
1272
1273@item INPUT ( @var{file}, @var{file}, @dots{} )
1274@itemx INPUT ( @var{file} @var{file} @dots{} )
1275
1276@item MAP ( @var{name} )
1277
1278@item OUTPUT ( @var{filename} )
f22eee08 1279
b4d4e8e3
RP
1280@item SEARCH_DIR ( @var{pathname} )
1281
1282@item STARTUP ( @var{name} )
1283
1284@item SYSLIB ( @var{file}, @var{file}, @dots{} )
1285@itemx SYSLIB ( @var{file} @var{file} @dots{} )
1286
1287@item TARGET ( @var{format} )
1288
1289@end table
1290
1291@node BFD,,,
f22eee08
RP
1292@chapter BFD
1293
1294The linker accesses object and archive files using the @code{bfd}
1295libraries. These libraries allow the linker to use the same routines
1296to operate on object files whatever the object file format.
1297
1298A different object file format can be supported simply by creating a
1299new @code{bfd} back end and adding it to the library.
1300
1301Formats currently supported:
1302@itemize @bullet
1303@item
b4d4e8e3 1304Sun3 68k @code{a.out}
f22eee08
RP
1305@item
1306IEEE-695 68k Object Module Format
1307@item
1308Oasys 68k Binary Relocatable Object File Format
1309@item
b4d4e8e3 1310Sun4 sparc @code{a.out}
f22eee08
RP
1311@item
131288k bcs coff
1313@item
1314i960 coff little endian
1315@item
1316i960 coff big endian
1317@item
b4d4e8e3 1318i960 @code{b.out} little endian
f22eee08 1319@item
b4d4e8e3 1320i960 @code{b.out} big endian
f22eee08
RP
1321@end itemize
1322
1323As with most implementations, @code{bfd} is a compromise between
1324several conflicting requirements. The major factor influencing
1325@code{bfd} design was efficiency, any time used converting between
1326formats is time which would not have been spent had @code{bfd} not
1327been involved. This is partly offset by abstraction payback; since
1328@code{bfd} simplifies applications and back ends, more time and care
1329may be spent optimizing algorithms for a greater speed.
1330
1331One minor artifact of the @code{bfd} solution which the
b4d4e8e3 1332user should be aware of is the potential for information loss.
f22eee08 1333There are two places where useful information can be lost using the
b4d4e8e3
RP
1334@code{bfd} mechanism; during conversion and during output. @xref{BFD
1335information loss}.
f22eee08 1336
b4d4e8e3
RP
1337@node BFD outline,,,
1338@section How it works: an outline of BFD
1339When an object file is opened, @code{bfd} subroutines automatically
1340determine the format of the input object file, and build a descriptor in
1341memory with pointers to routines that will be used to access elements of
1342the object file's data structures.
f22eee08
RP
1343
1344As different information from the the object files is required
b4d4e8e3
RP
1345@code{bfd} reads from different sections of the file and processes them.
1346For example a very common operation for the linker is processing symbol
1347tables. Each @code{bfd} back end provides a routine for converting
1348between the object file's representation of symbols and an internal
1349canonical format. When the linker asks for the symbol table of an object
1350file, it calls through the memory pointer to the relevant @code{bfd}
1351back end routine which reads and converts the table into a canonical
1352form. The linker then operates upon the common form. When the link is
1353finished and the linker writes the symbol table of the output file,
1354another @code{bfd} back end routine is called which takes the newly
1355created symbol table and converts it into the chosen output format.
1356
1357@node BFD information loss,,,
1358@section Information Loss
1359@emph{Information can be lost during output.} The output formats
1360supported by @code{bfd} do not provide identical facilities, and
1361information which may be described in one form has nowhere to go in
1362another format. One example of this is alignment information in
1363@code{b.out}. There is nowhere in an @code{a.out} format file to store
1364alignment information on the contained data, so when a file is linked
1365from @code{b.out} and an @code{a.out} image is produced, alignment
1366information will not propagate to the output file. (The linker will
1367still use the alignment information internally, so the link is performed
1368correctly).
f22eee08
RP
1369
1370Another example is COFF section names. COFF files may contain an
1371unlimited number of sections, each one with a textual section name. If
b4d4e8e3
RP
1372the target of the link is a format which does not have many sections (eg
1373@code{a.out}) or has sections without names (eg the Oasys format) the
1374link cannot be done simply. You can circumvent this problem by
1375describing the desired input-to-output section mapping with the command
1376language.
1377
1378@emph{Information lost during canonicalization.} The @code{bfd} internal
1379canonical form of the external formats is not exhaustive; there are
1380structures in input formats for which there is no direct representation
1381internally. This means that the @code{bfd} back ends cannot maintain
1382all possible data richness through the transformation between external to
1383internal and back to external formats.
f22eee08
RP
1384
1385This limitation is only a problem when using the linker to read one
1386format and write another. Each @code{bfd} back end is responsible for
1387maintaining as much data as possible, and the internal @code{bfd}
1388canonical form has structures which are opaque to the @code{bfd} core,
1389and exported only to the back ends. When a file is read in one format,
1390the canonical form is generated for @code{bfd} and the linker. At the
1391same time, the back end saves away any information which may otherwise
b4d4e8e3
RP
1392be lost. If the data is then written back to the same back end, the back
1393end routine will be able to use the canonical form provided by the
1394@code{bfd} core as well as the information it prepared earlier. Since
1395there is a great deal of commonality between back ends, this mechanism
1396is very useful. There is no information lost for this reason when
1397linking big endian COFF to little endian COFF, or from @code{a.out} to
1398@code{b.out}. When a mixture of formats is linked, the information is
1399only lost from the files whose format differs from the destination.
1400
1401@node Mechanism,,,
f22eee08 1402@section Mechanism
b4d4e8e3
RP
1403The greatest potential for loss of information is when there is least
1404overlap between the information provided by the source format, that
1405stored by the canonical format and the information needed by the
1406destination format. A brief description of the canonical form may help
1407you appreciate what kinds of data you can count on preserving across
1408conversions.
1409
1410@table @emph
1411@item files
1412Information on target machine architecture, particular implementation
1413and format type are stored on a per-file basis. Other information
1414includes a demand pageable bit and a write protected bit. Note that
1415information like Unix magic numbers is not stored here---only the magic
1416numbers' meaning, so a @code{ZMAGIC} file would have both the demand pageable
1417bit and the write protected text bit set.
1418
1419The byte order of the target is stored on a per-file basis, so that
1420both big- and little-endian object files may be linked with one another.
1421
1422@item sections
f22eee08
RP
1423Each section in the input file contains the name of the section, the
1424original address in the object file, various flags, size and alignment
1425information and pointers into other @code{bfd} data structures.
b4d4e8e3
RP
1426
1427@item symbols
f22eee08 1428Each symbol contains a pointer to the object file which originally
b4d4e8e3
RP
1429defined it, its name, value and various flag bits. When a symbol table
1430is read in, all symbols are relocated to make them relative to the base
1431of the section where they were defined, so that each symbol points to
1432its containing section. Each symbol also has a varying amount of hidden
1433data to contain private data for the BFD back end. Since the symbol
1434points to the original file, the private data format for that symbol is
1435accessible. @code{gld} can operate on a collection of symbols of wildly
f22eee08
RP
1436different formats without problems.
1437
1438Normal global and simple local symbols are maintained on output, so an
b4d4e8e3
RP
1439output file (no matter its format) will retain symbols pointing to
1440functions and to global, static, and common variables. Some symbol
1441information is not worth retaining; in @code{a.out} type information is
1442stored in the symbol table as long symbol names. This information would
1443be useless to most COFF debuggers and may be thrown away with
1444appropriate command line switches. (The GNU debugger @code{gdb} does
1445support @code{a.out} style debugging information in COFF).
f22eee08
RP
1446
1447There is one word of type information within the symbol, so if the
1448format supports symbol type information within symbols - (eg COFF,
1449IEEE, Oasys) and the type is simple enough to fit within one word
1450(nearly everything but aggregates) the information will be preserved.
1451
1452@item relocation level
b4d4e8e3
RP
1453@c FIXME: I don't understand "relocation record" from this so I can't
1454@c FIXME...improve the explanation to make it clear...
f22eee08
RP
1455Each canonical relocation record contains a pointer to the symbol to
1456relocate to, the offset of the data to relocate, the section the data
1457is in and a pointer to a relocation type descriptor. Relocation is
1458performed effectively by message passing through the relocation type
1459descriptor and symbol pointer. It allows relocations to be performed
1460on output data using a relocation method only available in one of the
1461input formats. For instance, Oasys provides a byte relocation format.
1462A relocation record requesting this relocation type would point
1463indirectly to a routine to perform this, so the relocation may be
1464performed on a byte being written to a COFF file, even though 68k COFF
1465has no such relocation type.
1466
1467@item line numbers
1468Line numbers have to be relocated along with the symbol information.
b4d4e8e3
RP
1469Each symbol with an associated list of line number records points to the
1470first record of the list. The head of a line number list consists of a
1471pointer to the symbol, which allows divination of the address of the
1472function whose line number is being described. The rest of the list is
1473made up of pairs: offsets into the section and line numbers. Any format
1474which can simply derive this information can pass it successfully
f22eee08
RP
1475between formats (COFF, IEEE and Oasys).
1476@end table
1477
b4d4e8e3 1478@contents
f22eee08
RP
1479@bye
1480
1481
This page took 0.087021 seconds and 4 git commands to generate.