ld(1) ld(1)NAME ld - link editor for common object files SYNOPSIS ld [-eepsym] [-ffill] [-lx] [-m] [-ooutfile] [-r] [-s] [-t] [-usymname] [-x] [-z] [-F] [-Ldir] [-M] [-N] [-V] [-VSnum] file ... DESCRIPTION ld combines several object files into one, performs reloca- tion, resolves external symbols, and supports symbol table information for symbolic debugging. In the simplest case, the names of several object programs are given, and ld com- bines them, producing an object module that can either be executed or used as input for a subsequent ld run. The out- put of ld is left in a.out. This file is executable if no errors occurred during the load. If any input file, filename, is not an object file, ld assumes it is either a text file containing link editor directives or an archive library. If any argument is a library, it is searched exactly once at the point it is encountered in the argument list. Only those routines defining an unresolved external reference are loaded. The library (archive) symbol table (see ar(4)) is searched sequentially with as many passes as are necessary to resolve external references that can be satisfied by li- brary members. Thus, the ordering of library members is unimportant. FLAG OPTIONS The following flag options are recognized by ld: -eepsym Set the default entry-point address for the output file to be that of the symbol epsym. -ffill Set the default fill pattern for holes within an output section as well as initialized bss sections. The argu- ment fill is a 2-byte constant. -lx Search a library libx.a, where x is up to seven charac- ters. A library is searched when its name is encoun- tered, so the placement of a -l is significant. The default library location is /lib. -m Produce a map or listing of the input/output sections on the standard output. -ooutfile Produce an output object file by the name outfile. The April, 1990 1
ld(1) ld(1)name of the default object file is a.out. -r Retain relocation entries in the output object file. Relocation entries must be saved if the output file is to become an input file in a subsequent ld run. The link editor does not complain about unresolved refer- ences. -s Strip line-number entries and symbol-table information from the output object file. -t Turn off the warning about multiply-defined symbols that are not the same size. -usymname Enter symname as an undefined symbol in the symbol table. This is useful for loading entirely from a li- brary, because initially the symbol table is empty and an unresolved reference is needed to force the loading of the first routine. -x Do not preserve local (nonglobal) symbols in the output symbol table; enter external and static symbols only. This option saves some space in the output file. -z Load the text segment at an offset from 0 so that null pointer references generate a segmentation violation. -F Create a demand-paged executable. -Ldir Change the algorithm of searching for libx.a to look in dir before looking in /lib and /usr/lib. This flag op- tion is effective only if it precedes the -l flag op- tion on the command line. -M Produce an output message for each multiply-defined external definition. However, if the objects being loaded include debugging information, extraneous output is produced. (See the -g option in cc(1). -N Put the data section immediately following the text in the output file. Note that the -N option must be used either with /usr/lib/unshared.ld or with a user- supplied .ld file. -V Produce an output a message giving information about the version of ld being used. -VSnum Use num as a decimal version stamp identifying the a.out file that is produced. The version stamp is 2 April, 1990
ld(1) ld(1)stored in the optional header. The following information about section-alignment and MMU requirements should be considered at system installation. The default section alignment action for ld on M68000 sys- tems is to align the code (.text) and data (.data and .bss combined) separately on 512-byte boundaries. Since MMU re- quirements vary from system to system, this alignment is not always desirable. This version of ld provides a mechanism to allow the specification of different section alignments for each system, allowing you to align each section separately on n-byte boundaries, where n is a multiple of 512. The default section-alignment action for ld on this system is to align the code (.text) at byte 0 and the data (.data and .bss combined) at the 4 megabyte boundary (byte 10487576). When all input files have been processed (and if no override is provided), ld searches the list of library directories (as with the -l flag option) for a file named default.ld. If this file is found, it is processed as an ld instruction file (or ifile). The default.ld file should specify the re- quired alignment as outlined below. If it does not exist, the default section-alignment action is taken. The default.ld file should appear as follows, with <align- ment> replaced by the alignment requirement in bytes: SECTIONS { .text : {} GROUP ALIGN(<alignment>) : { .data : {} .bss : {} } } Note: This system requires a data rounding that is an even multiple of 1 megabyte (1 megabyte is the segment size). For example, a default.ld file of the following form would provide the same alignment as the default (512-byte boun- dary): SECTIONS { .text : {} GROUP ALIGN(512) : { .data : {} .bss : {} } April, 1990 3
ld(1) ld(1)} To get alignment on 2K-byte boundaries, the following default.ld file should be specified: SECTIONS { .text : {} GROUP ALIGN(2048) : { .data : {} .bss : {} } } Note that this system requires a data rounding that is an even multiple of 1 megabyte (1 megabyte is the segment size). For more information about the format of ld instruction files or the meaning of the commands, see ``ld Reference'' in A/UX Programming Languages and Tools, Volume 2. FILES /bin/ld /lib/* /usr/lib/* a.out default output file SEE ALSO as(1), cc(1), a.out(4), ar(4), ``ld Reference'' in A/UX Programming Languages and Tools, Volume 2. WARNINGS Through its flag options and input directives, the common link editor gives you great flexibility; however, if you use the input directives, you must assume some added responsi- bilities. Input directives should insure the following pro- perties for programs: - C defines a zero pointer as null. A pointer to which zero has been assigned must not point to any object. To satisfy this, you must not place any object at vir- tual address zero in the data space. - When you call the link editor through cc(1), a startup routine is linked with your program. This routine calls exit( ) (see exit(2)) after execution of the main program. If you call the link editor directly, you must insure that the program always calls exit( ), rather than falling through the end of the entry rou- tine. 4 April, 1990