ld(1) ld(1)
NAME
ld - link editor for common object files
SYNOPSIS
ld [-eepsym] [-ffill] [-lx] [-m] [-ooutfile] [-r] [-s]
[-usymname] [-z] [-F] [-Ldir] [-N] [-V] [-VSnum] filenames
DESCRIPTION
The ld command combines several object files into one,
performs relocation, 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 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 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
library members. Thus, the ordering of library members is
unimportant.
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
argument fill is a two-byte constant.
-lx Search a library libx.a, where x is up to seven
characters. A library is searched when its name is
encountered, 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
name of the default object file is a.out.
Page 1 (last mod. 1/16/87)
ld(1) ld(1)
-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
references.
-s Strip line number entries and symbol table information
from the output object file.
-usymname
Enter symname as an undefined symbol in the symbol
table. This is useful for loading entirely from a
library, since initially the symbol table is empty and
an unresolved reference is needed to force the loading
of the first routine.
-z Load the text segment at an offset from zero 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
option is effective only if it precedes the -l flag
option on the command line.
-N Put the data section immediately following the text in
the output file.
-V 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
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
systems is to align the code (.text) and data (.data and
.bss combined) separately on 512-byte boundaries. Since MMU
requirements vary from system to system, alignment is not
always desirable. The version of ld for M68020 systems,
therefore, 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 MC68020 systems is to align the code
Page 2 (last mod. 1/16/87)
ld(1) ld(1)
(.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 will search 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
required alignment as outlined below. If it does not exist,
the default alignment action will be 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 : {}
}
}
The current (MC68020) system requires a data rounding of 2
megabytes. This is subject to change as systems evolve.
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 2K-byte boundaries, the following
default.ld file should be specified:
SECTIONS {
.text : {}
GROUP ALIGN(2048) : {
.data : {}
.bss : {}
}
}
The current (MC68020) system requires a data rounding of 2
megabytes. This is subject to change as systems evolve.
For more information about the format of ld instruction
files or the meaning of the commands, see the ``ld
Reference'' in Oreo Programming Languages and Tools, Volume
Page 3 (last mod. 1/16/87)
ld(1) ld(1)
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 Oreo 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
responsibilities. Input directives should insure 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, 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
must insure that the program always calls exit( ),
rather than falling through the end of the entry
routine.
Page 4 (last mod. 1/16/87)