28
MS-DOS LINKER Presented by : Dhriti Das (roll no-07) Simsima Gogoi (roll no-17) Tanmi Bharadwaj (roll no-18)

Ms-dos Linker (New)

Embed Size (px)

Citation preview

Page 1: Ms-dos Linker (New)

MS-DOS LINKER

Presented by:Dhriti Das (roll no-07)

Simsima Gogoi (roll no-17)Tanmi Bharadwaj (roll no-18)

Page 2: Ms-dos Linker (New)

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”.

Page 3: Ms-dos Linker (New)

Object module format:There are total of 8 object records types

corresponding to the following categories of informations:

Binary image

External references Public definations

Page 4: Ms-dos Linker (New)

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

Page 5: Ms-dos Linker (New)

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

Page 6: Ms-dos Linker (New)

LNAMES records

The LNAMES record lists the names for use by SEGDEF record.

96 H length Name list Check-sum

Page 7: Ms-dos Linker (New)

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

Page 8: Ms-dos Linker (New)

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

Page 9: Ms-dos Linker (New)

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.

Page 10: Ms-dos Linker (New)

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

Page 11: Ms-dos Linker (New)

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

Page 12: Ms-dos Linker (New)

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

Page 13: Ms-dos Linker (New)

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)

Page 14: Ms-dos Linker (New)

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

Page 15: Ms-dos Linker (New)

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

Page 16: Ms-dos Linker (New)

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

Page 17: Ms-dos Linker (New)

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.

Page 18: Ms-dos Linker (New)

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.

Page 19: Ms-dos Linker (New)

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

Page 20: Ms-dos Linker (New)

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

Page 21: Ms-dos Linker (New)

enter symbol and symbol address (i.e segment address from NTAB +

offset) in NTAB

Page 22: Ms-dos Linker (New)

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

Page 23: Ms-dos Linker (New)

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

Page 24: Ms-dos Linker (New)

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

Page 25: Ms-dos Linker (New)

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

Page 26: Ms-dos Linker (New)

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.

Page 27: Ms-dos Linker (New)

The LINKER invocation command has the following format:

LINKER <object module names> <executable file>

<load origin> <list of library files>

Page 28: Ms-dos Linker (New)

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.