LD.LLD(1) | General Commands Manual | LD.LLD(1) |
ld.lld
— ELF
linker from the LLVM project
ld.lld |
[options] objfile ... |
A linker takes one or more object, archive, and library files, and combines them into an output file (an executable, a shared library, or another object file). It relocates code and data from the input files and resolves symbol references between them.
ld.lld
is a drop-in replacement for the
GNU BFD and gold linkers. It accepts most of the same command line arguments
and linker scripts as GNU linkers.
ld.lld
currently supports i386, x86-64,
ARM, AArch64, PowerPC32, PowerPC64, MIPS32, MIPS64, RISC-V, AMDGPU, Hexagon
and SPARC V9 targets. ld.lld
acts as a Microsoft
link.exe-compatible linker if invoked as lld-link
and as macOS's ld if invoked as ld.ld64.
All these
targets are always supported however ld.lld
was
built, so you can always use ld.lld
as a native
linker as well as a cross linker.
Many options have both a single-letter and long form. When using
the long form options other than those beginning with the letter
o
may be specified using either one or two dashes
preceding the option name. Long options beginning with
o
require two dashes to avoid confusion with the
-o
path option.
--allow-multiple-definition
--allow-shlib-undefined
--apply-dynamic-relocs
--as-needed
DT_NEEDED
for shared libraries if
used.--auxiliary
=valueDT_AUXILIARY
field to the specified
name.--Bdynamic
,
--dy
--Bstatic
,
--static
, --dn
-Bno-symbolic
-shared
(default).-Bsymbolic
-shared.
Also set the
DF_SYMBOLIC
flag.-Bsymbolic-functions
-shared.
-Bsymbolic-non-weak-functions
-shared.
--build-id
=valuefast
, md5
,
sha1
, tree
,
uuid
,
0x
hex-string, and
none
. tree
is an alias for
sha1
. Build-IDs of type
fast
, md5
,
sha1
, and tree
are
calculated from the object contents. fast
is not
intended to be cryptographically secure.--build-id
--build-id
=fast
.--color-diagnostics
=valuealways
, auto
, and
never
. auto
enables color
if and only if output is to a terminal.--color-diagnostics
--color-diagnostics
=auto
.--compress-debug-sections
=valuenone
or zlib
. The default
compression level is 1 (fastest) as the debug info usually compresses well
at that level, but if you want to compress it more, you can specify
-O2
to set the compression level to 6.--cref
-Map
is
specified, print to the map file.--defsym
=symbol=expression--defsym=foo=bar
’ or
‘--defsym=foo=bar+0x100
’.--demangle
--discard-all
,
-x
--discard-locals
,
-X
--discard-none
--dynamic-linker
=valuePT_INTERP
.--dynamic-list
=file--export-dynamic-symbol-list
. When
creating a shared object, implies -Bsymbolic
but
does not set DF_SYMBOLIC--EB
--EL
--eh-frame-hdr
.eh_frame_hdr
section and
PT_GNU_EH_FRAME
segment header.--emit-relocs
,
-q
--end-lib
--entry
=entry--error-limit
=value--error-unresolved-symbols
--error-handing-script
=script_pathmissing-lib
followed by the name of the missing
library. undefined-symbol
followed by the name of
the undefined symbol.--execute-only
--exclude-libs
=value--export-dynamic
,
-E
--export-dynamic-symbol
=glob-Bsymbolic
,
-Bsymbolic-functions
or
--dynamic-list
--export-dynamic-symbol-list
=file--export-dynamic-symbol
on each
pattern.--fatal-warnings
--filter
=value,
-F
valueDT_FILTER
field to the specified
value.--fini
=symbol--format
=input-format,
-b
input-formatbinary
, elf
, and
default
. default
is a
synonym for elf
.--gc-sections
--gdb-index
.gdb_index
section.--hash-style
=valuesysv
, gnu
, or
both
. both
is the
default.--help
--icf
=all
--icf
=safe
--icf
=none
--ignore-data-address-equality
--ignore-function-address-equality
--image-base
=value--init
=symbol--keep-unique
=symbol-l
libName,
--library
=libName-L
dir,
--library-path
=dir--lto-aa-pipeline
=value--lto-newpm-passes
.--lto-newpm-passes
=value--lto-O
opt-level--lto-partitions
=value-m
value--Map
=file,
-M
file--nmagic
,
-n
--no-allow-shlib-undefined
--no-as-needed
DT_NEEDED
for shared libraries.--no-color-diagnostics
--no-demangle
--no-dynamic-linker
.interp
section.--no-fortran-common
--no-gc-sections
--no-gnu-unique
--no-merge-exidx-entries
--no-nmagic
--no-omagic
--no-relax
--no-rosegment
--no-undefined-version
--no-undefined
--no-warn-symbol-ordering
--no-whole-archive
--no-pie
,
--no-pic-executable
--noinhibit-exec
--nostdlib
-o
patha.out
is used as a default.-O
value0
1
2
--compress-debug-sections
is given, compress
debug sections at compression level 6 instead of 1.-O
1
is the
default.
--oformat
=formatbinary
, which
produces output with no ELF header.--omagic
,
-N
--opt-remarks-filename
file--opt-remarks-passes
pass-regex--opt-remarks-with-hotness
--orphan-handling
=modeplace
warn
place
and also
report a warning.error
place
and also
report an error.place
is the default.
--pack-dyn-relocs
=formatnone
android
relr
android+relr
none
is the default. If
--use-android-relr-tags
is specified, use
SHT_ANDROID_RELR instead of SHT_RELR.
--pic-veneer
--pie
,
--pic-executable
--power10-stubs
=mode
--print-gc-sections
--print-icf-sections
--print-map
--print-archive-stats
=file--push-state
--as-needed
,
--static
, and
--whole-archive.
--pop-state
--push-state.
--relocatable
,
-r
--reproduce
=path--retain-symbols-file
=file--rpath
=value,
-R
valueDT_RUNPATH
to the output.--rsp-quoting
=valuewindows
and posix
.--script
=file,
-T
file--section-start
=section=address--shuffle-sections
=seed--soname
=value,
-h
valueDT_SONAME
to value.--sort-common
--sort-section
=value--start-lib
--strip-all
,
-s
--strip-debug
.--strip-debug
,
-S
--symbol-ordering-file
=file--sysroot
=value--target1-abs
R_ARM_TARGET1
as
R_ARM_ABS32
.--target1-rel
R_ARM_TARGET1
as
R_ARM_REL32
.--target2
=typeR_ARM_TARGET2
as
type, where type is one of
rel
, abs
, or
got-rel
.--Tbss
=value--section-start
with
.bss
as the sectionname.--Tdata
=value--section-start
with
.data
as the sectionname.--Ttext
=value--section-start
with
.text
as the sectionname.--thinlto-cache-dir
=value--thinlto-cache-policy
=value--thinlto-jobs
=value--threads
=Nall
(default) means all of
concurrent threads supported. 1
disables
multi-threading.--time-trace
--time-trace-file
=file--time-trace-granularity
=value--trace
--trace-symbol
=symbol,
-y
symbol--undefined
=symbol,
-u
symbol--undefined-glob
=pattern--undefined
, except that it takes a
glob pattern. In a glob pattern, *
matches zero or
more characters, ? matches any single character, and
[...]
matches the characters within brackets. All
symbols that match a given pattern are handled as if they were given as
arguments of --undefined
.--unique
--unresolved-symbols
=value-v
-V
,
--version
--verbose
--version-script
=file--warn-backrefs
--warn-backrefs-exclude
=glob--warn-backrefs
--warn-common
--warn-ifunc-textrel
--warn-unresolved-symbols
--whole-archive
--why-extract
=file--wrap
=symbol-z
optiondead-reloc-in-nonalloc
=section_glob=valueexecstack
PT_GNU_STACK
segment.
bti-report
=[none|warning|error]none
is the default, linker will not
report the missing property otherwise will be reported as a warning or
an error.
cet-report
=[none|warning|error]none
is the default, linker will not report
the missing property otherwise will be reported as a warning or an
error.
force-bti
force-ibt
global
DF_1_GLOBAL flag in the
DYNAMIC
section. Different loaders can decide
how to handle this flag on their own.
ifunc-noplt
-z
notext
option.
initfirst
DF_1_INITFIRST
flag to indicate the
module should be initialized first.
interpose
DF_1_INTERPOSE
flag to indicate to the
runtime linker that the object is an interposer. During symbol
resolution interposers are searched after the application but before
other dependencies.
muldefs
--allow-multiple-definition.
nocombreloc
nocopyreloc
nodefaultlib
DF_1_NODEFLIB
flag to indicate that
default library search paths should be ignored.
nodelete
DF_1_NODELETE
flag to indicate that
the object cannot be unloaded from a process.
nodlopen
DF_1_NOOPEN
flag to indicate that the
object may not be opened by dlopen(3).
nognustack
PT_GNU_STACK
segment.
norelro
PT_GNU_RELRO
segment.
notext
DT_TEXTREL flag in the
DYNAMIC
section.
now
DF_BIND_NOW
flag to indicate that the
run-time loader should perform all relocation processing as part of
object initialization. By default relocations may be performed on
demand.
origin
DF_ORIGIN
flag to indicate that the
object requires $ORIGIN processing.
pac-plt
pack-relative-relocs
-pack-dyn-relocs=relr
, but
synthesizes the GLIBC_ABI_DT_RELR version dependency if there is a
GLIBC_2.* version dependency. glibc ld.so rejects loading a
dynamically linked object without the GLIBC_ABI_DT_RELR version
dependency.
rel
rela
retpolineplt
rodynamic
.dynamic
section read-only. The
DT_DEBUG
tag will not be emitted.
separate-loadable-segments
separate-code
noseparate-code
noseparate-code
(default) allows
overlap. separate-code
allows overlap between
two executable segments, or two non-executable segments.
separate-loadable-segments
disallows overlap.
shstk
stack-size
=sizePT_GNU_STACK
program segment.
start-stop-gc
nostart-stop-gc
text
wxneeded
PT_OPENBSD_WXNEEDED
segment.ld.lld
's handing of archive files (those
with a .a file extension) is different from
traditional linkers used on Unix-like systems.
Traditional linkers maintain a set of undefined symbols during linking. The linker processes each file in the order in which it appears on the command line, until the set of undefined symbols becomes empty. An object file is linked into the output object when it is encountered, with its undefined symbols added to the set. Upon encountering an archive file a traditional linker searches the objects contained therein, and processes those that satisfy symbols in the unresolved set.
Handling mutually dependent archives may be awkward when using a
traditional linker. Archive files may have to be specified multiple times,
or the special command line options --start-group
and --end-group
may be used to have the linker loop
over the files in the group until no new symbols are added to the set.
ld.lld
records all symbols found in
objects and archives as it iterates over command line arguments. When
ld.lld
encounters an undefined symbol that can be
resolved by an object file contained in a previously processed archive file,
it immediately extracts and links it into the output object.
With certain archive inputs ld.lld
may
produce different results compared to traditional linkers. In practice,
large bodies of third party software have been linked with
ld.lld
without material issues.
The --warn-backrefs
option may be used to
identify a linker invocation that may be incompatible with traditional
Unix-like linker behavior.
May 12, 2019 | Debian |