unit 3
Post on 06-May-2015
1.027 Views
Preview:
DESCRIPTION
TRANSCRIPT
UNIT III
LINKERS AND LOADERS AND SOFTWARE
TOOLS
� Pre requisite :-
� Know the basic of fundamental of operating system.
� Outcomes
� Aim of this chapter students are aware with loader .
� Software tool
UNIT III
LINKERS AND LOADERS AND SOFTWARE
TOOLS
� Contents :
� Basic loaders functions, central loaders scheme Absolute loaders,
Subroutine linkers, relocation
� Loader, Direct linking loader, Dynamic linking loader, Design of
absolute loaders direct linking loader,
� Implantation of MS DOS linker,� Implantation of MS DOS linker,
� Software tools for program development, editors, debug monitor,
programming environment, user interfaces.
LINKERS AND LOADERS & SOFTWARE TOOLS
� Execution of program involves the following steps
� Translation of the programs .
� Linking of the program with other program needed for its
execution.
� Relocation of the program to execute from the specific memory
area allocated to it.
� Loading of the program in the memory for the purpose of
execution .
LINKERS & LOADERS & SOFTWARE TOOLS
A schematic of Program execution
Translator Linker LoaderBinary
Program
Source
Program
Object
Modules
Binary
Programs
Control Flow Data Flow
FUNCTIONS OF LOADER
� Loader:
The loader is a program which accepts object codes and prepares
them for execution and initiates execution.
� The loader is responsible for the activities such as � The loader is responsible for the activities such as
allocation ,linking, relocation and loading
� It allocates the space for program in the memory, by
calculating the size of the program. This activity is
called allocation.
CONT…
�It resolves the symbolic reference (code/data) between
the object modules by assigning all the user subroutine
and library subroutine addresses. This activity is called
linking
�There are some address dependant locations in the program, such �There are some address dependant locations in the program, such
address constants must be adjusted according to allocated space,
such activity done by loader is called relocation.
� Finally it places all the machine instruction and data of correspondingprograms and subroutines into the memory .Thus program now become readyfor execution, this activity is called loading.
General loading scheme diagram-
object
Program moduls A and B are
loaded in memory after linking.
It is ready for execution.
Module A
Object
Module B
LOADER A
B
CONT…
� The following terminology is used to refer to the address
to refer to the address of the program entity at different
times
� Translation time(or translated) address : address
assigned by the translator
� Linked address : address by the linker
� load time(or load) address : address assigned by the
loader.loader.
CONT…
o The same prefixes above are used with the origin and
execution start address of a program. thus,-
1. Translated origin :
Address of the origin assumed by the translator .This is the address
specified by the programmer in an ORIGIN statement.
2. Linked Origin :2. Linked Origin :
Address of the origin assigned by the linker while producing a
binary program.
3. Load Origin :
Address of the origin assigned by the loader while loading the
program for execution.
TYPES OF LOADERS
1. General Loader
2. Bootstrap Loader (Absolute Loader)
3. Subroutine Linkage
4. Relocating Loaders
4.1- Relocation bits
4.2- Relocation maps (modification records)
5. Direct Linking Loader
GENERAL LOADERS
� In this scheme ,the source program is converted to object programby translator (assembler).
� The loader accepts these modules and puts machine instruction anddata in an executable form at their assigned memory.
Advantages:-
� The program need not be retranslated each time while running it.The program need not be retranslated each time while running it.
� There is no wastage of memory.
� It is possible to write source program with multiple programs andmultiple languages.
ASSEMBLE-&-GO LOADER
� Characteristics
� The Object Code is stored in Memory after Assembly.
� Single JUMP Instruction.
� Advantage
� Simple, Developing Environment.
� Disadvantage
� Whenever the Assembly Program is to be executed, it has to be
assembled again.
� Programs have to be coded in the same language.
ABSOLUTE LOADER
� It is kind of loader in which relocated object files are created
,loader accepts these files and places them at specified locations
in the memory.
� This type of loader is called absolute because no relocation
information is needed; rather it is obtained from the programmer information is needed; rather it is obtained from the programmer
or assembler.
� The task of an absolute loader is virtually trivial. The simply
accepts the machine language code produced by an assembler
and places it into main memory at the location specified by the
assembler.
ABSOLUTE LOADER
� If the operating system loads the loader, how the operating
system itself loaded into memory?
Given an idle computer with no program in
memory, how do we gets things started?
� Memory empty ⇒ no need for program relocation =>Memory empty ⇒ no need for program relocation =>
� OS kernel is loaded into a predefined location in memory by
absolute loader
� This absolute loader may be a software function, resident in
ROM or “primary loaded” by some hardware function.
ABSOLUTE LOADER
� Absolute Loader accepts machine language code produced
by an assembler & places it into main memory at the
location specified by the assembler.
� Absolute loader example –
The main program is assigned to location 100 to 250 and
the function F1 is assigned location 400 to 500. The
programmer should be careful not to assign overlapping programmer should be careful not to assign overlapping
location to modules to be linked.
ABSOLUTE LOADER
ABSOLUTE LOADER – ADVANTAGE & DISADVANTAGE
� Advantages
�Simple and Efficient.
�No reallocation information is required , so the size of
the object module is comparatively small.
�It makes memory available for loading, since the
assembler is not in memory at the time of loading.
�No modification of address sensitive entities is �No modification of address sensitive entities is
required & it supports multiple object modules.
CONT..
� Disadvantages
�The need for programmer to specify the actual address.
�Difficult to use Subroutine libraries.
�The programmer has to be careful not to assign �The programmer has to be careful not to assign overlapping location to modules to be linked.
�Lot of memory lying between modules will be wasted.
�If changes are made to one module that increses it size then it can overlap the start of another module. It may required manual shifting of module.thismanual shifting can become very complex and tedios.
ALGORITHM FOR AN ABSOLUTE LOADER
Begin
read Header record
verify program name and length
read first Text record
while record type is not ‘E’ dowhile record type is not ‘E’ do
begin
{if object code is in character form, convert into internal representation}
move object code to specified location in memory
read next object program record
end
jump to address specified in End record
end
ALGORITHM.
intialize
Read record
type=0 type=1Card
type
Mover binary image
at the address
specified in the record
Transfer the control
to the entry point
DESIGN.
� In absolute loading scheme the programmer and
the assembler perform the following tasks.
1) Allocation
2) Relocation
3) Linking3) Linking
4) Loading
� The absolute loader reads the object program
line by line and moves the text of the program
in to the memory at the location specified by the
assembler.
CONT.
� The object program generated by the assembler
must communicate the following information to
the loader.
1) It must convey the machine instructions that
the assembler has created along with the the assembler has created along with the
memory address.
2) It must convey the starting execution
point.program execution will start at this point
after the program is loaded.
CONT.
� The object program is a sequence of object record.
� Each object record specifies some specific aspect
of the program in the object module.
� There are two types of record:
1) Text record containing binary image of the 1) Text record containing binary image of the
assembly program
2) Transfer record containing the starting point of
execution.
CONT..
•TEXT RECORD
Record typeNumber bytes of
information
Memory
address
Binary image of
data or instruction
•TRANSFER RECORD
Record typeNumber of bytes of
information =0
Address of entry
point
SUBROUTINE LINKAGE
� A program consisting of main program and a set
of function(subroutine) could reside in several
files.
� The problem of subroutine linkage is this: A main
program a wishesh to call the subroutine B and if program a wishesh to call the subroutine B and if
the subroutine B resides in another file then the
assembler will not know the address of B and
declare it as an undefined symbol.
� To realize such interreaction,A and B must
contain public definition and external references.
EXTERN STATEMENT
� The EXTERN statement lists the symbol to
which external references are made in the
current program unit. These symbols are defined
in other program units.
ENTRY STATEMENT
� The ENTRY statement lists the public definition
of a program unit, i.e. it lists those symbols
defined in the program unit which may be
referenced in other program units.
RELOCATING LOADERS
� When a single subroutine is changed then all the subroutines need to be reassembled. The task of allocation and linking must be carried out once again.
To avoid this rework a new class of loaders is introduced which is called as relocating of loaders.
� Two methods for specifying relocation
◦ Modification record
◦ Relocation bit
� Each instruction is associated with one relocation bit.
� These relocation bits in a Text record is gathered into bit masks.
RELOCATING LOADERS (CONTD.)
� Absolute loader loads a program on a specific memory
location, but it is often desirable to have two or more
programs residing in memory sharing the different
resources of a computer system.
� It would be impractical to assign starting addresses to � It would be impractical to assign starting addresses to
each program to plan program execution.
� A loader able to load a program into memory wherever
there is room for it is called a Relocating Loader.
MODIFICATION RECORD
� Interleaving relocation bits with the program text makes
cumbersome the
process of loading the text directly into memory.
� This problem can be resolve by collecting all relocation bits into a
single
contiguous relocation map that we will call the relocation section contiguous relocation map that we will call the relocation section
of the
object code file.
� The relocation section will be appended to the text and data
sections.
� The header will contain the entry point and length of the relocation
section
in the object module.
RELOCATION BIT
� Used for simple machines.
� Relocation bit
� 0: no modification is necessary
� 1: modification is needed
� Twelve-bit mask is used in each Text record� Twelve-bit mask is used in each Text record
� Since each text record contains less than 12 words
� Unused words are set to 0
� Any value that is to be modified during relocation must
coincide with one of these 3-byte segments.
DIRECT LINKING LOADER
� It is a general relocated loader and is perhaps
the most popular loading scheme presently
used.
1. It is a relocatable loader
2. It allows multiple procedure segments and 2. It allows multiple procedure segments and
multiple data segment.
� The assembler must give the loader the
following information with each procedure or
data segment
CONT..
� The assembler must give the loader the following
information with each procedure or data segment
1. The lengthss of segment.
2. A list of symbols defined in the current segment
that may be referenced by other segments-that may be referenced by other segments-
public declaration.
3. A list of all symbols not defined in the segment
but referenced in the segment-external
variables.
4. Information about address constants.
5. The machine code translation of source program
and the relative addresses assigned.
CONT
� The object module produced by the assembler is
divided into 4 sections:
1. External symbol directory(ESD)
2. Actual assembled program(TXT)
3. Relocation directory(RLD)3. Relocation directory(RLD)
4. End of the object module(END)
EXTERNAL SYMBOL DIRECTORY(ESD)
� It contains information about all symbol that are
defined in this program but may be refrenced by
other programs.it also contains symbols
referenced in this program but defined in other
program.program.
CONT..
LC
1. MAIN START 0
2. ENTRY RESULT -
3. EXTRN SUM -
4. -4. -
5. -
6. -
7. -
8. -
9. -
10. RESULT DS 4 32
END 36
CONT..
� Line no. Symbol type relative location length
1. MAIN SD 0 36
2. RESULT LD 32 -
3. SUM ER - -
� SD- symbol is asegment definition
� LD- symbol is defined in this program but it can
be referenced by other program.
� ER- symbol is an external reference,it is defined
in some external program.
CONT..
• The relative location of the program (MAIN) is 0
and size is 36.
• The symbol RESULT is locally defined(LD) and
relative address is 32
• The symbol SUM is an external reference(ER).• The symbol SUM is an external reference(ER).
ACTUAL ASSEMBLED PROGRAM(TXT)
� Text portion of object module contain the
relocatable machine language instruction and
data that were produced during translation.
RELOCATION DIRECTORY(RLD)
� It contains one entry for each address that must
be changed when the module is loaded into main
memory.
� The relocation directory contains the following
information:information:
1. The address of each operand that needs to be
changed due to relocation.
2. By what it has to be changed
3. The operation to be performed
END OF OBJECT MODULE(END)
� This indicated the end of object module.
DESIGN OF DIRECT LINKING LOADER
� The design of adirect linking loader is more
complicated than that of the absolute loader.
� The input to the loader is set of object
programs(generated by assembler/compiler) to be
linked together. Each object module is divided in linked together. Each object module is divided in
to four section:
1. External symbol directory(ESD)
2. Actual assembled progrsm containing the
binary code(TXT)
3. Relocation directory(RLD)
4. End of the object module(END)
CONT…
� A direct linking loader requires two passes to
compelete the linking processes:
1. Pass 1,assigns addresses to all external symbol.
2. Pass 2,performs actual loading,relocation and
linking.linking.
� In pass 1 , aglobal external symbol table(GEST)
is prepared.it contains every exrernal symbol
and the corresponding absolute address value.
CONT…
� The two-pass limking loader scheme in shown
below:
Object
module
Copy of object
records
main
memory
Pass 1 of
loaderObject
module
Global external
symbol table
Pass 2 of
loader
LINKER FOR MS DOS
OBJECT MODULE FORMAT
� MS DOS compiler & assembler produces object modules. The
object module is a sequence of object records.
� There are 14 types of object records containing the following 5
basic categories of information:-
1) Binary image (i.e. code generated by a translator)
2) External references.2) External references.
3) Public definitions.
4) Debugging information (e.g. line number in source program).
5) Miscellaneous information (e.g. comments in the source
program).
We only consider the object record corresponding to first three
Categories - a total of 8 record types
OBJECT RECORDS OF INTEL 8088
1.THEADER RECORDS
� The module name in THEADER record is typically derived
by the translator from the source file name.
� This name is used by the linker to report errors.
80H length T-module name Check-sum
2.LNAMES RECORDS
� An assembly programmer can specify the module name
in NAME directive.
� This record lists the names for use by SEGDEF records.
96H length Name list Check-sum
3. SEGDEF RECORDS
� This record designates a segment name using an index
into LNAMES list.
� Attribute field indicates whether the segment is
rellocatable or absolute, whether (and in what manner )
it can be combined with other segments as also the it can be combined with other segments as also the
alignment requirement of its base address.
98H LengthAttributes
(1-4)Check-sum
Segment Length
(2)
Name
Index
(1)
SEGDEF RECORDS
� Stack segments with the same name are concatenated
with each other, while common segments with the same
name are overlapped with one another.
� The attribute field also contains the origin specification
for an absolute segment.for an absolute segment.
4. EXTDEF RECORDS
� This record contains a list of external references used by
the programs of this module.
� A FIXUPP record designates an external symbols name
by using an index into this list.
8CH Length External Reference List Check-sum
5. PUBDEF RECORDS
� It contains the list of public names declared in a
segment of the object module.
� The base specification identifies the segment.
� Each (name, offset) pair in the record defines � Each (name, offset) pair in the record defines
one public name, specifying the name of the
symbol and its offset within the segment
designed by the base specification.
90H Length Base(2-4) Name Offset(2) ..... Check-sum
6. LEDATA RECORDS
� It contains the binary image of the code generated by
the language translator.
� Segment index identifies the segment to which the code
belongs, and offset specifies the location of the code
within the segment.within the segment.
A0H Length Segment index(1-2) Data offset(2) Data Check-sum
7. FIXUPP RECORDS
� It contains information for one or more relocation and
linking fixups to be performed.
� The locat field contains a numeric code called loc code
to indicate the type of a fixup.
� The meanings of these codes are given below:� The meanings of these codes are given below:
9CH Length Locate(1) Fix datFrame
datum(1)
Target
datum(1)
Target
offset(2)… Check sum
CONT……
� Locat also contains the offset of the fixup location in the
previous LEDATA record.
� The frame datum field , which refers to a SEGDEF record ,
identifies the segment to which the fixup location belongs.
� The target datum and target offset fields specify the � The target datum and target offset fields specify the
relocation or linking information.
� target datum contains a segment index or an external index,
while target offset contains an offset from the name
indicated in target datum.
� The fix dat field indicates the manner in which the target
datum and target offset fields are to be interpreted.
� The numeric codes used for this purpose are given below
SOFTWARE TOOLS FOR PROGRAMMING DEVELOPMENT
� A software tool is system program which Interfaces a
program with the entity generating its input data or
interfaces the results of a program with the entity
consuming them.
CONT..
� The software tools include:-
� Assembler
� Linker
� Loader
� Macro processor
� Text editor� Text editor
� Compiler
� Operating system
� Debugging system
� Source Code Control System
� (Optional) Database Management System
� User Interface
A SOFTWARE TOOL
originator Software
tool
Consumer
Raw program or
data
Transformed program or data
FUNDAMENTAL STEPS IN PROGRAM
DEVELOPMENT
� Program design, coding, documentation.
� Preparation of programs in machine readable
form.
� Program translation, linking and loading.
Program testing and debugging.� Program testing and debugging.
� Performance tuning.
� Reformatting the data and results of a program
to suit other programs.
PROGRAM DESIGN AND CODING
� Two categories of tools used in program design and coding are :
�Program generators :A program generator generates a program which performs a set of functions described in its specification. Coding effort is saved since the program performs a set of functions described in its specification. Coding effort is saved since the program is generated rather than coded by hand.
�Programming environments :
A programming environment supports program
coding by incorporating awareness of the programming language syntax and semantics in the language editor.
PROGRAM ENTRY AND EDITING
� These tools are text editors or more sophisticated
programs with text editors as front ends. The
editor functions in two modes. In the command
mode, it accepts user commands specifying the
editing function to be performed. In the data editing function to be performed. In the data
mode, the user keys in the text to be added to the
file.
� Failure to recognize the current mode of the
editor can lead to mix up of command and data.
� This can be avoided by providing a quick exit e.g.
escape key, such that the editor enters the
command mode.
PROGRAM TESTING & DEBUGGING
� Important steps in program testing and debugging are selection of test data for the program, analysis of test results to detect errors and debugging, i.e. localization and removal of errors. Software tools to assist the programmer come in following form :come in following form :
1. Test data generators help the user in selecting test data for his program. Their use helps in ensuring that a program is thoroughly tested.
2. Automated test drivers help in regression testing, wherein a programs correctness is verified by subjecting it to a standard set of tests after every modification.
CONT..
Regression testing is performed as follows: Many
sets of test data are prepared for a program.
These are given as inputs to the test driver. The
driver selects one set of test data at a time and
organizes execution of the program on the data.organizes execution of the program on the data.
4. Debug monitors help in obtaining information for
localization of errors.
5. Source code control system help to keep track of
modifications in the source code.
DEBUGGING MONITOR
� An interactive debugging system provides programmers with facilities that aid in the testing & debugging of programs. Debug monitors provide following facilities:-
� 1. Setting Breakpoints
� 2. Initiating debug conversations
� 3. Single-stepping� 3. Single-stepping
� 4. Inspection & Assignment of variables
� Debugging system provides functions such as tracing & trace back.
Tracing can be used to track flow of execution logic & data modification.
� While debugging a program, user specifies a list of breakpoints & actions to be performed at breakpoints. Debug monitor builds a table containing statement no. & debug action.
ENHANCEMENT OF PROGRAM
PERFORMANCE
� A profile monitor is a software tool that collects
information regarding the execution behavior of a
program, e.g. the amount of execution time
consumed by its modules, and presents in the
form of an execution profile. form of an execution profile.
� Program efficiency depends on two factors :
1. The efficiency of the algorithm.
2. The efficiency of its coding.
3. An optimizing compiler can improve efficiency
of the code but it cannot improve efficiency of
the algorithm.
PROGRAM DOCUMENTATION
� Most programming projects suffer from lack of up
to date documentation. Automatic documentation
tools are motivated by the desire to overcome this
deficiency. These tools work on the source
program to produce different forms of program to produce different forms of
documentation, e.g. flow charts, IO specifications
showing files and their records, etc.
DESIGN OF SOFTWARE TOOLS
� Program preprocessing techniques are used to
support static analysis of programs. Tools
generating cross reference listings and lists of
unreferenced symbols; test data generators, and
documentation aids use this technique.documentation aids use this technique.
� Program instrumentation implies insertion of
statements in a program. The instrumented
program is translated using standard translator.
SOFTWARE TOOLS USING INTERPRETATION & PROGRAM GENERATION
InterpreterTask
specification
Results
Data
Program Generated Program
GeneratorTask specification Generated
program
Data
Results
EDITORS
� Text editors come in the following forms :
1. Line editors.
2. Stream editors.
3. Screen editors.
Word processors.4. Word processors.
5. Structure editors
EDITOR
� The scope of edit operations in a line editor is limited to a line of text. The primary advantage of line editors is there simplicity.
� A stream editor views the entire text as a stream of characters. This permits edit operations to cross line boundaries. Stream editors typically support character, line and context oriented commands based character, line and context oriented commands based on the current editing context indicated by the position of a text pointer.
� Screen editors display a screenful of text at a time. The user can move the cursor over the screen, position it at the point where he desires to perform some editing and proceed with the editing directly. Thus it is possible to see the effect of an edit operation on the screen. This is very useful while formatting the text to produce printed documents.
EDITOR
� Word processors are basically document editors with additional features to produce well formatted hard copy output. Essential features of word processors are commands for moving sections of text from one place to another, merging of text, and searching and replacement merging of text, and searching and replacement of words.
� A structural editors incorporates an awareness of the structure of a document. This is useful in browsing through a document, e.g. if a programmer wishes to edit a specific function in a program file. The structure is specified by the user while creating or modifying the document.
EDITOR STRUCTURE
Command
processor
Editing
manager
Viewing
managerTravelling
manager
Viewing filter
Editing bufferViewing
buffer
Editing filter
Test
USER INTERFACES
� A user interface plays a vital role in simplifying
the interaction of user with an
application.classically,UI functionalities have two
important aspects- issuing of commands and
exchange of data.exchange of data.
� Hence an understanding commands and data
was implicit in the use of an application.
� A UI can be visulized to consist of two compenent
a dialog manager and presentation manager
CONT…
� A dialog manager manages the conversation
between the user and the application. This
involves prompting the user for a command and
transmitting the command to the application.
� The presentation manager displays the data � The presentation manager displays the data
produced by the application in an appropriate
manner on the user’s display or printer device.
COMMAND DIALOG
� Command are issued to an application through a
command dialog. Three ways to implement
command dialogs are:
1) Command language
2) Command menus2) Command menus
3) Direct manipulation
� Command language for computer application
are similar to command language for operating
system.
� Primitive command language support
imperative commands with syntax<action>
<parameters>.sss
CONT..
� Command menus provide obivous advantades to
the casual user of an application,as the basic
funcationalities of the application are reflected in
the menu choices.
� A hierarchy of menus can be used to guide the � A hierarchy of menus can be used to guide the
user into the details concerning a functionality.
CONT…
� A direct manipulation system provides the user
with a visual display of the universe of the
application. The display shows the important
objects in the universe.
� Actions or opreations over objects are indicated � Actions or opreations over objects are indicated
using some kind of pointing device,
� EG. A cursor or mouse.
PRINCIPLE OF COMMAND DIALOG DESIGN
1) Ease of use
2) Consistency in command structure
3) Immediate feedback on user commands
4) Error handling
On line help to avoid memorizing command 5) On line help to avoid memorizing command
details
6) Undo facility
7) Shortcut for experienced users
STRUCTURE OF A USER INTERFACE
� The UI consist of two main compenents,presentation manager and dialog manager.
� Structure diagram for user interface:
Application
user
interface
user
Application
code
Graphics
package
Dialog
manager
Presentation
manager
USER INTERFACE MANAGEMENT SYSTEM
� A user interface management system automates
the generation of user interface. UIMS accepts
specification of the presentation and dialog
semantics to produce the presentation and dialog
managers of the UI resp. managers of the UI resp.
� In the following we describe two UIMS.
1) Menulay
2) hypercard
MENULAY
� Menulay is an early UIMS using the screen
layout as the basis for the dialog model. The UI
designer starts by designing the user screen.
HYPERCARD
� This UIMS from appale incorporates object
orientation in the event oriented approach.
� A card has an associated screen layout containing
buttons and field.
top related