Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chap 3 Loaders and Linkers. Object program contains translated instructions and data values from the source program. Loading, which brings the object.

Similar presentations


Presentation on theme: "Chap 3 Loaders and Linkers. Object program contains translated instructions and data values from the source program. Loading, which brings the object."— Presentation transcript:

1 Chap 3 Loaders and Linkers

2 Object program contains translated instructions and data values from the source program. Loading, which brings the object program into memory for execution. Relocation, which modifies the object program so that it can be loaded address different from the location originally specified. Linking, which combines two or more separate object programs and supplies the information needed to allow between them. 3.0preview

3 A loader is a system program that performs the loading function. Many loaders also support relocation and linking. Some loaders also support relocation and linking. Linker can be used regardless of the original source programming Loader in place of loader and/or linker.

4 Fundamental functions of a loader-bringing an object program into memory and stating its execution. Loader does not need to perform such functions as linking and program relocation is checked to verify that the correct been presented for loading. 3.1Basicloaderfunction 1/5

5 3.1Basicloaderfunction 2/52/5

6 3/53/5 (1)Fig 3.2 shows algorithm for an absolute loader. This operation code must be stored in a single byte with hexadecimal value. 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 (Figure 3.2 Algorithm for an absolute loader)

7 3.1Basicloaderfunction 4/54/5 (2)When a computer is first turned on started, a special type of absolute loader, called a bootstrap loader, is executed. It loads the first program to be the first program to be run by the computer-usually an operating system. (3)Fig 3.3 shows bootstrap loader for SIC/XE. How bootstrap loader working ?

8 The bootstrap address 0 in the memory of the machine (program load for the system). Address 80, which begins the program that was loaded. This subroutine reads one character from device F1 and converts ASCII character code to the value of the hexadecimal digit that is used to read and convert a pair of characters from device F1. 3.1Basicloaderfunction 5/55/5

9 The programmer to specify address at which it will be loaded into memory for program relocation and linking, as well as functions described in the preceding section. The need for program relocation is an indirect consequence of the change to larger and more powerful computers. 3.2 Machine-dependent loader feature 1/14

10 3.2 Machine-dependent loader feature (1) Since efficient sharing of the machine (i.e. relocation), loading the demanded routines. loaders that allow for program relocation are called relocating loaders or relative loaders. (i.e. relative loaders) 2/14

11 A Modification record is used to describe each part be changed when the program is relocated. Each Modification record specifies the starting address and length of the field whose value is to be altered. 3.2 Machine-dependent loader feature 3/14

12 The Modification record scheme is a convenient means for specifying, it is not well suited for use with all machine architectures. The important difference between this example and the one in Fig. 3.4 is that the standard SIC relative addressing. In 31 Modification records, in an object program twice as large as the in Fig Machine-dependent loader feature 4/14

13 3.2 Machine-dependent loader feature (2)How relocation ? A relocation bit associated with each word of object code is needed to modify the address is to be added to the word which relocation bit is set to 1 when the program is relocated. Ex. FFC ( 前 10 個都 須做 relocation M + copy 5/14

14 The Text records are the same as before except that there is a relocation bit associated with each word of object code. Address is to be added to this word when the program words are set to 0. All 10 words of object modified during relocation in the second. The first three words are to be modified and used by the by the loader to perform program relocation in the second, the first three words are to be modified. 3.2 Machine-dependent loader feature 6/14

15 3.2 Machine-dependent loader feature (3)Some computers provide a hardware solution to perform program relocation. Ex. X86 電腦 … CS : IP … 7/14

16 Section showed a program made up of three control sections that could be assembled independently of one. Program contains a list of items; the ends of these lists are marked by the beginnings and ends of the lists are external symbols(they are available for use in linking). 3.2 Machine-dependent loader feature 8/14

17 The first program(PROGA) reference to a label within the program. In PROGB, on the other hand, the same operand an extended-format instruction address field set to The symbol LISTA to this address field when the program is linked. 3.2 Machine-dependent loader feature 9/14

18 For PROGA, the operand expression consists of an external reference plus a constant, the assembler has all of the information necessary to compute this value. The values of the labels are unknown. Absolute value independent of the locations at which the programs are loaded. 3.2 Machine-dependent loader feature 10/14

19 3.2 Machine-dependent loader feature (4) Program linking *REF1: PROGApc relativeno relocation or linking. PROGB (and PROGC)modification record *REF2: PROGA (and PROGC)modification record PROGBpc relative no relocation or linking *REF3: PROGAimmediate operation PROGB (and PROGC)two external modification *REF4: PROGAsimple external reference PROGBcomplication of relocation and external reference Figure 3.10(b) shows the relocation and linking operations performed on REF4 from PROGA 11/14

20 The remaining term are passed on to the loader via Modification, the assembler for PROGA can evaluate. In PEF4 except for the value of LISTC in PROGB contains no terms that can be evaluated by the assembler, that can supply the value of LISTC relative to the beginning of the program relative address of LISTC instruct the loader to add the beginning address of the program add the value of ENDA relocation and external references for PROGC. 3.2 Machine-dependent loader feature 12/14

21 Program as they might appear in memory after loading and linking, reference REF4 in PROGA is located at address 4054 (address of PROGA plus 0054, the relative address PROGA), LISTC is 4112(the beginning address of PROGC), REF4 is located at relative address 70. The initial value (000000), the loader adds the values of LISTC (4112) and subtracts the value of LISTA (4040). 3.2 Machine-dependent loader feature 13/14

22 For the reference that are instruction operands, the calculated values after loading do not always appear to be equal. REF1 is an extended format instruction that contains a direct(actual) address. 3.2 Machine-dependent loader feature 14/14

23 Relocation and linking operations performed on REF4 from PROGA HPROGA …..(REF4) T F …... M LISTC … PROGA HPROGC ….. DLISTC …... PROGC … 0000 ….(REF4) 4050 …… ….….….…. Memory contents 4112 (Actual address PROGA of LISTC) + + LOAD addresses PROGB PROGC 0040E2 Fig3.10(b)

24 3.2.3 Tables and logic for a linking loader (1)The linking loader usually makes two passes over its input: Pass 1 assigns addresses to all external symbols pass 2 performs the actual loading, relocation, and linking.

25 The table also often indicates in which control section the symbol is defined. PROGADDR is the beginning address assigned to the control section currently to all relative addresses within convert them to actual addresses. The loader is concerned only with Define record types in the control sections Tables and logic for a linking loader

26 ESTAB contains all external symbols defined in the set with the address assigned to each. The ability to print a load map that shows these symbols and their addresses Tables and logic for a linking loader

27 3.2.3 Tables and logic for a linking loader (2) Algorithm for Pass 1 of a linking loader: Pass 1: begin get PROOADDR from operating system set CSADDR to PROOADDR {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 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'} add CSLTH to CSADDR {starting address for next control section} end {while not EOF} end {Pass 1} Figure 3.11 (a) Algorithm for Pass 1 of a linking loader.

28 3.2.3 Table b s egin and logic for a linking loader (3) Algorithm for Pass 2 of a linking loader: Pass 2: set CSADDR to PROOADDR set EXECADDR to PROOADDR 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 EXECADDR {to start execution of loaded program) end {Pass 2} Figure 3.11(b) Algorithm for Pass 2 of a linking loader.

29 The loader is usually the transferring of control to the loaded program to begin execution. The address of the first instruction in that control section specifies a transfer address, the loader arbitrarily uses the least one encountered. The reference number 01 to the control section symbols may be assigned number as part Tables and logic for a linking loader

30 3.3 MACHINE-INDEPENDENT LOADER FEATURES 1/6 Most loaders include fewer different features are found in the typical assembler. Automatic library search allows a programmer to use standard subroutines without explicitly including them in the program to be loaded.

31 Linking loaders can automatically incorporate routines from a subprogram library into the program being loaded. Libraries may be specified by control by parameters to the loader called by the program being loaded are automatically fetched from the library, the main program referred to as automatic library call to avoid confusion with the call feature found in most programming languages. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 1/6

32 3.3 MACHINE-INDEPENDENT LOADER FEATURES 2/6 (2)Linking loader with automatic library search must keep of symbols that are referred to, but not defined, enter symbols from each Refer record symbol table (ESTAB) unless these symbols are already present. At the end of Pass1, the symbols in ESTAB that remain undefined represent unresolved external references. Libraries specified for routines that contain the definition of these symbols. If there exists unresolved external references, these must be treated as errors.

33 The process just described allows the programmer to override, the library by supplying his or her own routines. For example, the end Pass 1 of the order, SQRT would already be defined, any library search that might be necessary. The subroutines contains a directory that of each routine and a pointer to its address within the file, both names are entered into the directory. The object programs indicated by this search. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 1/6

34 3.3 MACHINE-INDEPENDENT LOADER FEATURES 3/6 (3)Many loaders have a special command language that is used to specify options:.Selection of alternative sources of input: INCLUDE program-name (library-name).Deletion of the named control section(s): DELETE csect-name.Change external symbol name: CHAGNGE name1,name2.Automatic inclusion of library routines: LIBRARY MYLIB.Unresolved external references: NOCALL STDDEV,PL T,CORREL N.o external references are resolved by library search. O.utput from the loader.Executed starting address.Errors handling

35 Many loaders allow the user to specify options that modify the standard processing described in Section 3.2. Sometimes there is a separate input file to the loader that contains such control statements. Loader control source program, and the assembler or compiler retains, read the designed object program from a library, it were part of the primary loader input. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 2/6

36 3.3 MACHINE-INDEPENDENT LOADER FEATURES 4/6 (4)The actual loading of segment during program execution is handled by an overlay manager, which is automatically included in the root segment of the overlay program by the loader.

37 The external symbol name1 to be changed to name2 wherever containing the object program if Fig is the primary loader input with the loader commands. The loader to include control sections READ from the library UTLIB, COPY had been to READ and WRITE. Libraries are normally searched before the standard, some references not be resolved in this main function the data using the routines STDDEV, PLOT, and CORREL a statistical library. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 4/6

38 3.3 MACHINE-INDEPENDENT LOADER FEATURES 5/6 (5)Overlay rule:If a segment S is present in memory,all of the other segments that lie on the path from S to the root must also be present.

39 3.3 MACHINE-INDEPENDENT LOADER FEATURES 6/6 (6)Example of overlay management (Fig.3.16): Segments 1,2 and 4 are loaded ->+JSUB B ->SEGTAB ->segment 2 ->return to segment 1 ->+ JSUB D ->SEGTAB->OVLMGRsegment 6 is loaded from SEGFILE into memory and SEGTAB is updated and segments 4 and 2 are removed ->segment 6->return to segment 1.

40 Organizing the loading functions, including relocation and linking. Loaders as described, perform all linking and relocation at load time. We discuss two alternatives to this : linkage editors, which perform linking prior to load time, Linking in which the linking function is performed at execution time. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 6/6

41 Linkage editor performs linking and some relocation; however, the linked program is written library instead of being immediately loaded into memory. Reduces the overhead when the program is executed. At load time is a very simple form of relocation. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 6/6

42 Linking loader is illustrated in Fig The order hand, produces a linked version of the program (called a load module or an executable image). The linkage editor performs relocation of all control sections relative to the start of the linked program, symbol table required. This involves much less overhead than using a linking loader. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 6/6

43 A program is to be executed many times without being reassembled, required resolution references and library searching are only performed once, it is reassembled for nearly every execution, development and testing environment. The steps of writing and reading the linked program. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 6/6

44 The linked program produced by the linkage editor is generally in a form that is suitable for processing by a relocating loader. Some mechanism such as Modification records or a bit mask. References is often retained in the linked program. The linked reprocessed by the linkage editor. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 6/6

45 3.4 LOADER DESIGN OPTIONS (1) Linking loaders: it performs all linking and relocation at load time. Linkage editors: it performs linking prior to load time. Linkage linking: it performs linking at execution time. 1/14

46 Processing of an object program using (a) linking loader and (b)linkage editor Object program(s ) Linking loader memory (a) Library Object program(s ) Linkage loader Library Relocating loader memory (b)

47 3.4 LOADER DESIGN OPTIONS (2)If a program is to be executed many times without being reassembled, the use of a linkage editor substantially reduces the overhead required. 2/14

48 ( 3)Linkage editors often allow the user to specify that external references are not be resolved by automatic library search. Ex. consider 100 FORTRAN programs using the I/O routines stored on a library. Linkage editors can perform all of the needed relocation that is an exact image of the way the program during execution an absolute object program. 3.4 LOADER DESIGN OPTIONS 3/14

49 Many useful functions besides simply preparing an object program for execution. Program number of subroutines changed to correct an error or to improve efficiency. The new version of PROJECT is assembled or can be used to replace this subroutine in the linked version of PLANNER. 3.4 LOADER DESIGN OPTIONS 4/14

50 Linkage editors used to build packages of subroutines or general used together. Large number of subroutines that used to handle formatted input and output format specifications. Named FTNIO could be indexed in the directory of SUBLIB, search of SUBLIB retrieve FINIO instead of the separate routines. 3.4 LOADER DESIGN OPTIONS 5/14

51 Dynamic Linking Linking operations before the program is loaded for operations at load time. In the linking function until execution time : subroutine is loaded and linked to the rest of the program function is usually called dynamic linking, dynamic loading, or load on call. 3.4 LOADER DESIGN OPTIONS 6/14

52 Dynamic linking is often used to allow several executing programs to con copy of a subroutine or library, and used for references to software objects, makes it possible for one object to be shared by programs, as discussed previously. Dynamic linking library routines in this library could be loaded into the memory, separate copy into each object program. 3.4 LOADER DESIGN OPTIONS 7/14

53 Program contains subroutines that correct or clearly diagnose errors are rare, and diagnostic routines may during most executions of the program, every time the program is run the routines only when (and if) needed saving of time and memory space. 3.4 LOADER DESIGN OPTIONS 8/14

54 The exact routines needed cannot be predicted until the program examine its input. The library subroutines could potentially be needed, the entire library for each execution, set of subroutines that might be used. Figure 3.14 illustrates operating system service request. 3.4 LOADER DESIGN OPTIONS 9/14

55 3.4 LOADER DESIGN OPTIONS Dynamic linking avoids the necessity of loading the entire library for each execution. Instead of executing a JSUB instruction that refers to an external symbol, the program makes a load-and-call service request to the operating system (delayed binding). 10/14

56 BIOS Bootstrap loader Memory Disk Loader OS Bootstrap loader working !! BACK 1.Power on 2.Load Bootstrap loader from ROM to Memory 3.Bootstrap loader loads Loader from Disk 4.Loader loads OS from Disk 5.Transfer control form loader to OS ROM

57 Dynamic Linking working Load-and-call ERRHANDL Library Dynamic loader (part of the operating system) User program ERRHANDL

58 Dynamic Linking working Control transfer Library Dynamic loader User program ERRHANDL

59 Dynamic Linking working Load-and-call ERRHANDL Library Dynamic loader User program ERRHANDL

60 JSUB instruction that refers to an external symbol, a load-and-call service request to the operating system, not the routine is already loaded. The operating system to the routine being called. Subroutine completes its processing, it returns to its caller, then returns control to the program that request. Subroutine is completed, that was allocated to load it may be released for after use as long as the storage needed for other processing, shown in Fig LOADER DESIGN OPTIONS 11/14

61 The association of an actual address with the symbolic name of called routine is not made until the call statement is executed from load time until execution time. 3.4 LOADER DESIGN OPTIONS 12/14

62 How is the loader it self loaded into memory? A predefined location in memory, the object code for switches on the computer console. Absolute loader program is read-only memory (ROM). The machine begins to execute this ROM program. 3.4 LOADER DESIGN OPTIONS 13/14

63 Intermediate solution is to have a hardware function that reads a fixed-length record from some device into memory at a fixed location. This record contains machine instructions that load the absolute program that loading process requires more instructions than can be read. The first referred to as a bootstrap loader. 3.4 LOADER DESIGN OPTIONS 14/14


Download ppt "Chap 3 Loaders and Linkers. Object program contains translated instructions and data values from the source program. Loading, which brings the object."

Similar presentations


Ads by Google