]>
Commit | Line | Data |
---|---|---|
f22eee08 | 1 | \input texinfo |
c8072296 | 2 | @setfilename ld.info |
b4d4e8e3 RP |
3 | @c $Id$ |
4 | @syncodeindex ky cp | |
2d59b2c3 | 5 | @c @smallbook |
c8072296 | 6 | @c @cropmarks |
1c48127e RP |
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 | ||
b4d4e8e3 RP |
16 | @ifinfo |
17 | This file documents the GNU linker GLD. | |
18 | ||
2d59b2c3 | 19 | Copyright (C) 1991, 1992 Free Software Foundation, Inc. |
b4d4e8e3 RP |
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 | |
2c5c0674 RP |
45 | @iftex |
46 | @finalout | |
b4d4e8e3 RP |
47 | @setchapternewpage odd |
48 | @settitle GLD, the GNU linker | |
f22eee08 | 49 | @titlepage |
c8072296 RP |
50 | @title gld |
51 | @subtitle The GNU linker | |
f22eee08 | 52 | @sp 1 |
b4d4e8e3 | 53 | @subtitle Second Edition---@code{gld} version 2.0 |
2d59b2c3 | 54 | @subtitle January 1992 |
c8072296 RP |
55 | @author Steve Chamberlain and Roland Pesch |
56 | @author Cygnus Support | |
b4d4e8e3 RP |
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 | |
2c5c0674 | 64 | \hfill steve\@cygnus.com, pesch\@cygnus.com\par |
b4d4e8e3 RP |
65 | \hfill {\it GLD, the GNU linker}, \manvers\par |
66 | \hfill \TeX{}info \texinfoversion\par | |
b4d4e8e3 RP |
67 | } |
68 | \global\parindent=0pt % Steve likes it this way. | |
69 | @end tex | |
70 | ||
f22eee08 | 71 | @vskip 0pt plus 1filll |
2d59b2c3 | 72 | Copyright @copyright{} 1991, 1992 Free Software Foundation, Inc. |
f22eee08 RP |
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. | |
f22eee08 | 85 | @end titlepage |
2c5c0674 | 86 | @end iftex |
b4d4e8e3 | 87 | @c FIXME: Talk about importance of *order* of args, cmds to linker! |
f22eee08 | 88 | |
2c5c0674 | 89 | @node Top, Overview, (dir), (dir) |
f22eee08 RP |
90 | @ifinfo |
91 | This file documents the GNU linker gld. | |
92 | @end ifinfo | |
93 | ||
2c5c0674 | 94 | @menu |
2d59b2c3 RP |
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 | |
2c5c0674 RP |
102 | |
103 | --- The Detailed Node Listing --- | |
104 | ||
105 | Invocation | |
106 | ||
2d59b2c3 RP |
107 | * Options:: Command Line Options |
108 | * Environment:: Environment Variables | |
2c5c0674 RP |
109 | |
110 | Command Language | |
111 | ||
2d59b2c3 RP |
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 | |
2c5c0674 RP |
118 | |
119 | Expressions | |
120 | ||
2d59b2c3 RP |
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 | |
2c5c0674 RP |
128 | |
129 | SECTIONS Command | |
130 | ||
2d59b2c3 RP |
131 | * Section Definition:: Section Definitions |
132 | * Section Contents:: Section Contents | |
133 | * Section Options:: Optional Section Attributes | |
1c48127e RP |
134 | |
135 | Machine Dependent Features | |
136 | ||
2d59b2c3 RP |
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 | |
1c48127e RP |
141 | |
142 | @code{gld} and the Intel 960 family | |
143 | ||
2d59b2c3 RP |
144 | * i960-arch:: Linking for a Specific i960 Architecture |
145 | * i960-emulation:: Emulating Other i960 Linkers | |
146 | * i960-commands:: Command Language Extensions for i960 | |
2c5c0674 RP |
147 | |
148 | BFD | |
149 | ||
2d59b2c3 RP |
150 | * BFD outline:: How it works: an outline of BFD |
151 | * BFD information loss:: Information Loss | |
152 | * Mechanism:: Mechanism | |
2c5c0674 RP |
153 | @end menu |
154 | ||
155 | @node Overview, Invocation, Top, Top | |
f22eee08 RP |
156 | @chapter Overview |
157 | ||
2c5c0674 RP |
158 | @cindex GNU linker |
159 | @cindex what is this? | |
b4d4e8e3 RP |
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}. | |
f22eee08 | 163 | |
b4d4e8e3 | 164 | @code{gld} accepts Linker Command Language files written in |
2c5c0674 | 165 | a superset of AT&T's Link Editor Command Language syntax, |
b4d4e8e3 | 166 | to provide explicit and total control over the linking process. |
f22eee08 | 167 | |
2c5c0674 | 168 | This version of @code{gld} uses the general purpose BFD libraries |
b4d4e8e3 RP |
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. | |
f22eee08 | 174 | |
2c5c0674 RP |
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 | |
2d59b2c3 RP |
190 | * Options:: Command Line Options |
191 | * Environment:: Environment Variables | |
2c5c0674 | 192 | @end menu |
f22eee08 | 193 | |
2c5c0674 RP |
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: | |
f22eee08 | 201 | |
c8072296 | 202 | @smallexample |
b4d4e8e3 | 203 | gld [-o @var{output} ] @var{objfiles}@dots{} |
2c5c0674 | 204 | [ -A@var{architecture} ] [ -b @var{input-format} ] [ -Bstatic ] |
2d59b2c3 | 205 | [ -c @var{MRI-commandfile} ] [ -d | -dc | -dp ] |
2c5c0674 RP |
206 | [ -defsym @var{symbol} = @var{expression} ] |
207 | [ -e @var{entry} ] [ -F ] [ -F @var{format} ] | |
2c5c0674 | 208 | [ -format @var{input-format} ] [ -g ] [ -i ] |
b4d4e8e3 | 209 | [ -l@var{ar} ] [ -L@var{searchdir} ] [ -M | -m ] |
1c48127e | 210 | [ -n ] [ -noinhibit-exec ] [ -R @var{filename} ] [ -relax ] |
2c5c0674 | 211 | [ -r | -Ur ] [ -S ] [ -s ] [ -T @var{commandfile} ] |
b4d4e8e3 RP |
212 | [ -Ttext @var{textorg} ] [ -Tdata @var{dataorg} ] [ -Tbss @var{bssorg} ] |
213 | [ -t ] [ -u @var{sym}] [-v] [ -X ] [ -x ] | |
2c5c0674 | 214 | [ @{ @var{script} @} ] |
c8072296 | 215 | @end smallexample |
b4d4e8e3 RP |
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. | |
2c5c0674 | 219 | @cindex standard Unix system |
b4d4e8e3 RP |
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}: | |
f22eee08 | 223 | @example |
b4d4e8e3 | 224 | $ gld -o output /lib/crt0.o hello.o -lc |
f22eee08 | 225 | @end example |
b4d4e8e3 RP |
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. | |
f22eee08 | 230 | |
b4d4e8e3 | 231 | The command-line options to @code{gld} may be specified in any order, and |
f22eee08 RP |
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 | ||
2c5c0674 RP |
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}. | |
f22eee08 | 240 | |
2c5c0674 | 241 | @cindex object files |
b4d4e8e3 RP |
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. | |
f22eee08 | 246 | |
2c5c0674 RP |
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 | |
f22eee08 RP |
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{} | |
2c5c0674 | 259 | The object files @var{objfiles} to be linked. |
f22eee08 | 260 | |
2c5c0674 RP |
261 | @cindex architectures |
262 | @kindex -A@var{arch} | |
b4d4e8e3 RP |
263 | @item -A@var{architecture} |
264 | In the current release of @code{gld}, this option is useful only for the | |
2c5c0674 | 265 | Intel 960 family of architectures. In that @code{gld} configuration, the |
1c48127e RP |
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. | |
b4d4e8e3 RP |
270 | |
271 | Future releases of @code{gld} may support similar functionality for | |
272 | other architecture families. | |
273 | ||
2c5c0674 RP |
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 | |
f22eee08 RP |
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 | ||
2d59b2c3 RP |
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}. | |
f22eee08 | 308 | |
2d59b2c3 RP |
309 | Use the @samp{-T} option to run linker scripts written in the general-purpose |
310 | @code{ld} scripting language. | |
b4d4e8e3 | 311 | |
2c5c0674 RP |
312 | @cindex common allocation |
313 | @kindex -d | |
b4d4e8e3 | 314 | @item -d |
2c5c0674 | 315 | @kindex -dc |
b4d4e8e3 | 316 | @itemx -dc |
2c5c0674 | 317 | @kindex -dp |
b4d4e8e3 RP |
318 | @itemx -dp |
319 | These three options are equivalent; multiple forms are supported for | |
2c5c0674 RP |
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. | |
b4d4e8e3 | 324 | |
2c5c0674 RP |
325 | @cindex symbols, from command line |
326 | @kindex -defsym @var{symbol}=@var{exp} | |
b4d4e8e3 | 327 | @item -defsym @var{symbol} = @var{expression} |
2c5c0674 RP |
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} | |
f22eee08 RP |
339 | @item -e @var{entry} |
340 | Use @var{entry} as the explicit symbol for beginning execution of your | |
b4d4e8e3 RP |
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. | |
f22eee08 | 344 | |
2c5c0674 RP |
345 | @ignore |
346 | @cindex fill, from command line | |
347 | @kindex -f @var{fill} | |
348 | @c -f in older GNU linker, not in new | |
f22eee08 RP |
349 | @item -f @var{fill} |
350 | Sets the default fill pattern for ``holes'' in the output file to | |
2c5c0674 RP |
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 | |
f22eee08 | 356 | |
2c5c0674 | 357 | @kindex -F |
b4d4e8e3 | 358 | @item -F |
2c5c0674 RP |
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 | |
b4d4e8e3 RP |
373 | @item -g |
374 | Accepted, but ignored; provided for compatibility with other tools. | |
375 | ||
2c5c0674 RP |
376 | @kindex -i |
377 | @cindex incremental link | |
f22eee08 | 378 | @item -i |
2c5c0674 | 379 | Perform an incremental link (same as option @code{-r}). |
f22eee08 | 380 | |
2c5c0674 RP |
381 | @cindex archive files, from cmd line |
382 | @kindex -l@var{ar} | |
b4d4e8e3 RP |
383 | @item -l@var{ar} |
384 | Add an archive file @var{ar} to the list of files to link. This | |
f22eee08 | 385 | option may be used any number of times. @code{ld} will search its |
b4d4e8e3 | 386 | path-list for occurrences of @code{lib@var{ar}.a} for every @var{ar} |
f22eee08 RP |
387 | specified. |
388 | ||
2c5c0674 RP |
389 | @cindex search directory, from cmd line |
390 | @kindex -L@var{dir} | |
b4d4e8e3 RP |
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. | |
f22eee08 | 395 | |
2c5c0674 RP |
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. | |
f22eee08 | 401 | |
2c5c0674 RP |
402 | @cindex link map |
403 | @kindex -M | |
f22eee08 | 404 | @item -M |
2c5c0674 | 405 | @kindex -m |
f22eee08 RP |
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 | ||
2c5c0674 RP |
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 | |
f22eee08 | 416 | @item -N |
b4d4e8e3 RP |
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}. | |
2c5c0674 | 420 | @end ignore |
f22eee08 RP |
421 | |
422 | @item -n | |
2c5c0674 RP |
423 | @kindex -n |
424 | @cindex read-only text | |
425 | @kindex NMAGIC | |
f22eee08 RP |
426 | sets the text segment to be read only, and @code{NMAGIC} is written |
427 | if possible. | |
428 | ||
b4d4e8e3 | 429 | @item -noinhibit-exec |
2c5c0674 RP |
430 | @cindex output file after errors |
431 | @kindex -noinhibit-exec | |
b4d4e8e3 RP |
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 | |
2c5c0674 | 434 | you wish the output file retained even after non-fatal errors. |
b4d4e8e3 | 435 | |
f22eee08 | 436 | @item -o @var{output} |
2c5c0674 RP |
437 | @kindex -o @var{output} |
438 | @cindex naming the output file | |
f22eee08 | 439 | @var{output} is a name for the program produced by @code{ld}; if this |
2c5c0674 RP |
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. | |
f22eee08 | 442 | |
b4d4e8e3 | 443 | @item -R @var{filename} |
2c5c0674 RP |
444 | @kindex -R @var{file} |
445 | @cindex symbol-only input | |
b4d4e8e3 RP |
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. | |
b4d4e8e3 | 450 | |
1c48127e RP |
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 | ||
f22eee08 | 466 | @item -r |
b4d4e8e3 | 467 | @cindex partial link |
2c5c0674 RP |
468 | @cindex relocatable output |
469 | @kindex -r | |
f22eee08 | 470 | Generates relocatable output---i.e., generate an output file that can in |
b4d4e8e3 | 471 | turn serve as input to @code{gld}. This is often called @dfn{partial |
2c5c0674 RP |
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}. | |
f22eee08 RP |
481 | |
482 | @item -S | |
2c5c0674 RP |
483 | @kindex -S |
484 | @cindex strip debugger symbols | |
f22eee08 RP |
485 | Omits debugger symbol information (but not all symbols) from the output file. |
486 | ||
487 | @item -s | |
2c5c0674 RP |
488 | @kindex -s |
489 | @cindex strip all symbols | |
f22eee08 RP |
490 | Omits all symbol information from the output file. |
491 | ||
2c5c0674 RP |
492 | @item @{ @var{script} @} |
493 | @kindex @{ @var{script} @} | |
494 | @cindex scripts on command line | |
b4d4e8e3 RP |
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 | |
2c5c0674 | 497 | character @samp{@{} occurs on the command line, the linker switches to |
b4d4e8e3 | 498 | interpreting the command language until the end of the list of commands |
2c5c0674 RP |
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 | |
b4d4e8e3 RP |
511 | @code{bss}, @code{data}, or the @code{text} segment of the output file. |
512 | @var{textorg} must be a hexadecimal integer. | |
f22eee08 | 513 | |
b4d4e8e3 RP |
514 | @item -T @var{commandfile} |
515 | @itemx -T@var{commandfile} | |
2c5c0674 | 516 | @kindex -T @var{script} |
2d59b2c3 RP |
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. | |
f22eee08 RP |
526 | |
527 | @item -t | |
2c5c0674 RP |
528 | @kindex -t |
529 | @cindex verbose | |
530 | @cindex input files, displaying | |
f22eee08 RP |
531 | Prints names of input files as @code{ld} processes them. |
532 | ||
533 | @item -u @var{sym} | |
2c5c0674 RP |
534 | @kindex -u @var{sym} |
535 | @cindex undefined symbol | |
f22eee08 RP |
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 | |
2c5c0674 RP |
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. | |
f22eee08 | 542 | |
b4d4e8e3 | 543 | @item -Ur |
2c5c0674 | 544 | @kindex -Ur |
b4d4e8e3 RP |
545 | @cindex constructors |
546 | For anything other than C++ programs, this option is equivalent to | |
2c5c0674 RP |
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}. | |
b4d4e8e3 RP |
550 | |
551 | @item -v | |
2c5c0674 | 552 | @kindex -v |
b4d4e8e3 | 553 | @cindex version |
2c5c0674 | 554 | Display the version number for @code{gld}. |
b4d4e8e3 | 555 | |
f22eee08 | 556 | @item -X |
2c5c0674 RP |
557 | @kindex -X |
558 | @cindex local symbols, deleting | |
559 | @cindex L, deleting symbols beginning | |
f22eee08 RP |
560 | If @code{-s} or @code{-S} is also specified, delete only local symbols |
561 | beginning with @samp{L}. | |
562 | ||
b4d4e8e3 | 563 | @item -x |
2c5c0674 RP |
564 | @kindex -x |
565 | @cindex deleting local symbols | |
b4d4e8e3 RP |
566 | If @code{-s} or @code{-S} is also specified, delete all local symbols, |
567 | not just those beginning with @samp{L}. | |
568 | ||
2c5c0674 RP |
569 | @ignore |
570 | @c -z in older GNU linker, not in new | |
f22eee08 | 571 | @item -z |
2c5c0674 RP |
572 | @kindex -z |
573 | @cindex read-only text | |
b4d4e8e3 RP |
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. | |
f22eee08 | 577 | |
2c5c0674 RP |
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? | |
f22eee08 RP |
581 | Specifying a relocatable output file (@code{-r}) will also set the magic |
582 | number to @code{OMAGIC}. | |
583 | ||
2c5c0674 RP |
584 | See description of @code{-N}. |
585 | @end ignore | |
f22eee08 | 586 | |
f22eee08 | 587 | @end table |
b4d4e8e3 | 588 | |
2c5c0674 RP |
589 | @node Environment, , Options, Invocation |
590 | @section Environment Variables | |
591 | ||
2d59b2c3 | 592 | You can change the behavior of @code{gld} with two environment |
1c48127e RP |
593 | variables: @code{GNUTARGET} and @code{LDEMULATION}. Depending on the |
594 | setting of the latter, other environment variables may be used as well. | |
2c5c0674 RP |
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 | |
1c48127e RP |
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. | |
2c5c0674 RP |
653 | |
654 | @item LDEMULATION=gldm88kbcs | |
1c48127e RP |
655 | Configure the linker for the Motorola 88K family. |
656 | @xref{m88k,,@code{gld} and the Motorola 880x0 family}, for details. | |
2c5c0674 RP |
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. | |
2c5c0674 RP |
667 | @end table |
668 | ||
1c48127e | 669 | @node Commands, Machine Dependent, Invocation, Top |
2c5c0674 | 670 | @chapter Command Language |
f22eee08 | 671 | |
2c5c0674 | 672 | @cindex command files |
b4d4e8e3 RP |
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 | |
2c5c0674 RP |
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 | |
b4d4e8e3 | 687 | @end itemize |
f22eee08 | 688 | |
2c5c0674 | 689 | You may supply a command file (also known as a link script) to the |
2d59b2c3 | 690 | linker either explicitly through the @code{-T} option, or implicitly as |
2c5c0674 RP |
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 | |
2d59b2c3 RP |
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 | |
2c5c0674 RP |
705 | @end menu |
706 | ||
707 | @node Scripts, Expressions, Commands, Commands | |
b4d4e8e3 RP |
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 | ||
2c5c0674 RP |
714 | @cindex fundamental script commands |
715 | @cindex commands, fundamental | |
716 | @cindex output file layout | |
717 | @cindex layout of output file | |
b4d4e8e3 RP |
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 | |
2c5c0674 RP |
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}. | |
b4d4e8e3 | 729 | |
2c5c0674 RP |
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 | |
f22eee08 | 736 | @section Expressions |
2c5c0674 RP |
737 | @cindex expression syntax |
738 | @cindex arithmetic | |
b4d4e8e3 RP |
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 | |
2c5c0674 RP |
743 | @item |
744 | All expressions evaluated as integers and | |
f22eee08 | 745 | are of ``long'' or ``unsigned long'' type. |
2c5c0674 RP |
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. | |
b4d4e8e3 | 754 | @end itemize |
f22eee08 | 755 | |
2c5c0674 | 756 | @menu |
2d59b2c3 RP |
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 | |
2c5c0674 RP |
764 | @end menu |
765 | ||
766 | @node Integers, Symbols, Expressions, Expressions | |
f22eee08 | 767 | @subsection Integers |
2c5c0674 RP |
768 | @cindex integer notation |
769 | @cindex octal integers | |
f22eee08 RP |
770 | An octal integer is @samp{0} followed by zero or more of the octal |
771 | digits (@samp{01234567}). | |
b4d4e8e3 | 772 | @example |
2c5c0674 | 773 | _as_octal = 0157255; |
b4d4e8e3 | 774 | @end example |
f22eee08 | 775 | |
2c5c0674 | 776 | @cindex decimal integers |
f22eee08 RP |
777 | A decimal integer starts with a non-zero digit followed by zero or |
778 | more digits (@samp{0123456789}). | |
b4d4e8e3 | 779 | @example |
2c5c0674 | 780 | _as_decimal = 57005; |
b4d4e8e3 | 781 | @end example |
f22eee08 | 782 | |
2c5c0674 RP |
783 | @cindex hexadecimal integers |
784 | @kindex 0x | |
f22eee08 RP |
785 | A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or |
786 | more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}. | |
b4d4e8e3 RP |
787 | @example |
788 | _as_hex = 0xdead; | |
789 | @end example | |
f22eee08 | 790 | |
2c5c0674 RP |
791 | @cindex negative integers |
792 | Decimal integers have the usual values. To write a negative integer, use | |
b4d4e8e3 RP |
793 | the prefix operator @samp{-}; @pxref{Operators}. |
794 | @example | |
b4d4e8e3 RP |
795 | _as_neg = -57005; |
796 | @end example | |
f22eee08 | 797 | |
2c5c0674 RP |
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 | |
b4d4e8e3 RP |
803 | Additionally the suffixes @code{K} and @code{M} may be used to scale a |
804 | constant by | |
c8072296 RP |
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 | |
f22eee08 | 811 | @tex |
b4d4e8e3 | 812 | ${\rm 1024}$ or ${\rm 1024}^2$ |
f22eee08 | 813 | @end tex |
c8072296 | 814 | @c END TEXI2ROFF-KILL |
b4d4e8e3 | 815 | respectively. For example, the following all refer to the same quantity:@refill |
f22eee08 RP |
816 | |
817 | @example | |
2c5c0674 RP |
818 | _fourk_1 = 4K; |
819 | _fourk_2 = 4096; | |
820 | _fourk_3 = 0x1000; | |
f22eee08 | 821 | @end example |
b4d4e8e3 | 822 | |
2c5c0674 | 823 | @node Symbols, Location Counter, Integers, Expressions |
b4d4e8e3 | 824 | @subsection Symbol Names |
2c5c0674 RP |
825 | @cindex symbol names |
826 | @cindex names | |
827 | @cindex quoted symbol names | |
828 | @kindex " | |
b4d4e8e3 | 829 | Unless quoted, symbol names start with a letter, underscore, point or |
2c5c0674 | 830 | hyphen and may include any letters, underscores, digits, points, |
b4d4e8e3 RP |
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 | ||
2c5c0674 | 839 | @node Location Counter, Operators, Symbols, Expressions |
b4d4e8e3 | 840 | @subsection The Location Counter |
2c5c0674 RP |
841 | @kindex . |
842 | @cindex dot | |
843 | @cindex location counter | |
844 | @cindex current output location | |
b4d4e8e3 RP |
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. | |
2c5c0674 | 852 | @cindex holes |
b4d4e8e3 RP |
853 | This may be used to create holes in the output section. The location |
854 | counter may never be moved backwards. | |
855 | @example | |
2c5c0674 RP |
856 | SECTIONS |
857 | @{ | |
858 | output : | |
b4d4e8e3 | 859 | @{ |
2c5c0674 RP |
860 | file1(.text) |
861 | . = . + 1000; | |
862 | file2(.text) | |
863 | . += 1000; | |
864 | file3(.text) | |
865 | @} = 0x1234; | |
866 | @} | |
b4d4e8e3 | 867 | @end example |
2c5c0674 RP |
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}). | |
b4d4e8e3 | 874 | |
2c5c0674 | 875 | @node Operators, Evaluation, Location Counter, Expressions |
f22eee08 | 876 | @subsection Operators |
2c5c0674 RP |
877 | @cindex Operators for arithmetic |
878 | @cindex arithmetic operators | |
879 | @cindex precedence in expressions | |
b4d4e8e3 | 880 | The linker recognizes the standard C set of arithmetic operators, with |
f22eee08 | 881 | the standard bindings and precedence levels: |
c8072296 | 882 | @c TEXI2ROFF-KILL |
b4d4e8e3 | 883 | @ifinfo |
c8072296 | 884 | @c END TEXI2ROFF-KILL |
f22eee08 | 885 | @example |
c8072296 | 886 | precedence associativity Operators Notes |
b4d4e8e3 | 887 | (highest) |
c8072296 RP |
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) | |
b4d4e8e3 | 899 | (lowest) |
f22eee08 | 900 | @end example |
2c5c0674 RP |
901 | Notes: |
902 | (1) Prefix operators | |
903 | (2) @xref{Assignment} | |
c8072296 | 904 | @c TEXI2ROFF-KILL |
b4d4e8e3 | 905 | @end ifinfo |
f22eee08 | 906 | @tex |
2c5c0674 RP |
907 | \vskip \baselineskip |
908 | %"lispnarrowing" is the extra indent used generally for @example | |
909 | \hskip\lispnarrowing\vbox{\offinterlineskip | |
f22eee08 RP |
910 | \hrule |
911 | \halign | |
2c5c0674 RP |
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 | |
f22eee08 | 916 | \noalign{\hrule} |
2c5c0674 | 917 | height2pt&\omit&&\omit&&\omit&\cr |
b4d4e8e3 | 918 | &highest&&&&&\cr |
2c5c0674 RP |
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 | |
f22eee08 | 925 | &6&&left&&\&&\cr |
f22eee08 | 926 | &7&&left&&|&\cr |
f22eee08 | 927 | &8&&left&&{\&\&}&\cr |
f22eee08 | 928 | &9&&left&&||&\cr |
2c5c0674 RP |
929 | &10&&right&&? :&\cr |
930 | &11&&right&&\qquad\&= += -= *= /=\qquad\ddag&\cr | |
b4d4e8e3 | 931 | &lowest&&&&&\cr |
2c5c0674 | 932 | height2pt&\omit&&\omit&&\omit&\cr} |
f22eee08 RP |
933 | \hrule} |
934 | @end tex | |
2c5c0674 RP |
935 | @iftex |
936 | { | |
937 | @obeylines@parskip=0pt@parindent=0pt | |
938 | @dag@quad Prefix operators. | |
939 | @ddag@quad @xref{Assignment}. | |
940 | } | |
941 | @end iftex | |
c8072296 | 942 | @c END TEXI2ROFF-KILL |
f22eee08 | 943 | |
2c5c0674 | 944 | @node Evaluation, Assignment, Operators, Expressions |
b4d4e8e3 RP |
945 | @subsection Evaluation |
946 | ||
2c5c0674 RP |
947 | @cindex lazy evaluation |
948 | @cindex expression evaluation order | |
b4d4e8e3 RP |
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 | ||
2c5c0674 | 959 | @node Assignment, Built-ins, Evaluation, Expressions |
b4d4e8e3 | 960 | @subsection Assignment: Defining Symbols |
2c5c0674 RP |
961 | @cindex assignment in scripts |
962 | @cindex symbol definition, scripts | |
963 | @cindex variables, defining | |
b4d4e8e3 RP |
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} ; | |
2c5c0674 | 969 | @itemx @var{symbol} &= @var{expression} ; |
b4d4e8e3 RP |
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 | |
2c5c0674 RP |
979 | @item |
980 | Assignment may only be used at the root of an expression; | |
b4d4e8e3 | 981 | @samp{a=b+3;} is allowed, but @samp{a+b=3;} is an error. |
2c5c0674 RP |
982 | |
983 | @kindex ; | |
984 | @cindex semicolon | |
985 | @item | |
986 | A trailing semicolon is required at the end of an assignment | |
b4d4e8e3 RP |
987 | statement. |
988 | @end itemize | |
989 | ||
990 | Assignment statements may appear: | |
991 | @itemize @bullet | |
2c5c0674 RP |
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 | |
b4d4e8e3 RP |
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 | ||
2c5c0674 RP |
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. | |
b4d4e8e3 RP |
1013 | |
1014 | The type of the expression is controlled by its position in the script | |
2c5c0674 RP |
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}: | |
b4d4e8e3 | 1024 | @example |
2c5c0674 | 1025 | SECTIONS@{ @dots{} |
b4d4e8e3 RP |
1026 | .data : |
1027 | @{ | |
1028 | *(.data) | |
1029 | _edata = ABSOLUTE(.) ; | |
1030 | @} | |
2c5c0674 | 1031 | @dots{} @} |
b4d4e8e3 RP |
1032 | @end example |
1033 | ||
2c5c0674 RP |
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 | |
b4d4e8e3 | 1042 | @example |
2c5c0674 | 1043 | SECTIONS @{ @dots{} |
b4d4e8e3 RP |
1044 | text 9+this_isnt_constant: |
1045 | @{ @dots{} | |
1046 | @} | |
2c5c0674 | 1047 | @dots{} @} |
b4d4e8e3 | 1048 | @end example |
2c5c0674 RP |
1049 | @kindex Non constant expression |
1050 | @noindent | |
1051 | will cause the error message ``@code{Non constant expression for initial | |
b4d4e8e3 RP |
1052 | address}''. |
1053 | ||
2c5c0674 RP |
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 | |
b4d4e8e3 RP |
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: | |
f22eee08 | 1074 | @example |
2c5c0674 | 1075 | SECTIONS@{ @dots{} |
f22eee08 RP |
1076 | .output1: |
1077 | @{ | |
2c5c0674 RP |
1078 | start_of_output_1 = ABSOLUTE(.); |
1079 | @dots{} | |
f22eee08 RP |
1080 | @} |
1081 | .output: | |
1082 | @{ | |
1083 | symbol_1 = ADDR(.output1); | |
1084 | symbol_2 = start_of_output_1; | |
1085 | @} | |
2c5c0674 RP |
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: | |
c8072296 | 1129 | @smallexample |
2c5c0674 RP |
1130 | SECTIONS@{ @dots{} |
1131 | .text: @{ | |
1132 | begin = DEFINED(begin) ? begin : . ; | |
1133 | @dots{} | |
1134 | @} | |
1135 | @dots{} @} | |
c8072296 | 1136 | @end smallexample |
f22eee08 | 1137 | |
2c5c0674 RP |
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 | |
f22eee08 RP |
1150 | been allocated. In the following example the @code{symbol_1} and |
1151 | @code{symbol_2} are assigned identical values: | |
1152 | @example | |
2c5c0674 | 1153 | SECTIONS@{ @dots{} |
f22eee08 RP |
1154 | .output @{ |
1155 | .start = . ; | |
2c5c0674 | 1156 | @dots{} |
f22eee08 RP |
1157 | .end = .; |
1158 | @} | |
1159 | symbol_1 = .end - .start; | |
1160 | symbol_2 = SIZEOF(.output); | |
2c5c0674 | 1161 | @dots{} @} |
f22eee08 | 1162 | |
f22eee08 | 1163 | @end example |
b4d4e8e3 | 1164 | |
2c5c0674 RP |
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 | |
b4d4e8e3 | 1177 | @section MEMORY Command |
2c5c0674 RP |
1178 | @kindex MEMORY |
1179 | @cindex regions of memory | |
1180 | @cindex discontinuous memory | |
1181 | @cindex allocating memory | |
b4d4e8e3 RP |
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: | |
c8072296 | 1194 | |
f22eee08 | 1195 | @example |
b4d4e8e3 RP |
1196 | MEMORY |
1197 | @{ | |
1198 | @var{name} (@var{attr}): ORIGIN = @var{origin}, LENGTH = @var{len} | |
2c5c0674 | 1199 | @dots{} |
b4d4e8e3 | 1200 | @} |
f22eee08 RP |
1201 | @end example |
1202 | @table @code | |
1203 | @item @var{name} | |
2c5c0674 | 1204 | @cindex naming memory regions |
f22eee08 RP |
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 | |
b4d4e8e3 RP |
1208 | names. Use distinct names to specify multiple regions. |
1209 | @item (@var{attr}) | |
2c5c0674 RP |
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. | |
f22eee08 | 1216 | @item @var{origin} |
2c5c0674 RP |
1217 | @kindex ORIGIN= |
1218 | @kindex o= | |
1219 | @kindex org= | |
b4d4e8e3 RP |
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 | |
f22eee08 RP |
1222 | memory allocation is performed. The keyword @code{ORIGIN} may be |
1223 | abbreviated to @code{org} or @code{o}. | |
1224 | @item @var{len} | |
2c5c0674 RP |
1225 | @kindex LENGTH= |
1226 | @kindex len= | |
1227 | @kindex l= | |
b4d4e8e3 | 1228 | is the size in bytes of the region (an expression). |
2c5c0674 | 1229 | The keyword @code{LENGTH} may be abbreviated to @code{len} or @code{l}. |
f22eee08 RP |
1230 | @end table |
1231 | ||
1232 | For example, to specify that memory has two regions available for | |
2c5c0674 RP |
1233 | allocation---one starting at @code{0} for 256 kilobytes, and the other |
1234 | starting at @code{0x40000000} for four megabytes: | |
f22eee08 RP |
1235 | |
1236 | @example | |
b4d4e8e3 RP |
1237 | MEMORY |
1238 | @{ | |
1239 | rom : ORIGIN= 0, LENGTH = 256K | |
1240 | ram : org= 0x40000000, l = 4M | |
1241 | @} | |
f22eee08 RP |
1242 | @end example |
1243 | ||
b4d4e8e3 | 1244 | Once you have defined a region of memory named @var{mem}, you can direct |
2c5c0674 RP |
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. | |
b4d4e8e3 | 1249 | |
2c5c0674 | 1250 | @node SECTIONS, Entry Point, MEMORY, Commands |
b4d4e8e3 | 1251 | @section SECTIONS Command |
2c5c0674 | 1252 | @kindex SECTIONS |
b4d4e8e3 RP |
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 | |
2c5c0674 | 1271 | symbols---can also be done outside the @code{SECTIONS} command: |
b4d4e8e3 RP |
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. | |
f22eee08 | 1276 | |
b4d4e8e3 | 1277 | When no @code{SECTIONS} command is specified, the default action |
f22eee08 | 1278 | of the linker is to place each input section into an identically named |
b4d4e8e3 RP |
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 | ||
2c5c0674 | 1284 | @menu |
2d59b2c3 RP |
1285 | * Section Definition:: Section Definitions |
1286 | * Section Contents:: Section Contents | |
1287 | * Section Options:: Optional Section Attributes | |
2c5c0674 RP |
1288 | @end menu |
1289 | ||
1290 | @node Section Definition, Section Contents, SECTIONS, SECTIONS | |
b4d4e8e3 | 1291 | @subsection Section Definitions |
2c5c0674 | 1292 | @cindex section definition |
b4d4e8e3 RP |
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 | |
2c5c0674 | 1300 | SECTIONS @{ @dots{} |
b4d4e8e3 RP |
1301 | @var{secname} : @{ |
1302 | @var{contents} | |
1303 | @} | |
2c5c0674 | 1304 | @dots{} @} |
b4d4e8e3 | 1305 | @end example |
2c5c0674 | 1306 | @cindex naming output sections |
b4d4e8e3 RP |
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 | |
2c5c0674 RP |
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 | |
b4d4e8e3 | 1325 | @subsection Section Contents |
2c5c0674 | 1326 | @cindex contents of a section |
b4d4e8e3 RP |
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. | |
f22eee08 | 1337 | |
b4d4e8e3 | 1338 | @table @code |
b4d4e8e3 | 1339 | @item @var{filename} |
2c5c0674 RP |
1340 | @kindex @var{filename} |
1341 | @cindex input files, section defn | |
1342 | @cindex files, including in output sections | |
b4d4e8e3 | 1343 | You may simply name a particular input file to be placed in the current |
2c5c0674 RP |
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: | |
f22eee08 | 1347 | @example |
b4d4e8e3 | 1348 | .data: @{ afile.o bfile.o cfile.o @} |
f22eee08 | 1349 | @end example |
2c5c0674 RP |
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. | |
f22eee08 | 1354 | |
b4d4e8e3 RP |
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 | ||
2c5c0674 RP |
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 | ||
b4d4e8e3 RP |
1369 | @item * (@var{section}) |
1370 | @itemx * (@var{section}, @var{section}, @dots{}) | |
2c5c0674 RP |
1371 | @itemx * (@var{section} @var{section} @dots{} |
1372 | @cindex input sections to output section | |
1373 | @kindex *(@var{section}) | |
b4d4e8e3 RP |
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 | |
2c5c0674 | 1383 | SECTIONS @{ |
b4d4e8e3 RP |
1384 | .text :@{ |
1385 | *("1" "2" "3" "4") | |
1386 | @} | |
f22eee08 | 1387 | |
b4d4e8e3 RP |
1388 | .data :@{ |
1389 | *("13" "14") | |
f22eee08 | 1390 | @} |
b4d4e8e3 | 1391 | @} |
f22eee08 RP |
1392 | @end example |
1393 | ||
b4d4e8e3 RP |
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{} ] | |
2c5c0674 | 1401 | @kindex [ @var{sections} ] |
b4d4e8e3 RP |
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 ] | |
2c5c0674 RP |
1408 | @kindex [COMMON] |
1409 | @cindex uninitialized data | |
1410 | @cindex commons in output | |
b4d4e8e3 RP |
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 | ||
2c5c0674 | 1422 | For example, the following command script arranges the output file into |
b4d4e8e3 RP |
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: | |
f22eee08 | 1426 | @example |
2c5c0674 RP |
1427 | SECTIONS @{ |
1428 | .text: @{ *(.text) @} | |
1429 | .data: @{ *(.data) @} | |
1430 | .bss: @{ *(.bss) [COMMON] @} | |
1431 | @} | |
f22eee08 | 1432 | @end example |
b4d4e8e3 RP |
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 | |
2c5c0674 | 1444 | SECTIONS @{ |
b4d4e8e3 RP |
1445 | outputa 0x10000 : |
1446 | @{ | |
1447 | all.o | |
1448 | foo.o (.input1) | |
f22eee08 | 1449 | @} |
b4d4e8e3 RP |
1450 | outputb : |
1451 | @{ | |
1452 | foo.o (.input2) | |
1453 | foo1.o (.input1) | |
f22eee08 | 1454 | @} |
b4d4e8e3 RP |
1455 | outputc : |
1456 | @{ | |
1457 | *(.input1) | |
1458 | *(.input2) | |
f22eee08 | 1459 | @} |
2c5c0674 | 1460 | @} |
b4d4e8e3 RP |
1461 | @end example |
1462 | ||
1463 | There are still more kinds of statements permitted in the contents of | |
2c5c0674 | 1464 | output section definitions. The foregoing statements permitted you to |
b4d4e8e3 RP |
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. | |
f22eee08 | 1472 | |
b4d4e8e3 RP |
1473 | @table @code |
1474 | @item CREATE_OBJECT_SYMBOLS | |
2c5c0674 RP |
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 | |
f22eee08 | 1480 | data written from the input file. For instance, with @code{a.out} |
b4d4e8e3 RP |
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); | |
f22eee08 | 1490 | @} |
2c5c0674 RP |
1491 | @dots{} |
1492 | @} | |
f22eee08 | 1493 | @end example |
b4d4e8e3 RP |
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--- | |
f22eee08 | 1498 | @example |
b4d4e8e3 RP |
1499 | /* a.c */ |
1500 | ||
2c5c0674 | 1501 | afunction() @{ @} |
b4d4e8e3 RP |
1502 | int adata=1; |
1503 | int abss; | |
1504 | @end example | |
f22eee08 | 1505 | |
b4d4e8e3 RP |
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 | |
f22eee08 RP |
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 | |
f22eee08 RP |
1530 | @end example |
1531 | ||
b4d4e8e3 | 1532 | @item @var{symbol} = @var{expression} ; |
2c5c0674 | 1533 | @kindex @var{symbol} = @var{expression} ; |
b4d4e8e3 | 1534 | @itemx @var{symbol} @var{f}= @var{expression} ; |
2c5c0674 RP |
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 | |
b4d4e8e3 | 1544 | @example |
2c5c0674 | 1545 | SECTIONS @{ |
b4d4e8e3 | 1546 | abs = 14 ; |
2c5c0674 RP |
1547 | @dots{} |
1548 | .data: @{ @dots{} rel = 14 ; @dots{} @} | |
b4d4e8e3 | 1549 | abs2 = 14 + ADDR(.data); |
2c5c0674 RP |
1550 | @dots{} |
1551 | @} | |
f22eee08 | 1552 | @end example |
2c5c0674 | 1553 | @c FIXME: Try above example! |
b4d4e8e3 RP |
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 | ||
b4d4e8e3 | 1558 | @item BYTE(@var{expression}) |
2c5c0674 | 1559 | @kindex BYTE(@var{expression}) |
b4d4e8e3 | 1560 | @itemx SHORT(@var{expression}) |
2c5c0674 | 1561 | @kindex SHORT(@var{expression}) |
b4d4e8e3 | 1562 | @itemx LONG(@var{expression}) |
2c5c0674 RP |
1563 | @kindex LONG(@var{expression}) |
1564 | @cindex direct output | |
b4d4e8e3 RP |
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}) | |
2c5c0674 RP |
1572 | @kindex FILL(@var{expression}) |
1573 | @cindex holes, filling | |
1574 | @cindex unspecified memory | |
b4d4e8e3 RP |
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 | ||
2c5c0674 | 1585 | @node Section Options, , Section Contents, SECTIONS |
b4d4e8e3 | 1586 | @subsection Optional Section Attributes |
2c5c0674 | 1587 | @cindex section defn, full syntax |
b4d4e8e3 RP |
1588 | Here is the full syntax of a section definition, including all the |
1589 | optional portions: | |
1590 | ||
f22eee08 | 1591 | @example |
2c5c0674 RP |
1592 | SECTIONS @{ |
1593 | @dots{} | |
1594 | @var{secname} @var{start} BLOCK(@var{align}) : @{ @var{contents} @} =@var{fill} >@var{region} | |
1595 | @dots{} | |
b4d4e8e3 RP |
1596 | @} |
1597 | @end example | |
1598 | ||
1599 | @var{secname} and @var{contents} are required. @xref{Section | |
2c5c0674 RP |
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. | |
f22eee08 | 1603 | |
b4d4e8e3 RP |
1604 | @table @code |
1605 | @item @var{start} | |
2c5c0674 RP |
1606 | @cindex start address, section |
1607 | @cindex section start | |
1608 | @cindex section address | |
b4d4e8e3 RP |
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 @{ | |
2c5c0674 | 1616 | @dots{} |
b4d4e8e3 RP |
1617 | output 0x40000000: @{ |
1618 | @dots{} | |
1619 | @} | |
2c5c0674 | 1620 | @dots{} |
b4d4e8e3 | 1621 | @} |
f22eee08 | 1622 | @end example |
f22eee08 | 1623 | |
b4d4e8e3 | 1624 | @item BLOCK(@var{align}) |
2c5c0674 RP |
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. | |
f22eee08 | 1632 | |
b4d4e8e3 | 1633 | @item =@var{fill} |
2c5c0674 RP |
1634 | @kindex =@var{fill} |
1635 | @cindex section fill pattern | |
1636 | @cindex fill pattern, entire section | |
b4d4e8e3 RP |
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. | |
f22eee08 | 1644 | |
b4d4e8e3 | 1645 | @item >@var{region} |
2c5c0674 RP |
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}. | |
f22eee08 | 1651 | |
f22eee08 | 1652 | @end table |
b4d4e8e3 | 1653 | |
2c5c0674 | 1654 | @node Entry Point, Other Commands, SECTIONS, Commands |
b4d4e8e3 | 1655 | @section The Entry Point |
2c5c0674 RP |
1656 | @kindex ENTRY(@var{symbol}) |
1657 | @cindex start of execution | |
1658 | @cindex first instruction | |
b4d4e8e3 RP |
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: | |
f22eee08 | 1662 | @example |
b4d4e8e3 | 1663 | ENTRY(@var{symbol}) |
f22eee08 | 1664 | @end example |
b4d4e8e3 RP |
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 | ||
2c5c0674 | 1671 | @cindex entry point, defaults |
b4d4e8e3 RP |
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). | |
f22eee08 RP |
1675 | @itemize @bullet |
1676 | @item | |
b4d4e8e3 | 1677 | the @code{-e} @var{entry} command-line option; |
f22eee08 | 1678 | @item |
2c5c0674 | 1679 | the @code{ENTRY(@var{symbol}} command in a linker control script; |
f22eee08 | 1680 | @item |
b4d4e8e3 | 1681 | the value of the symbol @code{start}, if present; |
f22eee08 | 1682 | @item |
b4d4e8e3 | 1683 | the value of the symbol @code{_main}, if present; |
f22eee08 | 1684 | @item |
b4d4e8e3 | 1685 | the address of the first byte of the @code{.text} section, if present; |
f22eee08 | 1686 | @item |
b4d4e8e3 | 1687 | The address @code{0}. |
f22eee08 | 1688 | @end itemize |
b4d4e8e3 | 1689 | |
2c5c0674 RP |
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--- | |
f22eee08 | 1694 | @example |
b4d4e8e3 | 1695 | start = 0x2020; |
f22eee08 | 1696 | @end example |
b4d4e8e3 RP |
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}: | |
f22eee08 | 1703 | @example |
b4d4e8e3 | 1704 | start = other_symbol; |
f22eee08 | 1705 | @end example |
f22eee08 | 1706 | |
2c5c0674 | 1707 | @node Other Commands, , Entry Point, Commands |
b4d4e8e3 RP |
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 | |
2c5c0674 | 1715 | @kindex FLOAT |
b4d4e8e3 | 1716 | @itemx NOFLOAT |
2c5c0674 RP |
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}). | |
b4d4e8e3 | 1731 | |
b4d4e8e3 | 1732 | @item INPUT ( @var{file}, @var{file}, @dots{} ) |
2c5c0674 | 1733 | @kindex INPUT ( @var{files} ) |
b4d4e8e3 | 1734 | @itemx INPUT ( @var{file} @var{file} @dots{} ) |
2c5c0674 RP |
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. | |
b4d4e8e3 | 1739 | |
2c5c0674 | 1740 | @ignore |
b4d4e8e3 | 1741 | @item MAP ( @var{name} ) |
2c5c0674 RP |
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 | |
b4d4e8e3 RP |
1747 | |
1748 | @item OUTPUT ( @var{filename} ) | |
2c5c0674 RP |
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. | |
b4d4e8e3 | 1788 | |
b4d4e8e3 | 1789 | @item TARGET ( @var{format} ) |
2c5c0674 RP |
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. | |
b4d4e8e3 RP |
1805 | |
1806 | @end table | |
1807 | ||
1c48127e RP |
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 | |
2d59b2c3 RP |
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 | |
1c48127e RP |
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 | |
2d59b2c3 RP |
1854 | * i960-arch:: Linking for a Specific i960 Architecture |
1855 | * i960-emulation:: Emulating Other i960 Linkers | |
1856 | * i960-commands:: Command Language Extensions for i960 | |
1c48127e RP |
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 | ||
2d59b2c3 | 2026 | @node BFD, MRI, Machine Dependent, Top |
f22eee08 RP |
2027 | @chapter BFD |
2028 | ||
2c5c0674 RP |
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 | |
1c48127e RP |
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: | |
2c5c0674 RP |
2040 | @cindex formats available |
2041 | @cindex architectures available | |
2c5c0674 | 2042 | @example |
1c48127e RP |
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 | |
2c5c0674 | 2137 | @end example |
f22eee08 | 2138 | |
2c5c0674 RP |
2139 | @cindex BFD requirements |
2140 | @cindex requirements for BFD | |
2141 | As with most implementations, BFD is a compromise between | |
f22eee08 | 2142 | several conflicting requirements. The major factor influencing |
2c5c0674 RP |
2143 | BFD design was efficiency: any time used converting between |
2144 | formats is time which would not have been spent had BFD not | |
f22eee08 | 2145 | been involved. This is partly offset by abstraction payback; since |
2c5c0674 | 2146 | BFD simplifies applications and back ends, more time and care |
f22eee08 RP |
2147 | may be spent optimizing algorithms for a greater speed. |
2148 | ||
2c5c0674 RP |
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 | |
2d59b2c3 RP |
2155 | * BFD outline:: How it works: an outline of BFD |
2156 | * BFD information loss:: Information Loss | |
2157 | * Mechanism:: Mechanism | |
2c5c0674 | 2158 | @end menu |
f22eee08 | 2159 | |
2c5c0674 | 2160 | @node BFD outline, BFD information loss, BFD, BFD |
b4d4e8e3 | 2161 | @section How it works: an outline of BFD |
2c5c0674 RP |
2162 | @cindex opening object files |
2163 | When an object file is opened, BFD subroutines automatically | |
b4d4e8e3 RP |
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. | |
f22eee08 RP |
2167 | |
2168 | As different information from the the object files is required | |
2c5c0674 | 2169 | BFD reads from different sections of the file and processes them. |
b4d4e8e3 | 2170 | For example a very common operation for the linker is processing symbol |
2c5c0674 | 2171 | tables. Each BFD back end provides a routine for converting |
b4d4e8e3 RP |
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 | |
2c5c0674 | 2174 | file, it calls through the memory pointer to the relevant BFD |
b4d4e8e3 RP |
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, | |
2c5c0674 | 2178 | another BFD back end routine is called which takes the newly |
b4d4e8e3 RP |
2179 | created symbol table and converts it into the chosen output format. |
2180 | ||
2c5c0674 | 2181 | @node BFD information loss, Mechanism, BFD outline, BFD |
b4d4e8e3 RP |
2182 | @section Information Loss |
2183 | @emph{Information can be lost during output.} The output formats | |
2c5c0674 | 2184 | supported by BFD do not provide identical facilities, and |
b4d4e8e3 RP |
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). | |
f22eee08 RP |
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 | |
b4d4e8e3 RP |
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 | ||
2c5c0674 RP |
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. | |
f22eee08 RP |
2208 | |
2209 | This limitation is only a problem when using the linker to read one | |
2c5c0674 RP |
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, | |
f22eee08 | 2213 | and exported only to the back ends. When a file is read in one format, |
2c5c0674 | 2214 | the canonical form is generated for BFD and the linker. At the |
f22eee08 | 2215 | same time, the back end saves away any information which may otherwise |
2c5c0674 | 2216 | be lost. If the data is then written back in the same format, the back |
b4d4e8e3 | 2217 | end routine will be able to use the canonical form provided by the |
2c5c0674 | 2218 | BFD core as well as the information it prepared earlier. Since |
b4d4e8e3 RP |
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 | ||
2c5c0674 | 2225 | @node Mechanism, , BFD information loss, BFD |
f22eee08 | 2226 | @section Mechanism |
b4d4e8e3 RP |
2227 | The greatest potential for loss of information is when there is least |
2228 | overlap between the information provided by the source format, that | |
2c5c0674 | 2229 | stored by the canonical format, and the information needed by the |
b4d4e8e3 RP |
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. | |
2c5c0674 RP |
2233 | @cindex BFD canonical format |
2234 | @cindex internal object-file format | |
b4d4e8e3 RP |
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 | ||
2c5c0674 RP |
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. | |
b4d4e8e3 RP |
2247 | |
2248 | @item sections | |
f22eee08 RP |
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 | |
2c5c0674 | 2251 | information and pointers into other BFD data structures. |
b4d4e8e3 RP |
2252 | |
2253 | @item symbols | |
f22eee08 | 2254 | Each symbol contains a pointer to the object file which originally |
2c5c0674 RP |
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. | |
f22eee08 RP |
2264 | |
2265 | Normal global and simple local symbols are maintained on output, so an | |
b4d4e8e3 RP |
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). | |
f22eee08 RP |
2273 | |
2274 | There is one word of type information within the symbol, so if the | |
2c5c0674 | 2275 | format supports symbol type information within symbols (for example COFF, |
f22eee08 RP |
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 | |
2c5c0674 | 2280 | Each canonical BFD relocation record contains a pointer to the symbol to |
f22eee08 RP |
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. | |
1c48127e | 2291 | @c FIXME why specific reference to 68K above? |
f22eee08 RP |
2292 | |
2293 | @item line numbers | |
2c5c0674 RP |
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. | |
b4d4e8e3 RP |
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 | |
f22eee08 RP |
2303 | between formats (COFF, IEEE and Oasys). |
2304 | @end table | |
2305 | ||
2d59b2c3 RP |
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 | |
7b015547 | 2343 | @code{LOAD}) to resolve addresses in the output file. |
2d59b2c3 RP |
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 | |
2c5c0674 RP |
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: [email protected], 28mar91. | |
2448 | @end tex | |
2449 | ||
2450 | ||
b4d4e8e3 | 2451 | @contents |
f22eee08 RP |
2452 | @bye |
2453 | ||
2454 |