unit iii lodaers linkers pbb
DESCRIPTION
This ppt will help to understand the concept of loader and linkers in system softwareTRANSCRIPT
UNIT-IIILoaders and Linkers
1
Loaders
• A loader is a system program that performs the loading function.– many also support relocation & linking– others have a separate linker and loader
• Basic Functions– bringing an object program into memory– starting its execution
2
Input• Object program:
– contains translated instructions and data from the source program.
– specifies addresses in memory where these items are to be loaded.
3
Basic Functions
• Allocation: allocate space in memory for the programs
• Linking: Resolve symbolic references between object files– combines two or more separate object programs – supplies the information needed to allow
references between them
4
Basic Functions
• Relocation: Adjust all address dependent locations, such as address constants, to correspond to the allocated space– modifies the object program so that it can be
loaded at an address different from the location originally specified
• Loading: Physically place the machine instructions and data into memory
5
Basic Functions
6
Design of an AbsoluteLoader
• Its operation is very simple– no linking or relocation
• Single pass operation– check H record to verify that correct program has
been presented for loading– read each T record, and move object code into
the indicated address in memory– at E record, jump to the specified address to
begin execution of the loaded program.
7
8
Example of Object Program
H _ COPY 001000 _ 00107A
T _ 001000 _ 1E1 _ 41033 _ 482039 _ 001036 _ 281030 _ 301015 _ 482061 _ 3C1003 _ 00102A _ 0C1039 _ 00102D
T _ 00101E _ 15 _ 0C1036 _ 482061 _ 081033 _ 4C0000 _ 454F46 _ 000003 _ 000000
T _ 002039 _ 1E 041030 _ 001030 _ E0205D _ 30203F _ D8205D _ 281030 _ 302057 _ 549039 _ 2C205E _ 38203F
T _ 002057 _ 1C _ 101036 _ 4C0000 _ F1 _ 001000 _ 041030 _ E02079 _ 302064 _ 509039 _ DC2079 _ 2C1036
T _ 002073 _ 07 _ 382064 _ 4C000 _ 05
E _ 001000
Object Program – each byte of assembled code is given using its hexadecimal
representation in character form– easy to read by human beings
In general– each byte of object code is stored as a single byte – most machine store object programs in a binary form– we must be sure that our file and device conventions do not
cause some of the program bytes to be interpreted as control characters
No text record corresponds here.XXX indicates that the previouscontents of these locations remainunchanged.
Absolute Loader Algorithm
Begin
read Header record
verify program name and length
read first Text record
While record type ≠ ‘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
Loader Schemes
• Compile and Go– The assembler run in one part of memory– place the assembled machine instructions and
data, as they are assembled, directly into their assigned memory locations
– When the assembly is completed, the assembler causes a transfer to the starting instruction of the program
11
Absolute Loader
12
Disadvantages
• A portion of memory is wasted because the memory occupied by the assembler is unavailable to the object program.
• It is necessary to re-translate (assemble) the user's program file every time it is run.
• It is very difficult to handle multiple segments, especially if the source programs are in different.
13
Disadvantages• If changes were made to MAIN that increased its
length to more than 300 bytes– the end of MAIN (at 100 + 300 = 400) would overlap
the start of SQRT (at 400)– It would then be necessary to assign SQRT to a new
location • changing its START and re-assembling it
• Furthermore, it would also be necessarily to modify all other subroutines that referred to the address of SQRT.
14
A Simple Bootstrap Loader• Bootstrap Loader
– When a computer is first tuned on or restarted, a special type of absolute loader, called bootstrap loader is executed
– This bootstrap loads the first program to be run by the computer -- usually an operating system
• Example (SIC/XE bootstrap loader)– The bootstrap itself begins at address 0 – It loads the OS starting address 0x80– No header record or control information, the
object code is consecutive bytes of memory
SIC/XE Bootstrap Loader LogicBeginX=0x80 (the address of the next memory location to be loaded Loop
AGETC (and convert it from the ASCII character code to the value of the hexadecimal digit)
save the value in the high-order 4 bits of SAGETC
combine the value to form one byte A (A+S)store the value (in A) to the address in register XXX+1
End
0~9 : 48 A~F : 65
GETC Aread one characterif A=0x04 then jump to 0x80if A<48 then GETCA A-48 (0x30)if A<10 then returnA A-7 (48+7=55)return
BOOTSTRAP LOADERSHow is the loader itself loaded into the memory ?• When computer is started – with no program in
memory, a program present in ROM ( absolute address) can be made executed – may be OS itself or A Bootstrap loader, which in turn loads OS and prepares it for execution.
• The first record ( or records) is generally referred to as a bootstrap loader – makes the OS to be loaded
• Such a loader is added to the beginning of all object programs that are to be loaded into an empty and idle system
MACHINE-DEPENDENT LOADER FEATURES
Absolute Loader – Simple and efficient
Disadvantage is – programmer has to specify the starting address
One program to run – no problem – not for several
Difficult to use subroutine libraries efficiently
RELOCATION
Execution of the object program using any part of the available and sufficient memory
The object program is loaded into memory wherever there is room for it
The actual starting address of the object program is not known until load time
RELOCATING LOADERS
•Efficient sharing of the machine with larger memory and when several independent programs are to be run together•Support the use of subroutine libraries efficiently
METHODS FOR SPECIFYING RELOCATION
•Use of modification record Refer Figure•Use of relocation bit Refer Figure
•Each instruction is associated with one relocation bit•These relocation bits in a Text record is gathered into bit masks
MODIFICATION RECORD
Modification recordcol 1: Mcol 2-7: relocation address col 8-9: length (halfbyte)col 10: flag (+/-)col 11-17: segment name
•For complex machines•Also called RLD specification
- Relocation and Linkage Directory
HCOPY 000000 001077
T000000 1D17202D69202D48101036…
4B105D3F2FEC032010
T00001D130F20160100030F200D4B10105D3E2003454F46
T001035 1DB410B400B44075101000…
33200857C003B850
T0010531D3B2FEA1340004F0000F1..53C003DF2008B850
T00070073B2FEF4F000005
M00000705+COPY
M00001405+COPY
M00002705+COPY
E000000
Object program with relocation by Modification records
PROGRAM LOGIC FOR PASS 1
• Pass 1: – - Assign addresses to all external symbols
• Variables & Data structures• - PROGADDR (program load address) from OS• - CSADDR (control section address)• - CSLTH (control section length• - ESTAB• Refer Algorithm for Pass 1 of LL in Fig. 3.11(a)
– - Process Define Record
begin
get PROGADDR from operating system
set CSADDR to PROGADDR {for first control section}
while not end of input do
begin
read next input record {Header record for control section}
set CSLTH to control section length
search ESTAB for control section name
if found then set error flag {duplicate external symbol}
else enter control section name into ESTAB with value CSADDR
while record type != ‘E’ do
begin
read next input symbol
if record type = ‘D’ then
for each symbol in the record do
begin
search ESTAB for symbol name
if found then set error flag (duplicate external symbol)
else enter symbol into ESTAB with value (CSADDR + indicated address)
end {for}
end {while != ‘E’}
add CSLTH to CSADDR {starting address for next control section}
end {while not EOF}
Linking Loader - Pass1
(Assigns addresses to all external symbols)
ESTAB = External symbol tablePROGADDR = Program load addressCSADDR = Control section address
PROGRAM LOGIC FOR PASS 2
• Pass 2: – - Perform the actual loading, relocation, and
linking• Modification record
– - Lookup the symbol in ESTAB• End record for a main program
– - Transfer address• Refer Algorithm for Pass 2 of LL in Fig. 3.11(b)
– - Process Text record and Modification record
Begin
Set CSADDR to PROGADDR
Set EXECADDR to PROGADDR
While not end of input do
begin
read next input record {Header record}
set CSLTH to control section length
while record type != ‘E’ do
begin
read next input record
if record type = ‘T’ then
begin
{if object code is in character form, convert into internal representation}
move object code from record to location (CSADDR + specified address)
end {if ‘T’}
else if record type = ‘M’ then
begin
search ESTAB for modifying symbol name
if found then add or subtract symbol value at location (CSADDR + specified address)
else set error flag (undefined external symbol)
end {if ‘M’}
end {while != ‘E’}
if an address is specified {in End record} then set EXECADDR to (CSADDR + specified address)
add CSLTH to CSADDR
end {while not EOF}
Jump to location given by EXECDDR {to start execution of loaded program}
Pass2
(Perform actual loading, relocation, and linking)