Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3 Loaders and Linkers

Similar presentations


Presentation on theme: "Chapter 3 Loaders and Linkers"— Presentation transcript:

1 Chapter 3 Loaders and Linkers

2 Purpose and Function Places object program in memory Linking
Combines 2 or more obj programs Relocation Allows loading at different locations Linkage Editor Provides linking without loading

3 Kinds of Loaders Absolute Single pass Checks for correct header record
Checks for sufficient available memory Moves each text record to proper location Upon seeing END passes control to the pgm

4 Kinds of loaders (cont.)
Bootstrap A special absolute loader ROM Loads the OS

5 Kinds of loaders (cont.)
Relocating Modifies appropriate addresses Loads object program at a variety of locations May perform loading during execution (repeatedly) Allows for multiple programs (multiprocessing) System libraries require relocation

6 Methods of Relocation Modification records
Use absolute addressing and fixed format No modification records required Use same text records with flag (relocation bit) Relocation bits gathered into a mask If relocation bit is 1, add starting address to word

7 Modification Records H – header H PgmName Startaddr Length
1ch 6ch ch ch

8 Modification Records T – text T Startaddr Length records
1ch ch ch ???ch

9 Modification Records D – Define – defined here, used elsewhere
D Label addr Label addr Label addr …. 1ch 6ch 6ch 6ch 6ch 6ch 6ch

10 Modification Records R – Refer – used here, defined elsewhere
R Label Label Label …. 1ch 6ch 6ch 6ch

11 Modification Records M – Modification M addr len action
1ch 6ch 2ch +/- label Addr – location to modify Len – number of bytes to modify Action – how to modify

12 Modification Records E – Ebd E addr 1ch 6ch
Addr is the starting execution location

13 Mask Method of Relocation
HCOPY A ^ ^ ^ T EFFC C A0C D ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ FFC all 10 words need modification T 00001E 15 E00 0C C F ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ E instructions 0,1,2 need load addresses T EFFC E0105D30103FD8105D C105E38103F ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ T A C0000F ^ ^ ^ ^ ^ ^ ^ The F1 fouls up alignment, thus a new text record has to be started. FIGURE 3.7

14 Program Linking Necessary for separate CSECTS External References
External Definitions

15 LOADING Forward references to external symbols common Use 2 pass
Pass 1 assigns address to external symbols Provides a load map (info. in symbol table) Pass 2 performs actual loading, relocation, and linking

16 Data Structures for Loading
ESTAB external symbol table Stores Names Addresses CSECT of external symbols PROGADDR – program load address Provided by the OS CSADDR – CSECT addr. of control sect. loaded

17 Pass 1 All external symbols from define records are stored and have destination addresses Provides load map containing Header records Define records Efficiency can be increased if a reference number is given to each external symbol. Ref number indexes an array removing the need for a hash function.

18 Efficiency References
HPROGA DLISTA ENDA R 02LISTB 03ENDB 04LISTC 05ENDC (refer record) T A 03201D T F FFFFF F FFFFC0 M < references LISTB M M M M 00005A M 00005A M 00005A M 00005D M 00005D M M E Fig 3.12 Object program corresponding to Fig3.8 using reference numbers for code modification (PROGA only, PROGB and PROGC aresimilar)

19 Pass 2 Loads text records Resolves addresses (relocating)
Linking of CSECTS Starts execution at address of end record Uses last end record when each CSECT contains an END with an address

20 Machine Independent Loader Features
Include library routines -lm Specify options Load object program

21 Automatic Library Search
Library routines are external references Users can include routines to override library routines Library search is a search of the directory that contains addresses of the routines.

22 Loader Options Exist as a separate command language OR
As part of the compiled/assembled program

23 Loader Options (cont.) Select alternate source
Include program name Delete external symbols or entire CSECTS Change names

24 Loader Options Example
Fig2.15 is COPY using RDREC and WRREC. Suppose new routines READ and WRITE are to replace them, but we want to test READ and WRITE first. Without assembling we could give the loader: INCLUDE READ(UTLIB) INCLUDE WRITE(UTLIB) DELETE RDREC, WRREC CHANGE RDREC, READ CHANGE WRREC, WRITE Now we have the new routines for execution without removing and reassembling the source code.

25 Loader Options Libraries
Specify alternative libraries to be searched. These are searched before system libraries, allowing user versions to replace system versions. LIBRARY MYLIB

26 Loader Options Libraries
Specify that library routines not be included. If, for example, statistics were normally done, but not done in this run. NOCALL STDDEV, PLOT, CORREL allows these references to be unresolved, but the assemble to succeed.

27 Loader Options Libraries
Specify no external references be resolved. Good for programs are linked but not executed immediately. Calls to external references, of course, will error.

28 Loader Output Output from the loader can vary
load map with the level of detail. CSECT only CSECT and addresses, external symbol address and cross reference table showing where each is used.

29 Loader Design Options Linking loaders – all linking and relocation at load time Linkage editors – perform linking prior to load time Dynamic linking – performed at execution time

30 Linkage Editors Can replace one function without relinking. Similar to what make does for compiling INCLUDE PLANNER(PROGLIB) DELETE PROJECT (delete from existing planner) INCLUDE PROJECT(NEWLIB) (include new version) REPLACE PLANNER(PROGLIBK)

31 Linkage Editors (cont.)
Can be used to combine several library routines into a package so that they do not need to be recombined each time a program is run that uses those packages. INCLUDE READR(FTNLIB) INCLUDE WRITER(FTNLIB) INCLUE BLOCK(FTNLIB) . SAVE FTNIO(SUBLIB) Result is a much more efficient linking of functions.

32 Linkage Editors (cont.)
Can indicate that external references are not to be resolved by automatic library search Example: suppose 100 programs use I/O routes, if all external references were resolved, there would be 100 copies of the library. Using commands to the linkage editor like those above, the user could specify not to include the library. A linking loader could be used to include the routines at run time. There would be a little more overhead since two linking operations would be done, one for user external references by the linkage editor and one for libraries by the linking loader.

33 Dynamic Linking Perform the above operations but during load time.
For example, a subroutine is loaded and linked to the rest of the program when it is first called. Used to allow several executing programs to share one copy of a subroutine or library. One copy of the function could be provided for all programs executing that use that function.

34 Dynamic Linking (cont.)
Used in Object Oriented Programming Allows the object to be shared by several programs. An implementation of an object can be changed without effecting the program making use of the object.

35 Dynamic Linking (cont.)
Enhanced efficiency (time and space) A subroutine is loaded only if it is needed, maybe an error handler routine would never be loaded if the error was never found.

36 Dynamic Linking (cont.)
Implementation During execution time the loader must be kept and invoked when the function is needed. In this case the loader can be thought of as part of the OS and thus an OS call occurs. The binding is at execution time rather than load time. Delayed binding gives more capabilities at higher cost.

37 Bootstrap Loaders How is the loader loaded?
Machine is idle and empty, thus no need for relocation. Some computers have a permanently resident in read-only memory (ROM) an absolute loader. Upon hardware signal occurring the machine executes this ROM program.


Download ppt "Chapter 3 Loaders and Linkers"

Similar presentations


Ads by Google