Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter - 3 Loaders & Linkers. Overview of Chapter 3 Basic Loader Functions Design Issues of: An Absolute Loader Simple Bootstrap Loader Machine-Dependent.

Similar presentations


Presentation on theme: "Chapter - 3 Loaders & Linkers. Overview of Chapter 3 Basic Loader Functions Design Issues of: An Absolute Loader Simple Bootstrap Loader Machine-Dependent."— Presentation transcript:

1 Chapter - 3 Loaders & Linkers

2 Overview of Chapter 3 Basic Loader Functions Design Issues of: An Absolute Loader Simple Bootstrap Loader Machine-Dependent loader Features Relocation Program linking Algorithm & Data Structures for a Linking Loader Machine-Independent loader Features Automatic Library Search Loader Options

3 Loader Design options –Linkage Editors –Dynamic Linking –Bootstrap Loaders – Implementation Examples Overview of Chapter 3 (contd…)

4 Basic loader functions: The loader brings an object program into memory and starts its executions.

5 There are 2 type of loader:- 1) Absolute loader. 2) A simple bootstrap loader. Types of loaders:

6  Absolute loader need not perform the functions like:- Program Linking and Program Relocation  All the functions are performed in a single pass  Header record is checked for program correctness  Text records gets the object code is moved into the memory as per the indicated address Design of an absolute loader.

7 Consider the COPY program: Line Loc Source statement Object code 5 1000 COPY START 1000 --- 10 1000 STL RETADR 141033 15 1003 CLOOP JSUB RDREC 482039 20 1006 LDA LENGTH 001036 25 1009 COMP ZERO 281030 30 100C JEQ ENDFIL 301015 35 100F JSUB WRREC 482061 40 1012 J CLOOP 3C1003 45 1015 ENDFIL LDA EOF 00102A 50 1018 STA BUFFER 0C1039 55 101B LDA THREE 00102D 60 101E STA LENGTH 0C1036 65 1021 JSUB WRREC 482061 70 1024 LDL RETADR 081033

8 Line Loc Sourse StatementObject Code 75 1027 RSUB 4C0000 80 102A EOF BYTE C’EOF’ 454F46 85 102D THREE WORD 3 000003 90 1030 ZERO WORD 0 000000 95 1033 RETADR RESW1 100 1036 LENGTH RESW1 105 1039 BUFFER RESB4096 110. 115. subroutine to read record in to buffer 120. 125 2039 RDREC LDX ZERO 041030 130 203C LDA ZERO 001030

9 Line Loc Source Statement Object Code 135 203F RLOOP TD INPUT E0205D 140 2042 JEQ RLOOP 30203F 145 2045 RD INPUT D8205D 150 2048 COMP ZERO 281030 155 204B JEQ EXIT 302057 160 204E STCH BUFFER,X 549039 165 2051 TIX MAXLEN 2C205E 170 2054 JLT RLOOP 38203F 175 2057 EXIT STX LENGTH 101036 180 205A R SUB 4C0000 185 205D INPUT BYTE X ‘F1’ F1 190 205E MAXLEN WORD 4096 001000

10 Line Loc Source Statement Object Code 195. 200. Subroutine to write record from buffer 205. 210 2061 WRREC LDX ZERO 041030 215 2064 WLOOP TD OUTPUT E02079 220 2067 JEQ WLOOP 302064 225 206A LDCH BUFFER X 509039 230 206D WD OUTPUT DC2079 235 207D TIX LENGTH 2C1026 240 2073 JLT WLOOP 382064 245 2076 RSUB 4C0000 250 2079 OUTPUT BYTE X ‘05’ 05 255 END FIRST

11 Object program H ^ COPY ^ OO107A T ^ 001000 ^ 1E ^ 141033 ^ 482039 ^ 001036 ^ 281030 ^ 301015 ^ 482061 ^ 361003 ^ 00102A ^ OC1039 ^ 00102D T ^ 00101E ^ 15 ^ OC1036 ^ 482061 ^ 081033 ^ 4C000A 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 ^ 4C0000 ^ 05 E ^ 001000

12 Memory Address Contents 0000 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 0010 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx …………………………. 1000 14103348 20390010 36281030 30101548 1010 20613C10 0300102A OC103900 102D0C10 1020 36482061 0810334C 0000454F 46000003 1030 000000xx xxxxxxxx xxxxxxxx xxxxxxxx …………………………… 2030 xxxxxxxx xxxxxxxx XX041030 001030E0 2040 392C205E 45498989 3456D0C 045B0900 2050 9876B432 87654321 056430C1 09876455 2060 09890123 0210C012 0560C123 0C876543 2070 2C103638 20644C00 0005 xxxx xxxxxxxx Absolute Program loaded in memory 0123 COPY

13 Algorithm for an absolute loader begin read Header record verify program name and length read first Text record while record type is ≠ ‘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

14 Asimple bootstrap loader ¢ Bootstrap Loader (usually resides in ROM) ¢ When a computer is first tuned on or restarted, a special type of absolute loader, called the bootstrap loader loads the first program (usually O.S.) to be run into memory.

15 O.S “F1” device Bootstrap loader O.S 0 80 Example (SIC bootstrap loader) The bootstrap itself begins at address 0 It loads the OS starting address 0x80 After loading the OS, No header record or control information, The object code is consecutive bytes of memory the control is transferred to the instruction at address 80.

16 Bootstrap loader for SIC/XE START @ LOCATION 0 CLEAR REGISTER ‘A’ TO ZERO INITIALIZE REGISTER X TO HEX 80 READ HEX DIGIT FROM PROGRAM SAVE IN REGISTER S MOVE TO HIGH-ORDER 4 BITS OF BYTE GET NEXT HEX DIGIT COMBINE DIGITS TO FROM ONE BYTE STORE AT ADDRESS IN REGISTER X ADD 1 TO MEMORY ADDRESS BEING LOADED UNTIL END OF INPUT IS REACHED

17 SUBROUTINE GETC Begin TEST INPUT DEVICE LOOP UNTIL READY READ CHARCTER IF CHARACTER IS HEX 04(eof) JUMP TO START OF PROGRAM JUST LOADED COMPARE TO HEX 30 (CHARACTER ‘0’) SKIP CHARACTERS LESS THAN ‘0’ SUBTRAC HEX 30 FROM ASCII CODE IF RESULT IS LESS THAN 10, CONVERSION IS COMPLETE, RETURN else SUBTRACT #7 (FOR HEX DIGITS ‘A’ THROUGH ‘F’ ) RETURN TO CALLER END

18 Bootstrap loader for SIC/XE BOOT START #0 BOOTSTRAP LOADER FOR SIC/XE CLEAR A CLEAR REGISTER ‘A’ TO ZERO LDX #128 INITIALIZE REGISTER X TO HEX 80 LOOP JSUB GETC READ HEX DIGIT FROM PROGRAM BEING LOADED RMO A, S SAVE IN REGISTER S SHIFTL S, 4 MOVE TO HIGH-ORDER 4 BITS OF BYTE JSUB GETC GET NEXT HEX DIGIT ADDR S, A COMBINE DIGITS TO FROM ONE BYTE STCH 0, X STORE AT ADDRESS IN REGISTER X TIXR X, 1 ADD 1 TO MEMORY ADDRESS BEING LOADED J LOOP UNTIL END OF INPUT IS REACHED

19 SUBROUTINE GETC GETC TD INPUT TEST INPUT DEVICE JEQ GETC LOOP UNTIL READY RD INPUT READ CHARCTER COMP #4 IF CHARACTER IS HEX 04(eof) JEQ 80 JUMP TO START OF PROGRAM JUST LOADED COMP #48 COMPARE TO HEX 30 (CHARACTER ‘0’) JLT GETC SKIP CHARACTERS LESS THAN ‘0’ SUB #48 SUBTRAC HEX 30 FROM ASCII CODE COMP #10 IF RESULT IS LESS THAN 10, CONVERSION IS COMPLETE, JLT RETURN OTHERWISE, SUBTRACT #7 MORE SUB#7 (FOR HEX DIGITS ‘A’ THROUGH ‘F’ ) RETURN RSUB RETURN TO CALLER INPUT BYTE X’F1’ CODE FOR INPUT DEVICE END LOOP

20 Machine - Dependent Loader features There are three feature:- 1) Relocation 2) Program Linking 3) Algorithm and Data Structures for a Linking Loader.

21 1) Relocation The loaders that allow for program relocation are called relocating loaders or relative loaders Definition:-

22 a) Modification Records Extended Instruction formats

23 Example of a SIC/XE program Line Loc Source statement Object code 5 0000 COPY START 0 --- 10 0000 FIRST STL RETADR 17202D 12 0003 LDB #LENGTH 69202D 13 BASE LENGTH 15 0006 CLOOP +JSUB RDREC 4B101036 20 000A LDA LENGTH 032026 25 000D COMP #0 290000 30 0010 JEQ ENDFIL 332007 35 0013 +JSUB WRREC 4B10105D 40 0017 J CLOOP 3F2FEC 45 001A ENDFIL LDA EOF 032010 50 001D STA BUFFER 0F2016 55 0020 LDA #3 01 0003 60 0023 STA LENGTH 0F200D

24 Line Loc Sourse Statement Object Code 65 0026 +JSUB WRREC 4B1O1O5D 70 002A J @RETADR 3E2003 80 002D EOF BYTE C’EOF’ 454F46 95 0030 RETADR RESW 1 100 0033 LENGTH RESW 1 105 0036 BUFFER RESB 4096 110. 115. subroutine to read record in to buffer 120. 125 1036 RDREC CLEAR X B410 130 1038 CLEAR A B400 132 103A CLEAR S B440 133 103C +LDT #4096 75101000

25 Line Loc Source Statement Object Code 135 1040 RLOOP TD INPUT E32019 140 1043 JEQ RLOOP 332FFA 145 1046 RD INPUT DB2013 150 1049 COMPR A,S A004 155 104B JEQ EXIT 332008 160 104E STCH BUFFER,X 57C003 165 1051 TIXR T B850 170 1053 JLT RLOOP 3B2FEA 175 1056 EXIT STX LENGTH 134000 180 1059 RSUB 4F0000 185 105C INPUT BYTE X ‘F1’ F1 195. 200. Subroutine to write record from buffer 205. 210 105D WRREC CLEAR X B410

26 Line Loc Source Statement Object Code 195. 200. Subroutine to write record from buffer 205. 210 2061 WRREC LDT LENGTH 774000 215 2064 WLOOP TD OUTPUT E32011 220 2067 JEQ WLOOP 332FFA 225 206A LDCH BUFFER X 53C003 230 206D WD OUTPUT DF2008 235 207D TIXR T 2C1026 240 2073 JLT WLOOP 3B2FEF 245 2076 RSUB 4F0000 250 2079 OUTPUT BYTE X ‘05’ 05 255 END FIRST

27 Object program with relocation by Modification records H ^ COPY ^ OO1077 T ^ 001000 ^ 1D ^ 17202D ^ 69202D ^ 001036 ^ 281030 ^ 301015 ^ 482061 ^ 361003 ^ 00102A ^ OC1039 ^ 00102D T ^ 00101E ^ 15 ^ OC1036 ^ 482061 ^ 081033 ^ 4C000A 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 ^ 4C0000 ^ 05 M ^ 000007 ^ 05 + COPY M ^ 000014 ^ 05 + COPY M ^ 000027 ^ 05 + COPY E ^ 001000

28 b) Relocation bits  Relocation bits grouped into “bit mask”  12-bit fixed format  But the text record size is 10 to 69 = 60/2( 2columns / byte) =30 bytes => 10 words

29 Consider the COPY program: Line Loc Source statement Object code RB 5 1000 COPY START 1000 --- 10 1000 STL RETADR 141033 1 15 1003 CLOOP JSUB RDREC 482039 1 20 1006 LDA LENGTH 001036 1 25 1009 COMP ZERO 281030 1 30 100C JEQ ENDFIL 301015 1 35 100F JSUB WRREC 482061 1 40 1012 J CLOOP 3C1003 1 45 1015 ENDFIL LDA EOF 00102A 1 50 1018 STA BUFFER 0C1039 1 55 101B LDA THREE 00102D 1 60 101E STA LENGTH 0C1036 1 65 1021 JSUB WRREC 482061 1 70 1024 LDL RETADR 081033 1 1

30 Line Loc Sourse Statement Object Code RB 75 1027 RSUB 4C0000 0 80 102A EOF BYTE C’EOF’ 454F46 0 85 102D THREE WORD 3 000003 0 90 1030 ZERO WORD 0 000000 0 95 1033 RETADR RESW 1 0 100 1036 LENGTH RESW 1 0 105 1039 BUFFER RESB 4096 0 110. 115. subroutine to read record in to buffer 120. 125 2039 RDREC LDX ZERO 041030 130 203C LDA ZERO 001030

31 Line Loc Source Statement Object Code 135 203F RLOOP TD INPUT E0205D 140 2042 JEQ RLOOP 30203F 145 2045 RD INPUT D8205D 150 2048 COMP ZERO 281030 155 204B JEQ EXIT 302057 160 204E STCH BUFFER,X 549039 165 2051 TIX MAXLEN 2C205E 170 2054 JLT RLOOP 38203F 175 2057 EXIT STX LENGTH 101036 180 205A R SUB 4C0000 185 205D INPUT BYTE X ‘F1’ F1 190 205E MAXLEN WORD 4096 001000

32 Line Loc Source Statement Object Code 195. 200. Subroutine to write record from buffer 205. 210 2061 WRREC LDX ZERO 041030 215 2064 WLOOP TD OUTPUT E02079 220 2067 JEQ WLOOP 302064 225 206A LDCH BUFFER X 509039 230 206D WD OUTPUT DC2079 235 207D TIX LENGTH 2C1026 240 2073 JLT WLOOP 382064 245 2076 RSUB 4C0000 250 2079 OUTPUT BYTE X ‘05’ 05 255 END FIRST

33 Object program with relocation by bit mask H ^ COPY ^ OO107A T ^ 001000 ^ 1E ^ FFC ^ 141033 ^ 482039 ^ 001036 ^ 281030 ^ 301015 ^ 482061 ^ 361003 ^ 00102A ^ OC1039 ^ 00102D T ^ 00101E ^ 15 ^ E00 ^ OC1036 ^ 482061 ^ 081033 ^ 4C000A 454F46 ^ 000003 ^ 000000 T ^ 002039 ^ 1E ^ FFC ^ 041030 ^ 001030 ^ E0205D ^ 30203F ^ D8205D ^ 281030 ^ 302057 ^ 549039 ^ 2C205E ^ 38203F T ^ 002057 ^ 1A ^ 800 ^ 101036 ^ 4C0000 ^ F1 ^ 001000 ^ 041030 ^ E02079 ^ 302064 ^ 509039 ^ DC2079 ^ 2C1036 T ^ 002073 ^ 07 ^ 382064 ^ 4C0000 ^ 05 E ^ 001000

34 Program linking Goal  R R esolve the problems with EXTREF and EXTDEF from different control sections (sec 2.3.5)  A program is a logical entity that combines all of the related control sections.  C ontrol sections could be assembled together, or they could be assembled independently of one another.  C C ontrol sections are to be linked, relocated, and loaded by loaders.

35 Program linking Complex Example Program in Figure 3.8 and object code in Figure 3.9 Use modification records for both relocation and linking Consider : address constant external reference

36 Program for Linking and Relocation 0000PROGA+START+0+0 +EXTDEF+LISTA,ENDA +EXTREF+LISTB,ENDB,LISTC,ENDC +.+. +.+. 0020REF1+LDA+LISTA03201D 0023REF2+LDT+LISTB+477100004 0027REF3+LDX#ENDA-LISTA050014 +.+.+.+. 0040LISTA+EQU +*+* +.+.+.+. 0054ENDA+EQU +*+* 0054REF4+WORD000014 +ENDA-LISTA+LISTC 0057REF5+WORDFFFFF6 +ENDC-LISTC-10 005AREF6+WORD00003F +ENDC-LISTC+LISTA-1 005DREF7+WORD000014 +ENDA-LISTA-(ENDB-LISTB) 0060REF8 +WORD FFFFC0 +LISTB-LISTA +END +REF1 Instruction Operands { { Data Operands

37 Program for Linking and Relocation 0000PROGB+START+0+0 +EXTDEF+LISTB,ENDB +EXTREF+LISTA,ENDA,LISTC,ENDC +.+. +.+. 0036REF1+LDA+LISTA03100000 003AREF2+LDT+LISTB+4772027 003DREF3+LDX#ENDA-LISTA05100000 +.+.+.+. 0060LISTB+EQU +*+* +.+.+.+. 0070ENDB+EQU +*+* 0070REF4+WORD000000 +ENDA-LISTA+LISTC 0073REF5+WORDFFFFF6 +ENDC-LISTC-10 0076REF6+WORDFFFFFF +ENDC-LISTC+LISTA-1 0079REF7+WORDFFFFF0 +ENDA-LISTA-(ENDB-LISTB) 007CREF8 +WORD 000060 +LISTB-LISTA +END +

38 Program for Linking and Relocation 0000PROGC+START+0+0 +EXTDEF+LISTC,ENDC +EXTREF+LISTA,ENDA,LISTB,ENDB +.+. +.+. 0018REF1+LDA+LISTA03100000 001CREF2+LDT+LISTB+477100004 0020REF3+LDX#ENDA-LISTA05100000 +.+. +.+. 0030LISTC+EQU+*+* +.+. +.+. 0042ENDC+EQU+*+* 0042REF4+WORD+ENDA-LISTA+LISTC000030 0045REF5+WORD+ENDC-LISTC-10000008 0048REF6+WORD+ENDC-LISTC+LISTA-1000011 004BREF7+WORD+ENDA-LISTA-(ENDB-LISTB)000000 004EREF8 +WORD+LISTB-LISTA 000000 +END+

39

40 Algorithm and data structure for a linking loader considers the following conditions: Most instructions use relative addressing ; no relocation is necessary Modification records are used in this type of machine Because some external symbols are processed before read A linking loader usually makes two passes over its input.

41 Two passes linking loader Two Passes Logic Pass 1: Assign addresses to all external symbols Pass 2: Perform the actual loading, relocation, and linking Object Program (Control Sections) Pass 1 Pass 2Memory Load Map CSADDRESTAB

42 Linking loader -- Pass 1  A ssign address to all external symbols  O nly processes Header Record and Define Record  B uilds an external symbol table (ESTTAB) in which control section symbol is defined  Program Load Address (PROGADDR) The beginning address in memory where the linked program is to be loaded (supplied by OS).

43 Control Section Address (CSADDR) T he starting address assigned to the control section currently being scanned by the loader. C SADDR is added to all relative addresses within the control section.

44 Linking loader -- Pass 1 (Cond.) Add symbol to ESTAB Control section name: (name, CSADDR)  ESTAB Get control section name from H record If the first control section CSADDR = PROGADDR When E record is encountered, read the next control section CSADDR = CSADDR + CSLTH (known from H record) EXTDEF: (name, CSADDR+value in the record) ® ESTAB Get EXTDEF from D record

45 Print the load map if necessary (optional) ControlSymbolAddressLength sectionname PROGA40000063 LISTA4040 ENDA4054 PROGB4063007F LISTB40C3 ENDB40D3 PROGC40E20051 LISTC4112 ENDC4124

46 Algorithm for Pass 1 of a linking loader

47 Pass 1: begin get PROGADDR from operating system set CSSADDR 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

48 if found then set error flag {duplicate external symbol} else enter control section name into ESTAB with value CSADDR

49 While record type ≠’E’ do begin read next input record 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’ }

50 add CSLTH to CSADDR {starting address for next control section} end {while not EOF} End {Pass 1}

51 Algorithm for Pass 2 of a linking loader

52 Pass 2: begin get CSSADDR from PROGADDR set EXEADDR 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

53 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

54 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’ }

55 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 EXECADDR {to start execution of loaded program} End {Pass 2}

56 MACHINE-INDEPENDENT LOADER FEATURES The loader features that are not directly related to the machine architecture and design.

57 Two machine-independent features of the loaders:- 1) Automatic Library search 2) Loader Options

58 Automatic Library Search It allows a programmer to use standard subroutines without explicitly including them in the program to be loaded. In most cases there is a standard system. Subroutines called by the program being loaded are automatically retrieved from a library as they are needed during linking.

59 Implementation of Search Linking loader must keep track of external symbols that are referred to, but not defined. Enter symbol from each Refer record into the external symbol table (ESTAB) At the end of Pass 1, the symbol in table that remain undefined represents unresolved external references

60 The loader searches the library or libraries specified for routines that contain the definitions of these symbols Subroutines fetched from a library in this form may themselves in turn contain external references. Resolving the external references:-

61 The process allows the programmer to override the standard subroutines in the library by supplying his or her own routines The libraries to be searched by the loader ordinarily contain assembled or compiled versions of subroutines (i.e., object programs) for ex:- SQRT library function written by the programmer Override the standard subroutines

62 Directory:- In most cases, a special file structure is used for the libraries. This structure contains a directory. This directory gives the name of each routine and a pointer to its address within the file. some of the O.S’s keep the directory (commonly used libraries ) permanently in the memory

63 Loader Options Many loaders allow the user to specify options that modify the standard processing of :- Relocating and Program linking It is done with a “ special command language” (job control language) that is used to specify the option and is processed by the Operating system. Some times there is a separate input file to the loader that contains control statements. or Some times the control statements can be embedded into a control section.

64 One typical loader option allows the selection of alternative sources of input. The following are some of the loader option commands : 1) INCLUDE program-name (library-name) 2) DELETE csect - name 3) CHANGE name1 name2 4) LIBRARY MYLIB 5) NOCALL STDDEV, PLOT, CORREL

65 1) INCLUDE program-name (library-name) It directs the loader to read the designated object program from a library and treats it as if it were part of the primary loader input. Example:- INCLUDE READ(UTLIB) INCLUDE WRITE(UTLIB)

66 It instructs the loader to delete the named control sections from the set of programs being loaded. Example:- DELETE RDREC, WRREC 2) DELETE csect-name

67 It causes the “external symbol” name1 to be changed to name2 whenever it appears in the object program Example:- CHANGE RDREC, READ CHANGE WRREC WRITE 3) CHANGE name1 name2

68 The LIBRARY command allows the user to use special versions of the standard routine. Usually user-specified libraries are normally searched before the standard system libraries. 4) LIBRARY MYLIB

69 It instructs the loader to “ retain external references as unresolved”. Unresolved references may lead to error but this option is more useful when programs are to be linked but not executed immediately. This avoids the overhead of loading and linking the unnecessary routines and saves the memory space. 5) NOCALL STDDEV, PLOT, CORREL

70 Variety of other Loader options:- An ability to specify the location at which execution is to begin. Ability to control whether or not the loader should attempt to execute the program if errors are detected during the load.

71 LOADER DESIGN OPTIONS Some of the loader design options:- 1) Linkage Editor 2) Dynamic Linking 3) Bootstrap Loaders

72 Library Object programs Linking loader Memory Fig: Linking loader Linking Loader (a) Object programs (b) Linking Loader (c) Memory Perform all linking and relocation at load time

73 1) Linkage editors Perform linking prior to load time, and writes linked program (executable image) into file instead of being immediately loading into memory. Found on most systems in addition to linking loaders

74 Library Object programs Linkage editor Memory Relocating loader Linked programs Fig: Linkage editor

75 Object program:-  T he source program is first compiled or assembled, producing an object program. Linkage Editor:- II t produces an linked version of the object program which is written to a file or library for later execution. WW hen the user is ready to run the linked program, a simple relocating loader is used to load the program into memory. Linkage Editors

76 TT he linkage editor performs relocation of all control sections relative to the start of the program. TT he loading is accomplished in one pass, with no ESTAB requirement, reduces overhead II f a program is to be executed many time without being reassembled, the linkage editor comes in need. RR esolving the external references and library searching are performed only one.

77 Linked program: II t is generally in a form suitable for processing by a relocating loader AA ll external references are resolved and relocating is indicated by some mechanism, such as Modification record or bit mask EE ven though all linking has been performed, information concerning external references is often retained in the linked program RR etaining of external references allows subsequent re-linking of the program to replace control sections, modify external references, etc.  I f external symbols are not retained then the linked program cannot be reprocessed by the linkage editor.

78 Difference between linking & linkage loader Library Object programs Linking loader Memory Fig(a) : Linking loader Library Object programs Linkage editor Memory Relocating loader Linked programs Fig(b) : Linkage editor

79 Suitable Work Environments In an environment where program is to be executed many times without being reassembled use of a linkage editor -> reduces overhead resolution of external refs and library searching are performed only once (Compare to a linking loader!) In a development and testing environment a linking loader is more efficient.

80 Other Functions of Linkage Editors 1 ) when a change is made in the source code of a subroutine, linkage editor can replace this subroutine in the linked version of the program with out recompiling/reassembling all code. 2) It can be used to build packages of CSs that are generally used together Ex: FORTRAN has a large number of subroutines for formatted i/o with lots of cross-refs between them It is desirable to keep them as separate CSs for reasons of program modularity and maintainability

81 The following is a typical sequence of linkage editor commands used to accomplish the above task. INCLUDE PLANNER ( PROGLIB ) DELETE PROJECT ( Delete from existing planner ) INCLUDE PROJECT ( NEWLIB ) (include new version) REPLACE PLANNER ( PROGLIB )

82 2) Dynamic linking A subroutine is loaded and linked to the rest of the program when it is first called. This type of function is usually called dynamic linking, dynamic loading or load on cell. Dynamic linking is often used to allow several executing programs to share one copy of a subroutine or library. It is more used for reference in object oriented system. The implementation of the object & its methods to be determined at the time the program is running The implementation can be changed at any time without affecting the program that makes use of the object. Dynamic linking provides the ability to load the routines only when they are needed which save memory space and time.

83 The figure below illustrate a method in which routines requested by the user program are dynamically loaded via an operating system service request. Dynamic loader ( part of the OS ) User program Load-and–call ERRHANDL Dynamic loader ( part of the OS ) User program Library ERRHANDL ----- (a) (b)

84 Dynamic loader ( part of the OS ) User program Dynamic loader ( part of the OS ) User program ERRHANDL (c ) (d) ERRHANDL

85 Dynamic loader ( part of the OS ) User program Load-and–call ERRHANDL (e )


Download ppt "Chapter - 3 Loaders & Linkers. Overview of Chapter 3 Basic Loader Functions Design Issues of: An Absolute Loader Simple Bootstrap Loader Machine-Dependent."

Similar presentations


Ads by Google