📄 options.html
字号:
<br><dt><code>--no-whole-archive</code>
<dd>Turn off the effect of the <code>--whole-archive</code> option for subsequent
archive files.
<br><dt><code>--noinhibit-exec</code>
<dd>Retain the executable output file whenever it is still usable.
Normally, the linker will not produce an output file if it encounters
errors during the link process; it exits without writing an output file
when it issues any error whatsoever.
<br><dt><code>-nostdlib</code>
<dd>Only search library directories explicitly specified on the
command line. Library directories specified in linker scripts
(including linker scripts specified on the command line) are ignored.
<br><dt><code>--oformat </code><var>output-format</var><code></code>
<dd><code>ld</code> may be configured to support more than one kind of object
file. If your <code>ld</code> is configured this way, you can use the
<code>--oformat</code> option to specify the binary format for the output
object file. Even when <code>ld</code> is configured to support alternative
object formats, you don't usually need to specify this, as <code>ld</code>
should be configured to produce as a default output format the most
usual format on each machine. <var>output-format</var> is a text string, the
name of a particular format supported by the BFD libraries. (You can
list the available binary formats with <code>objdump -i</code>.) The script
command <code>OUTPUT_FORMAT</code> can also specify the output format, but
this option overrides it. See <a href="BFD.html#BFD">BFD</a>.
<br><dt><code>-qmagic</code>
<dd>This option is ignored for Linux compatibility.
<br><dt><code>-Qy</code>
<dd>This option is ignored for SVR4 compatibility.
<br><dt><code>--relax</code>
<dd>An option with machine dependent effects.
This option is only supported on a few targets.
See <a href="H8-300.html#H8%2f300"><code>ld</code> and the H8/300</a>.
See <a href="i960.html#i960"><code>ld</code> and the Intel 960 family</a>.
<p>On some platforms, the <code>--relax</code> option performs global
optimizations that become possible when the linker resolves addressing
in the program, such as relaxing address modes and synthesizing new
instructions in the output object file.
<p>On some platforms these link time global optimizations may make symbolic
debugging of the resulting executable impossible.
This is known to be
the case for the Matsushita MN10200 and MN10300 family of processors.
<p>On platforms where this is not supported, <code>--relax</code> is accepted,
but ignored.
<br><dt><code>--retain-symbols-file </code><var>filename</var><code></code>
<dd>Retain <em>only</em> the symbols listed in the file <var>filename</var>,
discarding all others. <var>filename</var> is simply a flat file, with one
symbol name per line. This option is especially useful in environments
(such as VxWorks)
where a large global symbol table is accumulated gradually, to conserve
run-time memory.
<p><code>--retain-symbols-file</code> does <em>not</em> discard undefined symbols,
or symbols needed for relocations.
<p>You may only specify <code>--retain-symbols-file</code> once in the command
line. It overrides <code>-s</code> and <code>-S</code>.
<br><dt><code>-rpath </code><var>dir</var><code></code>
<dd>Add a directory to the runtime library search path. This is used when
linking an ELF executable with shared objects. All <code>-rpath</code>
arguments are concatenated and passed to the runtime linker, which uses
them to locate shared objects at runtime. The <code>-rpath</code> option is
also used when locating shared objects which are needed by shared
objects explicitly included in the link; see the description of the
<code>-rpath-link</code> option. If <code>-rpath</code> is not used when linking an
ELF executable, the contents of the environment variable
<code>LD_RUN_PATH</code> will be used if it is defined.
<p>The <code>-rpath</code> option may also be used on SunOS. By default, on
SunOS, the linker will form a runtime search patch out of all the
<code>-L</code> options it is given. If a <code>-rpath</code> option is used, the
runtime search path will be formed exclusively using the <code>-rpath</code>
options, ignoring the <code>-L</code> options. This can be useful when using
gcc, which adds many <code>-L</code> options which may be on NFS mounted
filesystems.
<p>For compatibility with other ELF linkers, if the <code>-R</code> option is
followed by a directory name, rather than a file name, it is treated as
the <code>-rpath</code> option.
<br><dt><code>-rpath-link </code><var>DIR</var><code></code>
<dd>When using ELF or SunOS, one shared library may require another. This
happens when an <code>ld -shared</code> link includes a shared library as one
of the input files.
<p>When the linker encounters such a dependency when doing a non-shared,
non-relocatable link, it will automatically try to locate the required
shared library and include it in the link, if it is not included
explicitly. In such a case, the <code>-rpath-link</code> option
specifies the first set of directories to search. The
<code>-rpath-link</code> option may specify a sequence of directory names
either by specifying a list of names separated by colons, or by
appearing multiple times.
<p>This option should be used with caution as it overrides the search path
that may have been hard compiled into a shared library. In such a case it
is possible to use unintentionally a different search path than the
runtime linker would do.
<p>The linker uses the following search paths to locate required shared
libraries.
<ol type=1 start=1>
<li>Any directories specified by <code>-rpath-link</code> options.
<li>Any directories specified by <code>-rpath</code> options. The difference
between <code>-rpath</code> and <code>-rpath-link</code> is that directories
specified by <code>-rpath</code> options are included in the executable and
used at runtime, whereas the <code>-rpath-link</code> option is only effective
at link time. It is for the native linker only.
<li>On an ELF system, if the <code>-rpath</code> and <code>rpath-link</code> options
were not used, search the contents of the environment variable
<code>LD_RUN_PATH</code>. It is for the native linker only.
<li>On SunOS, if the <code>-rpath</code> option was not used, search any
directories specified using <code>-L</code> options.
<li>For a native linker, the contents of the environment variable
<code>LD_LIBRARY_PATH</code>.
<li>For a native ELF linker, the directories in <code>DT_RUNPATH</code> or
<code>DT_RPATH</code> of a shared library are searched for shared
libraries needed by it. The <code>DT_RPATH</code> entries are ignored if
<code>DT_RUNPATH</code> entries exist.
<li>The default directories, normally <code>/lib</code> and <code>/usr/lib</code>.
<li>For a native linker on an ELF system, if the file <code>/etc/ld.so.conf</code>
exists, the list of directories found in that file.
</ol>
<p>If the required shared library is not found, the linker will issue a
warning and continue with the link.
<br><dt><code>-shared</code>
<dd><dt><code>-Bshareable</code>
<dd>Create a shared library. This is currently only supported on ELF, XCOFF
and SunOS platforms. On SunOS, the linker will automatically create a
shared library if the <code>-e</code> option is not used and there are
undefined symbols in the link.
<br><dt><code>--sort-common</code>
<dd>This option tells <code>ld</code> to sort the common symbols by size when it
places them in the appropriate output sections. First come all the one
byte symbols, then all the two byte, then all the four byte, and then
everything else. This is to prevent gaps between symbols due to
alignment constraints.
<br><dt><code>--split-by-file [</code><var>size</var><code>]</code>
<dd>Similar to <code>--split-by-reloc</code> but creates a new output section for
each input file when <var>size</var> is reached. <var>size</var> defaults to a
size of 1 if not given.
<br><dt><code>--split-by-reloc [</code><var>count</var><code>]</code>
<dd>Tries to creates extra sections in the output file so that no single
output section in the file contains more than <var>count</var> relocations.
This is useful when generating huge relocatable files for downloading into
certain real time kernels with the COFF object file format; since COFF
cannot represent more than 65535 relocations in a single section. Note
that this will fail to work with object file formats which do not
support arbitrary sections. The linker will not split up individual
input sections for redistribution, so if a single input section contains
more than <var>count</var> relocations one output section will contain that
many relocations. <var>count</var> defaults to a value of 32768.
<br><dt><code>--stats</code>
<dd>Compute and display statistics about the operation of the linker, such
as execution time and memory usage.
<br><dt><code>--traditional-format</code>
<dd>For some targets, the output of <code>ld</code> is different in some ways from
the output of some existing linker. This switch requests <code>ld</code> to
use the traditional format instead.
<p>For example, on SunOS, <code>ld</code> combines duplicate entries in the
symbol string table. This can reduce the size of an output file with
full debugging information by over 30 percent. Unfortunately, the SunOS
<code>dbx</code> program can not read the resulting program (<code>gdb</code> has no
trouble). The <code>--traditional-format</code> switch tells <code>ld</code> to not
combine duplicate entries.
<br><dt><code>--section-start </code><var>sectionname</var><code>=</code><var>org</var><code></code>
<dd>Locate a section in the output file at the absolute
address given by <var>org</var>. You may use this option as many
times as necessary to locate multiple sections in the command
line.
<var>org</var> must be a single hexadecimal integer;
for compatibility with other linkers, you may omit the leading
<code>0x</code> usually associated with hexadecimal values. <em>Note:</em> there
should be no white space between <var>sectionname</var>, the equals
sign ("<=>"), and <var>org</var>.
<br><dt><code>-Tbss </code><var>org</var><code></code>
<dd><dt><code>-Tdata </code><var>org</var><code></code>
<dd><dt><code>-Ttext </code><var>org</var><code></code>
<dd>Use <var>org</var> as the starting address for--respectively--the
<code>bss</code>, <code>data</code>, or the <code>text</code> segment of the output file.
<var>org</var> must be a single hexadecimal integer;
for compatibility with other linkers, you may omit the leading
<code>0x</code> usually associated with hexadecimal values.
<br><dt><code>--dll-verbose</code>
<dd><dt><code>--verbose</code>
<dd>Display the version number for <code>ld</code> and list the linker emulations
supported. Display which input files can and cannot be opened. Display
the linker script being used by the linker.
<dt><code>--version-script=</code><var>version-scriptfile</var><code></code>
<dd>Specify the name of a version script to the linker. This is typically
used when creating shared libraries to specify additional information
about the version heirarchy for the library being created. This option
is only meaningful on ELF platforms which support shared libraries.
See <a href="VERSION.html#VERSION">VERSION</a>.
<br><dt><code>--warn-common</code>
<dd>Warn when a common symbol is combined with another common symbol or with
a symbol definition. Unix linkers allow this somewhat sloppy practice,
but linkers on some other operating systems do not. This option allows
you to find potential problems from combining global symbols.
Unfortunately, some C libraries use this practice, so you may get some
warnings about symbols in the libraries as well as in your programs.
<p>There are three kinds of global symbols, illustrated here by C examples:
<dl>
<dt><code>int i = 1;</code>
<dd>A definition, which goes in the initialized data section of the output
file.
<br><dt><code>extern int i;</code>
<dd>An undefined reference, which does not allocate space.
There must be either a definition or a common symbol for the
variable somewhere.
<br><dt><code>int i;</code>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -