ld(1) ld(1)NAME ld - invokes the link editor for common object files SYNOPSIS ld [-afactor] [-e epsym] [-f fill] [-ild] [-lx] [-m] [-o outfile] [-r] [-s] [-t] [-u symname] [-x] [-z] [-F] [-Ldir] [-M] [-N] [-S] [-V] [-VS num] file... ARGUMENTS -afactor Specifies the expansion factor to be used to increase the size of the default symbol table. -e epsym Sets the default entry point address for the output file to be that of the symbol epsym. -f fill Sets the default fill pattern for holes within an output section as well as initialized bss sections. The argument fill is a 2-byte constant. file Specifies the file to be processed by ld. -ild Generates the sections reserved for use by the incremental loader and retains relocation entries in the new object file (as does the -r option). -lx Searches a library libx.a, where x is a string of up to seven characters. A library is searched when its name is encountered, so the placement of this argument is significant. The default library location is /lib. -m Produces a map or listing of the input/output sections on the standard output. -o outfile Produces an output object file with the name outfile. The name of the default object file is a.out. -r Retains 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 references. -s Strips line-number entries and symbol table information from the output object file. -t Turns off the warning about multiply defined symbols that are not the same size. January 1992 1
ld(1) ld(1)-u symname Specifies an undefined symbol in the symbol table. This option is useful for loading entirely from a library, because initially the symbol table is empty and an unresolved reference is needed to force the loading of the first routine. Replace symname with the name of an undefined symbol. -x Causes the system not to 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 Loads the text segment at an offset from 0 so that null-pointer references generate a segmentation violation. -F Creates a demand-paged executable. -Ldir Changes the algorithm of searching for libx.a to look in dir before looking in /lib and /usr/lib. This option is effective only if it precedes the -l option on the command line. -M Produces an output message for each multiply defined external definition. However, if the objects being loaded include debugging information, extraneous output is produced. (See the description of -g option in cc(1).) -N Puts 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. -S Suppresses the display of progress and error messages unless an error message occurs that results in the termination of the program. -V Produces an output message giving information about the version of ld being used. -VS num Causes ld to use num as a decimal version stamp identifying the a.out file that is produced. The version stamp is stored in the optional header. DESCRIPTION ld combines several object files into one, performs relocation, resolves external symbols, and supports symbol table information for symbolic debugging. In the simplest 2 January 1992
ld(1) ld(1)case, the names of several object programs are given, and ld combines them, producing an object module that can either be executed or used as input for a subsequent ld run. The output 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 at which it is encountered in the argument list. Only routines that define an unresolved external reference are loaded. The library (archive) symbol table (described in ar(4)) is searched sequentially with as many passes as are necessary to resolve external references that can be satisfied by library members. Thus, the ordering of library members is unimportant. The following information about section alignment and MMU requirements should be considered at system installation. The default section-alignment action for ld on M68000 systems is to align the code (.text) and data (.dataand.bsscombined) separately on 512-byte boundaries. Since MMU requirements 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, so that you can 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 (.dataand.bsscombined) 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 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 required alignment as outlined here. If it does not exist, the default section-alignment action is taken. The default.ld file should appear as follows, with <alignment> replaced by the alignment requirement in bytes: SECTIONS { .text : {} GROUP ALIGN(<alignment>) : { .data : {} .bss : {} } } January 1992 3
ld(1) ld(1)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 boundary): SECTIONS { .text : {} GROUP ALIGN(512) : { .data : {} .bss : {} } } To get alignment on 2 kilobyte boundaries, you should specify 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 ``ldReference'' in A/UX Programming Languages and Tools, Volume 1. WARNINGS Through its options and input directives, the common link editor gives you great flexibility; however, if you use the input directives, you must assume some added responsibilities. Input directives should ensure the following properties 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 requirement, you must not place any object at virtual 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 4 January 1992
ld(1) ld(1)must ensure that the program always calls exit() rather than falling through the end of the entry routine. FILES /bin/ld Executable file /lib/* Various library files and directories /usr/lib/* Various library files and directories a.out Default output file SEE ALSO as(1), cc(1) a.out(4), ar(4) in A/UX Programmer's Reference ``ldReference'' in A/UX Programming Languages and Tools, Volume 1 January 1992 5