Chapter 3 Loaders and LinkersPurpose and FunctionKinds of LoadersKinds of loaders (cont.)Slide 5Methods of RelocationModification RecordsSlide 8Slide 9Slide 10Slide 11Slide 12Mask Method of RelocationProgram LinkingLOADINGData Structures for LoadingPass 1Efficiency ReferencesPass 2Machine Independent Loader FeaturesAutomatic Library SearchLoader OptionsLoader Options (cont.)Loader Options ExampleLoader Options LibrariesSlide 26Slide 27Loader OutputLoader Design OptionsLinkage EditorsLinkage Editors (cont.)Slide 32Dynamic LinkingDynamic Linking (cont.)Slide 35Slide 36Bootstrap LoadersChapter 3Loaders and LinkersPurpose and FunctionPlaces object program in memoryLinking–Combines 2 or more obj programsRelocation–Allows loading at different locationsLinkage Editor–Provides linking without loadingKinds of LoadersAbsolute–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 pgmKinds of loaders (cont.)Bootstrap–A special absolute loader–ROM–Loads the OSKinds 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 relocationMethods of RelocationModification recordsUse 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 wordModification RecordsH – header–H PgmName Startaddr Length–1ch 6ch 6ch 6chModification RecordsT – text–T Startaddr Length records–1ch 6ch 2ch ???chModification RecordsD – Define – defined here, used elsewhere–D Label addr Label addr Label addr ….–1ch 6ch 6ch 6ch 6ch 6ch 6chModification RecordsR – Refer – used here, defined elsewhere–R Label Label Label ….–1ch 6ch 6ch 6chModification RecordsM – Modification–M addr len action –1ch 6ch 2ch +/- label –Addr – location to modify–Len – number of bytes to modify–Action – how to modifyModification RecordsE – End–E addr –1ch 6ch –Addr is the starting execution locationMask Method of RelocationHCOPY 000000001077A ^ ^ ^T0000001EFFC1400334810390000362800303000154810613C000300002A0C003900002D ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^FFC 111111111100 all 10 words need modificationT 00001E 15 E00 0C0036 481061 080033 4C0000 454F46 000003 000000^ ^ ^ ^ ^ ^ ^ ^ ^ ^E00 111000000000 instructions 0,1,2 need load addresses T0000391EFFC0400300000030E0105D30103FD8105D2800303010575480392C105E38103F ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^T0010570A8001000364C0000F1001000^ ^ ^ ^ ^ ^ ^The F1 fouls up alignment, thus a new text record has to be started. FIGURE 3.7Program LinkingNecessary for separate CSECTSExternal ReferencesExternal DefinitionsLOADINGForward references to external symbols commonUse 2 pass–Pass 1 assigns address to external symbolsProvides a load map (info. in symbol table)–Pass 2 performs actual loading, relocation, and linkingData Structures for LoadingESTAB external symbol table –StoresNamesAddresses–CSECT of external symbolsPROGADDR – program load address–Provided by the OSCSADDR – CSECT addr. of control sect. loadedPass 1All external symbols from define records are stored and have destination addressesProvides load map containing–Header records–Define recordsEfficiency 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.Efficiency ReferencesHPROGA 000000 000063DLISTA 000040 ENDA 000054R 02LISTB 03ENDB 04LISTC 05ENDC (refer record)T 000020 0A 03201D 77100004 050014T 000054 0F 000014 FFFFF6 00003F 000014 FFFFC0M 000024 05 + 02 <----- 02 references LISTBM 000054 06 + 04M 000057 06 + 05M 000057 06 - 04M 00005A 06 + 05M 00005A 06 - 04M 00005A 06 + 01M 00005D 06 - 03M 00005D 06 + 02M 000060 06 + 02M 000060 06 - 01E 000020Fig 3.12 Object program corresponding to Fig3.8 using reference numbers for code modification (PROGA only, PROGB and PROGC are similar)Pass 2Loads text recordsResolves addresses (relocating)Linking of CSECTSStarts execution at address of end record–Uses last end record when each CSECT contains an END with an addressMachine Independent Loader FeaturesInclude library routines -lmSpecify optionsLoad object programAutomatic Library SearchLibrary routines are external referencesUsers can include routines to override library routinesLibrary search is a search of the directory that contains addresses of the routines.Loader OptionsExist as a separate command language ORAs part of the compiled/assembled programLoader Options (cont.)Select alternate source–Include program name Delete external symbols or entire CSECTSChange namesLoader Options ExampleFig2.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, WRITENow we have the new routines for execution without removingand reassembling the source code.Loader Options LibrariesSpecify alternative libraries to be searched. These are searched before system libraries, allowing user versions to replace system versions.LIBRARY MYLIBLoader Options LibrariesSpecify that library routines not be included. If, for example, statistics were normally done, but not done in this run.NOCALL STDDEV, PLOT, CORRELallows these references to be unresolved, but the assemble to succeed.Loader Options LibrariesSpecify no external references be resolved. Good for programs are linked but not executed immediately. Calls to external references, of course, will error.Loader OutputOutput from the loader can vary load map with the level of detail.–CSECT only–CSECT and
View Full Document