Unit 3


Published on

Linkers and Loaders and Software tools

Published in: Education, Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Unit 3

  1. 1. UNIT IIILINKERS AND LOADERS AND SOFTWARETOOLSPre requisite :-Know the basic of fundamental of operating system.OutcomesAim of this chapter students are aware with loader .Software tool
  2. 2. UNIT IIILINKERS AND LOADERS AND SOFTWARETOOLSContents :Basic loaders functions, central loaders scheme Absolute loaders,Subroutine linkers, relocationLoader, Direct linking loader, Dynamic linking loader, Design ofabsolute loaders direct linking loader,Implantation of MS DOS linker,Implantation of MS DOS linker,Software tools for program development, editors, debug monitor,programming environment, user interfaces.
  3. 3. LINKERS AND LOADERS & SOFTWARE TOOLSExecution of program involves the following stepsTranslation of the programs .Linking of the program with other program needed for itsexecution.Relocation of the program to execute from the specific memoryarea allocated to it.Loading of the program in the memory for the purpose ofexecution .
  4. 4. LINKERS & LOADERS & SOFTWARE TOOLSA schematic of Program executionTranslator Linker LoaderBinaryProgramSourceProgramObjectModulesBinaryProgramsControl FlowData Flow
  5. 5. FUNCTIONS OF LOADERLoader:The loader is a program which accepts object codes and preparesthem for execution and initiates execution.The loader is responsible for the activities such asThe loader is responsible for the activities such asallocation ,linking, relocation and loadingIt allocates the space for program in the memory, bycalculating the size of the program. This activity iscalled allocation.
  6. 6. CONT…It resolves the symbolic reference (code/data) betweenthe object modules by assigning all the user subroutineand library subroutine addresses. This activity is calledlinkingThere are some address dependant locations in the program, suchThere are some address dependant locations in the program, suchaddress constants must be adjusted according to allocated space,such activity done by loader is called relocation.
  7. 7. Finally it places all the machine instruction and data of correspondingprograms and subroutines into the memory .Thus program now become readyfor execution, this activity is called loading.General loading scheme diagram-objectProgram moduls A and B areloaded in memory after linking.It is ready for execution.Module AObjectModule BLOADER AB
  8. 8. CONT…The following terminology is used to refer to the addressto refer to the address of the program entity at differenttimesTranslation time(or translated) address : addressassigned by the translatorLinked address : address by the linkerload time(or load) address : address assigned by theloader.loader.
  9. 9. CONT…o The same prefixes above are used with the origin andexecution start address of a program. thus,-1. Translated origin :Address of the origin assumed by the translator .This is the addressspecified by the programmer in an ORIGIN statement.2. Linked Origin :2. Linked Origin :Address of the origin assigned by the linker while producing abinary program.3. Load Origin :Address of the origin assigned by the loader while loading theprogram for execution.
  10. 10. TYPES OF LOADERS1. General Loader2. Bootstrap Loader (Absolute Loader)3. Subroutine Linkage4. Relocating Loaders4.1- Relocation bits4.2- Relocation maps (modification records)5. Direct Linking Loader
  11. 11. GENERAL LOADERSIn this scheme ,the source program is converted to object programby translator (assembler).The loader accepts these modules and puts machine instruction anddata in an executable form at their assigned memory.Advantages:-The program need not be retranslated each time while running it.The program need not be retranslated each time while running it.There is no wastage of memory.It is possible to write source program with multiple programs andmultiple languages.
  12. 12. ASSEMBLE-&-GO LOADERCharacteristicsThe Object Code is stored in Memory after Assembly.Single JUMP Instruction.AdvantageSimple, Developing Environment.DisadvantageWhenever the Assembly Program is to be executed, it has to beassembled again.Programs have to be coded in the same language.
  13. 13. ABSOLUTE LOADERIt is kind of loader in which relocated object files are created,loader accepts these files and places them at specified locationsin the memory.This type of loader is called absolute because no relocationinformation is needed; rather it is obtained from the programmerinformation is needed; rather it is obtained from the programmeror assembler.The task of an absolute loader is virtually trivial. The simplyaccepts the machine language code produced by an assemblerand places it into main memory at the location specified by theassembler.
  14. 14. ABSOLUTE LOADERIf the operating system loads the loader, how the operatingsystem itself loaded into memory?Given an idle computer with no program inmemory, how do we gets things started?Memory empty ⇒ no need for program relocation =>Memory empty ⇒ no need for program relocation =>OS kernel is loaded into a predefined location in memory byabsolute loaderThis absolute loader may be a software function, resident inROM or “primary loaded” by some hardware function.
  15. 15. ABSOLUTE LOADERAbsolute Loader accepts machine language code producedby an assembler & places it into main memory at thelocation specified by the assembler.Absolute loader example –The main program is assigned to location 100 to 250 andthe function F1 is assigned location 400 to 500. Theprogrammer should be careful not to assign overlappingprogrammer should be careful not to assign overlappinglocation to modules to be linked.
  17. 17. ABSOLUTE LOADER – ADVANTAGE & DISADVANTAGEAdvantagesSimple and Efficient.No reallocation information is required , so the size ofthe object module is comparatively small.It makes memory available for loading, since theassembler is not in memory at the time of loading.No modification of address sensitive entities isNo modification of address sensitive entities isrequired & it supports multiple object modules.
  18. 18. CONT..DisadvantagesThe need for programmer to specify the actualaddress.Difficult to use Subroutine libraries.The programmer has to be careful not to assignThe programmer has to be careful not to assignoverlapping location to modules to be linked.Lot of memory lying between modules will bewasted.If changes are made to one module that increses itsize then it can overlap the start of another module.It may required manual shifting of module.thismanual shifting can become very complex andtedios.
  19. 19. ALGORITHM FOR AN ABSOLUTE LOADERBeginread Header recordverify program name and lengthread first Text recordwhile record type is not ‘E’ dowhile record type is not ‘E’ dobegin{if object code is in character form, convert into internalrepresentation}move object code to specified location in memoryread next object program recordendjump to address specified in End recordend
  20. 20. ALGORITHM.intializeRead recordtype=0 type=1CardtypeMover binary imageat the addressspecified in the recordTransfer the controlto the entry point
  21. 21. DESIGN.In absolute loading scheme the programmer andthe assembler perform the following tasks.1) Allocation2) Relocation3) Linking3) Linking4) LoadingThe absolute loader reads the object programline by line and moves the text of the programin to the memory at the location specified by theassembler.
  22. 22. CONT.The object program generated by the assemblermust communicate the following information tothe loader.1) It must convey the machine instructions thatthe assembler has created along with thethe assembler has created along with thememory address.2) It must convey the starting executionpoint.program execution will start at this pointafter the program is loaded.
  23. 23. CONT.The object program is a sequence of object record.Each object record specifies some specific aspectof the program in the object module.There are two types of record:1) Text record containing binary image of the1) Text record containing binary image of theassembly program2) Transfer record containing the starting point ofexecution.
  24. 24. CONT..•TEXT RECORDRecord typeNumber bytes ofinformationMemoryaddressBinary image ofdata or instruction•TRANSFER RECORDRecord typeNumber of bytes ofinformation =0Address of entrypoint
  25. 25. SUBROUTINE LINKAGEA program consisting of main program and a setof function(subroutine) could reside in severalfiles.The problem of subroutine linkage is this: A mainprogram a wishesh to call the subroutine B and ifprogram a wishesh to call the subroutine B and ifthe subroutine B resides in another file then theassembler will not know the address of B anddeclare it as an undefined symbol.To realize such interreaction,A and B mustcontain public definition and external references.
  26. 26. EXTERN STATEMENTThe EXTERN statement lists the symbol towhich external references are made in thecurrent program unit. These symbols are definedin other program units.
  27. 27. ENTRY STATEMENTThe ENTRY statement lists the public definitionof a program unit, i.e. it lists those symbolsdefined in the program unit which may bereferenced in other program units.
  28. 28. RELOCATING LOADERSWhen a single subroutine is changed then all thesubroutines need to be reassembled. The task ofallocation and linking must be carried out once again.To avoid this rework a new class of loaders isintroduced which is called as relocating of loaders.Two methods for specifying relocation◦ Modification record◦ Relocation bitEach instruction is associated with one relocation bit.These relocation bits in a Text record is gatheredinto bit masks.
  29. 29. RELOCATING LOADERS (CONTD.)Absolute loader loads a program on a specific memorylocation, but it is often desirable to have two or moreprograms residing in memory sharing the differentresources of a computer system.It would be impractical to assign starting addresses toIt would be impractical to assign starting addresses toeach program to plan program execution.A loader able to load a program into memory whereverthere is room for it is called a Relocating Loader.
  30. 30. MODIFICATION RECORDInterleaving relocation bits with the program text makescumbersome theprocess of loading the text directly into memory.This problem can be resolve by collecting all relocation bits into asinglecontiguous relocation map that we will call the relocation sectioncontiguous relocation map that we will call the relocation sectionof theobject code file.The relocation section will be appended to the text and datasections.The header will contain the entry point and length of the relocationsectionin the object module.
  31. 31. RELOCATION BITUsed for simple machines.Relocation bit0: no modification is necessary1: modification is neededTwelve-bit mask is used in each Text recordTwelve-bit mask is used in each Text recordSince each text record contains less than 12 wordsUnused words are set to 0Any value that is to be modified during relocation mustcoincide with one of these 3-byte segments.
  32. 32. DIRECT LINKING LOADERIt is a general relocated loader and is perhapsthe most popular loading scheme presentlyused.1. It is a relocatable loader2. It allows multiple procedure segments and2. It allows multiple procedure segments andmultiple data segment.The assembler must give the loader thefollowing information with each procedure ordata segment
  33. 33. CONT..The assembler must give the loader the followinginformation with each procedure or data segment1. The lengthss of segment.2. A list of symbols defined in the current segmentthat may be referenced by other segments-that may be referenced by other segments-public declaration.3. A list of all symbols not defined in the segmentbut referenced in the segment-externalvariables.4. Information about address constants.5. The machine code translation of source programand the relative addresses assigned.
  34. 34. CONTThe object module produced by the assembler isdivided into 4 sections:1. External symbol directory(ESD)2. Actual assembled program(TXT)3. Relocation directory(RLD)3. Relocation directory(RLD)4. End of the object module(END)
  35. 35. EXTERNAL SYMBOL DIRECTORY(ESD)It contains information about all symbol that aredefined in this program but may be refrenced byother programs.it also contains symbolsreferenced in this program but defined in otherprogram.program.
  36. 36. CONT..LC1. MAIN START 02. ENTRY RESULT -3. EXTRN SUM -4. -4. -5. -6. -7. -8. -9. -10. RESULT DS 4 32END 36
  37. 37. CONT..Line no. Symbol type relative location length1. MAIN SD 0 362. RESULT LD 32 -3. SUM ER - -SD- symbol is asegment definitionLD- symbol is defined in this program but it canbe referenced by other program.ER- symbol is an external reference,it is definedin some external program.
  38. 38. CONT..• The relative location of the program (MAIN) is 0and size is 36.• The symbol RESULT is locally defined(LD) andrelative address is 32• The symbol SUM is an external reference(ER).• The symbol SUM is an external reference(ER).
  39. 39. ACTUAL ASSEMBLED PROGRAM(TXT)Text portion of object module contain therelocatable machine language instruction anddata that were produced during translation.
  40. 40. RELOCATION DIRECTORY(RLD)It contains one entry for each address that mustbe changed when the module is loaded into mainmemory.The relocation directory contains the followinginformation:information:1. The address of each operand that needs to bechanged due to relocation.2. By what it has to be changed3. The operation to be performed
  41. 41. END OF OBJECT MODULE(END)This indicated the end of object module.
  42. 42. DESIGN OF DIRECT LINKING LOADERThe design of adirect linking loader is morecomplicated than that of the absolute loader.The input to the loader is set of objectprograms(generated by assembler/compiler) to belinked together. Each object module is divided inlinked together. Each object module is divided into four section:1. External symbol directory(ESD)2. Actual assembled progrsm containing thebinary code(TXT)3. Relocation directory(RLD)4. End of the object module(END)
  43. 43. CONT…A direct linking loader requires two passes tocompelete the linking processes:1. Pass 1,assigns addresses to all external symbol.2. Pass 2,performs actual loading,relocation andlinking.linking.In pass 1 , aglobal external symbol table(GEST)is prepared.it contains every exrernal symboland the corresponding absolute address value.
  44. 44. CONT…The two-pass limking loader scheme in shownbelow:ObjectmoduleCopy of objectrecordsmainmemoryPass 1 ofloaderObjectmoduleGlobal externalsymbol tablePass 2 ofloader
  45. 45. LINKER FOR MS DOSOBJECT MODULE FORMATMS DOS compiler & assembler produces object modules. Theobject module is a sequence of object records.There are 14 types of object records containing the following 5basic categories of information:-1) Binary image (i.e. code generated by a translator)2) External references.2) External references.3) Public definitions.4) Debugging information (e.g. line number in source program).5) Miscellaneous information (e.g. comments in the sourceprogram).We only consider the object record corresponding to first threeCategories - a total of 8 record types
  47. 47. 1.THEADER RECORDSThe module name in THEADER record is typically derivedby the translator from the source file name.This name is used by the linker to report errors.80H length T-module name Check-sum
  48. 48. 2.LNAMES RECORDSAn assembly programmer can specify the module namein NAME directive.This record lists the names for use by SEGDEF records.96H length Name list Check-sum
  49. 49. 3. SEGDEF RECORDSThis record designates a segment name using an indexinto LNAMES list.Attribute field indicates whether the segment isrellocatable or absolute, whether (and in what manner )it can be combined with other segments as also theit can be combined with other segments as also thealignment requirement of its base address.98H LengthAttributes(1-4)Check-sumSegment Length(2)NameIndex(1)
  50. 50. SEGDEF RECORDSStack segments with the same name are concatenatedwith each other, while common segments with the samename are overlapped with one another.The attribute field also contains the origin specificationfor an absolute segment.for an absolute segment.
  51. 51. 4. EXTDEF RECORDSThis record contains a list of external references used bythe programs of this module.A FIXUPP record designates an external symbols nameby using an index into this list.8CH Length External Reference List Check-sum
  52. 52. 5. PUBDEF RECORDSIt contains the list of public names declared in asegment of the object module.The base specification identifies the segment.Each (name, offset) pair in the record definesEach (name, offset) pair in the record definesone public name, specifying the name of thesymbol and its offset within the segmentdesigned by the base specification.90H Length Base(2-4) Name Offset(2) ..... Check-sum
  53. 53. 6. LEDATA RECORDSIt contains the binary image of the code generated bythe language translator.Segment index identifies the segment to which the codebelongs, and offset specifies the location of the codewithin the segment.within the segment.A0H Length Segment index(1-2) Data offset(2) Data Check-sum
  54. 54. 7. FIXUPP RECORDSIt contains information for one or more relocation andlinking fixups to be performed.The locat field contains a numeric code called loc codeto indicate the type of a fixup.The meanings of these codes are given below:The meanings of these codes are given below:9CH Length Locate(1) Fix datFramedatum(1)Targetdatum(1)Targetoffset(2)… Check sum
  55. 55. CONT……Locat also contains the offset of the fixup location in theprevious LEDATA record.The frame datum field , which refers to a SEGDEF record ,identifies the segment to which the fixup location belongs.The target datum and target offset fields specify theThe target datum and target offset fields specify therelocation or linking information.target datum contains a segment index or an external index,while target offset contains an offset from the nameindicated in target datum.The fix dat field indicates the manner in which the targetdatum and target offset fields are to be interpreted.The numeric codes used for this purpose are given below
  56. 56. SOFTWARE TOOLS FOR PROGRAMMING DEVELOPMENTA software tool is system program which Interfaces aprogram with the entity generating its input data orinterfaces the results of a program with the entityconsuming them.
  57. 57. CONT..The software tools include:-AssemblerLinkerLoaderMacro processorText editorText editorCompilerOperating systemDebugging systemSource Code Control System(Optional) Database Management SystemUser Interface
  58. 58. A SOFTWARE TOOLoriginator SoftwaretoolConsumerRaw program ordataTransformed program or data
  59. 59. FUNDAMENTAL STEPS IN PROGRAMDEVELOPMENTProgram design, coding, documentation.Preparation of programs in machine readableform.Program translation, linking and loading.Program testing and debugging.Program testing and debugging.Performance tuning.Reformatting the data and results of a programto suit other programs.
  60. 60. PROGRAM DESIGN AND CODINGTwo categories of tools used in program design andcoding are :Program generators :A program generator generates a program whichperforms a set of functions described in itsspecification. Coding effort is saved since the programperforms a set of functions described in itsspecification. Coding effort is saved since the programis generated rather than coded by hand.Programming environments :A programming environment supports programcoding by incorporating awareness of theprogramming language syntax and semantics in thelanguage editor.
  61. 61. PROGRAM ENTRY AND EDITINGThese tools are text editors or more sophisticatedprograms with text editors as front ends. Theeditor functions in two modes. In the commandmode, it accepts user commands specifying theediting function to be performed. In the dataediting function to be performed. In the datamode, the user keys in the text to be added to thefile.Failure to recognize the current mode of theeditor can lead to mix up of command and data.This can be avoided by providing a quick exit e.g.escape key, such that the editor enters thecommand mode.
  62. 62. PROGRAM TESTING & DEBUGGINGImportant steps in program testing anddebugging are selection of test data for theprogram, analysis of test results to detect errorsand debugging, i.e. localization and removal oferrors. Software tools to assist the programmercome in following form :come in following form :1. Test data generators help the user in selectingtest data for his program. Their use helps inensuring that a program is thoroughly tested.2. Automated test drivers help in regressiontesting, wherein a programs correctness isverified by subjecting it to a standard set oftests after every modification.
  63. 63. CONT..Regression testing is performed as follows: Manysets of test data are prepared for a program.These are given as inputs to the test driver. Thedriver selects one set of test data at a time andorganizes execution of the program on the data.organizes execution of the program on the data.4. Debug monitors help in obtaining information forlocalization of errors.5. Source code control system help to keep track ofmodifications in the source code.
  64. 64. DEBUGGING MONITORAn interactive debugging system provides programmers withfacilities that aid in the testing & debugging of programs.Debug monitors provide following facilities:-1. Setting Breakpoints2. Initiating debug conversations3. Single-stepping3. Single-stepping4. Inspection & Assignment of variablesDebugging system provides functions such as tracing & traceback.Tracing can be used to track flow of execution logic & datamodification.While debugging a program, user specifies a list ofbreakpoints & actions to be performed at breakpoints. Debugmonitor builds a table containing statement no. & debugaction.
  65. 65. ENHANCEMENT OF PROGRAMPERFORMANCEA profile monitor is a software tool that collectsinformation regarding the execution behavior of aprogram, e.g. the amount of execution timeconsumed by its modules, and presents in theform of an execution profile.form of an execution profile.Program efficiency depends on two factors :1. The efficiency of the algorithm.2. The efficiency of its coding.3. An optimizing compiler can improve efficiencyof the code but it cannot improve efficiency ofthe algorithm.
  66. 66. PROGRAM DOCUMENTATIONMost programming projects suffer from lack of upto date documentation. Automatic documentationtools are motivated by the desire to overcome thisdeficiency. These tools work on the sourceprogram to produce different forms ofprogram to produce different forms ofdocumentation, e.g. flow charts, IO specificationsshowing files and their records, etc.
  67. 67. DESIGN OF SOFTWARE TOOLSProgram preprocessing techniques are used tosupport static analysis of programs. Toolsgenerating cross reference listings and lists ofunreferenced symbols; test data generators, anddocumentation aids use this technique.documentation aids use this technique.Program instrumentation implies insertion ofstatements in a program. The instrumentedprogram is translated using standard translator.
  68. 68. SOFTWARE TOOLS USING INTERPRETATION & PROGRAM GENERATIONInterpreterTaskspecificationResultsDataProgram GeneratedProgramGeneratorTask specification GeneratedprogramDataResults
  69. 69. EDITORSText editors come in the following forms :1. Line editors.2. Stream editors.3. Screen editors.Word processors.4. Word processors.5. Structure editors
  70. 70. EDITORThe scope of edit operations in a line editor is limitedto a line of text. The primary advantage of line editorsis there simplicity.A stream editor views the entire text as a stream ofcharacters. This permits edit operations to cross lineboundaries. Stream editors typically supportcharacter, line and context oriented commands basedcharacter, line and context oriented commands basedon the current editing context indicated by theposition of a text pointer.Screen editors display a screenful of text at a time.The user can move the cursor over the screen,position it at the point where he desires to performsome editing and proceed with the editing directly.Thus it is possible to see the effect of an edit operationon the screen. This is very useful while formatting thetext to produce printed documents.
  71. 71. EDITORWord processors are basically document editorswith additional features to produce wellformatted hard copy output. Essential features ofword processors are commands for movingsections of text from one place to another,merging of text, and searching and replacementmerging of text, and searching and replacementof words.A structural editors incorporates an awareness ofthe structure of a document. This is useful inbrowsing through a document, e.g. if aprogrammer wishes to edit a specific function ina program file. The structure is specified by theuser while creating or modifying the document.
  72. 72. EDITOR STRUCTURECommandprocessorEditingmanagerViewingmanagerTravellingmanagerViewing filterEditing bufferViewingbufferEditing filterTest
  73. 73. USER INTERFACESA user interface plays a vital role in simplifyingthe interaction of user with anapplication.classically,UI functionalities have twoimportant aspects- issuing of commands andexchange of data.exchange of data.Hence an understanding commands and datawas implicit in the use of an application.A UI can be visulized to consist of two compenenta dialog manager and presentation manager
  74. 74. CONT…A dialog manager manages the conversationbetween the user and the application. Thisinvolves prompting the user for a command andtransmitting the command to the application.The presentation manager displays the dataThe presentation manager displays the dataproduced by the application in an appropriatemanner on the user’s display or printer device.
  75. 75. COMMAND DIALOGCommand are issued to an application through acommand dialog. Three ways to implementcommand dialogs are:1) Command language2) Command menus2) Command menus3) Direct manipulationCommand language for computer applicationare similar to command language for operatingsystem.Primitive command language supportimperative commands with syntax<action><parameters>.sss
  76. 76. CONT..Command menus provide obivous advantades tothe casual user of an application,as the basicfuncationalities of the application are reflected inthe menu choices.A hierarchy of menus can be used to guide theA hierarchy of menus can be used to guide theuser into the details concerning a functionality.
  77. 77. CONT…A direct manipulation system provides the userwith a visual display of the universe of theapplication. The display shows the importantobjects in the universe.Actions or opreations over objects are indicatedActions or opreations over objects are indicatedusing some kind of pointing device,EG. A cursor or mouse.
  78. 78. PRINCIPLE OF COMMAND DIALOG DESIGN1) Ease of use2) Consistency in command structure3) Immediate feedback on user commands4) Error handlingOn line help to avoid memorizing command5) On line help to avoid memorizing commanddetails6) Undo facility7) Shortcut for experienced users
  79. 79. STRUCTURE OF A USER INTERFACEThe UI consist of two maincompenents,presentation manager and dialogmanager.Structure diagram for user interface:ApplicationuserinterfaceuserApplicationcodeGraphicspackageDialogmanagerPresentationmanager
  80. 80. USER INTERFACE MANAGEMENT SYSTEMA user interface management system automatesthe generation of user interface. UIMS acceptsspecification of the presentation and dialogsemantics to produce the presentation and dialogmanagers of the UI resp.managers of the UI resp.In the following we describe two UIMS.1) Menulay2) hypercard
  81. 81. MENULAYMenulay is an early UIMS using the screenlayout as the basis for the dialog model. The UIdesigner starts by designing the user screen.
  82. 82. HYPERCARDThis UIMS from appale incorporates objectorientation in the event oriented approach.A card has an associated screen layout containingbuttons and field.