143702Scael.\" 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*44955Scael.\" @(#)ld.1 6.4 (Berkeley) 07/24/90 619166Smckusick.\" 743702Scael.Dd 843702Scael.Dt LD 1 943702Scael.Os BSD 4 1043702Scael.Sh NAME 1143702Scael.Nm ld 1243702Scael.Nd link editor 1343702Scael.Sh SYNOPSIS 1443702Scael.Nm ld 1543702Scael.Op option 1643702Scael\&... 1743702Scael.Ar file ... 1843702Scael.Sh DESCRIPTION 1943702Scael.Nm Ld 2019166Smckusickcombines several 2119166Smckusickobject programs into one, resolves external 2219166Smckusickreferences, and searches libraries. 2319166SmckusickIn the simplest case several object 2443702Scael.Ar files 2519166Smckusickare given, and 2643702Scael.Nm ld 2719166Smckusickcombines them, producing 2819166Smckusickan object module which can be either executed or 2919166Smckusickbecome the input for a further 3043702Scael.Nm ld 3119166Smckusickrun. 3219166Smckusick(In the latter case, the 3343702Scael.Fl r 3419166Smckusickoption must be given 35*44955Scaelto preserve the relocation bits.) 3619166SmckusickThe output of 3743702Scael.Nm ld 3819166Smckusickis left on 3943702Scael.Pa a.out . 4019166SmckusickThis file is made executable 4119166Smckusickonly if no errors occurred during the load. 4243702Scael.Pp 4319166SmckusickThe argument routines are concatenated in the order 4419166Smckusickspecified. The entry point of the output is the 4543702Scaelbeginning of the first routine (unless the 4643702Scael.Fl e 4743702Scaeloption is specified). 4843702Scael.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 5643702Scael.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 6443702Scael.Xr ranlib 1 ; 6519166Smckusickthe dictionary is searched iteratively to satisfy as many references as 6619166Smckusickpossible. 6743702Scael.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. 7543702Scael.Pp 7643702Scael.Nm Ld 7719166Smckusickunderstands several options. 7819166SmckusickExcept for 7943702Scael.Fl l , 8019166Smckusickthey should appear before the file names. 8143702Scael.Tw Ds 8243702Scael.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 8943702Scaeldata portions of 9043702Scael.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 9543702Scael.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. 10043702Scael.Tp Fl D 10119166SmckusickTake the next argument as a hexadecimal number and pad the data segment 10219166Smckusickwith zero bytes to the indicated length. 10343702Scael.Tp Fl d 10419166SmckusickForce definition of common storage 10519166Smckusickeven if the 10643702Scael.Fl r 10719166Smckusickflag is present. 10843702Scael.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. 11243702Scael.Tc Fl L 11343702Scael.Ar dir 11443702Scael.Cx 11519168SmckusickAdd 11643702Scael.Ar dir 11719168Smckusickto the list of directories in which libraries are searched for. 11843702ScaelDirectories specified with 11943702Scael.Fl L 12027900Slepreauare searched before the standard directories. 12143702Scael.Tc Fl l 12243702Scael.Ar x 12343702Scael.Cx 12419166SmckusickThis 12519166Smckusickoption is an abbreviation for the library name 12643702Scael.Sq Pa libx.a, 12719166Smckusickwhere 12843702Scael.Ar x 12919166Smckusickis a string. 13043702Scael.Nm Ld 13119168Smckusicksearches for libraries first in any directories 13219168Smckusickspecified with 13343702Scael.Fl L 134*44955Scaeloptions, then in the standard directories 135*44955Scael.Pa /lib , 136*44955Scael.Pa /usr/lib , 137*44955Scaeland 138*44955Scael.Pa /usr/local/lib . 13919166SmckusickA library is searched when its name is encountered, 14019166Smckusickso the placement of a 14143702Scael.Fl l 14219166Smckusickis significant. 14343702Scael.Tp Fl M 14419166Smckusickproduce a primitive load map, listing the names of the files 14519166Smckusickwhich will be loaded. 14643702Scael.Tp Fl N 14719166SmckusickDo not make the text portion read only or sharable. (Use "magic number" 0407.) 14843702Scael.Tp Fl n 14919166SmckusickArrange (by giving the output file a 0410 "magic number") that 15019166Smckusickwhen the output file is executed, 15119166Smckusickthe text portion will be read-only and shared 15219166Smckusickamong all users executing the file. 15319166SmckusickThis involves moving the data areas up to the first 15419166Smckusickpossible 1024 byte boundary following the 15519166Smckusickend of the text. 15643702Scael.Tp Fl o 15719166SmckusickThe 15843702Scael.Ar name 15919166Smckusickargument after 16043702Scael.Fl o 16119166Smckusickis used as the name of the 16243702Scael.Nm ld 16319166Smckusickoutput file, instead of 16443702Scael.Pa a.out . 16543702Scael.Tp Fl r 16619166SmckusickGenerate relocation bits in the output file 16719166Smckusickso that it can be the subject of another 16843702Scael.Nm ld 16919166Smckusickrun. 17019166SmckusickThis flag also prevents final definitions from being 17119166Smckusickgiven to common symbols, 17219166Smckusickand suppresses the `undefined symbol' diagnostics. 17343702Scael.Tp Fl S 17419166Smckusick`Strip' the output by removing all symbols except locals and globals. 17543702Scael.Tp Fl s 17619166Smckusick`Strip' the output, that is, remove the symbol table 17719166Smckusickand relocation bits to save space (but impair the 17819166Smckusickusefulness of the debuggers). 17919166SmckusickThis information can also be removed by 18043702Scael.Xr strip 1 . 18143702Scael.Tp Fl T 18219166SmckusickThe next argument is a hexadecimal number which sets the text segment origin. 18319166SmckusickThe default origin is 0. 18443702Scael.Tp Fl t 18519166Smckusick("trace") Print the name of each file as it is processed. 18643702Scael.Tp Fl u 18719166SmckusickTake the following argument as a symbol and enter 18819166Smckusickit as undefined in the symbol table. This is useful 18919166Smckusickfor loading wholly from a library, since initially the symbol 19019166Smckusicktable is empty and an unresolved reference is needed 19119166Smckusickto force the loading of the first routine. 19243702Scael.Tp Fl X 19319166SmckusickSave local symbols 19419166Smckusickexcept for those whose names begin with `L'. 19519166SmckusickThis option is used by 19643702Scael.Xr cc 1 19719166Smckusickto discard internally-generated labels while 19819166Smckusickretaining symbols local to routines. 19943702Scael.Tp Fl x 20019166SmckusickDo not preserve local 20119166Smckusick(non-.globl) symbols in the output symbol table; only enter 20219166Smckusickexternal symbols. 20319166SmckusickThis option saves some space in the output file. 20443702Scael.Tc Fl y 20543702Scael.Ar sym 20643702Scael.Cx 20719166SmckusickIndicate each file in which 20843702Scael.Ar sym 20919166Smckusickappears, its type and whether the file defines or references it. 21019166SmckusickMany such options may be given to trace many symbols. 21119166Smckusick(It is usually necessary to begin 21243702Scael.Ar sym 21319166Smckusickwith an `_', as external C, FORTRAN and Pascal variables begin 21419166Smckusickwith underscores.) 21543702Scael.Tp Fl z 21619166SmckusickArrange for the process to be loaded on 21719166Smckusickdemand from the resulting executable file (413 format) 21819166Smckusickrather than preloaded. 21919166SmckusickThis is the default. 22019166SmckusickResults in a 1024 byte header on the output file followed by 22119166Smckusicka text and data segment each of which have size a multiple of 1024 bytes 22219166Smckusick(being padded out with nulls in the file if necessary). 22319166SmckusickWith this format the first few BSS segment symbols may actually appear 22419166Smckusick(from the output of 22543702Scael.Xr size 1 ) 22619166Smckusickto live in the data segment; 22719166Smckusickthis to avoid wasting the space resulting from data segment size roundup. 22843702Scael.Tp 22943702Scael.Sh FILES 23043702Scael.Dw /usr/local/lib/lib*.a 23143702Scael.Di L 23243702Scael.Dp Pa /usr/lib/lib*.a 23343702Scaellibraries 23443702Scael.Dp Pa /usr/local/lib/lib*.a 23543702Scaelmore libraries 23643702Scael.Dp Pa a.out 23743702Scaeloutput file 23843702Scael.Dp 23943702Scael.Sh SEE ALSO 24043702Scael.Xr as 1 , 24143702Scael.Xr ar 1 , 24243702Scael.Xr cc 1 , 24343702Scael.Xr ranlib 1 24443702Scael.Sh HISTORY 24543702Scael.Nm Ld 24643702Scaelappeared in Version 6 AT&T Unix. 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