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