Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
Operating Systems1 9. Linking and Sharing 9.1 Single-Copy Sharing –Why Share –Requirements for Sharing –Linking and Sharing 9.2 Sharing in Systems without.
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
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
Chapter 3 Loaders and Linkers
Loaders and Linkers CS 230 이준원. 2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable.
Lecture 10: Linking and loading. Lecture 10 / Page 2AE4B33OSS 2011 Contents Linker vs. loader Linking the executable Libraries Loading executable ELF.
Mr. D. J. Patel, AITS, Rajkot 1 Operating Systems, by Dhananjay Dhamdhere1 Static and Dynamic Memory Allocation Memory allocation is an aspect of a more.
Linkers and Loaders 1 Linkers & Loaders – A Programmers Perspective.
Operating Systems Lecture Notes Memory Management Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
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++
Memory Management Chapter 7.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 33: Code Generation and Linking COMP 144 Programming Language Concepts Spring 2002.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Memory Management 2010.
Lecture 9: SHELL PROGRAMMING (continued) Creating shell scripts!
A. Frank - P. Weisberg Operating Systems Real Memory Management.
Operating Systems Memory Management (Ch )
Software Development and Software Loading in Embedded Systems.
Memory management. Instruction execution cycle Fetch instruction from main memory Decode instruction Fetch operands (if needed0 Execute instruction Store.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,
MIPS coding. SPIM Some links can be found such as:
OSes: 8. Mem. Mgmt. 1 Operating Systems v Objectives –describe some of the memory management schemes used by an OS so that several processes can be in.
© 2004, D. J. Foreman 1 Memory Management. © 2004, D. J. Foreman 2 Building a Module -1  Compiler ■ generates references for function addresses may be.
Chapter 4 Storage Management (Memory Management).
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.
Lecture 11 Dynamic link libraries. Differences between static libraries and DLLs In static library code is added to the executable. In DLL, the code is.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
CSE451 Linking and Loading Autumn 2002 Gary Kimura Lecture #21 December 9, 2002.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Chapter 4 Memory Management Virtual Memory.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
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.
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
The Assembly Language Level Part C – Linking and Loading.
WEEK 5 LINKING AND LOADING MEMORY MANAGEMENT PAGING AND SEGMENTATION Operating Systems CS3013 / CS502.
Program Libraries 1. What is a program library? A library is a collection of implementations of behavior, written in terms of a language, that has a well-defined.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
CSc 453 Linking and Loading
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
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)
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Lecture 3 Translation.
SLC/VER1.0/OS CONCEPTS/OCT'99
Memory management.
The University of Adelaide, School of Computer Science
Linking & Loading.
Memory Management © 2004, D. J. Foreman.
Chapter 8 Main Memory.
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
Program Execution in Linux
CS-3013 Operating Systems C-term 2008
The Assembly Language Level
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 Tasks
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
The Assembly Language Level
Linking & Loading CS-502 Operating Systems
Program Execution in Linux
Linking & Loading CS-502 Operating Systems
OPERATING SYSTEMS MEMORY MANAGEMENT BY DR.V.R.ELANGOVAN.
CSE 542: Operating Systems
Presentation transcript:

Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just one big program, saving the necessity of linking? – Efficiency: if just one function is changed in a 100K line program, why recompile the whole program? Just recompile the one function and relink. –Multiple-language programs –Other reasons?

Relocation Before widespread support for virtual memory, code had to be relocatable (could not contain fixed memory addresses) With VM, when a page is swapped out, bringing it back in makes the references change (update PT) With shared libraries, each library decides on its own (fixed) addresses  collision of addresses Relocation problem same as before virtual memory –What is the problem? No fixed addresses (calls, vars, ifs) –What is the solution? Shared libraries!

Object Modules: linking and loading Structure of an object module –Entry points –External symbols Binding time and dynamic relocation: possible binding times –Virtual addresses –Relocation register –Use addresses relative to program counter

Dynamic linking Unix systems: Code is typically compiled as a dynamic shared object (DSO): Dynamic vs. static linking $ gcc -static hello.c -o hello-static $ gcc hello.c -o hello-dynamic $ ls -l hello 80 hello.c hello-dynamic 383 hello.s hello-static if you are the sys admin, which do you prefer?

Advantages of dynamic linking The executable is smaller (it not include the library information explicitly), When the library is changed, the code that references it does not usually need to be recompiled. The executable accesses the.DLL at run time; therefore, multiple codes can access the same.DLL at the same time (saves memory)

Shortcomings of dynamic linking Performance hit ~10% –Need to load shared objects (once) –Need to resolve addresses (once or every time) What if the necessary dynamic library is missing? Could have the library, but wrong version

Unix Dynamic Objects (.so) Host library Target library Compiler Options (cont) –-nostartfiles skip linking of standard start files, like /usr/lib/crt[0,1].o, /usr/lib/crti.o, etc. –-static link only to static (.a=archive) libraries –-shared if possible, prefer shared libraries over static Linker Options (gcc gives unknown options to linker) –-l lib (default naming convention liblib.a) –-L lib path (in addition to default /usr/lib and /lib) –-s strip final executable code of symbol and relocation tables

DLL: dynamic link libraries Static Windows libraries are.LIB Implicit linking Statically linked to import library Checks which DLLs in memory & loads missing ones Have to map DLLs into program address space Explicit linking –prog makes explicit runtime to bind to DLL, then –makes a call per procedure to determine address –then calls procedure. What are the pros/cons of the two approaches?