Click on any of the 687 commands below to get a description and list of available options. All links in the command summaries point to the online version of the book on Safari Bookshelf.
Combine several objfiles, in the specified order, into a single executable object module (a.out by default). ld is the link editor and is often invoked automatically by compiler commands. ld accepts many options, the most common of which are listed here.
Options
-bformat, --format=format
If ld is configured to accept more than one kind of object file, this option can be used to specify the input format. format should be a GNU Binary File Descriptor (BFD), as described in the BFD library. Use objdump -i to list available formats.
-call_shared
Link with dynamic libraries.
-d, -dc, -dp
Force the assignment of space to common symbols.
-defsymsymbol=expression
Create the global symbol with the value expression.
-demangle[=style]
Force demangling of symbol names. Optionally set the demangling style. Turn off demangling with -nodemangle.
-esymbol
Set symbol as the address of the output file's entry point.
-fname
Set the DT_AUXILIARY field of ELF shared object to name.
-fininame
Set the DT_FINI field of ELF shared object to the address of function name. The default function is _fini.
-hname
Set the DT_SONAME field of ELF shared object to name.
--help
Print help message, then exit.
-i
Produce a linkable output file; attempt to set its magic number to OMAGIC.
-initname
Set the DT_INIT field of ELF shared object to the address of function name. The default function is _init.
-larch, --library=archive
Include the archive file arch in the list of files to link.
-mlinker
Emulate linker. List supported emulations with the -V option.
-n
Make text read-only; attempt to set NMAGIC.
-ooutput
Place output in output, instead of in a.out.
-oformatformat
Specify output format.
-q
Retain relocation sections and contents in linked executables.
-r
Produce a linkable output file; attempt to set its magic number to OMAGIC.
-rpathdir
Add directory dir to the runtime library search path. Ignore additional paths normally read from the LD_RUN_PATH environment variable.
-rpath-linkdirs
Specify path to search for shared libraries required by another shared library. The dirs argument can be a single directory, or multiple directories separated by colons. This overrides search paths specified in shared libraries themselves.
-s
Do not include any symbol information in output.
-shared
Create a shared library.
-static
Do not link with shared libraries.
-sort-common
Do not sort global common symbols by size.
-t
Print each input file's name as it is processed.
--target-help
Print target-specific options, then exit.
-usymbol
Force symbol to be undefined.
-v, --version
Show version number.
--verbose
Print information about ld; print the names of input files while attempting to open them.
-warn-common
Warn when encountering common symbols combined with other constructs.
-warn-once
Provide only one warning per undefined symbol.
-x
With -s or -S, delete all local symbols. These generally begin with L.
-zkeyword
Mark the object for special behavior specified by keyword. ld recognizes the following keywords:
combreloc
Object combines and sorts multiple relocation sections for dynamic symbol lookup caching.
defs
Disallow undefined symbols.
initfirst
Initialize object first at runtime.
interpose
Interpose object's symbol table before all but the primary executable's symbol table.
loadfltr
Process object's filter immediately at runtime.
multidefs
Allow multiple definitions of a single symbol. Use the first definition.
nocombreloc
Disable combining multiple relocation sections.
nocopyreloc
Disable copy relocation.
nodefaultlib
Ignore default library search path when seeking dependencies for object.
nodelete
Do not unload object at runtime.
nodlopen
Object is not available to dlopen.
nodump
Object cannot be dumped by dldump.
now
Non-lazy runtime binding.
origin
Object may contain $ORIGIN.
-E, --export-dynamic
Add all symbols to dynamic symbol table, not just those referenced by linked objects.
-EB
Link big-endian objects.
-EL
Link little-endian objects.
-Fname
Set DT_FILTER field of ELF shared object to name.
-Ldir, --library-path=dir
Search directory dir before standard search directories (this option must precede the -l option that searches that directory).
-M
Display a link map on standard output.
-Mapfile
Print a link map to file.
-N
Allow reading of and writing to both data and text. Mark ouput if it supports Unix magic numbers. Do not page-align data.
-Olevel
Optimize. level should be 1, 2, 3, or 0. The default is 1. 0 turns off optimization; 3 optimizes the most.
-Rfile
Obtain symbol names and addresses from file, but suppress relocation of file and its inclusion in output.
-S
Do not include debugger symbol information in output.
-Tfile
Execute script file instead of the default linker script.
-Tbssaddress
Begin bss segment of output at address.
-Tdataaddress
Begin data segment of output at address.
-Ttextaddress
Begin text segment of output at address.
-Ur
Synonymous with -r except when linking C++ programs, where it resolves constructor references.
-X
With -s or -S, delete local symbols beginning with L.
-V
Show version number and emulation linkers for -m option.