1 / 63

Cha p 3 Loader s an d Linkers

Cha p 3 Loader s an d Linkers. 3. 0 preview. Object program contains translated instructions and data values from the source program. Loading , which brings the object program into memory for execution.

norah
Download Presentation

Cha p 3 Loader s an d Linkers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chap3 Loaders and Linkers

  2. 3.0 preview • 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. 3.0 preview A loaderisasystemprogramthatperformstheloadingfunction. Many loaders also support relocation and linking. Some loaders also support relocationandlinking. Linker can be used regardless of the original source programming Loader in place of loader and/or linker.

  4. 3.1 Basic loader function 1/5 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.

  5. 3.1 Basic loader function 2/5 Text record for loading, the object code it contains is moved to the indicated address in memory. The specified address to begin execution of the loaded for which is not there is no Text record shown as .

  6. 3.1 Basic loader function 3/5 (1)Fig 3.2 shows algorithm for anabsolute 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 whilerecord type != 'E'do begin {if object code is in character form, convert into internal representation} moveobjectcodetospecifiedlocationinmemory read next object program record end jump to address specified in End record end (Figure 3.2 Algorithm for an absolute loader)

  7. 3.1 Basic loader function 4/5 (2)Whenacomputerisfirstturnedonstarted,aspecialtypeofabsolute loader,calledabootstraploader,is executed.Itloadsthefirstprogram tobethefirstprogramtoberunby thecomputer-usuallyanoperating system. (3)Fig 3.3 shows bootstrap loader for SIC/XE. How bootstrap loader working ?

  8. 3.1 Basic loader function 5/5 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.

  9. 3.2 Machine-dependent loader feature 1/14 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.

  10. 3.2 Machine-dependent loader feature 2/14 • (1)Since • efficientsharingofthemachine(i.e.relocation), • loadingthedemandedroutines. • loaders that allow for program relocation arecalled relocating loaders or relative loaders. • (i.e.relativeloaders)

  11. 3.2 Machine-dependent loader feature 3/14 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.

  12. 3.2 Machine-dependent loader feature 4/14 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. 3.5.

  13. 3.2 Machine-dependent loader feature 5/14 (2)How relocation ? A relocation bit associatedwitheachwordofobject codeisneededtomodifytheaddressisto beaddedtothewordwhich relocationbitissetto1whentheprogramis relocated. Ex. FFC 1111 140033 1111 1100 (前10個都 481039 須做relocation M+ copy M+copy

  14. 3.2 Machine-dependent loader feature 6/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.

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

  16. 3.2 Machine-dependent loader feature 8/14 Section 2.3.5 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).

  17. 3.2 Machine-dependent loader feature 9/14 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 00000. The symbol LISTA to this address field when the program is linked.

  18. 3.2 Machine-dependent loader feature 10/14 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.

  19. 3.2 Machine-dependent loader feature 11/14 • (4) Program linking • REF1: PROGA pc relative no relocation or linking. • PROGB (and PROGC) modification record • REF2: PROGA (and PROGC) modification record PROGB pcrelativenorelocationorlinking • REF3: PROGA immediate operation • PROGB (and PROGC) two external modification • REF4: PROGA simple external reference PROGB complicationofrelocationandexternal reference • Figure 3.10(b) shows the relocation and linking operations performed on REF4 from PROGA

  20. 3.2 Machine-dependent loader feature 12/14 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.

  21. 3.2 Machine-dependent loader feature 13/14 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).

  22. 3.2 Machine-dependent loader feature 14/14 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.

  23. Relocation and linking operations performed on REF4 from PROGA Memorycontents HPROGA… .. (REF4) T0000540F000014…. .. PROGA 0000 …. (REF4) 4050……004126 + …. …. M00005406+LISTC … … PROGC LOAD addresses HPROGC… 4112 + 004000 (Actualaddress PROGA .. DLISTC000030…. PROGB 004063 PROGC 0040E2 ofLISTC) .. Fig3.10(b)

  24. 3.2.3 Tables and logic fora 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. 3.2.3 Tables and logic fora linking loader 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.

  26. 3.2.3 Tables and logic fora linking loader 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.

  27. 3.2.3 Tables and logic fora linking (2) Algorithm for Pass 1of a linking loader: loader Pass 1: begin get PROOADDR from operating system set CSADDR to PROOADDR {for first controlsection} while not end of inputdo begin read next input record {Header recordfor 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 readnextinputrecord if record type = 'D' then for each symbol in the record do begin searchESTABforsymbolname iffoundthen set error flag (duplicate external symbol) else enter symbol into ESTAB withvalue (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) Algorithm for Pass 2of a linking loader: Pass 2: 3.2.3 Tablebseginand logic fora linking set CSADDR to PROOADDR set EXECADDR to PROOADDR while not end of inputdo begin read next input record {Header record} set CSLTH to control section length while record type != 'E' do begin readnextinputrecord if record type = 'T'then -~ begin {if object code is in character form, convert intointernalrepresentation} move object code from record to location (CSADDR + specified address) end {if 'T'} else if recordtype = 'M' then begin searchESTABformodifyingsymbolname if found then add or subtractsymbolvalue 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 givenby EXECADDR {to start execution of loadedprogram) end {Pass 2} Figure 3.11(b) Algorithm for Pass2 of a linking loader. loader

  29. 3.2.3 Tables and logic fora linking loader 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.

  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 withoutexplicitlyincludingtheminthe programtobeloaded.

  31. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 1/6 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.

  32. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 2/6 (2)Linkingloaderwithautomaticlibrary searchmust keep of symbols that are referred to, butnotdefined, enter symbols from each Refer record symbol table (ESTAB) unless these symbols are already present. Atthe endofPass1,the symbols in ESTAB that remain undefined represent unresolved external references. Librariesspecified for routines that contain the definition of these symbols. Ifthereexists unresolved external references, these must be treated as errors.

  33. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 1/6 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.

  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: CHAGNGEname1,name2 .Automatic inclusion of library routines: LIBRARY MYLIB .Unresolved external references: NOCALL STDDEV,PL T,CORREL o external references are resolved by library search. utput from the loader .Executedstartingaddress .Errors handling

  35. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 2/6 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.

  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. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 4/6 The external symbol name1 to be changed to name2 wherever containing the object program if Fig. 2.17 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.

  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 ->+ JSUBD ->SEGTAB->OVLMGRsegment6 is loaded from SEGFILE into memory and SEGTAB is updated and segments 4 and 2 are removed ->segment 6->return to segment 1.

  40. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 6/6 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.

  41. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 6/6 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.

  42. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 6/6 Linking loader is illustrated in Fig. 3.13. 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.

  43. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 6/6 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.

  44. 3.3 MACHINE-INDEPENDENT LOADER FEATURES 6/6 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.

  45. 3.4 LOADER DESIGNOPTIONS 1/14 (1) Linking loaders: it performs all linkingand relocation at loadtime. Linkageeditors: it performs linkingprior to load time. Linkage linking: it performs linkingat executiontime.

  46. Processingofanobjectprogramusing(a)linking loaderand (b) linkageeditor Object program(s) Object program(s) Linkageloader Library Library Linking loader Library Relocatingloader memory (a) (b) memory

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

  48. 3.4 LOADER DESIGN OPTIONS 3/14 (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.

  49. 3.4 LOADER DESIGN OPTIONS 4/14 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.

  50. 3.4 LOADER DESIGN OPTIONS 5/14 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.

More Related