LD(1) — UNIX Programmer’s Manual
NAME
ld − link editor
SYNOPSIS
ld [ option ] ... file ...
DESCRIPTION
Ld combines several object programs into one program, resolves external references, and searches libraries. In the simplest case, several object files are given, and ld combines them, producing an object module which can be either executed or become the input for a further ld run. (In the latter case, the −r option must be given to preserve the relocation bits.) The output of ld is left on a.out. This file is executable only if no errors occurred during the load.
The argument routines are concatenated in the order specified. The entry point of the output is the beginning of the first routine (unless the −e option is specified).
If any argument is a library, it is searched once at the point where it is encountered in the argument list. Only those routines defining an unresolved external reference are loaded. If a routine from a library references another routine in the library, and the library has not been processed by ranlib(1), the referenced routine must appear after the referencing routine in the library. Therefore, the order of programs within libraries may be important. The first member of a library should be a file named ‘__.SYMDEF’, which is understood to be a dictionary for the library as produced by ranlib(1); the dictionary is searched iteratively to satisfy as many references as possible.
The symbols ‘_etext’, ‘_edata’ and ‘_end’ (‘etext’, ‘edata’ and ‘end’ in C) are reserved, and if referred to, are set to the first location above the program, the first location above initialized data, and the first location above all data, respectively. It is erroneous to define these symbols.
Ld understands the following options. Except for −l, these options should appear before the file names.
−B Sets origin of common/bss segment.
−D Take the next argument as a hexadecimal number and pad the data segment with zero bytes to the indicated length.
−d Force definition of common storage, even if the −r flag is present.
−e The following argument is assumed to be the name of the entry point of the loaded program; location 0 is the default.
−L List symbols on list.out
−lx This option is an abbreviation for the library name ‘/lib/libx.a’, where x is a string. If this library name does not exist, ld tries ‘/usr/lib/libx.a’ A library is searched when its name is encountered; therefore, the placement of a −l is significant.
−n Arrange (by giving the output file a 0410 "magic number") that when the output file is executed, the text portion is read-only and shared among all users executing the file. This procedure involves moving the data areas up to the first possible 1024 byte boundary following the end of the text.
−o The name argument after −o is used as the name of the ld output file, instead of a.out.
−r Generate relocation bits in the output file so it can be the subject of another ld run. This flag also prevents final definitions from being given to common symbols, and suppresses the ‘undefined symbol’ diagnostics.
−S ‘Strip’ the output by removing all symbols except locals and globals.
−s ‘Strip’ the output; specifically, remove the symbol table and relocation bits to save space (but impair the usefulness of the debuggers). This information can also be removed by strip(1).
−T The next argument is a hexadecimal number which sets the text segment origin. The default origin is 0.
−u Take the following argument as a symbol and enter it as undefined in the symbol table. This procedure is useful for loading wholly from a library, since initially the symbol table is empty and an unresolved reference is needed to force the loading of the first routine.
−v Indicates what version. The default is 1.
−X Save local symbols, except those with names which begin with ‘L’. This option is used by cc(1) to discard internally-generated labels while retaining symbols local to routines.
−x Do not preserve local (non-.globl) symbols in the output symbol table; only enter external symbols. This option saves some space in the output file.
−ysym
Indicate each file in which sym appears, the file type and whether the file defines or references sym. Many such options may be given to trace numerous symbols. (It is usually necessary to begin sym with an ‘_’, as external C, FORTRAN and Pascal variables begin with underscores.)
−z Arrange for the process to be loaded on demand from the resulting executable file (413 format), rather than preloaded. This is the default. This procedure results in a 1024 byte header on the output file, followed by a text and data segment, each of which have size a multiple of 1024 bytes (padded out with nulls in the file, if necessary). With this format, the first few BSS segment symbols may actually appear (from the output of size(2)) to live in the data segment; this to avoid the space resulting from data segment size roundup.
FILES
/lib/lib\(**.alibraries
a.outoutput file
b.out
SEE ALSO
as(1), ar(1), cc(1), ranlib(1)
BUGS
There is no way to force data to be page aligned.
4th Berkeley Distribution — %W%%Q%%Y%