linking in ms-dos system
DESCRIPTION
A Complete tutorial on Linking in MS-DOS System in System SoftwareTRANSCRIPT
Linking In MS-DOSShubham Shah
Yashashwi Mahindrakar
Sagar Nadgauda
Linking In MS Dos System
First of All lets see what is linking…
Linking is the Process of collecting and combining various pieces of code and data into single fie.
Thus this file can be Loaded (Copied) into Main MEMORY and executed.
Linking can be performed at compile time, when the source code is translated into machine code, at load time, when the program is loaded into memory and executed by the loader, and even at run time, by application programs.
Linkers Intro.
On early computer systems, linking was performed manually.
On modern systems, linking is performed automatically by programs called linkers.
Linkers play a crucial role in software development because they enable separate compilation.
Instead of organizing a large application as one monolithic source file, we can decompose it into smaller, more manageable modules that can be modified and compiled separately.
When we change one of these modules, we simply recompile it and relink the application, without having to recompile the other files
Understanding Linkers will do???
Understanding linkers will help you build large programs. Programmers who build large programs often encounter linker errors caused by missing modules, missing libraries, or incompatible library versions. Unless you understand how a linker resolves references, what a library is, and how a linker uses a library to resolve references, these kinds of errors will be baffling and frustrating.
Understanding linkers will help you avoid dangerous programming errors. The decisions that Unix linkers make when they resolve symbol references can silently affect the correctness of your programs. Programs that incorrectly define multiple global variables pass through the linker without any warnings in the default case. The resulting programs can exhibit baffling run-time behavior and are extremely difficult to debug.
Understanding linking will help you understand other important systems concepts. The executable object files produced by linkers play key roles in important systems functions such as loading and running programs, virtual memory., paging, and memory mapping.
Understanding linking will enable you to exploit shared libraries. For many years, linking was considered to be fairly straightforward and uninteresting. However, with the increased importance of shared libraries and dynamic linking in modern operating systems, linking is a sophisticated process that provides the knowledgeable programmer with significant power. For example, many software products use shared libraries to upgrade shrink-wrapped binaries at run time. Also, most Web servers rely on dynamic linking of shared libraries to serve dynamic content.
===== LinKing ===== The Linker Diagram:-
More about Linking Static Linking
all code modules are copied into a single executable file
the same shared module may exist in many files
a location in this file implies the location in the memory image
target address for cross-module reference can be determined before run time
Dynamic Linking
needs help from OS ( that means the scheme varies depending on OS)
library modules are usually linked dynamically
inserts symbolic references in the executable file
these symbols are resolved at run time
Object Model Format The Object Module of MS DOS differs from the intel specification in
some respects .We also make some simplification for the purpose of this discussion. Details of the object module are as follows:
“An Object module is a sequence of object records.”
There are 14 types of object records, in which they contain 5 kinds of information :-
Binary Image , i.e the code and data generated by translator.
External references.
Public Definitions
Debugging information such as line number in the source program.
Miscellaneous information such as comments in the source program.
Object Records Of Intel 8088
Record Type Id(Hex) Description
THREADR 80 Translator header record
LNAMES 96 List of names record
SEGDEF 99 Segment definition record
EXTDEF 8C External names definition
PUBDEF 91 Public names definition record
LEDATA A1 Enumerated data(Binary Image)
LIDATA A3 Repeated data(binary Image)
FIXUPP 9D Fix up (i.e. relocation) record
MODEND 8B Module end record
Sample MS DOS assembly language program
Sr.no Statement Offset
0001 NAME FIRST
0002 COMPUTE SEGMENT
0003 EXTERN PHI:BYTE,PSI:WORD
0004 PUBLI APLHA, BETA
0007 ALPHA . . . . . . . 0015
. . .
. . .
. . .
0012 MOV AX, SEG PHI
0028
. . .
. . .
. . .
0029 BETA .. . . . . . . . . 0084
0036 COMPUTE ENDS
0037 END
Design of Linker
For linking in MS Dos system we will design a program named LINKER which performs both linking and relocation of absolute segments and of re locatable segments that cannot be combined with other re locatable segments.
Its output is a binary program which resembles a program with .COM extension in MS DOS.
This program is not relocated by the loader prior the execution .
(Note:- the difference between the LINKER and the LINK program of MS DOS :LINK produces a program with .EXE extension, which is relocated by the loader prior to execution)
Specification The LINKER invocation command has the following format:
LINKER <object module names> ,<executable file>,
<load origin>, <list of library files>
The linker performs relocation and linking of all named object modules to produce a binary program with the specified load origin.
The program is stored in the file with the name <executable file>.If the LINKER comes across an external symbol that is not defined in any of the object modules named in th LINKER command, it locates ian object module in one of the library files included in <list of library files>that contains a public definitions.
This method of resolving an external reference by automatically including an object module form a library file is called “AUTOLINKING”.
Datastructures.
Here the linker program has two pass organization .
In first pass object modules are processed to collect information concering segments and public definations into name table(NTAB)
The second pass performs relocation and linking to produce a binary program.
General Shortcut to remember of ms dos linking
pass 1:
allocates segments defined in SEGDEF
resolve external symbols
pass 2:
prepare memory image
if needed, disk space is also used
expand LIDATA
relocations within segment
write .EXE file
General Difference between linux and ms dos linker
Linux linker GOT(Global Offset table ) & lazy modeling.
Where as the ms dos linker does pass 1 & pass2 linking wise
Thank you
Any questions