Upload
mukut-jyoti-das
View
2.049
Download
66
Embed Size (px)
Citation preview
MS-DOS LINKER
Presented by:Dhriti Das (roll no-07)
Simsima Gogoi (roll no-17)Tanmi Bharadwaj (roll no-18)
What is MS-DOS linker?
Basically in MS-DOS compilers and assemblers object modules are created instead of executable machine language programs.
MS- DOS linker is a linkage editor that combines one or more object modules to produce a complete executable program.
This executable module has the file name extension “.exe”.
Object module format:There are total of 8 object records types
corresponding to the following categories of informations:
Binary image
External references Public definations
Each object record contains variable length information and may refer to the contents of previous object records . It must appear in a specific order as shown below-
RECORD TYPE
Id (Hex)
DESCRIPTION
THEADR 8O Translator header record
LNAMES 96 List of names record
SEGDEF 98 Segment defination record
EXTDEF 8C External names defination record
PUBDEF 9O Public names defination record
LEDATA AO Translated data (binary image)
FIXUPP 9C Relocation & linking information
MODEND 8A 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
nameCheck-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 Attribut
es (1-4)Segment length (2)
Name index ( 1)
Check-sum
EXTDEF records
The EXTDEF record contains a list of the external references used by the programs of this module.
8CH length External reference list
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
Base(2-4)
name
Offset (2)
…
Check sum
Identifies the segment
•Each (name, offset) pair defines one public name.•Specifies the name of the symbol.• Specifies its offset within the segment identified by the base specification.
LEDATA records LEDATA records contains translated
instructions and data from the source program.
AO H length Segment index (1-2)
Data offset (2)
Data Check sum
Identifies the segment to which the code belongs
Specifies the location of the code within the segment
FIXUPP records
FIXUPP records are used to resolve external references, and to perform address modification that are associated with relocation.
9CH
length
locat (1)
Fix dat (1)
Frame datum (1)
Target datum (1)
Target offset (1)
…
Check sum
Locat field: it contains a numeric code called loc code to indicate the type of a fixup.
Frame datum field: it refers to a SEGDEF record and identifies the segment to which the fixup location belongs.
Loc code
Meaning
0 Low order bytes is to be fixed
1 Offset is to be fixed
2 Segment is to be fixed
3 Pointer (segment : offset) is to be fixed
Target datum & target offset field: specifies the 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.
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 Segment index and displacement
2 External index and target displacement
4 Segment index (offset field is not used)
6 External index (offset field is not used)
MODEND records The MODEND specifies the end the object
module.
The indicates whether it is the main program.
This record also optionally indicates the execution start address.
8A H
length Type (1)
Start addr (5)
Check sum
Type field
Sample MS DOS assembly language programSr. no. Statement offset
0001 NAME FIRST0002 COMPUTE SEGMENT0003 EXTERN BETA:BYTE, GAMMA:WORD0004 PUBLIC ALPHA 00150007 ALPHA .. .. : : : :0012 MOV AX, SEG BETA 0028 : : : :0029 JMP GAMMA 0056 : : : :0036 COMPUTE ENDS0037 END
OBJECT Module “FIRST”Type Length Other fields Check sum8OH … 05 FIRST … THEADR96H … 07 COMPUTE … LNAMES98H … 20H 122 01 … SEGDEF 9oH … 01 05 ALPHA 0015 … PUBDEF8CH … 04 BETA 05 GAMMA … EXTDEFAOH … 01 0028 A1 00 00 … LEDATA9CH … 8801 06 01 01 … FIXUPPAOH … 01 0056 EA 00 00 … LEDATA9CH … 8C01 06 01 02 … FIXUPP8AH … 8OH … MODEND
Other types of records The data type for both EXTDEF and PUBDEF
are defined in TYPDEF record.
GRPDEF record specify how these segments are combined into groups.
LIDATA record specify translated instructions and data that occur in a repeating pattern.
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.
Data structure used in pass 1 is Name Table (NTAB). It has the following format-
In pass 1 the object modules are processed. A symbol 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.
PASS 1 of LINK
SYMBOL LOAD ADDRESS
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
While processing an LEDATA record the segment index can be used to index SEGTAB to obtain the segment’s load address.
SEGMENT NAME 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:
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.
EXTERNAL SYMBOL LOAD ADDRESS
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 linkerThe 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.
The LINKER invocation command has the following format:
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.