Professional Documents
Culture Documents
Ms Dos Linker New
Ms Dos Linker New
.exe .
information and may refer to the contents of previous object records . It must appear in a specific order as shown belowRECORD TYPE THEADR LNAMES SEGDEF EXTDEF PUBDEF LEDATA FIXUPP MODEND Id (Hex) 8O 96 98 8C 9O AO 9C 8A DESCRIPTION Translator header record List of names record Segment defination record External names defination record Public names defination record Translated data (binary image) Relocation & linking information End of object module record
THEADR records
The THEADR record specifies the name of the object
module. It is derived by the translator from the source file. This name is used by the linker to report errors.
8O H length T-module name Check-sum
LNAMES records
The LNAMES record lists the names for use by
SEGDEF record.
96 H
length
Name list
Check-sum
SEGDFEF records
SEGDEF records describe the segments in the
object module , including their name, length and alignment. It designates a segment name using an index into NAMELIST of LNAMES record. The attributes field indicates whether the segment is relocatable or absolute, alignment specification and other details. It also contains the origin specification for an absolute segment.
98 H
length
EXTDEF records
The EXTDEF record contains a list of the external
8CH
length
Check-sum
PUBDEF records
The PUBDEF record contains a list of the external
symbols (called public names) that are declared in a segment of the object module.
9O H Length
Check sum
LEDATA records
LEDATA records contains translated instructions and
FIXUPP records
FIXUPP records are used to resolve external references,
relocation or linking information. The target datum contains a segment/external index. The target offset contains an offset from the name indicated in target datum. y Fix dat field: indicates the manner in which the target datum & target offset fields are to be interpreted. C0des in fixdat field:
CODE Contents of target datum and offset fields O 2 4 6 Segment index and displacement External index and target displacement Segment index (offset field is not used) External index (offset field is not used)
MODEND records
The MODEND specifies the end the object module.
8A H length Type (1) Start addr (5) Check sum
The
Type field
program. This record also optionally indicates the execution start address.
Statement
offset
NAME FIRST COMPUTE SEGMENT EXTERN BETA:BYTE, GAMMA:WORD PUBLIC ALPHA 0015 ALPHA .. .. : : MOV AX, SEG BETA 0028 : : JMP GAMMA 0056 : : COMPUTE ENDS END
Other fields Check sum 05 FIRST 07 COMPUTE 20H 122 01 01 05 ALPHA 0015 04 BETA 05 GAMMA 01 0028 A1 00 00 8801 06 01 01 01 0056 EA 00 00 8C01 06 01 02 8OH
THEADR LNAMES SEGDEF PUBDEF EXTDEF LEDATA FIXUPP LEDATA FIXUPP MODEND
MS-DOS LINK performs linking, like compiling or assembling, in fundamentally a two pass process. Pass 1
In the first pass, object modules are processed to collect information concerning segments and public definations.
Pass 2
It performs relocation and linking.
PASS 1 of LINK
Data structure used in pass 1 is Name Table (NTAB). It
table is created and the addresses and name of each segment using SEGDEF, LNAMES respectively are recorded.
The external references are obtained using EXTDEF
and PUBDEF.
load the origin address (if not specified-> default address) when LNAMES record encountered enter the names in NAMELIST when SEGDEF encountered enter segment name & segment address in NTAB for each PUBDEF record
enter symbol and symbol address (i.e segment address from NTAB + offset) in NTAB
PASS 2 of LINK
The data structures used in pass 2 are SEGTAB and EXTTAB. LINKER builds table called SEGTAB (segment table) to contain all segment names defined in the object module. A SEGTAB has the following format
SEGMENT NAME LOAD ADDRESS
While processing an LEDATA record the segment index can be used to index SEGTAB to obtain the segment s load address.
Relocation and linking are performed using FIXUPP records. Since a linking specification in a FIXUPP record may contain a reference to an external symbol, LINKER builds an external symbol table( EXTTAB) with the following format:
EXTERNAL SYMBOL LOAD ADDRESS
EXTTAB is built by processing the EXTDEF record and copying the load addresses from NTAB. At the end, the executable file is prepared which is then loaded into the memory for execution.
prepares memory, if needed disk space is also used data from LEDATA records moved to the appropriate parts of work-area segment index of LEDATA used to obtain load origin of the segment from NTAB segment name can be obtained from LNAMES record this name can be searched in NTAB to obtain its load address
FIXUPP records are then processed to effect relocation & linking (using target datum)
to eliminate indirect references to NTAB , SEGTAB is built to contain all segment names in the object modules FIXUPP record may contain a reference to an external symbol, so EXTTAB is built
Working of a linker
The LINK program of MS DOS produces an executable program with extension .exe . The linker is invoked by a command. LINKER links object module names, executable files, load origins and names of library files. When LINKER encounters external symbols, it searches the references in the library files, as soon as they are obtained, the set of such object modules are linked and relocated. This process is called auto linking.
LINKER <object module names> <executable file> <load origin> <list of library files>
EXAMPLE
LINKER FIRST+SECOND, sum,10000,math.lib FIRST and SECOND are object modules which are to be linked. sum is the executable file name. 10000 is the load origin. The library file named math.lib is used in which the object modules FIRST and SECOND are searched.