Loaders and Linkers CS 230 이준원. 2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

1 Loaders and Linkers Chapter 3 System Software An introduction to systems programming Leland L. Beck.
1 Loaders and Linkers Chapter 3 System Software An introduction to systems programming Leland L. Beck.
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
Chapter 3 Loaders and Linkers
Linkage Editors Difference between a linkage editor and a linking loader: Linking loader performs all linking and relocation operations, including automatic.
Linking & Loading CS-502 Operating Systems
3. Loaders & Linkers1 Chapter III: Loaders and Linkers Chapter goal: r To realize how a source program be loaded into memory m Loading m Relocation m Linking.
Chapter 3 Loaders and Linkers
COP 3402 Systems Programming Dr. Ali Orooji School of EECS University of Central Florida.
Chapter 3 Loaders and Linkers. Purpose and Function Places object program in memory Linking – Combines 2 or more obj programs Relocation – Allows loading.
Lecture 10: Linking and loading. Lecture 10 / Page 2AE4B33OSS 2011 Contents Linker vs. loader Linking the executable Libraries Loading executable ELF.
Machine Independent Assembler Features
Computer Organization CS224 Fall 2012 Lesson 12. Synchronization  Two processors or threads sharing an area of memory l P1 writes, then P2 reads l Data.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Loaders and Linkers Object Program contains the information:
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
1 Machine-Independent Features Automatic Library Search automatically incorporate routines from a subprogram library Loading Options.
Loader- Machine Independent Loader Features
An introduction to systems programming
1 Chapter 3 Loaders and Linkers Source Program Assembler Object Code Loader Executable Code Linker.
Loader- Machine Dependent Loader Features
A. Frank - P. Weisberg Operating Systems Real Memory Management.
Operating System Concepts
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Software Development and Software Loading in Embedded Systems.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
OBJECT MODULE FORMATS. The object module format we have employed as an educational device is called OMF (relocatable object format). It’s one of the earliest.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Static Shared Library. Non-shared v.s. Shared Library A library is a collection of pre-written function calls. Using existing libraries can save a programmer.
Different Types of Libraries
Loader and Linker.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
LINKERS Execution of a program written in a language L involves the following steps: 1.Translation of the program: Performed by the translator for language.
CSc 453 Linking and Loading
Linking Loader untuk SIC/XE Machine. Lebih Lanjut mengenai Absolute Loader Shortcoming of an absolute loader –Programmer needs to specify the actual address.
UNIT III LOADERS AND LINKERS. This Unit gives you… Basic Loader Functions Machine-Dependent Loader Features Machine-Independent Loader Feature Loader.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
Object Files & Linking. Object Sections Compiled code store as object files – Linux : ELF : Extensible Linking Format – Windows : PE : Portable Execution.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 –Linkers.
Chapter Linkers and Loaders
Lecture 3 Translation.
System Programming and administration
Linking & Loading.
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
CS-3013 Operating Systems C-term 2008
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Loaders and Linkers CSCI/CMPE 3334 David Egle.
Loaders and Linkers: Features
Machine Independent Features
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Loaders and Linkers.
Memory Management Tasks
Linking & Loading CS-502 Operating Systems
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Machine Independent Assembler Features
Linking & Loading CS-502 Operating Systems
Machine Independent Assembler Features
An introduction to systems programming
Program Assembly.
UNIT III LOADERS AND LINKERS
Chapter 3 Loaders and Linkers
CSE 542: Operating Systems
Presentation transcript:

Loaders and Linkers CS 230 이준원

2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable and linking format) –assigns addresses to instructions and data »assuming the program starts at location 0 loader –loads a program into memory(or AS) for execution –also performs relocation and linking relocation –modifies the absolute addresses in the object program »assembler provides necessary information linking –combines several object programs –these programs are developed independently –a program may use a symbol defined in another program

3 Bootstrap Loader bootstrapping –actions taken when a computer is first powered on –the hardware logic reads a program from address 0 of ROM (Read Only Memory) »ROM is installed by the manufacturer »ROM contains bootstrapping program and some other routines that controls hardware (e.g. BIOS) bootstrapping is a loader –loads OS from disk into memory and makes it run –the location of OS on disk (or floppy) usually starts at the first sector –starting address in memory is usually fixed to 0 »no need of relocation –this kind of loader is simple »no relocation »no linking »called “absolute loader”

4 Relocation assembler review –assembler generates an object code assuming that the program starts at memory address 0 –loader decides the starting address of a program –assembler generates modification record limits of modification record –record format »(address, length) –it can be huge when direct addressing is frequently used –if instruction format is fixed for absolute addressing, the length part can be removed –instead of address field, bit-vector can be used » means instruction need to be modified hardware support for relocation –base register »assembler and loader do not need to worry about relocation

5 Linking background –a large problem is better broken into several small pieces –each piece is better implemented independently »assembled (compiled) independently –there are many data structures shared among those pieces »variables and procedures –some programs are used by many different programs »print(), file operations, exp(), sin(),... »these are usually provided as library functions

6 Linking (cont’d) requirements for linking –each module defines »which symbols are used by other modules »symbols undefined in a module are assumed to be defined in other modules if these symbols are declared explicitly, it helps linker to resolve principles –assembler evaluates as much as possible »expressions –if some cannot be resolved, »provide the modification records

7 Linking Example modification record from module A –for statement 20, assembler »leaves 4 in the operand2 field »prepares modification record as add LISTB to operand2 field of statement 20 –for statement 24, modification record will be »put LISTB-ENDB in operand2 field of statement 24 in module B –assembler prepares a symbol table containing external symbols name and value (LISTB,60) (ENDB,80) 00 PROGA START 0 EXTRN LISTA, ENDA EXTREF LISTB, ENDB 20 REF1 LD A, LISTB+4 24 REF2 LD B, LISTB-ENDB 48 LISTA EQU * ENDA EQU * 00 PROGB START 0 EXTRN LISTB, ENDB 60 LISTB EQU * ENDB EQU *

8 Linking Loader linking –combine all the programs assembled independently –resolves external symbols »actual value of a symbol is known only at loading time linking loader: pass 1 –decides where each module will be located »this information may be given by OS –modify absolute addresses as defined in modification record in the code itself –prepare an external symbol table »(control section, symbol name, value) linking loader: pass 2 –for a modification record (say the first one of A) »search all the external symbol tables for LISTB »add 60 to the operand2 field of statement 20 –transfers the control to the program loaded

9 Library a collection of popular routines –provided as object modules –linked together with user program –programmers just use a function in the library as if it is a language feature –contains a table of symbols exported when a user program is compiled (assembled) all the undefined symbols are kept in the external symbol table linking loader –execute modification records –resolve symbols in EST with standard libraries and user-specified libraries –if there remain symbols in EST unresolved, report ERROR

10 Library (cont’d) there may be thousands of routines(functions) in a library –directory is needed –(routine name, address) –hashing to locate the routine name fast searching all the symbol definitions of library takes long time –each program defines which library is used »or as an option at compile(assemble) time or link time

11 Linkage Editor linking loader –link object modules into a single module and load it into memory and starts the program linkage editor –just link and does some relocation –store the result on disk instead of running –programs once finished, are stored in this form –these programs are run by relocating loader later

12 Linkage Editor (illustration) object program(s) linking loader memory object program(s) linkage editor library linked program relocating loader memory library

13 Comparison of Linking Loader and Linkage Editor what it does –linking loader »get an starting address from OS (zero for VM) »processing modification record »resolution of external symbols »produce output into memory (or disk for VM) »transfer control to the program –linkage editor »resolution of external symbols absolute addresses are not processed yet »produce output on disk

14 Comparison of Linking Loader and Linkage Editor when to use –linking loader »when a program is in a development cycle modify the program assemble and run –linkage editor »when a program development is finished »when a library is built some linking is done here

15 More about Linking Static Linking –all code modules are copied into a single executable file »the same shared module may exist in many files –a location in this file implies the location in the memory image –target address for cross-module reference can be determined before run time Dynamic Linking –needs help from OS ( that means the scheme varies depending on OS) –library modules are usually linked dynamically –inserts symbolic references in the executable file –these symbols are resolved at run time

16 Dynamic Linking of Unix GOT (Global Offset Table) –a linker allocates GOT for each library module –contains the addresses of all dynamically linked external symbols (functions and variables) referenced by the module Steps –a program referencing a library module is loaded for execution –the imported modules are loaded (unless already resident) –a region in the AS is allocated to map the module –the loader initializes the module’s GOT (which may require loading of other library modules) lazy loading –load module only when it is accessed –the entry in the GOT points to stub code –the stub invokes dynamic loader which loads the referenced module and replaces the respective entries in GOT

17 Dynamic Linking against static linking –saves disk space »do not duplicate shared modules in each executable file –saves memory space »by sharing binary code –new versions of library code are immediately usable –a module in memory can be linked immediately drawbacks –extra work needs to be done to set up GOT (but much less modules need to be loaded since some are already in memory) –the location of module in AS is not determined until run time »the code of the module should be position-independent relative addresses only »indirect call via the GOT

18 MD DOS Linker object file (.OBJ) –generated by assembler (or compiler) –format THEADRname of this object module PUBDEFexternal symbols defined in this module EXTDEF external symbols used here TYPDEFdata types for pubdef and extdef SEGDEFdescribes segments in this module GRPDEFsegment grouping LNAMESname list indexed by segdef and grpdef LEDATA binary image of code LIDATArepeated data FIXUPPmodification record MODENDend

19 MS DOS Linker (cont’d) LINK –pass 1: »allocates segments defined in SEGDEF »resolve external symbols –pass 2: »prepare memory image if needed, disk space is also used »expand LIDATA »relocations within segment »write.EXE file

20 SunOS Linkers SunOS is UNIX two different linkers link-editor (ld) produces several types of output –relocatable object module »need to be link-edited later –static executable –dynamic executable –shared object »can be bounded at run time run-time linker –bind dynamic executables and shared object at execution time