143702Scael.\" Copyright (c) 1980, 1990 The Regents of the University of California. 247961Sbostic.\" All rights reserved. 319166Smckusick.\" 447961Sbostic.\" %sccs.include.proprietary.man% 519166Smckusick.\" 6*50836Scael.\" @(#)ld.1 6.7 (Berkeley) 08/09/91 747961Sbostic.\" 843702Scael.Dd 943702Scael.Dt LD 1 1043702Scael.Os BSD 4 1143702Scael.Sh NAME 1243702Scael.Nm ld 1343702Scael.Nd link editor 1443702Scael.Sh SYNOPSIS 1543702Scael.Nm ld 1643702Scael.Op option 17*50836Scael.Ar ... 1843702Scael.Ar file ... 1943702Scael.Sh DESCRIPTION 2043702Scael.Nm Ld 2119166Smckusickcombines several 2219166Smckusickobject programs into one, resolves external 2319166Smckusickreferences, and searches libraries. 2419166SmckusickIn the simplest case several object 2543702Scael.Ar files 2619166Smckusickare given, and 2743702Scael.Nm ld 2819166Smckusickcombines them, producing 2919166Smckusickan object module which can be either executed or 3019166Smckusickbecome the input for a further 3143702Scael.Nm ld 3219166Smckusickrun. 3319166Smckusick(In the latter case, the 3443702Scael.Fl r 3519166Smckusickoption must be given 3644955Scaelto preserve the relocation bits.) 3719166SmckusickThe output of 3843702Scael.Nm ld 3919166Smckusickis left on 4043702Scael.Pa a.out . 4119166SmckusickThis file is made executable 4219166Smckusickonly if no errors occurred during the load. 4343702Scael.Pp 4419166SmckusickThe argument routines are concatenated in the order 4519166Smckusickspecified. The entry point of the output is the 4643702Scaelbeginning of the first routine (unless the 4743702Scael.Fl e 4843702Scaeloption is specified). 4943702Scael.Pp 5019166SmckusickIf any argument is a library, it is searched exactly once 5119166Smckusickat the point it is encountered in the argument list. 5219166SmckusickOnly those routines defining an unresolved external 5319166Smckusickreference are loaded. 5419166SmckusickIf a routine from a library 5519166Smckusickreferences another routine in the library, 5619166Smckusickand the library has not been processed by 5743702Scael.Xr ranlib 1 , 5819166Smckusickthe referenced routine must appear after the 5919166Smckusickreferencing routine in the library. 6019166SmckusickThus the order of programs within libraries 6119166Smckusickmay be important. 6219166SmckusickThe first member of a library 6319166Smckusickshould be a file named `\_\^\_.SYMDEF', 6419166Smckusickwhich is understood to be a dictionary for the library as produced by 6543702Scael.Xr ranlib 1 ; 6619166Smckusickthe dictionary is searched iteratively to satisfy as many references as 6719166Smckusickpossible. 6843702Scael.Pp 6919166SmckusickThe symbols `\_etext', `\_edata' and `\_end' 7019166Smckusick(`etext', `edata' and `end' in C) 7119166Smckusickare reserved, and if referred to, 7219166Smckusickare set to the first location above the program, 7319166Smckusickthe first location above initialized data, 7419166Smckusickand the first location above all data respectively. 7519166SmckusickIt is erroneous to define these symbols. 7643702Scael.Pp 7743702Scael.Nm Ld 7819166Smckusickunderstands several options. 7919166SmckusickExcept for 8043702Scael.Fl l , 8119166Smckusickthey should appear before the file names. 82*50836Scael.Bl -tag -width flagx 83*50836Scael.It Fl A 8419166SmckusickThis option specifies incremental loading, i.e. 8519166Smckusicklinking is to be done in a manner so that the resulting object 8619166Smckusickmay be read into an already executing program. 8719166SmckusickThe next argument is the name of a file whose symbol table will be 8819166Smckusicktaken as a basis on which to define additional symbols. 8919166SmckusickOnly newly linked material will be entered into the text and 9043702Scaeldata portions of 9143702Scael.Xr a.out , 9219166Smckusickbut the new symbol table will reflect 9319166Smckusickevery symbol defined before and after the incremental load. 9419166SmckusickThis argument must appear before any other object file in the argument list. 9519166SmckusickThe 9643702Scael.Fl T 9719166Smckusickoption may be used as well, and will be taken to mean that the 9819166Smckusicknewly linked segment will commence at the corresponding address 9919166Smckusick(which must be a multiple of 1024). 10019166SmckusickThe default value is the old value of _end. 101*50836Scael.It Fl D 10219166SmckusickTake the next argument as a hexadecimal number and pad the data segment 10319166Smckusickwith zero bytes to the indicated length. 104*50836Scael.It Fl d 10519166SmckusickForce definition of common storage 10619166Smckusickeven if the 10743702Scael.Fl r 10819166Smckusickflag is present. 109*50836Scael.It Fl e 11019166SmckusickThe following argument is taken to be the 11119166Smckusickname of the entry point of the loaded 11219166Smckusickprogram; location 0 is the default. 113*50836Scael.It Fl L Ns Ar dir 11419168SmckusickAdd 11543702Scael.Ar dir 11619168Smckusickto the list of directories in which libraries are searched for. 11743702ScaelDirectories specified with 11843702Scael.Fl L 11927900Slepreauare searched before the standard directories. 120*50836Scael.It Fl l Ns Ar x 12119166SmckusickThis 12219166Smckusickoption is an abbreviation for the library name 12343702Scael.Sq Pa libx.a, 12419166Smckusickwhere 12543702Scael.Ar x 12619166Smckusickis a string. 12743702Scael.Nm Ld 12819168Smckusicksearches for libraries first in any directories 12919168Smckusickspecified with 13043702Scael.Fl L 13144955Scaeloptions, then in the standard directories 13244955Scael.Pa /lib , 13344955Scael.Pa /usr/lib , 13444955Scaeland 13544955Scael.Pa /usr/local/lib . 13619166SmckusickA library is searched when its name is encountered, 13719166Smckusickso the placement of a 13843702Scael.Fl l 13919166Smckusickis significant. 140*50836Scael.It Fl M 14119166Smckusickproduce a primitive load map, listing the names of the files 14219166Smckusickwhich will be loaded. 143*50836Scael.It Fl N 14419166SmckusickDo not make the text portion read only or sharable. (Use "magic number" 0407.) 145*50836Scael.It 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*50836Scael.It Fl o 15419166SmckusickThe 15543702Scael.Ar name 15619166Smckusickargument after 15743702Scael.Fl o 15819166Smckusickis used as the name of the 15943702Scael.Nm ld 16019166Smckusickoutput file, instead of 16143702Scael.Pa a.out . 162*50836Scael.It Fl r 16319166SmckusickGenerate relocation bits in the output file 16419166Smckusickso that it can be the subject of another 16543702Scael.Nm ld 16619166Smckusickrun. 16719166SmckusickThis flag also prevents final definitions from being 16819166Smckusickgiven to common symbols, 16919166Smckusickand suppresses the `undefined symbol' diagnostics. 170*50836Scael.It Fl S 17119166Smckusick`Strip' the output by removing all symbols except locals and globals. 172*50836Scael.It 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 17743702Scael.Xr strip 1 . 178*50836Scael.It Fl T 17919166SmckusickThe next argument is a hexadecimal number which sets the text segment origin. 18019166SmckusickThe default origin is 0. 181*50836Scael.It Fl t 18219166Smckusick("trace") Print the name of each file as it is processed. 183*50836Scael.It 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*50836Scael.It Fl X 19019166SmckusickSave local symbols 19119166Smckusickexcept for those whose names begin with `L'. 19219166SmckusickThis option is used by 19343702Scael.Xr cc 1 19419166Smckusickto discard internally-generated labels while 19519166Smckusickretaining symbols local to routines. 196*50836Scael.It 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*50836Scael.It Fl y Ns Ar sym 20219166SmckusickIndicate each file in which 20343702Scael.Ar sym 20419166Smckusickappears, its type and whether the file defines or references it. 20519166SmckusickMany such options may be given to trace many symbols. 20619166Smckusick(It is usually necessary to begin 20743702Scael.Ar sym 208*50836Scaelwith an `_', as external C, 209*50836Scael.Tn FORTRAN 210*50836Scaeland Pascal variables begin 21119166Smckusickwith underscores.) 212*50836Scael.It 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). 220*50836ScaelWith this format the first few 221*50836Scael.Tn BSS 222*50836Scaelsegment symbols may actually appear 22319166Smckusick(from the output of 22443702Scael.Xr size 1 ) 22519166Smckusickto live in the data segment; 22619166Smckusickthis to avoid wasting the space resulting from data segment size roundup. 227*50836Scael.El 22843702Scael.Sh FILES 229*50836Scael.Bl -tag -width /usr/local/lib/lib*.a -compact 230*50836Scael.It Pa /usr/lib/lib*.a 231*50836ScaelLibraries. 232*50836Scael.It Pa /usr/local/lib/lib*.a 233*50836ScaelMore libraries. 234*50836Scael.It Pa a.out 235*50836ScaelOutput file. 236*50836Scael.El 23743702Scael.Sh SEE ALSO 23843702Scael.Xr as 1 , 23943702Scael.Xr ar 1 , 24043702Scael.Xr cc 1 , 24143702Scael.Xr ranlib 1 24243702Scael.Sh HISTORY 243*50836ScaelThe 244*50836Scael.Nm ld 245*50836Scaelcommand appeared in 246*50836Scael.At v6 . 24743702Scael.Sh BUGS 24819166SmckusickThere is no way to force data to be page aligned. 24943702Scael.Nm Ld 25019167Smckusickpads images which are to be demand loaded from 25119167Smckusickthe file system to the next 25219167Smckusickpage boundary to avoid a bug in the system. 253