Loaders and Linkers: Essential Functions in Program Execution

Loaders and Linkers: Essential Functions in Program Execution
Slide Note
Embed
Share

Loaders and linkers are crucial components in the process of executing object programs. Loaders bring the program into memory for execution by modifying and relocating it to fit available memory. Linkers combine separate programs and establish references between them. Machine-dependent features like relocation and bit masks play a significant role in ensuring proper program execution.

  • Loaders
  • Linkers
  • Relocation
  • Program Execution
  • Machine-Dependent

Uploaded on Mar 16, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CHAPTER 4 LOADERS AND LINKERS

  2. Loaders and Linkers Loading: To bring the object program into memory for execution. This is done by the Loader Relocation: modify the object program so that it can be loaded at an address different from the location originally specified. Linking: Combine two or more separate object programs and supply the information needed to allow references between them.

  3. How is Loading done? The header record is checked to verify that the correct program has been presented for loading and that it will fit into the available memory. As each text record is read the object code it contains is moved to the indicated address in memory. When the END record is encountered the loader jumps to the specified address to begin execution of the object program.

  4. Machine Dependent Loader Features 1. Relocation Loaders that allow program relocation are called relocating or relative loaders. There are two methods for specifying relocation as part of the object program. The records. first method uses modification

  5. Machine Dependent Loader Features There is one modification record for each value that must be changed during relocation ( i.e. at addresses 0006, 0013 and 0026). All modifications add the value of the symbol COPY which starting address of the program. represents the This method is not suitable for a program which uses absolute addressing

  6. Machine Dependent Loader Features

  7. Machine Dependent Loader Features A second method is to use relocation bits associated with each word of the object code. The together into a bit mask following the length indicator in each text record. relocation bits are gathered

  8. Machine Dependent Loader Features The mask is represented as three hexadecimal digits. If the relocation bit corresponding to a word of object code is set to 1 the program s starting address is to be added to this word when the program is to be relocated. A bit value of 0 indicates that no modification is necessary. If a text record contains fewer than 12 words of object code, the bits corresponding to the unused words are set to 0.

  9. Machine Dependent Loader Features

  10. Machine Dependent Loader Features Program Linking There are three differently assembled programs each having a list of items LISTA, LISTB and LISTC. Their ends are marked by ENDA, ENDB and ENDC

  11. Machine Dependent Loader Features

  12. Machine Dependent Loader Features

  13. Machine Dependent Loader Features

  14. Machine Dependent Loader Features

  15. Machine Dependent Loader Features

  16. Machine Dependent Loader Features

  17. Machine Dependent Loader Features In PROGA, REF1 is a reference to a label within the program which is assembled by program counter relative. No modification is necessary. In PROGB, REF1 Refers to an external symbol LISTA. The assembler uses an extended format instruction with the address field set to 000000. There is a modification record in the object program instructing the loader to add the value of LISTA to this address field when the program is linked. REF2 and REF3 are explained similarly.

  18. Machine Dependent Loader Features In PROGA the assembler can evaluate all of the expression in REF4 except for the value of LISTC. This results in an initial value of 000014 and one modification record. The same expression in PROGB contains no terms that can be evaluated by the assembler. The object has an initial value of 000000 and three modification records. In PROGC the assembler can supply the value of LISTC relative to the beginning of the program which is not known until the program is loaded. The initial value for this data word contains the relative address of LISTC = 000030. The modification records instruct the loader to add the beginning address of the program (PROGC), to add the value of ENDA and to subtract the value of LISTA.

  19. Machine Dependent Loader Features Assume that PROGA starting at address 4000 followed immediately by PROGB and PROGC. has been loaded REF4 in PROGA is located at address 4054. The initial value was 000014. To this is added the address assigned to LISTC which is 4112 (40E2 + 30). This results in the value 004126. This value will be the same at address 70 (40D3) in PROGB and at address 0042 in PROGC.

  20. Tables and Logic for a Linking Loader A linking loader makes two passes just like the assembler. Pass 1 assigns addresses to all external symbols and pass 2 performs the actual loading, relocation and linking. The External symbol table (ESTAB) is similar to the SYMTAB. It is used to store names and addresses of each external symbol in the set of control sections being loaded. It also indicates in which control section the symbol is defined.

  21. Tables and Logic for a Linking Loader The beginning address in memory where the linked program is PROGADDR. Its value is supplied to the loader by the operating system. loaded is called CSADDR is the starting address assigned to the control section currently being scanned by the loader. It is added to all relative addresses within the control section to convert them to actual addresses. CSLTH is the length of each control section. A printout of ESTAB is called a load map.

  22. EXTERNAL SYMBOL TABLE (ESTAB)

  23. MACHINE INDEPENDENT LOADER FEATURES Automatic Library Search This feature allows the programmer to use standard subroutines without explicitly including them in the program to be loaded. The routines are automatically retrieved from a library, linked with the main program and they are loaded. The programmer just mentions the subroutine names as external references in the source program. Linking loaders that support automatic library search keep track of external symbols that are referred to but not defined in the input to the loader. This is done by entering symbols for each refer record into ESTAB.

  24. MACHINE INDEPENDENT LOADER FEATURES Automatic Library Search At the end of pass 1 symbols in ESTAB that remain undefined represent unresolved external references. The loader searches the libraries specified for routines that contain definitions of these symbols and processes the subroutines found by this search. Subroutines fetched from a library in this way may themselves contain external library search process must therefore be repeated until all external references are resolved. references. The The libraries to be searched by the loader usually contain assembled or compiled versions of the subroutines

  25. MACHINE INDEPENDENT LOADER FEATURES Loader Options They are processing of the program. options that modify the standard An option that allows the selection of alternative sources of input e.g. (library_name) directs designated object program from a library and treat it as if it were part of the primary loader input. INCLUDE program_name the loader to read the An option to allow the user to delete external symbols or entire control sections e.g. DELETE instructs the loader to delete the named control section from the set of programs being loaded. csect_name

  26. MACHINE INDEPENDENT LOADER FEATURES Loader Options An option to change external symbols e.g. CHANGE name1, name2 causes the external symbol name1 to be changed to name2 wherever it appears in the object programs. An option to specify alternative libraries to be searched e.g. LIBRARY MYLIB will cause library MYLIB to be searched before the standard system libraries. Loaders that perform automatic library search may be asked to exclude some functions that come with the library search e.g. NOCALL STDEV, PLOT, CORREL will instruct the loader to exclude the said functions.

  27. MACHINE INDEPENDENT LOADER FEATURES Loader Options Options to control outputs from the loader. The user can specify whether an output is needed or not. Options to specify whether external references will be resolved by library search. An option to specify the location at which execution is to begin thus overriding any information given in the object program. An option to control whether or not the loader should attempt to execute the program if errors are detected during the load.

  28. MACHINE INDEPENDENT LOADER FEATURES 3. Overlay Programs They are programs that are designed to execute in such a way that if both or all of them are not needed in memory at the same time, one can execute first and the other will execute in the same memory space after the first one has been executed.

  29. Overlay Programs

  30. Overlay Programs In the example Control section A (the root) can call B, C, or D/E etc. D/E means that control sections D and E are closely related and they are always used together. The nodes in the tree are called segments. The root segment (A) is loaded when execution of the program begins and it remains in memory until the program ends. The other segments are loaded as they are called.

  31. Overlay Programs If H is being executed both B and A should be in memory since H was called by B, and B was called by A. Thus the three sections A, B and H must be active. The other segments cannot be active since there is no path from them to H.

  32. Overlay Programs Segments at the same level cannot be required at the same time; thus they can be assigned to the same locations in memory. If a segment is loaded it overlays any segments at the same subordinate segments memory. level and their that may be in The executed memory. entire program a smaller therefore total can be of in amount

  33. Overlay Programs The structure of an overlay program is defined to the loader using the following commands: SEGMENTseg_name(control-section .) defines a segment, gives it a name and lists the control sections to be included in it. The first segment defined is the root. Two consecutive SEGMENT parent child relationship between the segments defined. statements specify a seg_name identifies the (already PARENT existing) segment that is to be the parent of the next segment defined.

  34. Overlay Programs The statements below define the above overlay structure. SEGMENT SEGMENT SEGMENT PARENT SEGMENT PARENT SEGMENT PARENT SEGMENT SEGMENT PARENT SEGMENT PARENT SEGMENT SEG1(A) SEG2(B) SEG3(F/G) SEG2 SEG4(H) SEG1 SEG5(C) SEG1 SEG6(D/E) SEG7(I) SEG6 SEG8(J) SEG6 SEG9(K)

  35. Overlay Programs

  36. Overlay Programs

  37. Overlay Programs The root segment can be loaded directly into memory; the other segments are loaded into working file called SEGFILE that is created by the loader. The actual loading of the segments during program execution is handled by an overlay manager, OVLMGR. The OVLMGR uses a segment table SEGTAB which has all the information about the overlay program.

  38. Overlay Programs SEGTAB also includes a transfer area for each segment except the root. If a segment is currently loaded in memory the transfer area instruction to the segment. contains entry a jump that point of If the segment is not currently loaded the transfer area contains instructions that invoke OVLMGR and pass to it information concerning the segment to be loaded.

More Related Content