1LD(1)                       General Commands Manual                      LD(1)
2
3
4

NAME

6       ld - loader
7

SYNOPSIS

9       ld [ option ] file ...
10

DESCRIPTION

12       Ld  combines several object programs into one, resolves external refer‐
13       ences, and searches libraries.  In the  simplest  case  several  object
14       files are given, and ld combines them, producing an object module which
15       can be either executed or become the input for a further ld  run.   (In
16       the latter case, the -r option must be given to preserve the relocation
17       bits.)  The output of ld is left on a.out.   This  file  is  made  exe‐
18       cutable only if no errors occurred during the load.
19
20       The  argument  routines  are  concatenated in the order specified.  The
21       entry point of the output is the beginning of the first routine.
22
23       If any argument is a library, it is searched exactly once at the  point
24       it  is  encountered in the argument list.  Only those routines defining
25       an unresolved external reference are  loaded.   If  a  routine  from  a
26       library  references another routine in the library, and the library has
27       not been processed by ranlib(1), the  referenced  routine  must  appear
28       after  the  referencing routine in the library.  Thus the order of pro‐
29       grams within libraries may be important.  If  the  first  member  of  a
30       library  is named `__.SYMDEF', then it is understood to be a dictionary
31       for the library such as produced by ranlib; the dictionary is  searched
32       iteratively to satisfy as many references as possible.
33
34       The  symbols  `_etext', `_edata' and `_end' (`etext', `edata' and `end'
35       in C) are reserved, and if referred to, are set to the  first  location
36       above  the  program, the first location above initialized data, and the
37       first location above all data respectively.  It is erroneous to  define
38       these symbols.
39
40       Ld  understands  several  options.   Except  for -l, they should appear
41       before the file names.
42
43       -s     `Strip' the output, that is, remove the symbol table and reloca‐
44              tion bits to save space (but impair the usefulness of the debug‐
45              ger).  This information can also be removed by strip(1).
46
47       -u     Take the following argument as a symbol and enter  it  as  unde‐
48              fined  in  the  symbol table.  This is useful for loading wholly
49              from a library, since initially the symbol table is empty and an
50              unresolved reference is needed to force the loading of the first
51              routine.
52
53       -lx    This  option  is  an   abbreviation   for   the   library   name
54              `/lib/libx.a',  where x is a string.  If that does not exist, ld
55              tries `/usr/lib/libx.a'.  A library is searched when its name is
56              encountered, so the placement of a -l is significant.
57
58       -x     Do  not preserve local (non-.globl) symbols in the output symbol
59              table; only enter external  symbols.   This  option  saves  some
60              space in the output file.
61
62       -X     Save  local symbols except for those whose names begin with `L'.
63              This option is used by cc(1)  to  discard  internally  generated
64              labels while retaining symbols local to routines.
65
66       -r     Generate  relocation  bits  in the output file so that it can be
67              the subject of another ld run.  This flag  also  prevents  final
68              definitions  from  being given to common symbols, and suppresses
69              the `undefined symbol' diagnostics.
70
71       -d     Force definition of common  storage  even  if  the  -r  flag  is
72              present.
73
74       -n     Arrange  that when the output file is executed, the text portion
75              will be read-only and shared among all users executing the file.
76              This  involves moving the data areas up to the first possible 4K
77              word boundary following the end of the text.
78
79       -i     When the output file is executed,  the  program  text  and  data
80              areas will live in separate address spaces.  The only difference
81              between this option and -n is that here the data starts at loca‐
82              tion 0.
83
84       -o     The  name argument after -o is used as the name of the ld output
85              file, instead of a.out.
86
87       -e     The following argument is taken to be  the  name  of  the  entry
88              point of the loaded program; location 0 is the default.
89
90       -O     This  is an overlay file, only the text segment will be replaced
91              by exec(2).  Shared data must have the same  layout  as  in  the
92              program overlaid.
93
94       -D     The  next argument is a decimal number that sets the size of the
95              data segment.
96

FILES

98       /lib/lib*.a      libraries
99       /usr/lib/lib*.a  more libraries
100       a.out            output file
101

SEE ALSO

103       as(1), ar(1), cc(1), ranlib(1)
104

BUGS

106                                                                         LD(1)
Impressum