xref: /csrg-svn/old/ld/ld.1 (revision 43702)
1*43702Scael.\" Copyright (c) 1980, 1990 The Regents of the University of California.
219166Smckusick.\" All rights reserved.  The Berkeley software License Agreement
319166Smckusick.\" specifies the terms and conditions for redistribution.
419166Smckusick.\"
5*43702Scael.\"     @(#)ld.1	6.3 (Berkeley) 06/24/90
619166Smckusick.\"
7*43702Scael.Dd
8*43702Scael.Dt LD 1
9*43702Scael.Os BSD 4
10*43702Scael.Sh NAME
11*43702Scael.Nm ld
12*43702Scael.Nd link editor
13*43702Scael.Sh SYNOPSIS
14*43702Scael.Nm ld
15*43702Scael.Op  option
16*43702Scael\&...
17*43702Scael.Ar file ...
18*43702Scael.Sh DESCRIPTION
19*43702Scael.Nm Ld
2019166Smckusickcombines several
2119166Smckusickobject programs into one, resolves external
2219166Smckusickreferences, and searches libraries.
2319166SmckusickIn the simplest case several object
24*43702Scael.Ar files
2519166Smckusickare given, and
26*43702Scael.Nm ld
2719166Smckusickcombines them, producing
2819166Smckusickan object module which can be either executed or
2919166Smckusickbecome the input for a further
30*43702Scael.Nm ld
3119166Smckusickrun.
3219166Smckusick(In the latter case, the
33*43702Scael.Fl r
3419166Smckusickoption must be given
35*43702Scaelto preserve the relocation bits.)\
3619166SmckusickThe output of
37*43702Scael.Nm ld
3819166Smckusickis left on
39*43702Scael.Pa a.out  .
4019166SmckusickThis file is made executable
4119166Smckusickonly if no errors occurred during the load.
42*43702Scael.Pp
4319166SmckusickThe argument routines are concatenated in the order
4419166Smckusickspecified.  The entry point of the output is the
45*43702Scaelbeginning of the first routine (unless the
46*43702Scael.Fl e
47*43702Scaeloption is specified).
48*43702Scael.Pp
4919166SmckusickIf any argument is a library, it is searched exactly once
5019166Smckusickat the point it is encountered in the argument list.
5119166SmckusickOnly those routines defining an unresolved external
5219166Smckusickreference are loaded.
5319166SmckusickIf a routine from a library
5419166Smckusickreferences another routine in the library,
5519166Smckusickand the library has not been processed by
56*43702Scael.Xr ranlib  1  ,
5719166Smckusickthe referenced routine must appear after the
5819166Smckusickreferencing routine in the library.
5919166SmckusickThus the order of programs within libraries
6019166Smckusickmay be important.
6119166SmckusickThe first member of a library
6219166Smckusickshould be a file named `\_\^\_.SYMDEF',
6319166Smckusickwhich is understood to be a dictionary for the library as produced by
64*43702Scael.Xr ranlib  1  ;
6519166Smckusickthe dictionary is searched iteratively to satisfy as many references as
6619166Smckusickpossible.
67*43702Scael.Pp
6819166SmckusickThe symbols `\_etext', `\_edata' and `\_end'
6919166Smckusick(`etext', `edata' and `end' in C)
7019166Smckusickare reserved, and if referred to,
7119166Smckusickare set to the first location above the program,
7219166Smckusickthe first location above initialized data,
7319166Smckusickand the first location above all data respectively.
7419166SmckusickIt is erroneous to define these symbols.
75*43702Scael.Pp
76*43702Scael.Nm Ld
7719166Smckusickunderstands several options.
7819166SmckusickExcept for
79*43702Scael.Fl l  ,
8019166Smckusickthey should appear before the file names.
81*43702Scael.Tw Ds
82*43702Scael.Tp Fl A
8319166SmckusickThis option specifies incremental loading, i.e.
8419166Smckusicklinking is to be done in a manner so that the resulting object
8519166Smckusickmay be read into an already executing program.
8619166SmckusickThe next argument is the name of a file whose symbol table will be
8719166Smckusicktaken as a basis on which to define additional symbols.
8819166SmckusickOnly newly linked material will be entered into the text and
89*43702Scaeldata portions of
90*43702Scael.Xr a.out ,
9119166Smckusickbut the new symbol table will reflect
9219166Smckusickevery symbol defined before and after the incremental load.
9319166SmckusickThis argument must appear before any other object file in the argument list.
9419166SmckusickThe
95*43702Scael.Fl T
9619166Smckusickoption may be used as well, and will be taken to mean that the
9719166Smckusicknewly linked segment will commence at the corresponding address
9819166Smckusick(which must be a multiple of 1024).
9919166SmckusickThe default value is the old value of _end.
100*43702Scael.Tp Fl D
10119166SmckusickTake the next argument as a hexadecimal number and pad the data segment
10219166Smckusickwith zero bytes to the indicated length.
103*43702Scael.Tp Fl d
10419166SmckusickForce definition of common storage
10519166Smckusickeven if the
106*43702Scael.Fl r
10719166Smckusickflag is present.
108*43702Scael.Tp Fl e
10919166SmckusickThe following argument is taken to be the
11019166Smckusickname of the entry point of the loaded
11119166Smckusickprogram; location 0 is the default.
112*43702Scael.Tc Fl L
113*43702Scael.Ar dir
114*43702Scael.Cx
11519168SmckusickAdd
116*43702Scael.Ar dir
11719168Smckusickto the list of directories in which libraries are searched for.
118*43702ScaelDirectories specified with
119*43702Scael.Fl L
12027900Slepreauare searched before the standard directories.
121*43702Scael.Tc Fl l
122*43702Scael.Ar x
123*43702Scael.Cx
12419166SmckusickThis
12519166Smckusickoption is an abbreviation for the library name
126*43702Scael.Sq Pa libx.a,
12719166Smckusickwhere
128*43702Scael.Ar x
12919166Smckusickis a string.
130*43702Scael.Nm Ld
13119168Smckusicksearches for libraries first in any directories
13219168Smckusickspecified with
133*43702Scael.Fl L
13427900Slepreauoptions, then in the standard directories `/lib', `/usr/lib', and
13527900Slepreau`/usr/local/lib'.
13619166SmckusickA library is searched when its name is encountered,
13719166Smckusickso the placement of a
138*43702Scael.Fl l
13919166Smckusickis significant.
140*43702Scael.Tp Fl M
14119166Smckusickproduce a primitive load map, listing the names of the files
14219166Smckusickwhich will be loaded.
143*43702Scael.Tp Fl N
14419166SmckusickDo not make the text portion read only or sharable.  (Use "magic number" 0407.)
145*43702Scael.Tp Fl n
14619166SmckusickArrange (by giving the output file a 0410 "magic number") that
14719166Smckusickwhen the output file is executed,
14819166Smckusickthe text portion will be read-only and shared
14919166Smckusickamong all users executing the file.
15019166SmckusickThis involves moving the data areas up to the first
15119166Smckusickpossible 1024 byte boundary following the
15219166Smckusickend of the text.
153*43702Scael.Tp Fl o
15419166SmckusickThe
155*43702Scael.Ar name
15619166Smckusickargument after
157*43702Scael.Fl o
15819166Smckusickis used as the name of the
159*43702Scael.Nm ld
16019166Smckusickoutput file, instead of
161*43702Scael.Pa a.out  .
162*43702Scael.Tp Fl r
16319166SmckusickGenerate relocation bits in the output file
16419166Smckusickso that it can be the subject of another
165*43702Scael.Nm ld
16619166Smckusickrun.
16719166SmckusickThis flag also prevents final definitions from being
16819166Smckusickgiven to common symbols,
16919166Smckusickand suppresses the `undefined symbol' diagnostics.
170*43702Scael.Tp Fl S
17119166Smckusick`Strip' the output by removing all symbols except locals and globals.
172*43702Scael.Tp Fl s
17319166Smckusick`Strip' the output, that is, remove the symbol table
17419166Smckusickand relocation bits to save space (but impair the
17519166Smckusickusefulness of the debuggers).
17619166SmckusickThis information can also be removed by
177*43702Scael.Xr strip  1  .
178*43702Scael.Tp Fl T
17919166SmckusickThe next argument is a hexadecimal number which sets the text segment origin.
18019166SmckusickThe default origin is 0.
181*43702Scael.Tp Fl t
18219166Smckusick("trace")  Print the name of each file as it is processed.
183*43702Scael.Tp Fl u
18419166SmckusickTake the following argument as a symbol and enter
18519166Smckusickit as undefined in the symbol table.  This is useful
18619166Smckusickfor loading wholly from a library, since initially the symbol
18719166Smckusicktable is empty and an unresolved reference is needed
18819166Smckusickto force the loading of the first routine.
189*43702Scael.Tp Fl X
19019166SmckusickSave local symbols
19119166Smckusickexcept for those whose names begin with `L'.
19219166SmckusickThis option is used by
193*43702Scael.Xr cc  1
19419166Smckusickto discard internally-generated labels while
19519166Smckusickretaining symbols local to routines.
196*43702Scael.Tp Fl x
19719166SmckusickDo not preserve local
19819166Smckusick(non-.globl) symbols in the output symbol table; only enter
19919166Smckusickexternal symbols.
20019166SmckusickThis option saves some space in the output file.
201*43702Scael.Tc Fl y
202*43702Scael.Ar sym
203*43702Scael.Cx
20419166SmckusickIndicate each file in which
205*43702Scael.Ar sym
20619166Smckusickappears, its type and whether the file defines or references it.
20719166SmckusickMany such options may be given to trace many symbols.
20819166Smckusick(It is usually necessary to begin
209*43702Scael.Ar sym
21019166Smckusickwith an `_', as external C, FORTRAN and Pascal variables begin
21119166Smckusickwith underscores.)
212*43702Scael.Tp Fl z
21319166SmckusickArrange for the process to be loaded on
21419166Smckusickdemand from the resulting executable file (413 format)
21519166Smckusickrather than preloaded.
21619166SmckusickThis is the default.
21719166SmckusickResults in a 1024 byte header on the output file followed by
21819166Smckusicka text and data segment each of which have size a multiple of 1024 bytes
21919166Smckusick(being padded out with nulls in the file if necessary).
22019166SmckusickWith this format the first few BSS segment symbols may actually appear
22119166Smckusick(from the output of
222*43702Scael.Xr size  1  )
22319166Smckusickto live in the data segment;
22419166Smckusickthis to avoid wasting the space resulting from data segment size roundup.
225*43702Scael.Tp
226*43702Scael.Sh FILES
227*43702Scael.Dw /usr/local/lib/lib*.a
228*43702Scael.Di L
229*43702Scael.Dp Pa /usr/lib/lib*.a
230*43702Scaellibraries
231*43702Scael.Dp Pa /usr/local/lib/lib*.a
232*43702Scaelmore libraries
233*43702Scael.Dp Pa a.out
234*43702Scaeloutput file
235*43702Scael.Dp
236*43702Scael.Sh SEE ALSO
237*43702Scael.Xr as 1 ,
238*43702Scael.Xr ar 1 ,
239*43702Scael.Xr cc 1 ,
240*43702Scael.Xr ranlib 1
241*43702Scael.Sh HISTORY
242*43702Scael.Nm Ld
243*43702Scaelappeared in Version 6 AT&T Unix.
244*43702Scael.Sh BUGS
24519166SmckusickThere is no way to force data to be page aligned.
246*43702Scael.Nm Ld
24719167Smckusickpads images which are to be demand loaded from
24819167Smckusickthe file system to the next
24919167Smckusickpage boundary to avoid a bug in the system.
250