linker and loader ppt

Upload: kim-ayekpam

Post on 07-Jul-2018

291 views

Category:

Documents


7 download

TRANSCRIPT

  • 8/19/2019 Linker and Loader Ppt

    1/25

    Loaders and Linkers

    Submitted to: Submitted by:

    Ramakrishna A. Sonu Devi Asst. Prof. Ayush Upadhyay

      Dipti Rani

      Lincoln

  • 8/19/2019 Linker and Loader Ppt

    2/25

    Content ntroduction

    !asic Loader "unctions Desi#n of an Absolute Loader 

     Al#orithm for an Absolute Loader 

     A Simple !ootstrap Loader 

    $achine%Dependent Loader "eatures

    Relocatin# Loaders

     $odification Record

    Relocation !it

    Pro#ram Linkin#

    Linkin# Loader 

     Al#orithm and Data structures of a Linkin# Loader 

  • 8/19/2019 Linker and Loader Ppt

    3/25

    ntroduction

    Loadin#: brin#s the ob&ect pro#ram into memoryfor e'ecution

    Relocation: modifies the ob&ect pro#ram so thatit can be loaded at an address different from thelocation ori#inally specified

  • 8/19/2019 Linker and Loader Ppt

    4/25

    Linkin#: combines t(o or more separate

    ob&ect pro#rams and supplies theinformation needed to allo( referencesbet(een them.

     A loader is a system pro#ram thatperforms the loadin# function

  • 8/19/2019 Linker and Loader Ppt

    5/25

    !asic Loader "unctions

    !rin#in# an ob&ect pro#ram into memory andstartin# its e'ecution.

     Absolute loader: )he *eader record is checked to verify that the

    correct pro#ram has been presented for loadin#

     As each )e't record is read+ the ob&ect code itcontains is moved to the indicated address in memory

  • 8/19/2019 Linker and Loader Ppt

    6/25

    ,hen the -nd record is encountered+ the loader &umps to the specified address to be#in e'ecution

    !ootstrap loader: loads the first pro#ram to berun by the computerusually an operatin#

    system

  • 8/19/2019 Linker and Loader Ppt

    7/25

    Desi#n of an Absolute Loader 

     Absolute Pro#ram Advanta#e

    Simple and efficient

    Disadvanta#e the need for pro#rammer to specify the actual

    address

    difficult to use subroutine libraries

    Pro#ram Lo#ic

  • 8/19/2019 Linker and Loader Ppt

    8/25

     Al#orithm for an Absolute Loader 

  • 8/19/2019 Linker and Loader Ppt

    9/25

     A Simple !ootstrap Loader 

    !ootstrap Loader 

    ,hen a computer is first tuned on or restarted+ a special type of

    absolute loader+ called bootstrap loader  is e'ecuted

    )his bootstrap loads the first pro#ram to be run by the computer

    %% usually an operatin# system

  • 8/19/2019 Linker and Loader Ppt

    10/25

    -'ample /SC bootstrap loader0

    )he bootstrap itself be#ins at address 1

    t loads the 2S startin# address 1'31

    4o header record or control information+ the ob&ect code is

    consecutive bytes of memory

  • 8/19/2019 Linker and Loader Ppt

    11/25

    $achine%Dependent Loader

    "eatures Relocation

    Pro#ram linkin#

    Linkin# loader 

  • 8/19/2019 Linker and Loader Ppt

    12/25

    Relocatin# Loaders

    $otivation

    efficient sharin# of the machine (ith lar#er memory and (hen

    several independent pro#rams are to be run to#ether 

    support the use of subroutine libraries efficiently

  • 8/19/2019 Linker and Loader Ppt

    13/25

    )(o methods for specifyin# relocation

    modification record

    relocation bit

    each instruction is associated (ith one relocation bit

    these relocation bits in a )e't record is #athered into bit

    masks

  • 8/19/2019 Linker and Loader Ppt

    14/25

      $odification Record

    "or comple' machines

     Also called RLD specificationRelocation and Linka#e Directory

      $odification recordcol 5: $col 6%7: relocationaddress

    col 3%8: len#th /halfbyte0col 51: fla# /9%0col 55%57: se#mentname

  • 8/19/2019 Linker and Loader Ppt

    15/25

    Relocation !it

    "or simple machines

    Relocation bit

    1: no modification is necessary

    5: modification is needed

    )(elve%bit mask is used in each )e't record

    since each te't record contains less than 56 (ords

    unused (ords are set to 1 any value that is to be modified durin# relocation must coincide (ith one

    of these ;%byte se#ments

    e.#. line 651

    )e't recordcol 5: )col 6%7: startin# addresscol 3%8: len#th /byte0col 51%56: relocation bitscol 5;%76: ob&ect code

  • 8/19/2019 Linker and Loader Ppt

    16/25

    Pro#ram Linkin#

  • 8/19/2019 Linker and Loader Ppt

    17/25

    Pro#ram Linkin# -'ample

    Program A Program B Program C

    Label Expression LISTA, ENDA LISTB, ENDB LISTC, ENDC

    REF1 LISTA local, R, PC external external

    REF LISTB!" external local, R, PC external

    REF# ENDA$LISTA local, A external external

    REF" ENDA$LISTA!LISTC local, A external local, R  

    REF% ENDC$LISTC$1& external external local, A

    REF' ENDC$LISTC!LISTA$1 local, R external local, A

    REF( ENDA$LISTA$)ENDB$LISTB* local, A local, A external

    REF+ LISTB$LISTA local, R local, R external

  • 8/19/2019 Linker and Loader Ppt

    18/25

    Linkin# Loader 

    )(o important variables are PR2

  • 8/19/2019 Linker and Loader Ppt

    19/25

    Linkin# Loader 

    )he last step performed by the loader is usually thetransferrin# of control to the loaded pro#ram to be#ine'ecution

    )he -nd record for each control section may contain theaddress of the first instruction in that control section to bee'ecuted

    f more than one control section specifies a transferaddress+ the loader arbitrarily uses the last one

    encountered f no control section contains transfer address+ the loaderuses the be#innin# of the linked pro#ram as the transferpoint

  • 8/19/2019 Linker and Loader Ppt

    20/25

    Linkin# Loader 

     Assi#n a reference number to each e'ternalsymbol referred to in a control section to makethe al#orithm more efficient

     )he main advanta#e of this reference%numbermechanism is that it avoids multiple searches of-S)A! for the same symbol

     An e'ternal reference symbol can be looked upin -S)A! once for each control section that usesit

    )he values for code modification can then beobtained by simply inde'in# into an array ofthese values

  • 8/19/2019 Linker and Loader Ppt

    21/25

     Al#orithms and Data structures for a linkin# loader 

    $odification record:

    $ake the linkin# and relocation to be processed similarly

    .

    )(o passes:

     Assi#n addresses to all e'ternal symbols

    Perform actual loadin#+ relocation+ and linkin#.

    Data structures used by linkin# loaders

    -'ternal symbol tab: -S)A!

    4ame+ address+ and control session belon#in# to

     Also control sessions /name+ address+ len#th0

    *ash table

    -S)A! (ith control sessions and e'ternal symbols

    http://figures/Fig-extra-Page143.pdfhttp://figures/Fig-extra-Page143.pdf

  • 8/19/2019 Linker and Loader Ppt

    22/25

     Al#orithms and Data structures for a linkin# loader /cont.0

    Pro#ram load address : PR2

  • 8/19/2019 Linker and Loader Ppt

    23/25

     Al#orithms and Data structures for a linkin# loader /cont.0

     Al#orithms for Pass 5 of a linkin# loader  

    n Pass 5:

    >ust process *eader and Define records

    PR2

  • 8/19/2019 Linker and Loader Ppt

    24/25

     Al#orithms and Data structures for a linkin# loader /cont.0

    n pass 6:

    $ay print a load map for all control sessions and symbols+ useful in pro#ram debu##in#

     Actually loadin#+ relocation+ and linkin#

    CSADDR is used as in Pass 5 "or each )e't record+ the ob&ect code is placed to the address /@the address in the

    instruction 9 CSADDR0.

    "or each $odification record+ from the name+ lookin# for -S)A! to #et the address /in

    another control session0+ then add or subtract from the indicated location.

    )ransfer the control to the startin# address indicated by -=-CADDR

  • 8/19/2019 Linker and Loader Ppt

    25/25

    )*A4 B2U