-

Changes

Jump to: navigation, search

Linker Reference Manual

11 bytes removed, 11:16, 31 July 2017
no edit summary
This means that a program may be divided into several source
files, each of which may be kept to a manageable size for
ease of editing and compilation, then each object file com-piled compiled separately and finally all the object files linked
together into a single executable program.
information in them so that any references to program or
data addresses (e.g. the address of a function) within the
file may be adjusted according to where the file is ulti-mately ultimately located in memory after the linkage process. Thus the
file is said to be relocatable. Relocation may take two
basic forms; relocation by name, i.e. relocation by the
Any object file may contain bytes to be stored in
memory in one or more program sections, which will be
referred to as psects. These psects represent logical group-ings groupings of certain types of code bytes in the program. The
section of the program containing executable instructions is
normally referred to as the text psect. Other sections are
In fact the linker will handle any number of psects,
and in fact more may be used in special applications. How-ever However the C compiler uses only the three mentioned, and thenames text, data and bss are simply chosen for identifica-tionidentification; the linker assigns no special significance to the name
of a psect.
The difference between the data and bss psects may be
exemplified by considering two external variables; one is
initialized to the value 1, and the other is not initial-izedinitialized. The first will be placed into the data psect, and the
second in the bss psect. The bss psect is always cleared to
zeros on startup of the program, thus the second variable
will be initialized at run time to zero. The first will how-ever however occupy space in the program file, and will maintain its
initialized value of 1 at startup. It is quite possible to
modify the value of a variable in the data psect during exe-cutionexecution, however it is better practice not to do so, since
this leads to more consistent use of variables, and allows
for restartable and romable programs.
The text psect is the section into which all executable
instructions are placed. On CP/M-80 the text psect will nor-mally normally start at the base of the TPA, which is where execution
commences. The data psect will normally follow the text
psect, and the bss will be last. The bss does not occupy
space in the program (.COM) file. This ordering of psects
may be overridden by an option to the linker. This is espe-cially especially useful when producing code for special hardware.
For MS-DOS and CP/M-86 the psects are ordered in the
providing relocation, both the text and data psects start at
0, even though they will be loaded one after the other in
memory. This allows 64k code and 64k data and stack. Suffi-cient Sufficient information is placed in the executable file (.EXE or
.CMD) for the operating system to load the program in
memory.
collective referencing of local psects via the -P option
(described later) a local psect may have a class name asso-
ciated with it. This is achieved witht the _�C_�L_�A_�S_�S <strong>CLASS</strong> flag on the
.psect directive.
The linker handles only symbols which have been
declared as global to the assembler. From the C source
level, this means all names which have storage class exter-nal external and which are not declared as static. These symbols may
be referred to by modules other than the one in which they
are defined. It is the linker's job to match up the defini-tion definition of a global symbol with the references to it.
== Operation ==
A command to the linker takes the following form:
LINK options files ...
will be recognized in upper or lower case.
;-R :Leave the output relocatable.
;-L :Retain absolute relocation info. -LM will retain onlysegement relocation information.
;-I :Ignore undefined symbols.
;-N :Sort symbols by address.
;-Caddr:Produce a binary output file offset by addr.
;-S :Strip symbol information from the output file.
;-X :Suppress local symbols in the output file.
;-Z :Suppress trivial (compiler-generated) symbols in theoutput file.
;-Oname:Call the output file name.
;-Pspec:Spec is a psect location specification.
;-Mname:Write a link map to the file name.
;-Usymbol:Make symbol initially undefined.
;-Dfile:Write a symbol file.
;-Wwidth:Specify map width.
Taking each of these in turn:
used as input to the linker subsequently. Without this
option, the linker will make the output file absolute, that
is with all relocatable addresses made into absolute refer-encesreferences. This option may not be used with the -L or -C
options.
The -L option will cause the linker to output null
relocation information even though the file will be abso-luteabsolute. This information allows self-relocating programs to
know what addresses must be relocated at run time. This
option is not usable with the -C option. In order to create
an executable file (i.e. a .COM file) the program objtohex
must be used. If a -LM option is used, only segment reloca-tion relocation information will be retained. This is used in conjuc-
tion with the large memory model. Objtohex will use the
relocation information (when invoked with a -L flag) to
The -I option is used when it is desired to link code
which contains symbols which are not defined in any module.
This is normally only used during top-down program develop-mentdevelopment, when routines are referenced in code written before
the routines themselves have been coded.
file formats for MS-DOS and CP/M-86, LINK will not produce
these (.EXE and .CMD resp.) formats directly. The compiler
automatically runs OBJTOHEX with appropriate options to gen-erate generate the correct file format.
The -S, -X and -Z options, which are meaningless when
the -C option is used, will strip respectively all symbols,
all local symbols or all trivial local symbols from the out-
put file. Trivial symbols are symbols produced by the com-pilercompiler, and have the form of one of a set of alphabetic char-
acters followed by a digit string.
The default output file name is _�l<strong>l._�o_�b_�jobj</strong>, or _�l<strong>l._�b_�i_�n bin</strong> whenthe -C option is used. This may be overridden by the -O_�n_�a_�m_�eO<strong>name</strong>option. The output file will be called _�n_�a_�m_�e <strong>name</strong> in this
instance. Note that no suffix is appended to the name; the
file will be called exactly the argument to the option.
separated list of psect names, each with an optional address
specification. In the absence of an address specification
for a psect listed, it will be concatenated with the previ-ous previous psect. For example
-Ptext=0c000h,data,bss=8000h
address, that is the address offset within the output file,
are different (e.g for the 8086) it is possible to specify
the load address separately from the link address. For exam-pleexample:
-Ptext=100h/0,data=0C000h/
address.
The -Mname option requests a link map, containing sym-bol symbol table and module load address information to be written
onto the file name. If name is omitted, the map will be
written to standard output. -W may be used to specify the
If it is desired to use the debugger on the program
being linked, it is useful to produce a symbol file. The
-D_�f_�i_�l_�e D<strong>file</strong> option will write such a symbol file onto the named_�f_�i_�l_�e<strong>file</strong>, or _�l<strong>l._�s_�y_�m sym</strong> if no file is given. The symbol file consists
of a list of addresses and symbols, one per line.
== Examples ==
Here are some examples of using the linker. Note how-ever however that in the normal case it is not necessary to invoke
the linker explicitly, since it is invoked automatically by
the C command.
LINK -MMAP -C100H START.OBJ MAIN.OBJ A:LIBC.LIB
executed when the program is run, since it will be at 100H.
LINK -X -R -OX.OBJ FILE1.OBJ FILE2.OBJ A:LIBC.LIB
A: drive, under CP/M, or in the directory A:\HITECH\ under
MS-DOS. It may be invoked with no arguments, in which case
it will prompt for input from standard input. If the stan-dard standard input is a file, no prompts will be printed. The input
supplied in this manner may contain lower case, whereas CP/M
converts the entire command line to upper case by default.

Navigation menu