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