]> Git Repo - binutils.git/blame_incremental - ld/ld.texinfo
Initial revision
[binutils.git] / ld / ld.texinfo
... / ...
CommitLineData
1\input texinfo
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@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
61Copyright @copyright{} 1991 Free Software Foundation, Inc.
62
63Permission is granted to make and distribute verbatim copies of
64this manual provided the copyright notice and this permission notice
65are preserved on all copies.
66
67Permission is granted to copy and distribute modified versions of this
68manual under the conditions for verbatim copying, provided also that
69the entire resulting derived work is distributed under the terms of a
70permission notice identical to this one.
71
72Permission is granted to copy and distribute translations of this manual
73into 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
80This 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
92Invocation
93
94* Options:: Command Line Options
95* Environment:: Environment Variables
96
97Command 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
106Expressions
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
116SECTIONS Command
117
118* Section Definition:: Section Definitions
119* Section Contents:: Section Contents
120* Section Options:: Optional Section Attributes
121
122BFD
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
135their data and ties up symbol references. Often the last step in
136building a new compiled program to run is a call to @code{gld}.
137
138@code{gld} accepts Linker Command Language files written in
139a superset of AT&T's Link Editor Command Language syntax,
140to provide explicit and total control over the linking process.
141
142This version of @code{gld} uses the general purpose BFD libraries
143to operate on object files. This allows @code{gld} to read, combine, and
144write object files in many different formats---for example, COFF or
145@code{a.out}. Different formats may be linked together to produce any
146available kind of object file. @xref{BFD} for a list of formats
147supported on various architectures.
148
149Aside from its flexibility, the GNU linker is more helpful than other
150linkers in providing diagnostic information. Many linkers abandon
151execution 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
158The GNU linker @code{gld} is meant to cover a broad range of situations,
159and to be as compatible as possible with other linkers. As a result,
160you have many choices to control its behavior through the command line,
161and 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
173Here is a sketch of the options you can use on the @code{gld} command
174line:
175
176@example
177gld [-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
195This plethora of command-line options may seem intimidating, but in
196actual practice few of them are used in any particular context.
197@cindex standard Unix system
198For instance, a frequent use of @code{gld} is to link standard Unix
199object files on a standard, supported Unix system. On such a system, to
200link a file @code{hello.o}:
201@example
202$ gld -o output /lib/crt0.o hello.o -lc
203@end example
204This tells @code{gld} to produce a file called @code{output} as the
205result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
206the library @code{libc.a} which will come from the standard search
207directories.
208
209The command-line options to @code{gld} may be specified in any order, and
210may be repeated at will. For the most part, repeating an option with a
211different argument will either have no further effect, or override prior
212occurrences (those further to the left on the command line) of an
213option.
214
215The 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
220The list of object files to be linked together, shown as @var{objfiles},
221may follow, precede, or be mixed in with command-line options; save that
222an @var{objfiles} argument may not be placed between an option flag and
223its argument.
224
225Usually the linker is invoked with at least one object file, but other
226forms of binary input files can also be specified with @code{-l},
227@code{-R}, and the script command language. If @emph{no} binary input
228files at all are specified, the linker does not produce any output, and
229issues the message @samp{No input files}.
230
231Option arguments must either follow the option letter without intervening
232whitespace, or be given as separate arguments immediately following the
233option that requires them.
234
235@table @code
236@item @var{objfiles}@dots{}
237The object files @var{objfiles} to be linked.
238
239@cindex architectures
240@kindex -A@var{arch}
241@item -A@var{architecture}
242In the current release of @code{gld}, this option is useful only for the
243Intel 960 family of architectures. In that @code{gld} configuration, the
244@var{architecture} argument is one of the two-letter names identifying
245members of the 960 family; the option specifies the desired output
246target, and warns of any incompatible instructions in the input files.
247It also modifies the linker's search strategy for archive libraries, to
248support the use of libraries specific to each particular
249architecture, by including in the search loop names suffixed with the
250string identifying the architecture.
251
252For example, if your @code{gld} command line included @w{@samp{-ACA}} as
253well as @w{@samp{-ltry}}, the linker would look (in its built-in search
254paths, and in any paths you specify with @code{-L}) for a library with
255the names
256@example
257try
258libtry.a
259tryca
260libtryca.a
261@end example
262@noindent
263The first two possibilities would be considered in any event; the last
264two are due to the use of @w{@samp{-ACA}}.
265
266Future releases of @code{gld} may support similar functionality for
267other architecture families.
268
269You can meaningfully use @code{-A} more than once on a command line, if
270an architecture family allows combination of target architectures; each
271use will add another pair of name variants to search for when @w{@code{-l}}
272specifies 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
279Specify the binary format for input object files that follow this option
280on 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
282usual format on each machine. @var{input-format} is a text string, the
283name of a particular format supported by the BFD libraries. @xref{BFD}.
284@code{-format @var{input-format}} has the same effect.@refill
285
286You may want to use this option if you are linking files with an unusual
287binary format. You can also use @code{-b} to switch formats explicitly (when
288linking object files of different formats), by including
289@code{-b @var{input-format}} before each group of object files in a
290particular format.
291
292The default format is taken from the environment variable
293@code{GNUTARGET}. @xref{Environment}. You can also define the input
294format from a script, using the command @code{TARGET}.
295
296@kindex -Bstatic
297@item -Bstatic
298This flag is accepted for command-line compatibility with the SunOS linker,
299but has no effect on @code{gld}.
300
301@kindex -c @var{cmdfile}
302@cindex script files
303@item -c @var{commandfile}
304Directs @code{gld} to read link commands from the file
305@var{commandfile}. These commands will completely override @code{gld}'s
306default link format (rather than adding to it); @var{commandfile} must
307specify everything necessary to describe the target format.
308@xref{Commands}.
309
310You may also include a script of link commands directly in the command
311line 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
320These three options are equivalent; multiple forms are supported for
321compatibility with other linkers. Use any of them to make @code{ld}
322assign space to common symbols even if a relocatable output file is
323specified (@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}
329Create a global symbol in the output file, containing the absolute
330address given by @var{expression}. You may use this option as many
331times as necessary to define multiple symbols in the command line. A
332limited form of arithmetic is supported for the @var{expression} in this
333context: you may give a hexadecimal constant or the name of an existing
334symbol, or use @code{+} and @code{-} to add or subtract hexadecimal
335constants or symbols. If you need more elaborate expressions, consider
336using 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}
341Use @var{entry} as the explicit symbol for beginning execution of your
342program, rather than the default entry point. @xref{Entry Point}, for a
343discussion of defaults and other ways of specifying the
344entry 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}
351Sets the default fill pattern for ``holes'' in the output file to
352the lowest two bytes of the expression specified. Holes are created
353when you advance the location counter (@xref{Location Counter}), or when
354there 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}
361Some older linkers used this option throughout a compilation toolchain
362for specifying object-file format for both input and output object
363files. @code{gld}'s mechanisms (the @code{-b} or @code{-format} options
364for input files, the @code{TARGET} command in linker scripts for output
365files, the @code{GNUTARGET} environment variable) are more flexible, but
366but it accepts (and ignores) the @code{-F} option flag for compatibility
367with scripts written to call the old linker.
368
369@kindex -format
370@item -format @var{input-format}
371Synonym for @code{-b} @var{input-format}.
372
373@kindex -g
374@item -g
375Accepted, but ignored; provided for compatibility with other tools.
376
377@kindex -i
378@cindex incremental link
379@item -i
380Perform 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}
385Add an archive file @var{ar} to the list of files to link. This
386option may be used any number of times. @code{ld} will search its
387path-list for occurrences of @code{lib@var{ar}.a} for every @var{ar}
388specified.
389
390@cindex search directory, from cmd line
391@kindex -L@var{dir}
392@item -L@var{searchdir}
393This command adds path @var{searchdir} to the list of paths that
394@code{gld} will search for archive libraries. You may use this option
395any number of times.
396
397The default set of paths searched (without being specified with
398@code{-L}) depends on what emulation mode @code{gld} is using, and in
399some cases also on how it was configured. @xref{Environment}. The
400paths can also be specified in a link script with the @code{SEARCH_DIR}
401command.
402
403@cindex link map
404@kindex -M
405@item -M
406@kindex -m
407@itemx -m
408Print (to the standard output file) a link map---diagnostic information
409about where symbols are mapped by @code{ld}, and information on global
410common 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
418specifies readable and writable @code{text} and @code{data} sections. If
419the output format supports Unix style magic numbers, the output is
420marked as @code{OMAGIC}.
421@end ignore
422
423@item -n
424@kindex -n
425@cindex read-only text
426@kindex NMAGIC
427sets the text segment to be read only, and @code{NMAGIC} is written
428if possible.
429
430@item -noinhibit-exec
431@cindex output file after errors
432@kindex -noinhibit-exec
433Normally, the linker will not produce an output file if it encounters
434errors during the link process. With this flag, you can specify that
435you 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
441option is not specified, the name @samp{a.out} is used by default. The
442script 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
447Read symbol names and their addresses from @var{filename}, but do not
448relocate it or include it in the output. This allows your output file
449to refer symbolically to absolute locations of memory defined in other
450programs.
451
452@item -r
453@cindex partial link
454@cindex relocatable output
455@kindex -r
456Generates relocatable output---i.e., generate an output file that can in
457turn serve as input to @code{gld}. This is often called @dfn{partial
458linking}. As a side effect, in environments that support standard Unix
459magic numbers, this option also sets the output file's magic number to
460@code{OMAGIC}.
461@c ; see @code{-N}.
462If this option is not specified, an absolute file is produced. When
463linking C++ programs, this option @emph{will not} resolve references to
464constructors; @code{-Ur} is an alternative. @refill
465
466This option does the same as @code{-i}.
467
468@item -S
469@kindex -S
470@cindex strip debugger symbols
471Omits debugger symbol information (but not all symbols) from the output file.
472
473@item -s
474@kindex -s
475@cindex strip all symbols
476Omits all symbol information from the output file.
477
478@item @{ @var{script} @}
479@kindex @{ @var{script} @}
480@cindex scripts on command line
481You can, if you wish, include a script of linker commands directly in
482the command line instead of referring to it via an input file. When the
483character @samp{@{} occurs on the command line, the linker switches to
484interpreting the command language until the end of the list of commands
485is reached---flagged with a closing brace @samp{@}}. Other command-line
486options 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
496Use @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}
503Equivalent to @code{-c @var{commandfile}}; supported for compatibility with
504other tools.
505
506@item -t
507@kindex -t
508@cindex verbose
509@cindex input files, displaying
510Prints names of input files as @code{ld} processes them.
511
512@item -u @var{sym}
513@kindex -u @var{sym}
514@cindex undefined symbol
515Forces @var{sym} to be entered in the output file as an undefined symbol.
516This may, for example, trigger linking of additional modules from
517standard libraries. @code{-u} may be repeated with different option
518arguments 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
525For 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
527turn 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
533Display the version number for @code{gld}.
534
535@item -X
536@kindex -X
537@cindex local symbols, deleting
538@cindex L, deleting symbols beginning
539If @code{-s} or @code{-S} is also specified, delete only local symbols
540beginning with @samp{L}.
541
542@item -x
543@kindex -x
544@cindex deleting local symbols
545If @code{-s} or @code{-S} is also specified, delete all local symbols,
546not 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
553Specifies a read-only, demand pageable, and shared @code{text} segment.
554If the output format supports Unix-style magic numbers, @code{-z} also
555marks 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?
560Specifying a relocatable output file (@code{-r}) will also set the magic
561number to @code{OMAGIC}.
562
563See 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}
572and @code{LDEMULATION}. Depending on the setting of the latter, other
573environment 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
578use @code{-b} (or its synonym @code{-format}). Its value should be one
579of 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
581of the host. If @code{GNUTARGET} is set to @code{default} then BFD attempts to discover the
582input format by examining binary input files; this method often
583succeeds, but there are potential ambiguities, since there is no method
584of ensuring that the magic number used to flag object-file formats is
585unique. However, the configuration procedure for BFD on each system
586places the conventional format for that system first in the search-list,
587so 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
593personality. Although @code{gld} is flexible enough to permit its use
594in many contexts regardless of configuration, you can use this variable
595to make it act more like one or another older linker by default.
596
597@cindex defaults
598@cindex library paths, default
599In particular, the value of @code{LDEMULATION} controls what default
600linker script is used (thereby controlling the default input and output
601formats; @pxref{BFD}); what default paths are searched for
602archive libraries; and in some cases whether additional linker script
603commands are available.
604
605Here is the current set of emulations available:
606@table @code
607
608@item LDEMULATION=gld
609@kindex gld
610@cindex emulating old GNU linker
611Emulate the older GNU linker. When this emulation is selected, the
612default library search paths are
613@example
614/lib
615/usr/lib
616/usr/local/lib/lib
617@end example
618@noindent
619The default output format is set to @code{a.out-generic-big}, and the
620default machine is the system's configured BFD default.
621
622@item LDEMULATION=gld68k
623@kindex gld68k
624@cindex m68k
625A variant of the @code{gld} emulation; only differs in specifically
626setting the default BFD machine as @code{m68k}.
627
628@item LDEMULATION=gld960
629@kindex gld960
630@kindex G960LIB
631@kindex G960BASE
632@cindex i960
633Emulate the Intel port of the older @code{gld} for the i960
634architectures. The default library search paths are taken from two
635other environment variables, @code{G960LIB} and @code{G960BASE}. The
636default architecture is @code{i960}. The default output format is set
637to @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
639format, for this emulation.
640
641@kindex GNU960
642This emulation can behave slightly differently depending on the setting
643of the @code{gld} compile-time switch @code{GNU960}. If @code{gld} is
644compiled with @code{GNU960} defined, then an additional environment
645variable---@code{GNUTARGET}---is available; its value, if available,
646specifies some other default output format than @code{b.out.big}.
647
648@item LDEMULATION=gldm88kbcs
649@kindex gldm88kbcs
650@cindex m88k
651Sets 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
663Emulate the Intel linker @code{lnk960}. The default output format is
664@code{coff-Intel-big}. With this emulation, @code{gld}
665supports the additional script commands @code{HLL} and @code{SYSLIB} for
666specification of library archives. This is the only emulation with
667extensive support for the @code{-A} (architecture) command-line option.
668By default, the architecture @code{CORE} is assumed, but you can choose
669additional features from the i960 architecture family by using one of
670the following with @code{-A} (or by using the @code{OUTPUT_ARCH} command
671from a script):
672@example
673CORE
674KB
675SB
676MC
677XA
678CA
679KA
680SA
681@end example
682
683The default libraries are chosen with some attention to the architecture
684selected; 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
689Like @code{gld960}, this emulation uses additional environment variables
690to set the default library search paths. Also like @code{gld960}, the
691behavior 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
697If your @code{gld} was compiled with @code{GNU960} defined, the default
698paths are taken from all three of @code{G960LIB}, @code{G960BASE}, and
699@code{I960BASE}. For the first two, paths you supply are automatically
700suffixed with @samp{/lib/libcoff}; for the last, your path is
701automatically suffixed with @samp{/lib}.
702
703If your @code{gld} was @emph{not} compiled with @code{GNU960} defined,
704the default paths are taken from @code{I960BASE}, and @code{G960BASE} is
705only 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
712This is the least specific setting for @code{gld}. You can set
713@code{LDEMULATION=vanilla} to disable emulation of other linkers. This
714setting makes @code{gld} take the default machine from the BFD
715configuration on your system; @code{a.out-generic-big} is the default
716target. 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
724The command language allows explicit control over the link process,
725allowing complete specification of the mapping between the linker's
726input files and its output. This includes:
727@itemize @bullet
728@item
729input files
730@item
731file formats
732@item
733output file format
734@item
735addresses of sections
736@item
737placement of common blocks
738@end itemize
739
740You may supply a command file (also known as a link script) to the
741linker either explicitly through the @code{-c} option, or implicitly as
742an ordinary file. If the linker opens a file which it cannot recognize
743as a supported object or archive format, it tries to interpret the file
744as a command file.
745
746You can also include a script directly on the @code{gld} command line,
747delimited 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
760The @code{gld} command language is a collection of statements; some are
761simple keywords setting a particular flag, some are used to select and
762group input files or name output files; and two particular statement
763types 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
769The most fundamental command of the @code{gld} command language is the
770@code{SECTIONS} command (@pxref{SECTIONS}). Every meaningful command
771script must have a @code{SECTIONS} command: it specifies a
772``picture'' of the output file's layout, in varying degrees of detail.
773No other command is required in all cases.
774
775The @code{MEMORY} command complements @code{SECTIONS} by describing the
776available memory in the target architecture. This command is optional;
777if you don't use a @code{MEMORY} command, @code{gld} assumes sufficient
778memory is available in a contiguous block for all output.
779@xref{MEMORY}.
780
781@cindex comments
782You may include comments in linker scripts just as in C: delimited
783by @samp{/*} and @samp{*/}. As in C, comments are syntactically
784equivalent to whitespace.
785
786@node Expressions, MEMORY, Scripts, Commands
787@section Expressions
788@cindex expression syntax
789@cindex arithmetic
790Many useful commands involve arithmetic expressions. The syntax for
791expressions in the command language is identical to that of C
792expressions, with the following features:
793@itemize @bullet
794@item
795All expressions evaluated as integers and
796are of ``long'' or ``unsigned long'' type.
797@item
798All constants are integers.
799@item
800All of the C arithmetic operators are provided.
801@item
802You may reference, define, and create global variables.
803@item
804You 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
821An octal integer is @samp{0} followed by zero or more of the octal
822digits (@samp{01234567}).
823@example
824_as_octal = 0157255;
825@end example
826
827@cindex decimal integers
828A decimal integer starts with a non-zero digit followed by zero or
829more digits (@samp{0123456789}).
830@example
831_as_decimal = 57005;
832@end example
833
834@cindex hexadecimal integers
835@kindex 0x
836A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or
837more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}.
838@example
839_as_hex = 0xdead;
840@end example
841
842@cindex negative integers
843Decimal integers have the usual values. To write a negative integer, use
844the 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
854Additionally the suffixes @code{K} and @code{M} may be used to scale a
855constant by
856@tex
857${\rm 1024}$ or ${\rm 1024}^2$
858@end tex
859@ifinfo
8601024 or 1024*1024
861@end ifinfo
862respectively. 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 "
876Unless quoted, symbol names start with a letter, underscore, point or
877hyphen and may include any letters, underscores, digits, points,
878and minus signs. Unquoted symbol names must not conflict with any
879keywords. You can specify a symbol which contains odd characters or has
880the 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
892The special linker variable @dfn{dot} @samp{.} always contains the
893current output location counter. Since the @code{.} always refers to
894a location in an output section, it must always appear in an
895expression within a @code{SECTIONS} command. The @code{.} symbol
896may appear anywhere that an ordinary symbol is allowed in an
897expression, but its assignments have a side effect. Assigning a value
898to the @code{.} symbol will cause the location counter to be moved.
899@cindex holes
900This may be used to create holes in the output section. The location
901counter may never be moved backwards.
902@example
903SECTIONS
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
916In the previous example, @code{file1} is located at the beginning of the
917output section, then there is a 1000 byte gap. Then @code{file2}
918appears, also with a 1000 byte gap following before @code{file3} is
919loaded. The notation @samp{= 0x1234} specifies what data to write in
920the 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
927The linker recognizes the standard C set of arithmetic operators, with
928the standard bindings and precedence levels:
929@ifinfo
930@example
931precedence associativity Operators Notes
932(highest)
9331 left ! - ~ (1)
9342 left * / %
9353 left + -
9364 left >> <<
9375 left == != > < <= >=
9386 left &
9397 left |
9408 left &&
9419 left ||
94210 right ? :
94311 right &= += -= *= /= (2)
944(lowest)
945@end example
946Notes:
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
957height2pt&\omit&&\omit&&\omit&\cr
958&Precedence&& Associativity &&{\rm Operators}&\cr
959height2pt&\omit&&\omit&&\omit&\cr
960\noalign{\hrule}
961height2pt&\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
976height2pt&\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
992The linker uses ``lazy evaluation'' for expressions; it only calculates
993an expression when absolutely necessary. The linker needs the value of
994the start address, and the lengths of memory regions, in order to do any
995linking at all; these values are computed as soon as possible when the
996linker reads in the command file. However, other values (such as symbol
997values) are not known or needed until after storage allocation. Such
998values are evaluated later, when other information (such as the sizes of
999output sections) is available for use in the symbol assignment
1000expression.
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
1007You may create global symbols, and assign values (addresses) to global
1008symbols, 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
1019Two things distinguish assignment from other operators in @code{gld}
1020expressions.
1021@itemize @bullet
1022@item
1023Assignment 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
1029A trailing semicolon is required at the end of an assignment
1030statement.
1031@end itemize
1032
1033Assignment statements may appear:
1034@itemize @bullet
1035@item
1036as commands in their own right in a @code{gld} script; or
1037@item
1038as independent statements within a @code{SECTIONS} command; or
1039@item
1040as part of the contents of a section definition in a
1041@code{SECTIONS} command.
1042@end itemize
1043
1044The first two cases are equivalent in effect---both define a symbol with
1045an absolute address; the last case defines a symbol whose address is
1046relative 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
1051When a linker expression is evaluated and assigned to a variable, it is
1052given either an absolute or a relocatable type. An absolute expression
1053type is one in which the symbol contains the value that it will have in
1054the output file, a relocateable expression type is one in which the
1055value is expressed as a fixed offset from the base of a section.
1056
1057The type of the expression is controlled by its position in the script
1058file. A symbol assigned within a section definition is created relative
1059to the base of the section; a symbol assigned in any other place is
1060created as an absolute symbol. Since a symbol created within a
1061section definition is relative to the base of the section, it
1062will remain relocatable if relocatable output is requested. A symbol
1063may be created with an absolute value even when assigned to within a
1064section definition by using the absolute assignment function
1065@code{ABSOLUTE}. For example, to create an absolute symbol whose address
1066is the last byte of an output section named @code{.data}:
1067@example
1068SECTIONS@{ @dots{}
1069.data :
1070 @{
1071 *(.data)
1072 _edata = ABSOLUTE(.) ;
1073 @}
1074@dots{} @}
1075@end example
1076
1077The linker tries to put off the evaluation of an assignment until all
1078the terms in the source expression are known (@pxref{Evaluation}). For
1079instance the sizes of sections cannot be known until after allocation,
1080so assignments dependent upon these are not performed until after
1081allocation. Some expressions, such as those depending upon the location
1082counter @dfn{dot}, @samp{.} must be evaluated during allocation. If the
1083result of an expression is required, but the value is not available,
1084then an error results. For example, a script like the following
1085@example
1086SECTIONS @{ @dots{}
1087 text 9+this_isnt_constant:
1088 @{ @dots{}
1089 @}
1090@dots{} @}
1091@end example
1092@kindex Non constant expression
1093@noindent
1094will cause the error message ``@code{Non constant expression for initial
1095address}''.
1096
1097@node Built-ins, , Assignment, Expressions
1098@subsection Built-In Functions
1099@cindex functions in expression language
1100The command language includes a number of special purpose built-in
1101functions for use in link script expressions.
1102@table @code
1103@item ABSOLUTE(@var{exp})
1104@kindex ABSOLUTE(@var{exp})
1105@cindex expression, absolute
1106returns the absolute value of the expression @var{exp}. Primarily
1107useful to assign an absolute value to a symbol within a section
1108definition, where symbol values are normally section-relative.
1109
1110@item ADDR(@var{section})
1111@kindex ADDR(@var{section})
1112@cindex section address
1113returns the absolute address of the named @var{section}. Your script must
1114previously have defined the location of that section. In the following
1115example the @code{symbol_1} and @code{symbol_2} are assigned identical
1116values:
1117@example
1118SECTIONS@{ @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
1135returns the result of the current location counter (@code{.}) aligned to
1136the next @var{exp} boundary. @var{exp} must be an expression whose
1137value 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
1143does arithmetic on it. As an example, to align the output @code{.data}
1144section to the next @code{0x2000} byte boundary after the preceding
1145section and to set a variable within the section to the next
1146@code{0x8000} boundary after the input sections:
1147@example
1148SECTIONS@{ @dots{}
1149 .data ALIGN(0x2000): @{
1150 *(.data)
1151 variable = ALIGN(0x8000);
1152 @}
1153@dots{} @}
1154@end example
1155@noindent
1156The first use of @code{ALIGN} in this example specifies the location of
1157a section because it is used as the optional @var{start} attribute of a
1158section definition (@pxref{Section Options}). The second use simply
1159defines the value of a variable.
1160
1161The 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
1166Returns @code{1} if @var{symbol} is in the linker global symbol table and is
1167defined, otherwise it returns @code{0}. You can use this to provide default
1168values for symbols. For example, this command-file fragment shows how
1169to set a global symbol @code{begin} to the first location in the
1170@code{.text} section---but if a symbol called @code{begin} already
1171existed, its value is preserved:
1172@example
1173SECTIONS@{ @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
1184Returns the next unallocated address that is a multiple of @var{exp}.
1185This command is closely related to @code{ALIGN(@var{exp})}; unless you
1186use the @code{MEMORY} command to define discontinuous memory for the
1187output file, the two commands are equivalent.
1188
1189@item SIZEOF(@var{section})
1190@kindex SIZEOF(@var{section})
1191@cindex section size
1192returns the size in bytes of the named @var{section}, if the section has
1193been allocated. In the following example the @code{symbol_1} and
1194@code{symbol_2} are assigned identical values:
1195@example
1196SECTIONS@{ @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
1213the size in bytes of the output file's headers. You can use this number
1214as the start address of the first section, if you choose, to facilitate
1215paging.
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
1225The linker's default configuration permits allocation of all memory.
1226You can override this by using the @code{MEMORY} command. The
1227@code{MEMORY} command describes the location and size of blocks of
1228memory in the target. By using it carefully, you can describe which
1229memory regions may be used by the linker, and which memory regions it
1230must avoid. The linker does not shuffle sections to fit into the
1231available regions, but does move the requested sections into the correct
1232regions and issue errors when the regions become too full.
1233
1234Command files may contain at most one use of the @code{MEMORY}
1235command; however, you can define as many blocks of memory within it as
1236you wish. The syntax is:
1237
1238@example
1239MEMORY
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
1248is a name used internally by the linker to refer to the region. Any
1249symbol name may be used. The region names are stored in a separate
1250name space, and will not conflict with symbols, filenames or section
1251names. Use distinct names to specify multiple regions.
1252@item (@var{attr})
1253@cindex memory region attributes
1254is an optional list of attributes, permitted for compatibility with the
1255AT&T linker but not used by @code{gld} beyond checking that the
1256attribute list is valid. Valid attribute lists must be made up of the
1257characters ``@code{LIRWX}''. If you omit the attribute list, you may
1258omit the parentheses around it as well.
1259@item @var{origin}
1260@kindex ORIGIN=
1261@kindex o=
1262@kindex org=
1263is the start address of the region in physical memory. It is expressed as
1264an expression, which must evaluate to a constant before
1265memory allocation is performed. The keyword @code{ORIGIN} may be
1266abbreviated to @code{org} or @code{o}.
1267@item @var{len}
1268@kindex LENGTH=
1269@kindex len=
1270@kindex l=
1271is the size in bytes of the region (an expression).
1272The keyword @code{LENGTH} may be abbreviated to @code{len} or @code{l}.
1273@end table
1274
1275For example, to specify that memory has two regions available for
1276allocation---one starting at @code{0} for 256 kilobytes, and the other
1277starting at @code{0x40000000} for four megabytes:
1278
1279@example
1280MEMORY
1281 @{
1282 rom : ORIGIN= 0, LENGTH = 256K
1283 ram : org= 0x40000000, l = 4M
1284 @}
1285@end example
1286
1287Once you have defined a region of memory named @var{mem}, you can direct
1288specific output sections there by using a command ending in
1289@samp{>@var{mem}} within the @code{SECTIONS} command (@pxref{Section
1290Options}). If the combined output sections directed to a region are too
1291big 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
1296The @code{SECTIONS} command controls exactly where input sections are
1297placed into output sections, their order and to which output sections
1298they are allocated.
1299
1300You may use at most one @code{SECTIONS} command in a commands file,
1301but you can have as many statements within it as you wish. Statements
1302within the @code{SECTIONS} command can do one of three things:
1303@itemize @bullet
1304@item
1305define the entry point;
1306@item
1307assign a value to a symbol;
1308@item
1309describe the placement of a named output section, and what input
1310sections make it up.
1311@end itemize
1312
1313The first two possibilities---defining the entry point, and defining
1314symbols---can also be done outside the @code{SECTIONS} command:
1315@pxref{Entry Point}, @pxref{Assignment}. They are permitted here as
1316well for your convenience in reading the script, so that symbols or the
1317entry point can be defined at meaningful points in your output-file
1318layout.
1319
1320When no @code{SECTIONS} command is specified, the default action
1321of the linker is to place each input section into an identically named
1322output section in the order that the sections are first encountered in
1323the input files; if all input sections are present in the first file,
1324for example, the order of sections in the output file will match the
1325order 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
1336The most frequently used statement in the @code{SECTIONS} command is
1337the @dfn{section definition}, which you can use to specify the
1338properties of an output section: its location, alignment, contents,
1339fill pattern, and target memory region can all be specified. Most of
1340these specifications are optional; the simplest form of a section
1341definition is
1342@example
1343SECTIONS @{ @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
1352specification of what goes there---for example a list of input files or
1353sections of input files. As you might assume, the whitespace shown is
1354optional; you do need the colon @samp{:} and the braces @samp{@{@}},
1355however.
1356
1357@var{secname} must meet the constraints of your output format. In
1358formats 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
1362with numbers and not names (as is the case for Oasys), the name should be
1363supplied as a quoted numeric string. A section name may consist of any
1364sequence 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
1370In a section definition, you can specify the contents of an output section by
1371listing particular object files; by listing particular input-file
1372sections; or a combination of the two. You can also place arbitrary
1373data in the section, and define symbols relative to the beginning of the
1374section.
1375
1376The @var{contents} of a section definition may include any of the
1377following kinds of statement. You can include as many of these as you
1378like in a single section definition, separated from one another by
1379whitespace.
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
1386You may simply name a particular input file to be placed in the current
1387output section; @emph{all} sections from that file are placed in the
1388current section definition. To specify a list of particular files by
1389name:
1390@example
1391.data: @{ afile.o bfile.o cfile.o @}
1392@end example
1393@noindent
1394The example also illustrates that multiple statements can be included in
1395the contents of a section definition, since each filename is a separate
1396statement.
1397
1398If the file name has already been mentioned in another section
1399definition, with an explicit section name list, then only those sections
1400which 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
1407You can name one or more sections from your input files, for
1408insertion in the current output section. If you wish to specify a list
1409of input-file sections inside the parentheses, you may separate the
1410section 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})
1417Instead of explicitly naming particular input files in a link control
1418script, you can refer to @emph{all} files from the @code{gld} command
1419line: use @samp{*} instead of a particular filename before the
1420parenthesized input-file section list.
1421
1422For example, to copy sections @code{1} through @code{4} from a Oasys file
1423into the @code{.text} section of an @code{a.out} file, and sections @code{13}
1424and @code{14} into the @code{.data} section:
1425@example
1426SECTIONS @{
1427 .text :@{
1428 *("1" "2" "3" "4")
1429 @}
1430
1431 .data :@{
1432 *("13" "14")
1433 @}
1434@}
1435@end example
1436
1437If you have already explicitly included some files by name, @samp{*}
1438refers to all @emph{remaining} files---those whose places in the output
1439file 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} ]
1445This is an alternate notation to specify named sections from all
1446unallocated 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
1454Specify where in your output file to place uninitialized data
1455with this notation. @code{[COMMON]} by itself refers to all
1456uninitialized data from all input files (so far as it is not yet
1457allocated); @var{filename}@code{(COMMON)} refers to uninitialized data
1458from a particular file. Both are special cases of the general
1459mechanisms for specifying where to place input-file sections:
1460@code{gld} permits you to refer to uninitialized data as if it
1461were in an input-file section named @code{COMMON}, regardless of the
1462input file's format.
1463@end table
1464
1465For example, the following command script arranges the output file into
1466three consecutive sections, named @code{.text}, @code{.data}, and
1467@code{.bss}, taking the input for each from the correspondingly named
1468sections of all the input files:
1469@example
1470SECTIONS @{
1471 .text: @{ *(.text) @}
1472 .data: @{ *(.data) @}
1473 .bss: @{ *(.bss) [COMMON] @}
1474@}
1475@end example
1476
1477The following example reads all of the sections from file @code{all.o}
1478and places them at the start of output section @code{outputa} which
1479starts at location @code{0x10000}. All of section @code{.input1} from
1480file @code{foo.o} follows immediately, in the same output section. All
1481of section @code{.input2} from @code{foo.o} goes into output section
1482@code{outputb}, followed by section @code{.input1} from @code{foo1.o}.
1483All of the remaining @code{.input1} and @code{.input2} sections from any
1484files are written to output section @code{outputc}.
1485
1486@example
1487SECTIONS @{
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
1506There are still more kinds of statements permitted in the contents of
1507output section definitions. The foregoing statements permitted you to
1508arrange, in your output file, data originating from your input files.
1509You can also place data directly in an output section from the link
1510command script. Most of these additional statements involve
1511expressions; @pxref{Expressions}. Although these statements are shown
1512separately here for ease of presentation, no such segregation is needed
1513within a section definition in the @code{SECTIONS} command; you can
1514intermix 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
1521instructs the linker to create a symbol for each input file
1522in the current section, set with the address of the first byte of
1523data written from the input file. For instance, with @code{a.out}
1524files it is conventional to have a symbol for each input file. You can
1525accomplish this by defining the output @code{.text} section as follows:
1526@example
1527SECTIONS @{
1528 .text 0x2020 :
1529 @{
1530 CREATE_OBJECT_SYMBOLS
1531 *(.text)
1532 _etext = ALIGN(0x2000);
1533 @}
1534 @dots{}
1535@}
1536@end example
1537
1538If @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
1540contents like the following---
1541@example
1542/* a.c */
1543
1544afunction() @{ @}
1545int adata=1;
1546int 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,
1551containing symbols matching the object file names:
1552@example
155300000000 A __DYNAMIC
155400004020 B _abss
155500004000 D _adata
155600002020 T _afunction
155700004024 B _bbss
155800004008 D _bdata
155900002038 T _bfunction
156000004028 B _cbss
156100004010 D _cdata
156200002050 T _cfunction
15630000402c B _dbss
156400004018 D _ddata
156500002068 T _dfunction
156600004020 D _edata
156700004030 B _end
156800004000 T _etext
156900002020 t a.o
157000002038 t b.o
157100002050 t c.o
157200002068 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}=''
1580refers to any of the operators @code{&= += -= *= /=} which combine
1581arithmetic and assignment.
1582
1583@cindex assignment, in section defn
1584When you assign a value to a symbol within a particular section
1585definition, the value is relative to the beginning of the section
1586(@pxref{Assignment}). If you write
1587@example
1588SECTIONS @{
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
1599same 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
1608By including one of these three statements in a section definition, you
1609can explicitly place one, two, or four bytes (respectively) at the
1610current address of that section. Multiple-byte quantities are
1611represented in whatever byte order is appropriate for the output file
1612format (@pxref{BFD}).
1613
1614@item FILL(@var{expression})
1615@kindex FILL(@var{expression})
1616@cindex holes, filling
1617@cindex unspecified memory
1618Specifies the ``fill pattern'' for the current section. Any otherwise
1619unspecified regions of memory within the section (for example, regions
1620you skip over by assigning a new value to the location counter @samp{.})
1621are filled with the two least significant bytes from the
1622@var{expression} argument. A @code{FILL} statement covers memory
1623locations @emph{after} the point it occurs in the section definition; by
1624including more than one @code{FILL} statement, you can have different
1625fill 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
1631Here is the full syntax of a section definition, including all the
1632optional portions:
1633
1634@example
1635SECTIONS @{
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
1643Definition}, and @pxref{Section Contents} for details on @var{contents}.
1644The 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
1652You can force the output section to be loaded at a specified address by
1653specifying @var{start} immediately following the section name.
1654@var{start} can be represented as any expression. The following
1655example generates section @var{output} at location
1656@code{0x40000000}:
1657@example
1658SECTIONS @{
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
1671You can include @code{BLOCK()} specification to advance the location of
1672the location counter @code{.} prior to the beginning of the section, so
1673that the section will begin at the specified alignment. @var{align} is
1674an expression.
1675
1676@item =@var{fill}
1677@kindex =@var{fill}
1678@cindex section fill pattern
1679@cindex fill pattern, entire section
1680You may use any expression to specify @var{fill}. Including
1681@code{=@var{fill}} in a section definition specifies the initial fill
1682value for that section. Any unallocated holes in the current output
1683section when written to the output file will be filled with the two
1684least significant bytes of the value, repeated as necessary. You can
1685also 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
1692Assign 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
1702The linker command language includes a command specifically for
1703defining the first executable instruction in an output file (its
1704@dfn{entry point}). Its argument is a symbol name:
1705@example
1706ENTRY(@var{symbol})
1707@end example
1708
1709Like symbol assignments, the @code{ENTRY} command may be placed either
1710as an independent command in the command file, or among the section
1711definitions within the @code{SECTIONS} command---whatever makes the most
1712sense for your layout.
1713
1714@cindex entry point, defaults
1715@code{ENTRY} is only one of several ways of choosing the entry point.
1716You may indicate it in any of the following ways (shown in descending
1717order of priority: methods higher in the list override methods lower down).
1718@itemize @bullet
1719@item
1720the @code{-e} @var{entry} command-line option;
1721@item
1722the @code{ENTRY(@var{symbol}} command in a linker control script;
1723@item
1724the value of the symbol @code{start}, if present;
1725@item
1726the value of the symbol @code{_main}, if present;
1727@item
1728the address of the first byte of the @code{.text} section, if present;
1729@item
1730The address @code{0}.
1731@end itemize
1732
1733For example, you can use these rules to generate an entry point with an
1734assignment statement: if no symbol @code{start} is defined within your
1735input files, you can simply define it, assigning it an appropriate
1736value---
1737@example
1738start = 0x2020;
1739@end example
1740
1741@noindent
1742The example shows an absolute address, but you can use any expression.
1743For example, if your input object files use some other symbol-name
1744convention for the entry point, you can just assign the value of
1745whatever symbol contains the start address to @code{start}:
1746@example
1747start = other_symbol;
1748@end example
1749
1750@node Other Commands, , Entry Point, Commands
1751@section Other Commands
1752The command language includes a number of other commands that you can
1753use for specialized purposes. They are similar in purpose to
1754command-line options.
1755
1756@table @code
1757@item FLOAT
1758@kindex FLOAT
1759@itemx NOFLOAT
1760@kindex NOFLOAT
1761These keywords were used in some older linkers to request a particular
1762math subroutine library. @code{gld} doesn't use the keywords, assuming
1763instead that any necessary subroutines are in libraries specified using
1764the general mechanisms for linking to archives; but to permit the use of
1765scripts 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
1771This command has the same effect as the @code{-d} command-line option:
1772to make @code{ld} assign space to common symbols even if a relocatable
1773output 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 ( )
1779Include ``high-level libraries'' or archives as input files in the link.
1780Using @code{HLL(@var{file}} in a linker script is equivalent to
1781including @code{-l}@var{file} on the command line.
1782
1783@cindex @code{lnk960} command @code{HLL}
1784The @code{HLL} command is only supported when @code{gld} emulates
1785@code{lnk960}, as specified by the @code{LDEMULATION} environment
1786variable.
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
1792Use this command to include binary input files in the link, without
1793including them in a particular section definition. Files specified this
1794way 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
1807Name 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
1810control the name actually used to name the output file. In particular,
1811you 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
1817Specify a particular output machine architecture, with one of the names
1818used by the BFD back-end routines (@pxref{BFD}). This command is often
1819unnecessary; the architecture is most often set implicitly by either the
1820system BFD configuration or as a side effect of the @code{OUTPUT_FORMAT}
1821command. @refill
1822
1823@item OUTPUT_FORMAT ( @var{bfdname} )
1824@kindex OUTPUT_FORMAT ( @var{bfdname} )
1825@cindex format, output file
1826Specify a particular output format, with one of the names used by the
1827BFD back-end routines (@pxref{BFD}). This selection will only affect
1828the output file; the related command @code{TARGET} affects primarily
1829input 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
1835Add @var{path} to the list of paths where @code{gld} looks for
1836archive libraries. @code{SEARCH_DIR(@var{path})} has the same
1837effect 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
1842Ensure that @var{filename} is the first input file used in the link
1843process.
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{} )
1848Use the named @var{file}s as binary input files, searching for them in
1849the same list of paths as archives.
1850
1851@cindex @code{lnk960} command @code{SYSLIB}
1852The @code{SYSLIB} command is only supported when @code{gld} emulates
1853@code{lnk960}, as specified by the @code{LDEMULATION} environment
1854variable.
1855
1856@item TARGET ( @var{format} )
1857@cindex input file format
1858@kindex TARGET ( @var{format} )
1859Change the input-file object code format (like the command-line option
1860@code{-b} or its synonym @code{-format}). The argument @var{format} is
1861one 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
1864used as the default format for the @code{gld} output file.
1865@xref{BFD}.@refill
1866
1867@kindex GNUTARGET
1868If you don't use the @code{TARGET} command, @code{gld} uses the value of
1869the environment variable @code{GNUTARGET}, if available, to select the
1870output file format. If that variable is also absent, @code{gld} uses
1871the 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
1880The linker accesses object and archive files using the BFD libraries.
1881These libraries allow the linker to use the same routines to operate on
1882object files whatever the object file format. A different object file
1883format can be supported simply by creating a new BFD back end and adding
1884it to the library. BFD supports the following combinations of
1885architectures (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
1901ARCHITECTURES | | | | | | | | | |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
1965As with most implementations, BFD is a compromise between
1966several conflicting requirements. The major factor influencing
1967BFD design was efficiency: any time used converting between
1968formats is time which would not have been spent had BFD not
1969been involved. This is partly offset by abstraction payback; since
1970BFD simplifies applications and back ends, more time and care
1971may be spent optimizing algorithms for a greater speed.
1972
1973One minor artifact of the BFD solution which you should bear in
1974mind is the potential for information loss. There are two places where
1975useful information can be lost using the BFD mechanism; during
1976conversion 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
1987When an object file is opened, BFD subroutines automatically
1988determine the format of the input object file, and build a descriptor in
1989memory with pointers to routines that will be used to access elements of
1990the object file's data structures.
1991
1992As different information from the the object files is required
1993BFD reads from different sections of the file and processes them.
1994For example a very common operation for the linker is processing symbol
1995tables. Each BFD back end provides a routine for converting
1996between the object file's representation of symbols and an internal
1997canonical format. When the linker asks for the symbol table of an object
1998file, it calls through the memory pointer to the relevant BFD
1999back end routine which reads and converts the table into a canonical
2000form. The linker then operates upon the common form. When the link is
2001finished and the linker writes the symbol table of the output file,
2002another BFD back end routine is called which takes the newly
2003created 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
2008supported by BFD do not provide identical facilities, and
2009information which may be described in one form has nowhere to go in
2010another 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
2012alignment information on the contained data, so when a file is linked
2013from @code{b.out} and an @code{a.out} image is produced, alignment
2014information will not propagate to the output file. (The linker will
2015still use the alignment information internally, so the link is performed
2016correctly).
2017
2018Another example is COFF section names. COFF files may contain an
2019unlimited number of sections, each one with a textual section name. If
2020the 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
2022link cannot be done simply. You can circumvent this problem by
2023describing the desired input-to-output section mapping with the command
2024language.
2025
2026@emph{Information can be lost during canonicalization.} The BFD
2027internal canonical form of the external formats is not exhaustive; there
2028are structures in input formats for which there is no direct
2029representation internally. This means that the BFD back ends
2030cannot maintain all possible data richness through the transformation
2031between external to internal and back to external formats.
2032
2033This limitation is only a problem when using the linker to read one
2034format and write another. Each BFD back end is responsible for
2035maintaining as much data as possible, and the internal BFD
2036canonical form has structures which are opaque to the BFD core,
2037and exported only to the back ends. When a file is read in one format,
2038the canonical form is generated for BFD and the linker. At the
2039same time, the back end saves away any information which may otherwise
2040be lost. If the data is then written back in the same format, the back
2041end routine will be able to use the canonical form provided by the
2042BFD core as well as the information it prepared earlier. Since
2043there is a great deal of commonality between back ends, this mechanism
2044is very useful. There is no information lost for this reason when
2045linking 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
2047only lost from the files whose format differs from the destination.
2048
2049@node Mechanism, , BFD information loss, BFD
2050@section Mechanism
2051The greatest potential for loss of information is when there is least
2052overlap between the information provided by the source format, that
2053stored by the canonical format, and the information needed by the
2054destination format. A brief description of the canonical form may help
2055you appreciate what kinds of data you can count on preserving across
2056conversions.
2057@cindex BFD canonical format
2058@cindex internal object-file format
2059
2060@table @emph
2061@item files
2062Information on target machine architecture, particular implementation
2063and format type are stored on a per-file basis. Other information
2064includes a demand pageable bit and a write protected bit. Note that
2065information like Unix magic numbers is not stored here---only the magic
2066numbers' meaning, so a @code{ZMAGIC} file would have both the demand pageable
2067bit and the write protected text bit set.
2068
2069The byte order of the target is stored on a per-file basis, so that big-
2070and little-endian object files may be linked with one another.
2071
2072@item sections
2073Each section in the input file contains the name of the section, the
2074original address in the object file, various flags, size and alignment
2075information and pointers into other BFD data structures.
2076
2077@item symbols
2078Each symbol contains a pointer to the object file which originally
2079defined it, its name, its value, and various flag bits. When a
2080BFD back end reads in a symbol table, the back end relocates all
2081symbols to make them relative to the base of the section where they were
2082defined. This ensures that each symbol points to its containing
2083section. Each symbol also has a varying amount of hidden data to contain
2084private data for the BFD back end. Since the symbol points to the
2085original file, the private data format for that symbol is accessible.
2086@code{gld} can operate on a collection of symbols of wildly different
2087formats without problems.
2088
2089Normal global and simple local symbols are maintained on output, so an
2090output file (no matter its format) will retain symbols pointing to
2091functions and to global, static, and common variables. Some symbol
2092information is not worth retaining; in @code{a.out} type information is
2093stored in the symbol table as long symbol names. This information would
2094be useless to most COFF debuggers and may be thrown away with
2095appropriate command line switches. (The GNU debugger @code{gdb} does
2096support @code{a.out} style debugging information in COFF).
2097
2098There is one word of type information within the symbol, so if the
2099format supports symbol type information within symbols (for example COFF,
2100IEEE, 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
2104Each canonical BFD relocation record contains a pointer to the symbol to
2105relocate to, the offset of the data to relocate, the section the data
2106is in and a pointer to a relocation type descriptor. Relocation is
2107performed effectively by message passing through the relocation type
2108descriptor and symbol pointer. It allows relocations to be performed
2109on output data using a relocation method only available in one of the
2110input formats. For instance, Oasys provides a byte relocation format.
2111A relocation record requesting this relocation type would point
2112indirectly to a routine to perform this, so the relocation may be
2113performed on a byte being written to a COFF file, even though 68k COFF
2114has no such relocation type.
2115
2116@item line numbers
2117Object formats can contain, for debugging purposes, some form of mapping
2118between symbols, source line numbers, and addresses in the output file.
2119These addresses have to be relocated along with the symbol information.
2120Each symbol with an associated list of line number records points to the
2121first record of the list. The head of a line number list consists of a
2122pointer to the symbol, which allows divination of the address of the
2123function whose line number is being described. The rest of the list is
2124made up of pairs: offsets into the section and line numbers. Any format
2125which can simply derive this information can pass it successfully
2126between 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: [email protected], 28mar91.
2147@end tex
2148
2149
2150@contents
2151@bye
2152
2153
This page took 0.043936 seconds and 4 git commands to generate.