25836196 linkers amp loaders

Upload: lersi-silva-silva

Post on 03-Apr-2018

235 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 25836196 Linkers Amp Loaders

    1/29

    Chapter 5 (System Programming by John J. Donovan)

  • 7/28/2019 25836196 Linkers Amp Loaders

    2/29

    Chapter Content:

  • 7/28/2019 25836196 Linkers Amp Loaders

    3/29

    Users source program decks areconverted to object program decks byassembler & compilers.

    The Loaderis a program whichaccepts the object program forexecution by computer & initiates the

    execution.

  • 7/28/2019 25836196 Linkers Amp Loaders

    4/29

    Allocate space in memory for the program(Allocation).

    Resolve symbolic references between objectdecks (Linking).

    Adjust all address dependent locations suchas address constants, to corresponds to theallocated space (Relocation).

    Physically place the machine instruction &data into the memory (Loading)

  • 7/28/2019 25836196 Linkers Amp Loaders

    5/29

  • 7/28/2019 25836196 Linkers Amp Loaders

    6/29

    In this scheme the assembler runs in one part of thememory.

    The assembler places the assembled machineinstructions and data as they are assembled directly

    into their assigned memory locations. When the assembly is complete the assembler

    causes a transfer to the starting instruction of theprogram.

    This scheme was used by WATFOR FORTAN Compiler. In this scheme the assembler simply places the code

    into the core & the loader consists of one instructionthat transfers to the starting address of newlyassembled program.

  • 7/28/2019 25836196 Linkers Amp Loaders

    7/29

    Disadvantages:

    The portion of memory is wantedbecause the core occupied by assembleris unavailable to the object Program.

    It is necessary to retranslate the user

    program decks, every time it is run. It is very difficult to handle multiple

    segments, specially if the source

    program are in different languages. It is difficult to produce orderly modularprogram.

  • 7/28/2019 25836196 Linkers Amp Loaders

    8/29

    SourceProgram

    deck

    Compile-and-go translator

    Programloaded inmemory

    Assembler

  • 7/28/2019 25836196 Linkers Amp Loaders

    9/29

    In this scheme the assembled program isloaded into the core, which eventually freesup the space allocated to assembler in theprevious scheme.

    This scheme requires a LOADER, whichaccepts the assemble machine instructions,data & other information present in theobject format and place machine instruction& data in core in an executable format.

    No reassembly requires to run the programat later date.

    Possible to write different subroutines indifferent languages.

  • 7/28/2019 25836196 Linkers Amp Loaders

    10/29

    Figure 5.3

    Loader

  • 7/28/2019 25836196 Linkers Amp Loaders

    11/29

    In this scheme the assembler outputsthe machine language translation ofthe source program in same form as

    that of assemble-and-go scheme,except that the data is punched oncards.

    The loader simply accepts the machinelanguage text & places it into core at alocation prescribed by the assembler.

  • 7/28/2019 25836196 Linkers Amp Loaders

    12/29

    Figure 5.4

  • 7/28/2019 25836196 Linkers Amp Loaders

    13/29

    Disadvantages:

    The programmer must specify theassembler the address in the core wherethe program is to be loaded.

    In case of multiple subroutines, the

    programmer must remember the addressof each and use that absolute addressexplicitly in other subroutines to performsubroutine linkages.

  • 7/28/2019 25836196 Linkers Amp Loaders

    14/29

    When we call a subroutine with a symbolreference rather than its absolute address, aseparate mechanism is needed to understandthe symbol reference. Ex: Branching stmt.

    The mechanism is typically implemented witha relocating or direct linking loader.

    EXTERN: Symbols are defined in one programbut are used in present program.

    ENTRY: Symbol defined in one program andreferenced in other.

  • 7/28/2019 25836196 Linkers Amp Loaders

    15/29

    The assembler assembles each proceduresegment independently and pass on to theloader text & information as to relocation& intersegment reference.

    There are two methods for specifyingrelocation as part of the object program.

    a) Modification Record : In this, for each

    source program the assembler outputs thetext prefix by a transfer vector thatconsists of address containing names ofthe subroutines referenced by the source

    program.

  • 7/28/2019 25836196 Linkers Amp Loaders

    16/29

    The length of entire program and length oftransfer vector portion is provided by the

    assembler to the loader.

    Call tosubroutine

    Transfervector

    location tosubroutine

    Actual corelocation ofSub routine

    B) Relocation Bit: The assemblerassociates a bit with each instruction or

    address field. If this bit field equals 1then corresponding address field mustbe relocated, otherwise the field is notrelocated.

  • 7/28/2019 25836196 Linkers Amp Loaders

    17/29

    Disadvantages:

    The Transfer vector linkage is onlyuseful for transfers, and is not suitedfor loading or storing external data.

    The transfer vector increases the sizeof object program in memory.

  • 7/28/2019 25836196 Linkers Amp Loaders

    18/29

    The assembler provides1. The length of segment

    2. A list of all entries and their relative locationwithin the segment

    3. A list of all external symbols

    4. Information as to where address constants areloaded in the segment and a description ofhow to revise their values.

    5. The machine code translation of the sourceprogram and the relative addresses assigned

  • 7/28/2019 25836196 Linkers Amp Loaders

    19/29

    Fig 5.7

  • 7/28/2019 25836196 Linkers Amp Loaders

    20/29

    External Symbol Dictionary (ESD) record:Entries and Externals

    (TXT) records control the actual object

    code translated version of the sourceprogram.

    The Relocation and Linkage Directory

    (RLD) records relocation informationThe END record specifies the starting

    address for execution

  • 7/28/2019 25836196 Linkers Amp Loaders

    21/29

    Di d

  • 7/28/2019 25836196 Linkers Amp Loaders

    22/29

    Disadvantages:

    It is necessary to allocate, relocate,

    link, and load all of the subroutineseach time in order to execute aprogram

    loading process can be extremely timeconsuming.

    Though smaller than the assembler,the loader absorbs a considerableamount of spaceDividing the loading process into two

    separate programs a binder and a

    module loader can solve these

  • 7/28/2019 25836196 Linkers Amp Loaders

    23/29

    Binder :

    A binder is a program that performs the samefunctions as the direct linking loader

    allocation, relocation, and linkingOutputs the text in a file rather than memorycalled a load module.

    The module loader merely has to physically

    load the module into memory.

  • 7/28/2019 25836196 Linkers Amp Loaders

    24/29

    Core image builder: Produces a load module that looks verymuch like a "snapshot" or "image" of asection of core,

    Called Core image module.

    Link editor, can keep track of therelocation InformationThe load module can be further

    relocated

    The module loader must perform

    allocation and relocation as well as

    Di d t

  • 7/28/2019 25836196 Linkers Amp Loaders

    25/29

    Disadvantages:

    If a subroutine is referenced butnever executed if the programmer had placed a call

    statement in the program but was never

    executed because of a condition thatbranched around it

    the loader would still incur the

    overhead or linking the subroutine.All of these schemes require the

    programmer to explicitly name allprocedures that might be called.

  • 7/28/2019 25836196 Linkers Amp Loaders

    26/29

    If the total amount of memory required by allsubroutines exceeds the amount available

    The module loader loads the only the proceduresas they are needed.

    Allocating an overlay structureThe Flipper or overlay supervisor is the portion of

    the loader that actually intercepts the "calls" andloads the necessary procedure.

  • 7/28/2019 25836196 Linkers Amp Loaders

    27/29

    Example:

    Suppose a program consisting of fivesubprograms (A{20k},B{20k},C{30k}, D{10k}, and E{20k}) thatrequire 100K bytes of core.Subprogram A only calls B, D and E;subprogram B only calls C and E;

    subprogram D only calls E

    subprogram C and E do not call anyother routines

    Note that procedures B and D are

    never in used the same time; neither

  • 7/28/2019 25836196 Linkers Amp Loaders

    28/29

    A20K

    B20K

    C30K

    D10K

    E20K

  • 7/28/2019 25836196 Linkers Amp Loaders

    29/29

    The loading and linking of external referencesare postponed until execution time.

    The loader loads only the main program

    If the main program shouldexecute a branch to an external address,

    reference an external variable

    The loader is called

    Only then has the segment containing the externalreference loaded.