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