chapter 9 and 10.pptx
Document Details
Uploaded by MagnificentLavender
Debre Markos University
Tags
Related
- omscs-notes-notes_operating-systems_thread-performance-considerations.md at 1e77184ce6ad5faefba8709d6a249888a005f542 · m4ttsch_omscs-notes-notes · GitHub.pdf
- omscs-notes-notes_operating-systems_midterm-exam-review-questions.md at 1e77184ce6ad5faefba8709d6a249888a005f542 · m4ttsch_omscs-notes-notes · GitHub.pdf
- swe-sheet-sol-full-operating-systems.pdf
- OPERATING SYSTEMS SLM.pdf
- Front-End Loader Safety Training 2024 PDF
- Linux Boot Process PDF
Full Transcript
Debremarkos University College of Technology Department of Software Engineering Operating Systems and System Programming (SEng2034) Chapter Nine LOADERS AND LINKERS By: Alehegn A. Contents Basic loade...
Debremarkos University College of Technology Department of Software Engineering Operating Systems and System Programming (SEng2034) Chapter Nine LOADERS AND LINKERS By: Alehegn A. Contents Basic loader functions Design of an Absolute Loader Machine dependent loader features Relocation Program Linking Algorithm and Data Structures for Linking Loader Machine-independent loader features Automatic Library Search 1. Introduction What are Loader? A loader is a part of the operating system that loads an executable file into memory and prepares it for execution It is a system software that performs loading function Loading is the process of placing the program from secondary memory, main memory, catch memory..etc. into memory for execution Loader is responsible for initiating the execution of the process 1. Introduction Functions of loader Loading: Reads the executable file from the disk and loads it into the appropriate memory locations. Relocation: Adjusts addresses in the loaded program to match the actual memory addresses assigned during loading. This may involve resolving absolute addresses to actual memory locations. Initialization: Sets up initial values for the program's stack, registers, and other necessary runtime components. Transfer Control: Hands over control to the program by setting the program counter to the entry point of the executable. Types of loader Based on the above four functions the loader is divided into six types, they are Compile and go loader or Assemble and go loader General Loader Absolute Loader Relocation Loader Practical Relocation Loader Linking Loader Types of loader Compile and go loader or Assemble and go loader: The instruction is read line by line, its machine code is obtained and it is directly put in the main memory at some known address. That means the assembler works as loader and execute in one part of memory and the assembled machine instructions and data is directly put into their assigned memory locations. After completion of assembly process, it assign starting address of the program to the location counter Used in languages developed before C or C++ like FORTRAN Advantages Types of loader It is easy to design and implement Relocation performed by translator Suitable for basic programs disadvantages There is no production of.obj file Portion of memory is wasted because combination of assembler and loader activities, this combination program occupies large block of memory It cannot handle multiple source programs or multiple programs written in different languages The execution time will be more in this scheme as every time program is assembled and then executed Wastage in memory space due to the presence of assembler Types of loader General Loader Scheme: the source program is converted to object program by some translator (assembler). The loader accepts these object modules and puts machine instruction and data in an executable form at their assigned memory. The loader occupies some portion of main memory smaller than assembler in size Advantages: The program need not be retranslated each time while running it There is no wastage of memory, because assembler is not placed in the memory It is possible to write source program with multiple programs and multiple languages More memory is available to the user Disadvantage The loader cannot handle different object module obtained from different kind of computers Types of loader Absolute Loader: is a kind of loader in which relocated object files are created, loader accepts these files and places them at specified locations in the memory. This type of loader is called absolute because no relocation information is needed; rather it is obtained from the programmer or assembler. The starting address of every module is known to the programmer, this corresponding starting address is stored in the object file. Types of loader Advantages of Absolute Loader It is easy to design and implement Allows multiple programs written in different language Language converter is used to for converting source code to object file only Execution process is efficient No linking and relocation required Allocation is done by either programmer or assembler Linking and Resolution is done by the programmer or assembler and loading is done by the loader Disadvantage Programmer should specify address to assembler to perform where it should be loaded If modification done, update the address of a program so that the programmer must know the concept of memory management Types of loader Direct Linking Loaders: is the most common type of loader in which loader cannot have the direct access to the source code. Also called Reloadable loader To place the object code into memory there are two situations Either the address of the object code should be Absolute which can be directly placed in memory Address is relative then the assembler informs the loader about relative address of object file Types of loader The assembler should give the following information to the loader i. The length of the object code segment ii. The list of all the symbols which are not defined in the current segment(external symbols) but can be used in the current segment. iii.The list of all the symbols which are defined in the current segment but can be referred by the other segments. The list of symbols which are not defined in the current segment but can be used in the current segment are stored in a data structure called USE table. The list of symbols which are defined in the current segment and can be referred by the other segments are stored in a data structure called DEFINITION table iv. Information about address constant Types of loader There are 4 types of cards available in the direct linking loader produced by assembler in the object code. They are. External symbol directory(ESD) card: contain information about all symbols that are defined in the program but that may be referenced somewhere. There are again ESD cards classified into 3 types of mnemonics. They are i. SD [Segment Definition]: It refers to the segment definition ii. LD; It refers to the local definition iii. ER: it refers to the external reference they are used in the [EXTRN] pseudo op code Types of loader Text Card(TXT): contains the actual object code translated version of xource program Relocation and linkage directory(RLD) card: contain information about those locations in the program whose content depends on the address at which the program is placed The RLD card contain the following information The location of each constant that needs to be changed due to relocation By what it has to be changed The operations to be performed END card: It indicates end of the object program and specifies the starting address for execution of assembled program Read about Practical Relocation Loader and Linking Loader Machine dependent loader features The features of loader that depends on machine architecture are called machine dependent loader features. It includes: Program Relocation and Program Linking Program Relocation (Relocating Loader) : It loads a program at any memory location, and then adjusts all memory references in the program to reflect the new location. This allows the same program to be loaded into different memory locations without having to modify the program's object code. Program Linking is a program that has the capability to perform relocation, linking and. loading. Linking and relocation is performed at load time Machine independent loader features The features of loader that doesn’t depends the architecture of machine are called machine independent loader features. It includes: Automatic Library search and Loader Options that can be selected at the time of loading and linking Automatic Library Search: used for handling external reference. Linking loaders that support automatic library search must keep track of external symbols that are referred to, but not defined, in the primary input to the loader. Many linking loaders can automatically incorporate routines from a subprogram library into the program being loaded. The subroutines called by the program being loaded are automatically fetched from the library, linked with the main program, and loaded. Machine independent loader features The library contains an internal directory where each files along with their address are stored. This facilitates the linking of library functions more easy, because whenever a library function is needed its address can be directly obtained from internal directory. Loader Options: Many loaders allow the user to specify options that modify the standard processing. It allows the selection of alternative sources of input. It allows the user to delete external symbols or entire control sections. It allows the user to change the name of external symbol This involves the automatic inclusion of library routines to satisfy external references. See about Linkage Editors Dynamic Linking Unit 10 MACRO PROCESSORS A macro processor is a software that automates the process of inserting commonly used sequences of code into a program. It allows for code to be written in a more efficient and readable manner by providing mechanisms for abstraction and code reuse. The advantage of using maro in a program are Simplicity: Simplify and reduce the amount of repetitive coding Code Reusability: Macros allow you to write code once and use it in multiple places, reducing redundancy. Readability: Macros can make complex code more readable by abstracting away details. Maintainability: Changes to the macro definition automatically propagate to all macro invocations, simplifying maintenance. Reduce the possibility of errors caused by repetitive coding MACRO PROCESSORS The disadvantage of using maro in a program Are the size of the program. The reason is the pre-processor will replace all the macros in the program by its real definition prior to the compilation process of the program Debugging Difficulty: Macro expansion can make debugging more challenging because errors in the expanded code may not be immediately obvious. Complexity: Overuse of macros can lead to complex and hard-to- read code. Namespace Pollution: Macros do not respect scope, which can lead to name collisions. MACRO PROCESSORS Here are the basics on macro processor functions: Definition of a Macro: A macro is a sequence of instructions or code that can be defined once and reused multiple times throughout a program. Macros can be defined to perform specific tasks and can include parameters to make them more flexible. Macro Expansion: when a macro is used in a program, the macro processor replaces the macro call with the corresponding sequence of code (macro expansion). This occurs before the actual compilation or interpretation of the code. Macro Definition Syntax: The syntax for defining a macro can vary depending on the programming language or macro processor being used. Generally, it includes a name, a set of parameters, and a body of code. For example, in C, a macro definition might look like: #define SQUARE(x) ((x) * (x)) Macro Invocation: To use a macro, you simply invoke it by its name and provide any necessary arguments. you would invoke the SQUARE macro as follows: MACRO PROCESSORS Parameter Substitution: when a macro with parameters is expanded, the provided arguments replace the parameters in the macro definition. This allows for dynamic code generation based on the arguments passed. Conditional Compilation: Macros can also be used to include or exclude code segments based on certain conditions. This is often used for cross-platform code or debugging. For example, in C: #ifdef DEBUG printf("Debugging information\n"); #endif File Inclusion: Macros can be used to include entire files within a program. This is commonly used to include header files in C and C++: #include Machine-independent Macro-Processor Features. The design of macro processor doesn’t depend on the architecture of the machine. This macro processor has different features like: Concatenation of Macro Parameters: Most macro processor allows parameters to be concatenated with other character strings. Generation of unique labels : use the technique of generating unique labels for every macro invocation and expansion. Conditional Macro Expansion: are applications of macro processors that are not related to assemblers or assembler programming. Keyword Macro Parameters: Parameters and arguments are matched according to their positions in the macro prototype and the macro invocation statement. The programmer needs to be careful while specifying the arguments Positional parameters are suitable for the macro invocation. General-Purpose Macro Processors Macro processors that do not dependent on any particular programming language, but can be used with a variety of different languages Pros Programmers do not need to learn many macro languages. Although its development costs are somewhat greater than those for a language specific macro processor, this expense does not need to be repeated for each language, thus save substantial overall cost Cons Large number of details must be dealt with in a real programming language Situations in which normal macro parameter substitution should not occur, e.g., comments. Facilities for grouping together terms, expressions, or statements Tokens, e.g., identifiers, constants, operators, keywords Syntax had better be consistent with the source Macro Processing within Language Translator The macro processors we discussed are called “Preprocessors”. Process macro definitions Expand macro invocation Produce an expanded version of the source program, which is then used as input to an assembler or compiler You may also combine the macro processing functions with the language translator: Line-by-line macro processor Integrated macro processor Line-by-Line Macro Processor: Used as a sort of input routine for the assembler or compiler Read source program Process macro definitions and expand macro invocations Pass output lines to the assembler or compiler Integrated Macro Processor: An integrated macro processor can potentially make use of any information about the source program that is extracted by the language translator It can support macro instructions that depend upon the context in which they occur !! ! o u y n k h a T 25