1 | This is ld.info, produced by makeinfo version 4.3 from ./ld.texinfo.
|
---|
2 |
|
---|
3 | START-INFO-DIR-ENTRY
|
---|
4 | * Ld: (ld). The GNU linker.
|
---|
5 | END-INFO-DIR-ENTRY
|
---|
6 |
|
---|
7 | This file documents the GNU linker LD version 2.14.
|
---|
8 |
|
---|
9 | Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001,
|
---|
10 | 2002, 2003 Free Software Foundation, Inc.
|
---|
11 |
|
---|
12 |
|
---|
13 | File: ld.info, Node: Options, Next: Environment, Up: Invocation
|
---|
14 |
|
---|
15 | Command Line Options
|
---|
16 | ====================
|
---|
17 |
|
---|
18 | The linker supports a plethora of command-line options, but in actual
|
---|
19 | practice few of them are used in any particular context. For instance,
|
---|
20 | a frequent use of `ld' is to link standard Unix object files on a
|
---|
21 | standard, supported Unix system. On such a system, to link a file
|
---|
22 | `hello.o':
|
---|
23 |
|
---|
24 | ld -o OUTPUT /lib/crt0.o hello.o -lc
|
---|
25 |
|
---|
26 | This tells `ld' to produce a file called OUTPUT as the result of
|
---|
27 | linking the file `/lib/crt0.o' with `hello.o' and the library `libc.a',
|
---|
28 | which will come from the standard search directories. (See the
|
---|
29 | discussion of the `-l' option below.)
|
---|
30 |
|
---|
31 | Some of the command-line options to `ld' may be specified at any
|
---|
32 | point in the command line. However, options which refer to files, such
|
---|
33 | as `-l' or `-T', cause the file to be read at the point at which the
|
---|
34 | option appears in the command line, relative to the object files and
|
---|
35 | other file options. Repeating non-file options with a different
|
---|
36 | argument will either have no further effect, or override prior
|
---|
37 | occurrences (those further to the left on the command line) of that
|
---|
38 | option. Options which may be meaningfully specified more than once are
|
---|
39 | noted in the descriptions below.
|
---|
40 |
|
---|
41 | Non-option arguments are object files or archives which are to be
|
---|
42 | linked together. They may follow, precede, or be mixed in with
|
---|
43 | command-line options, except that an object file argument may not be
|
---|
44 | placed between an option and its argument.
|
---|
45 |
|
---|
46 | Usually the linker is invoked with at least one object file, but you
|
---|
47 | can specify other forms of binary input files using `-l', `-R', and the
|
---|
48 | script command language. If _no_ binary input files at all are
|
---|
49 | specified, the linker does not produce any output, and issues the
|
---|
50 | message `No input files'.
|
---|
51 |
|
---|
52 | If the linker cannot recognize the format of an object file, it will
|
---|
53 | assume that it is a linker script. A script specified in this way
|
---|
54 | augments the main linker script used for the link (either the default
|
---|
55 | linker script or the one specified by using `-T'). This feature
|
---|
56 | permits the linker to link against a file which appears to be an object
|
---|
57 | or an archive, but actually merely defines some symbol values, or uses
|
---|
58 | `INPUT' or `GROUP' to load other objects. Note that specifying a
|
---|
59 | script in this way merely augments the main linker script; use the `-T'
|
---|
60 | option to replace the default linker script entirely. *Note Scripts::.
|
---|
61 |
|
---|
62 | For options whose names are a single letter, option arguments must
|
---|
63 | either follow the option letter without intervening whitespace, or be
|
---|
64 | given as separate arguments immediately following the option that
|
---|
65 | requires them.
|
---|
66 |
|
---|
67 | For options whose names are multiple letters, either one dash or two
|
---|
68 | can precede the option name; for example, `-trace-symbol' and
|
---|
69 | `--trace-symbol' are equivalent. Note--there is one exception to this
|
---|
70 | rule. Multiple letter options that start with a lower case 'o' can
|
---|
71 | only be preceeded by two dashes. This is to reduce confusion with the
|
---|
72 | `-o' option. So for example `-omagic' sets the output file name to
|
---|
73 | `magic' whereas `--omagic' sets the NMAGIC flag on the output.
|
---|
74 |
|
---|
75 | Arguments to multiple-letter options must either be separated from
|
---|
76 | the option name by an equals sign, or be given as separate arguments
|
---|
77 | immediately following the option that requires them. For example,
|
---|
78 | `--trace-symbol foo' and `--trace-symbol=foo' are equivalent. Unique
|
---|
79 | abbreviations of the names of multiple-letter options are accepted.
|
---|
80 |
|
---|
81 | Note--if the linker is being invoked indirectly, via a compiler
|
---|
82 | driver (e.g. `gcc') then all the linker command line options should be
|
---|
83 | prefixed by `-Wl,' (or whatever is appropriate for the particular
|
---|
84 | compiler driver) like this:
|
---|
85 |
|
---|
86 | gcc -Wl,--startgroup foo.o bar.o -Wl,--endgroup
|
---|
87 |
|
---|
88 | This is important, because otherwise the compiler driver program may
|
---|
89 | silently drop the linker options, resulting in a bad link.
|
---|
90 |
|
---|
91 | Here is a table of the generic command line switches accepted by the
|
---|
92 | GNU linker:
|
---|
93 |
|
---|
94 | `-aKEYWORD'
|
---|
95 | This option is supported for HP/UX compatibility. The KEYWORD
|
---|
96 | argument must be one of the strings `archive', `shared', or
|
---|
97 | `default'. `-aarchive' is functionally equivalent to `-Bstatic',
|
---|
98 | and the other two keywords are functionally equivalent to
|
---|
99 | `-Bdynamic'. This option may be used any number of times.
|
---|
100 |
|
---|
101 | `-AARCHITECTURE'
|
---|
102 | `--architecture=ARCHITECTURE'
|
---|
103 | In the current release of `ld', this option is useful only for the
|
---|
104 | Intel 960 family of architectures. In that `ld' configuration, the
|
---|
105 | ARCHITECTURE argument identifies the particular architecture in
|
---|
106 | the 960 family, enabling some safeguards and modifying the
|
---|
107 | archive-library search path. *Note `ld' and the Intel 960 family:
|
---|
108 | i960, for details.
|
---|
109 |
|
---|
110 | Future releases of `ld' may support similar functionality for
|
---|
111 | other architecture families.
|
---|
112 |
|
---|
113 | `-b INPUT-FORMAT'
|
---|
114 | `--format=INPUT-FORMAT'
|
---|
115 | `ld' may be configured to support more than one kind of object
|
---|
116 | file. If your `ld' is configured this way, you can use the `-b'
|
---|
117 | option to specify the binary format for input object files that
|
---|
118 | follow this option on the command line. Even when `ld' is
|
---|
119 | configured to support alternative object formats, you don't
|
---|
120 | usually need to specify this, as `ld' should be configured to
|
---|
121 | expect as a default input format the most usual format on each
|
---|
122 | machine. INPUT-FORMAT is a text string, the name of a particular
|
---|
123 | format supported by the BFD libraries. (You can list the
|
---|
124 | available binary formats with `objdump -i'.) *Note BFD::.
|
---|
125 |
|
---|
126 | You may want to use this option if you are linking files with an
|
---|
127 | unusual binary format. You can also use `-b' to switch formats
|
---|
128 | explicitly (when linking object files of different formats), by
|
---|
129 | including `-b INPUT-FORMAT' before each group of object files in a
|
---|
130 | particular format.
|
---|
131 |
|
---|
132 | The default format is taken from the environment variable
|
---|
133 | `GNUTARGET'. *Note Environment::. You can also define the input
|
---|
134 | format from a script, using the command `TARGET'; see *Note Format
|
---|
135 | Commands::.
|
---|
136 |
|
---|
137 | `-c MRI-COMMANDFILE'
|
---|
138 | `--mri-script=MRI-COMMANDFILE'
|
---|
139 | For compatibility with linkers produced by MRI, `ld' accepts script
|
---|
140 | files written in an alternate, restricted command language,
|
---|
141 | described in *Note MRI Compatible Script Files: MRI. Introduce
|
---|
142 | MRI script files with the option `-c'; use the `-T' option to run
|
---|
143 | linker scripts written in the general-purpose `ld' scripting
|
---|
144 | language. If MRI-CMDFILE does not exist, `ld' looks for it in the
|
---|
145 | directories specified by any `-L' options.
|
---|
146 |
|
---|
147 | `-d'
|
---|
148 | `-dc'
|
---|
149 | `-dp'
|
---|
150 | These three options are equivalent; multiple forms are supported
|
---|
151 | for compatibility with other linkers. They assign space to common
|
---|
152 | symbols even if a relocatable output file is specified (with
|
---|
153 | `-r'). The script command `FORCE_COMMON_ALLOCATION' has the same
|
---|
154 | effect. *Note Miscellaneous Commands::.
|
---|
155 |
|
---|
156 | `-e ENTRY'
|
---|
157 | `--entry=ENTRY'
|
---|
158 | Use ENTRY as the explicit symbol for beginning execution of your
|
---|
159 | program, rather than the default entry point. If there is no
|
---|
160 | symbol named ENTRY, the linker will try to parse ENTRY as a number,
|
---|
161 | and use that as the entry address (the number will be interpreted
|
---|
162 | in base 10; you may use a leading `0x' for base 16, or a leading
|
---|
163 | `0' for base 8). *Note Entry Point::, for a discussion of defaults
|
---|
164 | and other ways of specifying the entry point.
|
---|
165 |
|
---|
166 | `-E'
|
---|
167 | `--export-dynamic'
|
---|
168 | When creating a dynamically linked executable, add all symbols to
|
---|
169 | the dynamic symbol table. The dynamic symbol table is the set of
|
---|
170 | symbols which are visible from dynamic objects at run time.
|
---|
171 |
|
---|
172 | If you do not use this option, the dynamic symbol table will
|
---|
173 | normally contain only those symbols which are referenced by some
|
---|
174 | dynamic object mentioned in the link.
|
---|
175 |
|
---|
176 | If you use `dlopen' to load a dynamic object which needs to refer
|
---|
177 | back to the symbols defined by the program, rather than some other
|
---|
178 | dynamic object, then you will probably need to use this option when
|
---|
179 | linking the program itself.
|
---|
180 |
|
---|
181 | You can also use the version script to control what symbols should
|
---|
182 | be added to the dynamic symbol table if the output format supports
|
---|
183 | it. See the description of `--version-script' in *Note VERSION::.
|
---|
184 |
|
---|
185 | `-EB'
|
---|
186 | Link big-endian objects. This affects the default output format.
|
---|
187 |
|
---|
188 | `-EL'
|
---|
189 | Link little-endian objects. This affects the default output
|
---|
190 | format.
|
---|
191 |
|
---|
192 | `-f'
|
---|
193 | `--auxiliary NAME'
|
---|
194 | When creating an ELF shared object, set the internal DT_AUXILIARY
|
---|
195 | field to the specified name. This tells the dynamic linker that
|
---|
196 | the symbol table of the shared object should be used as an
|
---|
197 | auxiliary filter on the symbol table of the shared object NAME.
|
---|
198 |
|
---|
199 | If you later link a program against this filter object, then, when
|
---|
200 | you run the program, the dynamic linker will see the DT_AUXILIARY
|
---|
201 | field. If the dynamic linker resolves any symbols from the filter
|
---|
202 | object, it will first check whether there is a definition in the
|
---|
203 | shared object NAME. If there is one, it will be used instead of
|
---|
204 | the definition in the filter object. The shared object NAME need
|
---|
205 | not exist. Thus the shared object NAME may be used to provide an
|
---|
206 | alternative implementation of certain functions, perhaps for
|
---|
207 | debugging or for machine specific performance.
|
---|
208 |
|
---|
209 | This option may be specified more than once. The DT_AUXILIARY
|
---|
210 | entries will be created in the order in which they appear on the
|
---|
211 | command line.
|
---|
212 |
|
---|
213 | `-F NAME'
|
---|
214 | `--filter NAME'
|
---|
215 | When creating an ELF shared object, set the internal DT_FILTER
|
---|
216 | field to the specified name. This tells the dynamic linker that
|
---|
217 | the symbol table of the shared object which is being created
|
---|
218 | should be used as a filter on the symbol table of the shared
|
---|
219 | object NAME.
|
---|
220 |
|
---|
221 | If you later link a program against this filter object, then, when
|
---|
222 | you run the program, the dynamic linker will see the DT_FILTER
|
---|
223 | field. The dynamic linker will resolve symbols according to the
|
---|
224 | symbol table of the filter object as usual, but it will actually
|
---|
225 | link to the definitions found in the shared object NAME. Thus the
|
---|
226 | filter object can be used to select a subset of the symbols
|
---|
227 | provided by the object NAME.
|
---|
228 |
|
---|
229 | Some older linkers used the `-F' option throughout a compilation
|
---|
230 | toolchain for specifying object-file format for both input and
|
---|
231 | output object files. The GNU linker uses other mechanisms for
|
---|
232 | this purpose: the `-b', `--format', `--oformat' options, the
|
---|
233 | `TARGET' command in linker scripts, and the `GNUTARGET'
|
---|
234 | environment variable. The GNU linker will ignore the `-F' option
|
---|
235 | when not creating an ELF shared object.
|
---|
236 |
|
---|
237 | `-fini NAME'
|
---|
238 | When creating an ELF executable or shared object, call NAME when
|
---|
239 | the executable or shared object is unloaded, by setting DT_FINI to
|
---|
240 | the address of the function. By default, the linker uses `_fini'
|
---|
241 | as the function to call.
|
---|
242 |
|
---|
243 | `-g'
|
---|
244 | Ignored. Provided for compatibility with other tools.
|
---|
245 |
|
---|
246 | `-GVALUE'
|
---|
247 | `--gpsize=VALUE'
|
---|
248 | Set the maximum size of objects to be optimized using the GP
|
---|
249 | register to SIZE. This is only meaningful for object file formats
|
---|
250 | such as MIPS ECOFF which supports putting large and small objects
|
---|
251 | into different sections. This is ignored for other object file
|
---|
252 | formats.
|
---|
253 |
|
---|
254 | `-hNAME'
|
---|
255 | `-soname=NAME'
|
---|
256 | When creating an ELF shared object, set the internal DT_SONAME
|
---|
257 | field to the specified name. When an executable is linked with a
|
---|
258 | shared object which has a DT_SONAME field, then when the
|
---|
259 | executable is run the dynamic linker will attempt to load the
|
---|
260 | shared object specified by the DT_SONAME field rather than the
|
---|
261 | using the file name given to the linker.
|
---|
262 |
|
---|
263 | `-i'
|
---|
264 | Perform an incremental link (same as option `-r').
|
---|
265 |
|
---|
266 | `-init NAME'
|
---|
267 | When creating an ELF executable or shared object, call NAME when
|
---|
268 | the executable or shared object is loaded, by setting DT_INIT to
|
---|
269 | the address of the function. By default, the linker uses `_init'
|
---|
270 | as the function to call.
|
---|
271 |
|
---|
272 | `-lARCHIVE'
|
---|
273 | `--library=ARCHIVE'
|
---|
274 | Add archive file ARCHIVE to the list of files to link. This
|
---|
275 | option may be used any number of times. `ld' will search its
|
---|
276 | path-list for occurrences of `libARCHIVE.a' for every ARCHIVE
|
---|
277 | specified.
|
---|
278 |
|
---|
279 | On systems which support shared libraries, `ld' may also search for
|
---|
280 | libraries with extensions other than `.a'. Specifically, on ELF
|
---|
281 | and SunOS systems, `ld' will search a directory for a library with
|
---|
282 | an extension of `.so' before searching for one with an extension of
|
---|
283 | `.a'. By convention, a `.so' extension indicates a shared library.
|
---|
284 |
|
---|
285 | The linker will search an archive only once, at the location where
|
---|
286 | it is specified on the command line. If the archive defines a
|
---|
287 | symbol which was undefined in some object which appeared before
|
---|
288 | the archive on the command line, the linker will include the
|
---|
289 | appropriate file(s) from the archive. However, an undefined
|
---|
290 | symbol in an object appearing later on the command line will not
|
---|
291 | cause the linker to search the archive again.
|
---|
292 |
|
---|
293 | See the `-(' option for a way to force the linker to search
|
---|
294 | archives multiple times.
|
---|
295 |
|
---|
296 | You may list the same archive multiple times on the command line.
|
---|
297 |
|
---|
298 | This type of archive searching is standard for Unix linkers.
|
---|
299 | However, if you are using `ld' on AIX, note that it is different
|
---|
300 | from the behaviour of the AIX linker.
|
---|
301 |
|
---|
302 | `-LSEARCHDIR'
|
---|
303 | `--library-path=SEARCHDIR'
|
---|
304 | Add path SEARCHDIR to the list of paths that `ld' will search for
|
---|
305 | archive libraries and `ld' control scripts. You may use this
|
---|
306 | option any number of times. The directories are searched in the
|
---|
307 | order in which they are specified on the command line.
|
---|
308 | Directories specified on the command line are searched before the
|
---|
309 | default directories. All `-L' options apply to all `-l' options,
|
---|
310 | regardless of the order in which the options appear.
|
---|
311 |
|
---|
312 | If SEARCHDIR begins with `=', then the `=' will be replaced by the
|
---|
313 | "sysroot prefix", a path specified when the linker is configured.
|
---|
314 |
|
---|
315 | The default set of paths searched (without being specified with
|
---|
316 | `-L') depends on which emulation mode `ld' is using, and in some
|
---|
317 | cases also on how it was configured. *Note Environment::.
|
---|
318 |
|
---|
319 | The paths can also be specified in a link script with the
|
---|
320 | `SEARCH_DIR' command. Directories specified this way are searched
|
---|
321 | at the point in which the linker script appears in the command
|
---|
322 | line.
|
---|
323 |
|
---|
324 | `-mEMULATION'
|
---|
325 | Emulate the EMULATION linker. You can list the available
|
---|
326 | emulations with the `--verbose' or `-V' options.
|
---|
327 |
|
---|
328 | If the `-m' option is not used, the emulation is taken from the
|
---|
329 | `LDEMULATION' environment variable, if that is defined.
|
---|
330 |
|
---|
331 | Otherwise, the default emulation depends upon how the linker was
|
---|
332 | configured.
|
---|
333 |
|
---|
334 | `-M'
|
---|
335 | `--print-map'
|
---|
336 | Print a link map to the standard output. A link map provides
|
---|
337 | information about the link, including the following:
|
---|
338 |
|
---|
339 | * Where object files and symbols are mapped into memory.
|
---|
340 |
|
---|
341 | * How common symbols are allocated.
|
---|
342 |
|
---|
343 | * All archive members included in the link, with a mention of
|
---|
344 | the symbol which caused the archive member to be brought in.
|
---|
345 |
|
---|
346 | `-n'
|
---|
347 | `--nmagic'
|
---|
348 | Turn off page alignment of sections, and mark the output as
|
---|
349 | `NMAGIC' if possible.
|
---|
350 |
|
---|
351 | `-N'
|
---|
352 | `--omagic'
|
---|
353 | Set the text and data sections to be readable and writable. Also,
|
---|
354 | do not page-align the data segment, and disable linking against
|
---|
355 | shared libraries. If the output format supports Unix style magic
|
---|
356 | numbers, mark the output as `OMAGIC'.
|
---|
357 |
|
---|
358 | `--no-omagic'
|
---|
359 | This option negates most of the effects of the `-N' option. It
|
---|
360 | sets the text section to be read-only, and forces the data segment
|
---|
361 | to be page-aligned. Note - this option does not enable linking
|
---|
362 | against shared libraries. Use `-Bdynamic' for this.
|
---|
363 |
|
---|
364 | `-o OUTPUT'
|
---|
365 | `--output=OUTPUT'
|
---|
366 | Use OUTPUT as the name for the program produced by `ld'; if this
|
---|
367 | option is not specified, the name `a.out' is used by default. The
|
---|
368 | script command `OUTPUT' can also specify the output file name.
|
---|
369 |
|
---|
370 | `-O LEVEL'
|
---|
371 | If LEVEL is a numeric values greater than zero `ld' optimizes the
|
---|
372 | output. This might take significantly longer and therefore
|
---|
373 | probably should only be enabled for the final binary.
|
---|
374 |
|
---|
375 | `-q'
|
---|
376 | `--emit-relocs'
|
---|
377 | Leave relocation sections and contents in fully linked
|
---|
378 | exececutables. Post link analysis and optimization tools may need
|
---|
379 | this information in order to perform correct modifications of
|
---|
380 | executables. This results in larger executables.
|
---|
381 |
|
---|
382 | This option is currently only supported on ELF platforms.
|
---|
383 |
|
---|
384 | `-r'
|
---|
385 | `--relocateable'
|
---|
386 | Generate relocatable output--i.e., generate an output file that
|
---|
387 | can in turn serve as input to `ld'. This is often called "partial
|
---|
388 | linking". As a side effect, in environments that support standard
|
---|
389 | Unix magic numbers, this option also sets the output file's magic
|
---|
390 | number to `OMAGIC'. If this option is not specified, an absolute
|
---|
391 | file is produced. When linking C++ programs, this option _will
|
---|
392 | not_ resolve references to constructors; to do that, use `-Ur'.
|
---|
393 |
|
---|
394 | When an input file does not have the same format as the output
|
---|
395 | file, partial linking is only supported if that input file does
|
---|
396 | not contain any relocations. Different output formats can have
|
---|
397 | further restrictions; for example some `a.out'-based formats do
|
---|
398 | not support partial linking with input files in other formats at
|
---|
399 | all.
|
---|
400 |
|
---|
401 | This option does the same thing as `-i'.
|
---|
402 |
|
---|
403 | `-R FILENAME'
|
---|
404 | `--just-symbols=FILENAME'
|
---|
405 | Read symbol names and their addresses from FILENAME, but do not
|
---|
406 | relocate it or include it in the output. This allows your output
|
---|
407 | file to refer symbolically to absolute locations of memory defined
|
---|
408 | in other programs. You may use this option more than once.
|
---|
409 |
|
---|
410 | For compatibility with other ELF linkers, if the `-R' option is
|
---|
411 | followed by a directory name, rather than a file name, it is
|
---|
412 | treated as the `-rpath' option.
|
---|
413 |
|
---|
414 | `-s'
|
---|
415 | `--strip-all'
|
---|
416 | Omit all symbol information from the output file.
|
---|
417 |
|
---|
418 | `-S'
|
---|
419 | `--strip-debug'
|
---|
420 | Omit debugger symbol information (but not all symbols) from the
|
---|
421 | output file.
|
---|
422 |
|
---|
423 | `-t'
|
---|
424 | `--trace'
|
---|
425 | Print the names of the input files as `ld' processes them.
|
---|
426 |
|
---|
427 | `-T SCRIPTFILE'
|
---|
428 | `--script=SCRIPTFILE'
|
---|
429 | Use SCRIPTFILE as the linker script. This script replaces `ld''s
|
---|
430 | default linker script (rather than adding to it), so COMMANDFILE
|
---|
431 | must specify everything necessary to describe the output file.
|
---|
432 | *Note Scripts::. If SCRIPTFILE does not exist in the current
|
---|
433 | directory, `ld' looks for it in the directories specified by any
|
---|
434 | preceding `-L' options. Multiple `-T' options accumulate.
|
---|
435 |
|
---|
436 | `-u SYMBOL'
|
---|
437 | `--undefined=SYMBOL'
|
---|
438 | Force SYMBOL to be entered in the output file as an undefined
|
---|
439 | symbol. Doing this may, for example, trigger linking of additional
|
---|
440 | modules from standard libraries. `-u' may be repeated with
|
---|
441 | different option arguments to enter additional undefined symbols.
|
---|
442 | This option is equivalent to the `EXTERN' linker script command.
|
---|
443 |
|
---|
444 | `-Ur'
|
---|
445 | For anything other than C++ programs, this option is equivalent to
|
---|
446 | `-r': it generates relocatable output--i.e., an output file that
|
---|
447 | can in turn serve as input to `ld'. When linking C++ programs,
|
---|
448 | `-Ur' _does_ resolve references to constructors, unlike `-r'. It
|
---|
449 | does not work to use `-Ur' on files that were themselves linked
|
---|
450 | with `-Ur'; once the constructor table has been built, it cannot
|
---|
451 | be added to. Use `-Ur' only for the last partial link, and `-r'
|
---|
452 | for the others.
|
---|
453 |
|
---|
454 | `--unique[=SECTION]'
|
---|
455 | Creates a separate output section for every input section matching
|
---|
456 | SECTION, or if the optional wildcard SECTION argument is missing,
|
---|
457 | for every orphan input section. An orphan section is one not
|
---|
458 | specifically mentioned in a linker script. You may use this option
|
---|
459 | multiple times on the command line; It prevents the normal
|
---|
460 | merging of input sections with the same name, overriding output
|
---|
461 | section assignments in a linker script.
|
---|
462 |
|
---|
463 | `-v'
|
---|
464 | `--version'
|
---|
465 | `-V'
|
---|
466 | Display the version number for `ld'. The `-V' option also lists
|
---|
467 | the supported emulations.
|
---|
468 |
|
---|
469 | `-x'
|
---|
470 | `--discard-all'
|
---|
471 | Delete all local symbols.
|
---|
472 |
|
---|
473 | `-X'
|
---|
474 | `--discard-locals'
|
---|
475 | Delete all temporary local symbols. For most targets, this is all
|
---|
476 | local symbols whose names begin with `L'.
|
---|
477 |
|
---|
478 | `-y SYMBOL'
|
---|
479 | `--trace-symbol=SYMBOL'
|
---|
480 | Print the name of each linked file in which SYMBOL appears. This
|
---|
481 | option may be given any number of times. On many systems it is
|
---|
482 | necessary to prepend an underscore.
|
---|
483 |
|
---|
484 | This option is useful when you have an undefined symbol in your
|
---|
485 | link but don't know where the reference is coming from.
|
---|
486 |
|
---|
487 | `-Y PATH'
|
---|
488 | Add PATH to the default library search path. This option exists
|
---|
489 | for Solaris compatibility.
|
---|
490 |
|
---|
491 | `-z KEYWORD'
|
---|
492 | The recognized keywords are `initfirst', `interpose', `loadfltr',
|
---|
493 | `nodefaultlib', `nodelete', `nodlopen', `nodump', `now', `origin',
|
---|
494 | `combreloc', `nocombreloc' and `nocopyreloc'. The other keywords
|
---|
495 | are ignored for Solaris compatibility. `initfirst' marks the object
|
---|
496 | to be initialized first at runtime before any other objects.
|
---|
497 | `interpose' marks the object that its symbol table interposes
|
---|
498 | before all symbols but the primary executable. `loadfltr' marks
|
---|
499 | the object that its filtees be processed immediately at runtime.
|
---|
500 | `nodefaultlib' marks the object that the search for dependencies
|
---|
501 | of this object will ignore any default library search paths.
|
---|
502 | `nodelete' marks the object shouldn't be unloaded at runtime.
|
---|
503 | `nodlopen' marks the object not available to `dlopen'. `nodump'
|
---|
504 | marks the object can not be dumped by `dldump'. `now' marks the
|
---|
505 | object with the non-lazy runtime binding. `origin' marks the
|
---|
506 | object may contain $ORIGIN. `defs' disallows undefined symbols.
|
---|
507 | `muldefs' allows multiple definitions. `combreloc' combines
|
---|
508 | multiple reloc sections and sorts them to make dynamic symbol
|
---|
509 | lookup caching possible. `nocombreloc' disables multiple reloc
|
---|
510 | sections combining. `nocopyreloc' disables production of copy
|
---|
511 | relocs.
|
---|
512 |
|
---|
513 | `-( ARCHIVES -)'
|
---|
514 | `--start-group ARCHIVES --end-group'
|
---|
515 | The ARCHIVES should be a list of archive files. They may be
|
---|
516 | either explicit file names, or `-l' options.
|
---|
517 |
|
---|
518 | The specified archives are searched repeatedly until no new
|
---|
519 | undefined references are created. Normally, an archive is
|
---|
520 | searched only once in the order that it is specified on the
|
---|
521 | command line. If a symbol in that archive is needed to resolve an
|
---|
522 | undefined symbol referred to by an object in an archive that
|
---|
523 | appears later on the command line, the linker would not be able to
|
---|
524 | resolve that reference. By grouping the archives, they all be
|
---|
525 | searched repeatedly until all possible references are resolved.
|
---|
526 |
|
---|
527 | Using this option has a significant performance cost. It is best
|
---|
528 | to use it only when there are unavoidable circular references
|
---|
529 | between two or more archives.
|
---|
530 |
|
---|
531 | `--accept-unknown-input-arch'
|
---|
532 | `--no-accept-unknown-input-arch'
|
---|
533 | Tells the linker to accept input files whose architecture cannot be
|
---|
534 | recognised. The assumption is that the user knows what they are
|
---|
535 | doing and deliberately wants to link in these unknown input files.
|
---|
536 | This was the default behaviour of the linker, before release
|
---|
537 | 2.14. The default behaviour from release 2.14 onwards is to
|
---|
538 | reject such input files, and so the `--accept-unknown-input-arch'
|
---|
539 | option has been added to restore the old behaviour.
|
---|
540 |
|
---|
541 | `-assert KEYWORD'
|
---|
542 | This option is ignored for SunOS compatibility.
|
---|
543 |
|
---|
544 | `-Bdynamic'
|
---|
545 | `-dy'
|
---|
546 | `-call_shared'
|
---|
547 | Link against dynamic libraries. This is only meaningful on
|
---|
548 | platforms for which shared libraries are supported. This option
|
---|
549 | is normally the default on such platforms. The different variants
|
---|
550 | of this option are for compatibility with various systems. You
|
---|
551 | may use this option multiple times on the command line: it affects
|
---|
552 | library searching for `-l' options which follow it.
|
---|
553 |
|
---|
554 | `-Bgroup'
|
---|
555 | Set the `DF_1_GROUP' flag in the `DT_FLAGS_1' entry in the dynamic
|
---|
556 | section. This causes the runtime linker to handle lookups in this
|
---|
557 | object and its dependencies to be performed only inside the group.
|
---|
558 | `--no-undefined' is implied. This option is only meaningful on ELF
|
---|
559 | platforms which support shared libraries.
|
---|
560 |
|
---|
561 | `-Bstatic'
|
---|
562 | `-dn'
|
---|
563 | `-non_shared'
|
---|
564 | `-static'
|
---|
565 | Do not link against shared libraries. This is only meaningful on
|
---|
566 | platforms for which shared libraries are supported. The different
|
---|
567 | variants of this option are for compatibility with various
|
---|
568 | systems. You may use this option multiple times on the command
|
---|
569 | line: it affects library searching for `-l' options which follow
|
---|
570 | it.
|
---|
571 |
|
---|
572 | `-Bsymbolic'
|
---|
573 | When creating a shared library, bind references to global symbols
|
---|
574 | to the definition within the shared library, if any. Normally, it
|
---|
575 | is possible for a program linked against a shared library to
|
---|
576 | override the definition within the shared library. This option is
|
---|
577 | only meaningful on ELF platforms which support shared libraries.
|
---|
578 |
|
---|
579 | `--check-sections'
|
---|
580 | `--no-check-sections'
|
---|
581 | Asks the linker _not_ to check section addresses after they have
|
---|
582 | been assigned to see if there any overlaps. Normally the linker
|
---|
583 | will perform this check, and if it finds any overlaps it will
|
---|
584 | produce suitable error messages. The linker does know about, and
|
---|
585 | does make allowances for sections in overlays. The default
|
---|
586 | behaviour can be restored by using the command line switch
|
---|
587 | `--check-sections'.
|
---|
588 |
|
---|
589 | `--cref'
|
---|
590 | Output a cross reference table. If a linker map file is being
|
---|
591 | generated, the cross reference table is printed to the map file.
|
---|
592 | Otherwise, it is printed on the standard output.
|
---|
593 |
|
---|
594 | The format of the table is intentionally simple, so that it may be
|
---|
595 | easily processed by a script if necessary. The symbols are
|
---|
596 | printed out, sorted by name. For each symbol, a list of file
|
---|
597 | names is given. If the symbol is defined, the first file listed
|
---|
598 | is the location of the definition. The remaining files contain
|
---|
599 | references to the symbol.
|
---|
600 |
|
---|
601 | `--no-define-common'
|
---|
602 | This option inhibits the assignment of addresses to common symbols.
|
---|
603 | The script command `INHIBIT_COMMON_ALLOCATION' has the same effect.
|
---|
604 | *Note Miscellaneous Commands::.
|
---|
605 |
|
---|
606 | The `--no-define-common' option allows decoupling the decision to
|
---|
607 | assign addresses to Common symbols from the choice of the output
|
---|
608 | file type; otherwise a non-Relocatable output type forces
|
---|
609 | assigning addresses to Common symbols. Using `--no-define-common'
|
---|
610 | allows Common symbols that are referenced from a shared library to
|
---|
611 | be assigned addresses only in the main program. This eliminates
|
---|
612 | the unused duplicate space in the shared library, and also
|
---|
613 | prevents any possible confusion over resolving to the wrong
|
---|
614 | duplicate when there are many dynamic modules with specialized
|
---|
615 | search paths for runtime symbol resolution.
|
---|
616 |
|
---|
617 | `--defsym SYMBOL=EXPRESSION'
|
---|
618 | Create a global symbol in the output file, containing the absolute
|
---|
619 | address given by EXPRESSION. You may use this option as many
|
---|
620 | times as necessary to define multiple symbols in the command line.
|
---|
621 | A limited form of arithmetic is supported for the EXPRESSION in
|
---|
622 | this context: you may give a hexadecimal constant or the name of
|
---|
623 | an existing symbol, or use `+' and `-' to add or subtract
|
---|
624 | hexadecimal constants or symbols. If you need more elaborate
|
---|
625 | expressions, consider using the linker command language from a
|
---|
626 | script (*note Assignment: Symbol Definitions: Assignments.).
|
---|
627 | _Note:_ there should be no white space between SYMBOL, the equals
|
---|
628 | sign ("<=>"), and EXPRESSION.
|
---|
629 |
|
---|
630 | `--demangle[=STYLE]'
|
---|
631 | `--no-demangle'
|
---|
632 | These options control whether to demangle symbol names in error
|
---|
633 | messages and other output. When the linker is told to demangle,
|
---|
634 | it tries to present symbol names in a readable fashion: it strips
|
---|
635 | leading underscores if they are used by the object file format,
|
---|
636 | and converts C++ mangled symbol names into user readable names.
|
---|
637 | Different compilers have different mangling styles. The optional
|
---|
638 | demangling style argument can be used to choose an appropriate
|
---|
639 | demangling style for your compiler. The linker will demangle by
|
---|
640 | default unless the environment variable `COLLECT_NO_DEMANGLE' is
|
---|
641 | set. These options may be used to override the default.
|
---|
642 |
|
---|
643 | `--dynamic-linker FILE'
|
---|
644 | Set the name of the dynamic linker. This is only meaningful when
|
---|
645 | generating dynamically linked ELF executables. The default dynamic
|
---|
646 | linker is normally correct; don't use this unless you know what
|
---|
647 | you are doing.
|
---|
648 |
|
---|
649 | `--embedded-relocs'
|
---|
650 | This option is only meaningful when linking MIPS embedded PIC code,
|
---|
651 | generated by the -membedded-pic option to the GNU compiler and
|
---|
652 | assembler. It causes the linker to create a table which may be
|
---|
653 | used at runtime to relocate any data which was statically
|
---|
654 | initialized to pointer values. See the code in testsuite/ld-empic
|
---|
655 | for details.
|
---|
656 |
|
---|
657 | `--fatal-warnings'
|
---|
658 | Treat all warnings as errors.
|
---|
659 |
|
---|
660 | `--force-exe-suffix'
|
---|
661 | Make sure that an output file has a .exe suffix.
|
---|
662 |
|
---|
663 | If a successfully built fully linked output file does not have a
|
---|
664 | `.exe' or `.dll' suffix, this option forces the linker to copy the
|
---|
665 | output file to one of the same name with a `.exe' suffix. This
|
---|
666 | option is useful when using unmodified Unix makefiles on a
|
---|
667 | Microsoft Windows host, since some versions of Windows won't run
|
---|
668 | an image unless it ends in a `.exe' suffix.
|
---|
669 |
|
---|
670 | `--no-gc-sections'
|
---|
671 | `--gc-sections'
|
---|
672 | Enable garbage collection of unused input sections. It is ignored
|
---|
673 | on targets that do not support this option. This option is not
|
---|
674 | compatible with `-r', nor should it be used with dynamic linking.
|
---|
675 | The default behaviour (of not performing this garbage collection)
|
---|
676 | can be restored by specifying `--no-gc-sections' on the command
|
---|
677 | line.
|
---|
678 |
|
---|
679 | `--help'
|
---|
680 | Print a summary of the command-line options on the standard output
|
---|
681 | and exit.
|
---|
682 |
|
---|
683 | `--target-help'
|
---|
684 | Print a summary of all target specific options on the standard
|
---|
685 | output and exit.
|
---|
686 |
|
---|
687 | `-Map MAPFILE'
|
---|
688 | Print a link map to the file MAPFILE. See the description of the
|
---|
689 | `-M' option, above.
|
---|
690 |
|
---|
691 | `--no-keep-memory'
|
---|
692 | `ld' normally optimizes for speed over memory usage by caching the
|
---|
693 | symbol tables of input files in memory. This option tells `ld' to
|
---|
694 | instead optimize for memory usage, by rereading the symbol tables
|
---|
695 | as necessary. This may be required if `ld' runs out of memory
|
---|
696 | space while linking a large executable.
|
---|
697 |
|
---|
698 | `--no-undefined'
|
---|
699 | `-z defs'
|
---|
700 | Normally when creating a non-symbolic shared library, undefined
|
---|
701 | symbols are allowed and left to be resolved by the runtime loader.
|
---|
702 | This option disallows such undefined symbols if they come from
|
---|
703 | regular object files. The switch `--no-allow-shlib-undefined'
|
---|
704 | controls the behaviour for shared objects being linked into the
|
---|
705 | shared library.
|
---|
706 |
|
---|
707 | `--allow-multiple-definition'
|
---|
708 | `-z muldefs'
|
---|
709 | Normally when a symbol is defined multiple times, the linker will
|
---|
710 | report a fatal error. These options allow multiple definitions and
|
---|
711 | the first definition will be used.
|
---|
712 |
|
---|
713 | `--allow-shlib-undefined'
|
---|
714 | `--no-allow-shlib-undefined'
|
---|
715 | Allow (the default) or disallow undefined symbols in shared
|
---|
716 | objects. The setting of this switch overrides `--no-undefined'
|
---|
717 | where shared objects are concerned. Thus if `--no-undefined' is
|
---|
718 | set but `--no-allow-shlib-undefined' is not, the net result will be
|
---|
719 | that undefined symbols in regular object files will trigger an
|
---|
720 | error, but undefined symbols in shared objects will be ignored.
|
---|
721 |
|
---|
722 | The reason that `--allow-shlib-undefined' is the default is that
|
---|
723 | the shared object being specified at link time may not be the same
|
---|
724 | one that is available at load time, so the symbols might actually
|
---|
725 | be resolvable at load time. Plus there are some systems, (eg
|
---|
726 | BeOS) where undefined symbols in shared libraries is normal since
|
---|
727 | the kernel patches them at load time to select which function is
|
---|
728 | most appropriate for the current architecture. eg. to dynamically
|
---|
729 | select an appropriate memset function. Apparently it is also
|
---|
730 | normal for HPPA shared libraries to have undefined symbols.
|
---|
731 |
|
---|
732 | `--no-undefined-version'
|
---|
733 | Normally when a symbol has an undefined version, the linker will
|
---|
734 | ignore it. This option disallows symbols with undefined version
|
---|
735 | and a fatal error will be issued instead.
|
---|
736 |
|
---|
737 | `--no-warn-mismatch'
|
---|
738 | Normally `ld' will give an error if you try to link together input
|
---|
739 | files that are mismatched for some reason, perhaps because they
|
---|
740 | have been compiled for different processors or for different
|
---|
741 | endiannesses. This option tells `ld' that it should silently
|
---|
742 | permit such possible errors. This option should only be used with
|
---|
743 | care, in cases when you have taken some special action that
|
---|
744 | ensures that the linker errors are inappropriate.
|
---|
745 |
|
---|
746 | `--no-whole-archive'
|
---|
747 | Turn off the effect of the `--whole-archive' option for subsequent
|
---|
748 | archive files.
|
---|
749 |
|
---|
750 | `--noinhibit-exec'
|
---|
751 | Retain the executable output file whenever it is still usable.
|
---|
752 | Normally, the linker will not produce an output file if it
|
---|
753 | encounters errors during the link process; it exits without
|
---|
754 | writing an output file when it issues any error whatsoever.
|
---|
755 |
|
---|
756 | `-nostdlib'
|
---|
757 | Only search library directories explicitly specified on the
|
---|
758 | command line. Library directories specified in linker scripts
|
---|
759 | (including linker scripts specified on the command line) are
|
---|
760 | ignored.
|
---|
761 |
|
---|
762 | `--oformat OUTPUT-FORMAT'
|
---|
763 | `ld' may be configured to support more than one kind of object
|
---|
764 | file. If your `ld' is configured this way, you can use the
|
---|
765 | `--oformat' option to specify the binary format for the output
|
---|
766 | object file. Even when `ld' is configured to support alternative
|
---|
767 | object formats, you don't usually need to specify this, as `ld'
|
---|
768 | should be configured to produce as a default output format the most
|
---|
769 | usual format on each machine. OUTPUT-FORMAT is a text string, the
|
---|
770 | name of a particular format supported by the BFD libraries. (You
|
---|
771 | can list the available binary formats with `objdump -i'.) The
|
---|
772 | script command `OUTPUT_FORMAT' can also specify the output format,
|
---|
773 | but this option overrides it. *Note BFD::.
|
---|
774 |
|
---|
775 | `-qmagic'
|
---|
776 | This option is ignored for Linux compatibility.
|
---|
777 |
|
---|
778 | `-Qy'
|
---|
779 | This option is ignored for SVR4 compatibility.
|
---|
780 |
|
---|
781 | `--relax'
|
---|
782 | An option with machine dependent effects. This option is only
|
---|
783 | supported on a few targets. *Note `ld' and the H8/300: H8/300.
|
---|
784 | *Note `ld' and the Intel 960 family: i960. *Note `ld' and Xtensa
|
---|
785 | Processors: Xtensa.
|
---|
786 |
|
---|
787 | On some platforms, the `--relax' option performs global
|
---|
788 | optimizations that become possible when the linker resolves
|
---|
789 | addressing in the program, such as relaxing address modes and
|
---|
790 | synthesizing new instructions in the output object file.
|
---|
791 |
|
---|
792 | On some platforms these link time global optimizations may make
|
---|
793 | symbolic debugging of the resulting executable impossible. This
|
---|
794 | is known to be the case for the Matsushita MN10200 and MN10300
|
---|
795 | family of processors.
|
---|
796 |
|
---|
797 | On platforms where this is not supported, `--relax' is accepted,
|
---|
798 | but ignored.
|
---|
799 |
|
---|
800 | `--retain-symbols-file FILENAME'
|
---|
801 | Retain _only_ the symbols listed in the file FILENAME, discarding
|
---|
802 | all others. FILENAME is simply a flat file, with one symbol name
|
---|
803 | per line. This option is especially useful in environments (such
|
---|
804 | as VxWorks) where a large global symbol table is accumulated
|
---|
805 | gradually, to conserve run-time memory.
|
---|
806 |
|
---|
807 | `--retain-symbols-file' does _not_ discard undefined symbols, or
|
---|
808 | symbols needed for relocations.
|
---|
809 |
|
---|
810 | You may only specify `--retain-symbols-file' once in the command
|
---|
811 | line. It overrides `-s' and `-S'.
|
---|
812 |
|
---|
813 | `-rpath DIR'
|
---|
814 | Add a directory to the runtime library search path. This is used
|
---|
815 | when linking an ELF executable with shared objects. All `-rpath'
|
---|
816 | arguments are concatenated and passed to the runtime linker, which
|
---|
817 | uses them to locate shared objects at runtime. The `-rpath'
|
---|
818 | option is also used when locating shared objects which are needed
|
---|
819 | by shared objects explicitly included in the link; see the
|
---|
820 | description of the `-rpath-link' option. If `-rpath' is not used
|
---|
821 | when linking an ELF executable, the contents of the environment
|
---|
822 | variable `LD_RUN_PATH' will be used if it is defined.
|
---|
823 |
|
---|
824 | The `-rpath' option may also be used on SunOS. By default, on
|
---|
825 | SunOS, the linker will form a runtime search patch out of all the
|
---|
826 | `-L' options it is given. If a `-rpath' option is used, the
|
---|
827 | runtime search path will be formed exclusively using the `-rpath'
|
---|
828 | options, ignoring the `-L' options. This can be useful when using
|
---|
829 | gcc, which adds many `-L' options which may be on NFS mounted
|
---|
830 | filesystems.
|
---|
831 |
|
---|
832 | For compatibility with other ELF linkers, if the `-R' option is
|
---|
833 | followed by a directory name, rather than a file name, it is
|
---|
834 | treated as the `-rpath' option.
|
---|
835 |
|
---|
836 | `-rpath-link DIR'
|
---|
837 | When using ELF or SunOS, one shared library may require another.
|
---|
838 | This happens when an `ld -shared' link includes a shared library
|
---|
839 | as one of the input files.
|
---|
840 |
|
---|
841 | When the linker encounters such a dependency when doing a
|
---|
842 | non-shared, non-relocatable link, it will automatically try to
|
---|
843 | locate the required shared library and include it in the link, if
|
---|
844 | it is not included explicitly. In such a case, the `-rpath-link'
|
---|
845 | option specifies the first set of directories to search. The
|
---|
846 | `-rpath-link' option may specify a sequence of directory names
|
---|
847 | either by specifying a list of names separated by colons, or by
|
---|
848 | appearing multiple times.
|
---|
849 |
|
---|
850 | This option should be used with caution as it overrides the search
|
---|
851 | path that may have been hard compiled into a shared library. In
|
---|
852 | such a case it is possible to use unintentionally a different
|
---|
853 | search path than the runtime linker would do.
|
---|
854 |
|
---|
855 | The linker uses the following search paths to locate required
|
---|
856 | shared libraries.
|
---|
857 | 1. Any directories specified by `-rpath-link' options.
|
---|
858 |
|
---|
859 | 2. Any directories specified by `-rpath' options. The difference
|
---|
860 | between `-rpath' and `-rpath-link' is that directories
|
---|
861 | specified by `-rpath' options are included in the executable
|
---|
862 | and used at runtime, whereas the `-rpath-link' option is only
|
---|
863 | effective at link time. It is for the native linker only.
|
---|
864 |
|
---|
865 | 3. On an ELF system, if the `-rpath' and `rpath-link' options
|
---|
866 | were not used, search the contents of the environment variable
|
---|
867 | `LD_RUN_PATH'. It is for the native linker only.
|
---|
868 |
|
---|
869 | 4. On SunOS, if the `-rpath' option was not used, search any
|
---|
870 | directories specified using `-L' options.
|
---|
871 |
|
---|
872 | 5. For a native linker, the contents of the environment variable
|
---|
873 | `LD_LIBRARY_PATH'.
|
---|
874 |
|
---|
875 | 6. For a native ELF linker, the directories in `DT_RUNPATH' or
|
---|
876 | `DT_RPATH' of a shared library are searched for shared
|
---|
877 | libraries needed by it. The `DT_RPATH' entries are ignored if
|
---|
878 | `DT_RUNPATH' entries exist.
|
---|
879 |
|
---|
880 | 7. The default directories, normally `/lib' and `/usr/lib'.
|
---|
881 |
|
---|
882 | 8. For a native linker on an ELF system, if the file
|
---|
883 | `/etc/ld.so.conf' exists, the list of directories found in
|
---|
884 | that file.
|
---|
885 |
|
---|
886 | If the required shared library is not found, the linker will issue
|
---|
887 | a warning and continue with the link.
|
---|
888 |
|
---|
889 | `-shared'
|
---|
890 | `-Bshareable'
|
---|
891 | Create a shared library. This is currently only supported on ELF,
|
---|
892 | XCOFF and SunOS platforms. On SunOS, the linker will
|
---|
893 | automatically create a shared library if the `-e' option is not
|
---|
894 | used and there are undefined symbols in the link.
|
---|
895 |
|
---|
896 | `--sort-common'
|
---|
897 | This option tells `ld' to sort the common symbols by size when it
|
---|
898 | places them in the appropriate output sections. First come all
|
---|
899 | the one byte symbols, then all the two byte, then all the four
|
---|
900 | byte, and then everything else. This is to prevent gaps between
|
---|
901 | symbols due to alignment constraints.
|
---|
902 |
|
---|
903 | `--split-by-file [SIZE]'
|
---|
904 | Similar to `--split-by-reloc' but creates a new output section for
|
---|
905 | each input file when SIZE is reached. SIZE defaults to a size of
|
---|
906 | 1 if not given.
|
---|
907 |
|
---|
908 | `--split-by-reloc [COUNT]'
|
---|
909 | Tries to creates extra sections in the output file so that no
|
---|
910 | single output section in the file contains more than COUNT
|
---|
911 | relocations. This is useful when generating huge relocatable
|
---|
912 | files for downloading into certain real time kernels with the COFF
|
---|
913 | object file format; since COFF cannot represent more than 65535
|
---|
914 | relocations in a single section. Note that this will fail to work
|
---|
915 | with object file formats which do not support arbitrary sections.
|
---|
916 | The linker will not split up individual input sections for
|
---|
917 | redistribution, so if a single input section contains more than
|
---|
918 | COUNT relocations one output section will contain that many
|
---|
919 | relocations. COUNT defaults to a value of 32768.
|
---|
920 |
|
---|
921 | `--stats'
|
---|
922 | Compute and display statistics about the operation of the linker,
|
---|
923 | such as execution time and memory usage.
|
---|
924 |
|
---|
925 | `--traditional-format'
|
---|
926 | For some targets, the output of `ld' is different in some ways from
|
---|
927 | the output of some existing linker. This switch requests `ld' to
|
---|
928 | use the traditional format instead.
|
---|
929 |
|
---|
930 | For example, on SunOS, `ld' combines duplicate entries in the
|
---|
931 | symbol string table. This can reduce the size of an output file
|
---|
932 | with full debugging information by over 30 percent.
|
---|
933 | Unfortunately, the SunOS `dbx' program can not read the resulting
|
---|
934 | program (`gdb' has no trouble). The `--traditional-format' switch
|
---|
935 | tells `ld' to not combine duplicate entries.
|
---|
936 |
|
---|
937 | `--section-start SECTIONNAME=ORG'
|
---|
938 | Locate a section in the output file at the absolute address given
|
---|
939 | by ORG. You may use this option as many times as necessary to
|
---|
940 | locate multiple sections in the command line. ORG must be a
|
---|
941 | single hexadecimal integer; for compatibility with other linkers,
|
---|
942 | you may omit the leading `0x' usually associated with hexadecimal
|
---|
943 | values. _Note:_ there should be no white space between
|
---|
944 | SECTIONNAME, the equals sign ("<=>"), and ORG.
|
---|
945 |
|
---|
946 | `-Tbss ORG'
|
---|
947 | `-Tdata ORG'
|
---|
948 | `-Ttext ORG'
|
---|
949 | Same as -section-start, with `.bss', `.data' or `.text' as the
|
---|
950 | SECTIONNAME.
|
---|
951 |
|
---|
952 | `--dll-verbose'
|
---|
953 | `--verbose'
|
---|
954 | Display the version number for `ld' and list the linker emulations
|
---|
955 | supported. Display which input files can and cannot be opened.
|
---|
956 | Display the linker script being used by the linker.
|
---|
957 |
|
---|
958 | `--version-script=VERSION-SCRIPTFILE'
|
---|
959 | Specify the name of a version script to the linker. This is
|
---|
960 | typically used when creating shared libraries to specify
|
---|
961 | additional information about the version hierarchy for the library
|
---|
962 | being created. This option is only meaningful on ELF platforms
|
---|
963 | which support shared libraries. *Note VERSION::.
|
---|
964 |
|
---|
965 | `--warn-common'
|
---|
966 | Warn when a common symbol is combined with another common symbol
|
---|
967 | or with a symbol definition. Unix linkers allow this somewhat
|
---|
968 | sloppy practice, but linkers on some other operating systems do
|
---|
969 | not. This option allows you to find potential problems from
|
---|
970 | combining global symbols. Unfortunately, some C libraries use
|
---|
971 | this practice, so you may get some warnings about symbols in the
|
---|
972 | libraries as well as in your programs.
|
---|
973 |
|
---|
974 | There are three kinds of global symbols, illustrated here by C
|
---|
975 | examples:
|
---|
976 |
|
---|
977 | `int i = 1;'
|
---|
978 | A definition, which goes in the initialized data section of
|
---|
979 | the output file.
|
---|
980 |
|
---|
981 | `extern int i;'
|
---|
982 | An undefined reference, which does not allocate space. There
|
---|
983 | must be either a definition or a common symbol for the
|
---|
984 | variable somewhere.
|
---|
985 |
|
---|
986 | `int i;'
|
---|
987 | A common symbol. If there are only (one or more) common
|
---|
988 | symbols for a variable, it goes in the uninitialized data
|
---|
989 | area of the output file. The linker merges multiple common
|
---|
990 | symbols for the same variable into a single symbol. If they
|
---|
991 | are of different sizes, it picks the largest size. The
|
---|
992 | linker turns a common symbol into a declaration, if there is
|
---|
993 | a definition of the same variable.
|
---|
994 |
|
---|
995 | The `--warn-common' option can produce five kinds of warnings.
|
---|
996 | Each warning consists of a pair of lines: the first describes the
|
---|
997 | symbol just encountered, and the second describes the previous
|
---|
998 | symbol encountered with the same name. One or both of the two
|
---|
999 | symbols will be a common symbol.
|
---|
1000 |
|
---|
1001 | 1. Turning a common symbol into a reference, because there is
|
---|
1002 | already a definition for the symbol.
|
---|
1003 | FILE(SECTION): warning: common of `SYMBOL'
|
---|
1004 | overridden by definition
|
---|
1005 | FILE(SECTION): warning: defined here
|
---|
1006 |
|
---|
1007 | 2. Turning a common symbol into a reference, because a later
|
---|
1008 | definition for the symbol is encountered. This is the same
|
---|
1009 | as the previous case, except that the symbols are encountered
|
---|
1010 | in a different order.
|
---|
1011 | FILE(SECTION): warning: definition of `SYMBOL'
|
---|
1012 | overriding common
|
---|
1013 | FILE(SECTION): warning: common is here
|
---|
1014 |
|
---|
1015 | 3. Merging a common symbol with a previous same-sized common
|
---|
1016 | symbol.
|
---|
1017 | FILE(SECTION): warning: multiple common
|
---|
1018 | of `SYMBOL'
|
---|
1019 | FILE(SECTION): warning: previous common is here
|
---|
1020 |
|
---|
1021 | 4. Merging a common symbol with a previous larger common symbol.
|
---|
1022 | FILE(SECTION): warning: common of `SYMBOL'
|
---|
1023 | overridden by larger common
|
---|
1024 | FILE(SECTION): warning: larger common is here
|
---|
1025 |
|
---|
1026 | 5. Merging a common symbol with a previous smaller common
|
---|
1027 | symbol. This is the same as the previous case, except that
|
---|
1028 | the symbols are encountered in a different order.
|
---|
1029 | FILE(SECTION): warning: common of `SYMBOL'
|
---|
1030 | overriding smaller common
|
---|
1031 | FILE(SECTION): warning: smaller common is here
|
---|
1032 |
|
---|
1033 | `--warn-constructors'
|
---|
1034 | Warn if any global constructors are used. This is only useful for
|
---|
1035 | a few object file formats. For formats like COFF or ELF, the
|
---|
1036 | linker can not detect the use of global constructors.
|
---|
1037 |
|
---|
1038 | `--warn-multiple-gp'
|
---|
1039 | Warn if multiple global pointer values are required in the output
|
---|
1040 | file. This is only meaningful for certain processors, such as the
|
---|
1041 | Alpha. Specifically, some processors put large-valued constants
|
---|
1042 | in a special section. A special register (the global pointer)
|
---|
1043 | points into the middle of this section, so that constants can be
|
---|
1044 | loaded efficiently via a base-register relative addressing mode.
|
---|
1045 | Since the offset in base-register relative mode is fixed and
|
---|
1046 | relatively small (e.g., 16 bits), this limits the maximum size of
|
---|
1047 | the constant pool. Thus, in large programs, it is often necessary
|
---|
1048 | to use multiple global pointer values in order to be able to
|
---|
1049 | address all possible constants. This option causes a warning to
|
---|
1050 | be issued whenever this case occurs.
|
---|
1051 |
|
---|
1052 | `--warn-once'
|
---|
1053 | Only warn once for each undefined symbol, rather than once per
|
---|
1054 | module which refers to it.
|
---|
1055 |
|
---|
1056 | `--warn-section-align'
|
---|
1057 | Warn if the address of an output section is changed because of
|
---|
1058 | alignment. Typically, the alignment will be set by an input
|
---|
1059 | section. The address will only be changed if it not explicitly
|
---|
1060 | specified; that is, if the `SECTIONS' command does not specify a
|
---|
1061 | start address for the section (*note SECTIONS::).
|
---|
1062 |
|
---|
1063 | `--whole-archive'
|
---|
1064 | For each archive mentioned on the command line after the
|
---|
1065 | `--whole-archive' option, include every object file in the archive
|
---|
1066 | in the link, rather than searching the archive for the required
|
---|
1067 | object files. This is normally used to turn an archive file into
|
---|
1068 | a shared library, forcing every object to be included in the
|
---|
1069 | resulting shared library. This option may be used more than once.
|
---|
1070 |
|
---|
1071 | Two notes when using this option from gcc: First, gcc doesn't know
|
---|
1072 | about this option, so you have to use `-Wl,-whole-archive'.
|
---|
1073 | Second, don't forget to use `-Wl,-no-whole-archive' after your
|
---|
1074 | list of archives, because gcc will add its own list of archives to
|
---|
1075 | your link and you may not want this flag to affect those as well.
|
---|
1076 |
|
---|
1077 | `--wrap SYMBOL'
|
---|
1078 | Use a wrapper function for SYMBOL. Any undefined reference to
|
---|
1079 | SYMBOL will be resolved to `__wrap_SYMBOL'. Any undefined
|
---|
1080 | reference to `__real_SYMBOL' will be resolved to SYMBOL.
|
---|
1081 |
|
---|
1082 | This can be used to provide a wrapper for a system function. The
|
---|
1083 | wrapper function should be called `__wrap_SYMBOL'. If it wishes
|
---|
1084 | to call the system function, it should call `__real_SYMBOL'.
|
---|
1085 |
|
---|
1086 | Here is a trivial example:
|
---|
1087 |
|
---|
1088 | void *
|
---|
1089 | __wrap_malloc (int c)
|
---|
1090 | {
|
---|
1091 | printf ("malloc called with %ld\n", c);
|
---|
1092 | return __real_malloc (c);
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | If you link other code with this file using `--wrap malloc', then
|
---|
1096 | all calls to `malloc' will call the function `__wrap_malloc'
|
---|
1097 | instead. The call to `__real_malloc' in `__wrap_malloc' will call
|
---|
1098 | the real `malloc' function.
|
---|
1099 |
|
---|
1100 | You may wish to provide a `__real_malloc' function as well, so that
|
---|
1101 | links without the `--wrap' option will succeed. If you do this,
|
---|
1102 | you should not put the definition of `__real_malloc' in the same
|
---|
1103 | file as `__wrap_malloc'; if you do, the assembler may resolve the
|
---|
1104 | call before the linker has a chance to wrap it to `malloc'.
|
---|
1105 |
|
---|
1106 | `--enable-new-dtags'
|
---|
1107 | `--disable-new-dtags'
|
---|
1108 | This linker can create the new dynamic tags in ELF. But the older
|
---|
1109 | ELF systems may not understand them. If you specify
|
---|
1110 | `--enable-new-dtags', the dynamic tags will be created as needed.
|
---|
1111 | If you specify `--disable-new-dtags', no new dynamic tags will be
|
---|
1112 | created. By default, the new dynamic tags are not created. Note
|
---|
1113 | that those options are only available for ELF systems.
|
---|
1114 |
|
---|
1115 | Options Specific to i386 PE Targets
|
---|
1116 | -----------------------------------
|
---|
1117 |
|
---|
1118 | The i386 PE linker supports the `-shared' option, which causes the
|
---|
1119 | output to be a dynamically linked library (DLL) instead of a normal
|
---|
1120 | executable. You should name the output `*.dll' when you use this
|
---|
1121 | option. In addition, the linker fully supports the standard `*.def'
|
---|
1122 | files, which may be specified on the linker command line like an object
|
---|
1123 | file (in fact, it should precede archives it exports symbols from, to
|
---|
1124 | ensure that they get linked in, just like a normal object file).
|
---|
1125 |
|
---|
1126 | In addition to the options common to all targets, the i386 PE linker
|
---|
1127 | support additional command line options that are specific to the i386
|
---|
1128 | PE target. Options that take values may be separated from their values
|
---|
1129 | by either a space or an equals sign.
|
---|
1130 |
|
---|
1131 | `--add-stdcall-alias'
|
---|
1132 | If given, symbols with a stdcall suffix (@NN) will be exported
|
---|
1133 | as-is and also with the suffix stripped. [This option is specific
|
---|
1134 | to the i386 PE targeted port of the linker]
|
---|
1135 |
|
---|
1136 | `--base-file FILE'
|
---|
1137 | Use FILE as the name of a file in which to save the base addresses
|
---|
1138 | of all the relocations needed for generating DLLs with `dlltool'.
|
---|
1139 | [This is an i386 PE specific option]
|
---|
1140 |
|
---|
1141 | `--dll'
|
---|
1142 | Create a DLL instead of a regular executable. You may also use
|
---|
1143 | `-shared' or specify a `LIBRARY' in a given `.def' file. [This
|
---|
1144 | option is specific to the i386 PE targeted port of the linker]
|
---|
1145 |
|
---|
1146 | `--enable-stdcall-fixup'
|
---|
1147 | `--disable-stdcall-fixup'
|
---|
1148 | If the link finds a symbol that it cannot resolve, it will attempt
|
---|
1149 | to do "fuzzy linking" by looking for another defined symbol that
|
---|
1150 | differs only in the format of the symbol name (cdecl vs stdcall)
|
---|
1151 | and will resolve that symbol by linking to the match. For
|
---|
1152 | example, the undefined symbol `_foo' might be linked to the
|
---|
1153 | function `_foo@12', or the undefined symbol `_bar@16' might be
|
---|
1154 | linked to the function `_bar'. When the linker does this, it
|
---|
1155 | prints a warning, since it normally should have failed to link,
|
---|
1156 | but sometimes import libraries generated from third-party dlls may
|
---|
1157 | need this feature to be usable. If you specify
|
---|
1158 | `--enable-stdcall-fixup', this feature is fully enabled and
|
---|
1159 | warnings are not printed. If you specify
|
---|
1160 | `--disable-stdcall-fixup', this feature is disabled and such
|
---|
1161 | mismatches are considered to be errors. [This option is specific
|
---|
1162 | to the i386 PE targeted port of the linker]
|
---|
1163 |
|
---|
1164 | `--export-all-symbols'
|
---|
1165 | If given, all global symbols in the objects used to build a DLL
|
---|
1166 | will be exported by the DLL. Note that this is the default if
|
---|
1167 | there otherwise wouldn't be any exported symbols. When symbols are
|
---|
1168 | explicitly exported via DEF files or implicitly exported via
|
---|
1169 | function attributes, the default is to not export anything else
|
---|
1170 | unless this option is given. Note that the symbols `DllMain@12',
|
---|
1171 | `DllEntryPoint@0', `DllMainCRTStartup@12', and `impure_ptr' will
|
---|
1172 | not be automatically exported. Also, symbols imported from other
|
---|
1173 | DLLs will not be re-exported, nor will symbols specifying the
|
---|
1174 | DLL's internal layout such as those beginning with `_head_' or
|
---|
1175 | ending with `_iname'. In addition, no symbols from `libgcc',
|
---|
1176 | `libstd++', `libmingw32', or `crtX.o' will be exported. Symbols
|
---|
1177 | whose names begin with `__rtti_' or `__builtin_' will not be
|
---|
1178 | exported, to help with C++ DLLs. Finally, there is an extensive
|
---|
1179 | list of cygwin-private symbols that are not exported (obviously,
|
---|
1180 | this applies on when building DLLs for cygwin targets). These
|
---|
1181 | cygwin-excludes are: `_cygwin_dll_entry@12',
|
---|
1182 | `_cygwin_crt0_common@8', `_cygwin_noncygwin_dll_entry@12',
|
---|
1183 | `_fmode', `_impure_ptr', `cygwin_attach_dll', `cygwin_premain0',
|
---|
1184 | `cygwin_premain1', `cygwin_premain2', `cygwin_premain3', and
|
---|
1185 | `environ'. [This option is specific to the i386 PE targeted port
|
---|
1186 | of the linker]
|
---|
1187 |
|
---|
1188 | `--exclude-symbols SYMBOL,SYMBOL,...'
|
---|
1189 | Specifies a list of symbols which should not be automatically
|
---|
1190 | exported. The symbol names may be delimited by commas or colons.
|
---|
1191 | [This option is specific to the i386 PE targeted port of the
|
---|
1192 | linker]
|
---|
1193 |
|
---|
1194 | `--exclude-libs LIB,LIB,...'
|
---|
1195 | Specifies a list of archive libraries from which symbols should
|
---|
1196 | not be automatically exported. The library names may be delimited
|
---|
1197 | by commas or colons. Specifying `--exclude-libs ALL' excludes
|
---|
1198 | symbols in all archive libraries from automatic export. Symbols
|
---|
1199 | explicitly listed in a .def file are still exported, regardless of
|
---|
1200 | this option. [This option is specific to the i386 PE targeted
|
---|
1201 | port of the linker]
|
---|
1202 |
|
---|
1203 | `--file-alignment'
|
---|
1204 | Specify the file alignment. Sections in the file will always
|
---|
1205 | begin at file offsets which are multiples of this number. This
|
---|
1206 | defaults to 512. [This option is specific to the i386 PE targeted
|
---|
1207 | port of the linker]
|
---|
1208 |
|
---|
1209 | `--heap RESERVE'
|
---|
1210 | `--heap RESERVE,COMMIT'
|
---|
1211 | Specify the amount of memory to reserve (and optionally commit) to
|
---|
1212 | be used as heap for this program. The default is 1Mb reserved, 4K
|
---|
1213 | committed. [This option is specific to the i386 PE targeted port
|
---|
1214 | of the linker]
|
---|
1215 |
|
---|
1216 | `--image-base VALUE'
|
---|
1217 | Use VALUE as the base address of your program or dll. This is the
|
---|
1218 | lowest memory location that will be used when your program or dll
|
---|
1219 | is loaded. To reduce the need to relocate and improve performance
|
---|
1220 | of your dlls, each should have a unique base address and not
|
---|
1221 | overlap any other dlls. The default is 0x400000 for executables,
|
---|
1222 | and 0x10000000 for dlls. [This option is specific to the i386 PE
|
---|
1223 | targeted port of the linker]
|
---|
1224 |
|
---|
1225 | `--kill-at'
|
---|
1226 | If given, the stdcall suffixes (@NN) will be stripped from symbols
|
---|
1227 | before they are exported. [This option is specific to the i386 PE
|
---|
1228 | targeted port of the linker]
|
---|
1229 |
|
---|
1230 | `--major-image-version VALUE'
|
---|
1231 | Sets the major number of the "image version". Defaults to 1.
|
---|
1232 | [This option is specific to the i386 PE targeted port of the
|
---|
1233 | linker]
|
---|
1234 |
|
---|
1235 | `--major-os-version VALUE'
|
---|
1236 | Sets the major number of the "os version". Defaults to 4. [This
|
---|
1237 | option is specific to the i386 PE targeted port of the linker]
|
---|
1238 |
|
---|
1239 | `--major-subsystem-version VALUE'
|
---|
1240 | Sets the major number of the "subsystem version". Defaults to 4.
|
---|
1241 | [This option is specific to the i386 PE targeted port of the
|
---|
1242 | linker]
|
---|
1243 |
|
---|
1244 | `--minor-image-version VALUE'
|
---|
1245 | Sets the minor number of the "image version". Defaults to 0.
|
---|
1246 | [This option is specific to the i386 PE targeted port of the
|
---|
1247 | linker]
|
---|
1248 |
|
---|
1249 | `--minor-os-version VALUE'
|
---|
1250 | Sets the minor number of the "os version". Defaults to 0. [This
|
---|
1251 | option is specific to the i386 PE targeted port of the linker]
|
---|
1252 |
|
---|
1253 | `--minor-subsystem-version VALUE'
|
---|
1254 | Sets the minor number of the "subsystem version". Defaults to 0.
|
---|
1255 | [This option is specific to the i386 PE targeted port of the
|
---|
1256 | linker]
|
---|
1257 |
|
---|
1258 | `--output-def FILE'
|
---|
1259 | The linker will create the file FILE which will contain a DEF file
|
---|
1260 | corresponding to the DLL the linker is generating. This DEF file
|
---|
1261 | (which should be called `*.def') may be used to create an import
|
---|
1262 | library with `dlltool' or may be used as a reference to
|
---|
1263 | automatically or implicitly exported symbols. [This option is
|
---|
1264 | specific to the i386 PE targeted port of the linker]
|
---|
1265 |
|
---|
1266 | `--out-implib FILE'
|
---|
1267 | The linker will create the file FILE which will contain an import
|
---|
1268 | lib corresponding to the DLL the linker is generating. This import
|
---|
1269 | lib (which should be called `*.dll.a' or `*.a' may be used to link
|
---|
1270 | clients against the generated DLL; this behavior makes it possible
|
---|
1271 | to skip a separate `dlltool' import library creation step. [This
|
---|
1272 | option is specific to the i386 PE targeted port of the linker]
|
---|
1273 |
|
---|
1274 | `--enable-auto-image-base'
|
---|
1275 | Automatically choose the image base for DLLs, unless one is
|
---|
1276 | specified using the `--image-base' argument. By using a hash
|
---|
1277 | generated from the dllname to create unique image bases for each
|
---|
1278 | DLL, in-memory collisions and relocations which can delay program
|
---|
1279 | execution are avoided. [This option is specific to the i386 PE
|
---|
1280 | targeted port of the linker]
|
---|
1281 |
|
---|
1282 | `--disable-auto-image-base'
|
---|
1283 | Do not automatically generate a unique image base. If there is no
|
---|
1284 | user-specified image base (`--image-base') then use the platform
|
---|
1285 | default. [This option is specific to the i386 PE targeted port of
|
---|
1286 | the linker]
|
---|
1287 |
|
---|
1288 | `--dll-search-prefix STRING'
|
---|
1289 | When linking dynamically to a dll without an import library,
|
---|
1290 | search for `<string><basename>.dll' in preference to
|
---|
1291 | `lib<basename>.dll'. This behavior allows easy distinction between
|
---|
1292 | DLLs built for the various "subplatforms": native, cygwin, uwin,
|
---|
1293 | pw, etc. For instance, cygwin DLLs typically use
|
---|
1294 | `--dll-search-prefix=cyg'. [This option is specific to the i386
|
---|
1295 | PE targeted port of the linker]
|
---|
1296 |
|
---|
1297 | `--enable-auto-import'
|
---|
1298 | Do sophisticated linking of `_symbol' to `__imp__symbol' for DATA
|
---|
1299 | imports from DLLs, and create the necessary thunking symbols when
|
---|
1300 | building the import libraries with those DATA exports. This
|
---|
1301 | generally will 'just work' - but sometimes you may see this
|
---|
1302 | message:
|
---|
1303 |
|
---|
1304 | "variable '<var>' can't be auto-imported. Please read the
|
---|
1305 | documentation for ld's `--enable-auto-import' for details."
|
---|
1306 |
|
---|
1307 | This message occurs when some (sub)expression accesses an address
|
---|
1308 | ultimately given by the sum of two constants (Win32 import tables
|
---|
1309 | only allow one). Instances where this may occur include accesses
|
---|
1310 | to member fields of struct variables imported from a DLL, as well
|
---|
1311 | as using a constant index into an array variable imported from a
|
---|
1312 | DLL. Any multiword variable (arrays, structs, long long, etc) may
|
---|
1313 | trigger this error condition. However, regardless of the exact
|
---|
1314 | data type of the offending exported variable, ld will always
|
---|
1315 | detect it, issue the warning, and exit.
|
---|
1316 |
|
---|
1317 | There are several ways to address this difficulty, regardless of
|
---|
1318 | the data type of the exported variable:
|
---|
1319 |
|
---|
1320 | One way is to use -enable-runtime-pseudo-reloc switch. This leaves
|
---|
1321 | the task of adjusting references in your client code for runtime
|
---|
1322 | environment, so this method works only when runtime environtment
|
---|
1323 | supports this feature.
|
---|
1324 |
|
---|
1325 | A second solution is to force one of the 'constants' to be a
|
---|
1326 | variable - that is, unknown and un-optimizable at compile time.
|
---|
1327 | For arrays, there are two possibilities: a) make the indexee (the
|
---|
1328 | array's address) a variable, or b) make the 'constant' index a
|
---|
1329 | variable. Thus:
|
---|
1330 |
|
---|
1331 | extern type extern_array[];
|
---|
1332 | extern_array[1] -->
|
---|
1333 | { volatile type *t=extern_array; t[1] }
|
---|
1334 |
|
---|
1335 | or
|
---|
1336 |
|
---|
1337 | extern type extern_array[];
|
---|
1338 | extern_array[1] -->
|
---|
1339 | { volatile int t=1; extern_array[t] }
|
---|
1340 |
|
---|
1341 | For structs (and most other multiword data types) the only option
|
---|
1342 | is to make the struct itself (or the long long, or the ...)
|
---|
1343 | variable:
|
---|
1344 |
|
---|
1345 | extern struct s extern_struct;
|
---|
1346 | extern_struct.field -->
|
---|
1347 | { volatile struct s *t=&extern_struct; t->field }
|
---|
1348 |
|
---|
1349 | or
|
---|
1350 |
|
---|
1351 | extern long long extern_ll;
|
---|
1352 | extern_ll -->
|
---|
1353 | { volatile long long * local_ll=&extern_ll; *local_ll }
|
---|
1354 |
|
---|
1355 | A third method of dealing with this difficulty is to abandon
|
---|
1356 | 'auto-import' for the offending symbol and mark it with
|
---|
1357 | `__declspec(dllimport)'. However, in practice that requires using
|
---|
1358 | compile-time #defines to indicate whether you are building a DLL,
|
---|
1359 | building client code that will link to the DLL, or merely
|
---|
1360 | building/linking to a static library. In making the choice
|
---|
1361 | between the various methods of resolving the 'direct address with
|
---|
1362 | constant offset' problem, you should consider typical real-world
|
---|
1363 | usage:
|
---|
1364 |
|
---|
1365 | Original:
|
---|
1366 | --foo.h
|
---|
1367 | extern int arr[];
|
---|
1368 | --foo.c
|
---|
1369 | #include "foo.h"
|
---|
1370 | void main(int argc, char **argv){
|
---|
1371 | printf("%d\n",arr[1]);
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | Solution 1:
|
---|
1375 | --foo.h
|
---|
1376 | extern int arr[];
|
---|
1377 | --foo.c
|
---|
1378 | #include "foo.h"
|
---|
1379 | void main(int argc, char **argv){
|
---|
1380 | /* This workaround is for win32 and cygwin; do not "optimize" */
|
---|
1381 | volatile int *parr = arr;
|
---|
1382 | printf("%d\n",parr[1]);
|
---|
1383 | }
|
---|
1384 |
|
---|
1385 | Solution 2:
|
---|
1386 | --foo.h
|
---|
1387 | /* Note: auto-export is assumed (no __declspec(dllexport)) */
|
---|
1388 | #if (defined(_WIN32) || defined(__CYGWIN__)) && \
|
---|
1389 | !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC))
|
---|
1390 | #define FOO_IMPORT __declspec(dllimport)
|
---|
1391 | #else
|
---|
1392 | #define FOO_IMPORT
|
---|
1393 | #endif
|
---|
1394 | extern FOO_IMPORT int arr[];
|
---|
1395 | --foo.c
|
---|
1396 | #include "foo.h"
|
---|
1397 | void main(int argc, char **argv){
|
---|
1398 | printf("%d\n",arr[1]);
|
---|
1399 | }
|
---|
1400 |
|
---|
1401 | A fourth way to avoid this problem is to re-code your library to
|
---|
1402 | use a functional interface rather than a data interface for the
|
---|
1403 | offending variables (e.g. set_foo() and get_foo() accessor
|
---|
1404 | functions). [This option is specific to the i386 PE targeted port
|
---|
1405 | of the linker]
|
---|
1406 |
|
---|
1407 | `--disable-auto-import'
|
---|
1408 | Do not attempt to do sophisticalted linking of `_symbol' to
|
---|
1409 | `__imp__symbol' for DATA imports from DLLs. [This option is
|
---|
1410 | specific to the i386 PE targeted port of the linker]
|
---|
1411 |
|
---|
1412 | `--enable-runtime-pseudo-reloc'
|
---|
1413 | If your code contains expressions described in -enable-auto-import
|
---|
1414 | section, that is, DATA imports from DLL with non-zero offset, this
|
---|
1415 | switch will create a vector of 'runtime pseudo relocations' which
|
---|
1416 | can be used by runtime environment to adjust references to such
|
---|
1417 | data in your client code. [This option is specific to the i386 PE
|
---|
1418 | targeted port of the linker]
|
---|
1419 |
|
---|
1420 | `--disable-runtime-pseudo-reloc'
|
---|
1421 | Do not create pseudo relocations for non-zero offset DATA imports
|
---|
1422 | from DLLs. This is the default. [This option is specific to the
|
---|
1423 | i386 PE targeted port of the linker]
|
---|
1424 |
|
---|
1425 | `--enable-extra-pe-debug'
|
---|
1426 | Show additional debug info related to auto-import symbol thunking.
|
---|
1427 | [This option is specific to the i386 PE targeted port of the
|
---|
1428 | linker]
|
---|
1429 |
|
---|
1430 | `--section-alignment'
|
---|
1431 | Sets the section alignment. Sections in memory will always begin
|
---|
1432 | at addresses which are a multiple of this number. Defaults to
|
---|
1433 | 0x1000. [This option is specific to the i386 PE targeted port of
|
---|
1434 | the linker]
|
---|
1435 |
|
---|
1436 | `--stack RESERVE'
|
---|
1437 | `--stack RESERVE,COMMIT'
|
---|
1438 | Specify the amount of memory to reserve (and optionally commit) to
|
---|
1439 | be used as stack for this program. The default is 2Mb reserved, 4K
|
---|
1440 | committed. [This option is specific to the i386 PE targeted port
|
---|
1441 | of the linker]
|
---|
1442 |
|
---|
1443 | `--subsystem WHICH'
|
---|
1444 | `--subsystem WHICH:MAJOR'
|
---|
1445 | `--subsystem WHICH:MAJOR.MINOR'
|
---|
1446 | Specifies the subsystem under which your program will execute. The
|
---|
1447 | legal values for WHICH are `native', `windows', `console', and
|
---|
1448 | `posix'. You may optionally set the subsystem version also.
|
---|
1449 | [This option is specific to the i386 PE targeted port of the
|
---|
1450 | linker]
|
---|
1451 |
|
---|