CS-3013 Operating Systems C-term 2008

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
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
Loaders and Linkers CS 230 이준원. 2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable.
Linkers and Loaders 1 Linkers & Loaders – A Programmers Perspective.
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
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.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
CS 311 – Lecture 21 Outline Memory management in UNIX
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
03/09/2007CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
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.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
Lecture 13 L.Mohammad R.Alkafagee1.  The concept of a logical address space that is bound to a separate physical address space is central to proper memory.
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.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
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.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Operating Systems Lecture 31.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
WEEK 5 LINKING AND LOADING MEMORY MANAGEMENT PAGING AND SEGMENTATION Operating Systems CS3013 / CS502.
Lecture XII: Runtime Software Evolution CS 4593 Cloud-Oriented Big Data and Software Engineering.
Slide 11-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 11.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Introduction to C Topics Compilation Using the gcc Compiler
SLC/VER1.0/OS CONCEPTS/OCT'99
Slides adapted from Bryant and O’Hallaron
Real Memory Management
Linking & Loading.
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
Processes in Unix, Linux, and Windows
Main Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Loaders and Linkers: Features
Machine Independent Features
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
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.
CSE 451: Operating Systems Winter 2010 Module 16 Linking, Loading and Process Startup Mark Zbikowski Gary Kimura 1.
Linking & Loading CS-502 Operating Systems
Your first C and C++ programs
CSE 303 Concepts and Tools for Software Development
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Program Execution in Linux
Processes in Unix, Linux, and Windows
CSE 451: Operating Systems Winter 2009 Module 16 Linking, Loading and Process Startup Mark Zbikowski Gary Kimura 1.
Grades so far (max was 31).
10/6: Lecture Topics C Brainteaser More on Procedure Call
Linking & Loading CS-502 Operating Systems
OPERATING SYSTEMS MEMORY MANAGEMENT BY DR.V.R.ELANGOVAN.
CSE 542: Operating Systems
Presentation transcript:

CS-3013 Operating Systems C-term 2008 Linking & Loading CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System Concepts, 7th ed., by Silbershatz, Galvin, & Gagne and from Modern Operating Systems, 2nd ed., by Tanenbaum) Assumptions: Graduate level Operating Systems Making Choices about operation systems Why a micro-century? …just about enough time for one concept CS-3013 C-term 2008 Linking and Loading

What happens to your program … …after it is compiled, but before it can be run? CS-3013 C-term 2008 Linking and Loading

Executable files Every OS expects executable files to have a specific format Header info Code locations Data locations Code & data Symbol Table List of names of things defined in your program and where they are located within your program. List of names of things defined elsewhere that are used by your program, and where they are used. CS-3013 C-term 2008 Linking and Loading

Example Symbol defined in your program and used elsewhere #include <stdio.h> int main () { printf (“hello, world\n”) } Symbol defined in your program and used elsewhere main Symbol defined elsewhere and used by your program printf CS-3013 C-term 2008 Linking and Loading

Example Symbol defined in your program and used elsewhere #include <stdio.h> extern int errno; int main () { printf (“hello, world\n”) <check errno for errors> } Symbol defined in your program and used elsewhere main Symbol defined elsewhere and used by your program printf errno CS-3013 C-term 2008 Linking and Loading

Two-step operation (in most systems) Linking: Combining a set of programs, including library routines, to create a loadable image Resolving symbols defined within the set Listing symbols needing to be resolved by loader Loading: Copying the loadable image into memory, connecting it with any other programs already loaded, and updating addresses as needed (In Unix) interpreting file to initialize the process address space (in all systems) kernel image is special (own format) CS-3013 C-term 2008 Linking and Loading

From source code to a process Source (.c, .cc) Binding is the act of connecting names to addresses Most compilers produce relocatable object code Addresses relative to zero The linker combines multiple object files and library modules into a single executable file Addresses also relative to zero The Loader reads the executable file Allocates memory Maps addresses within file to memory addresses Resolves names of dynamic library items Compiler Object (.o) Other Objects (.o) Static libraries (.a) Linker Executable Correct - $190, Possible - $90, $200 Dynamic libraries (.dll) Loader In-memory Image CS-3013 C-term 2008 Linking and Loading

Static Linking and Loading Printf.c Printf.o Static Library gcc ar Linker Memory HelloWorld.c HelloWorld.o Loader a.Out (or name of your command) CS-3013 C-term 2008 Linking and Loading

Classic Unix Linker lives inside of cc or gcc command Loader is part of exec system call Executable image contains all object and library modules needed by program Entire image is loaded at once Every image contains its own copy of common library routines Every loaded program contain duplicate copy of library routines CS-3013 C-term 2008 Linking and Loading

Dynamic Loading Routine is not loaded until it is called Better memory-space utilization; unused routines are never loaded. Useful when large amounts of code are needed to handle infrequently occurring cases. Silbershatz says [incorrectly] No special support from the operating system is required Must be implemented through program design CS-3013 C-term 2008 Linking and Loading

Program-controlled Dynamic Loading Requires: A load system call to invoke loader (not in classical Unix) ability to leave symbols unresolved and resolve at run time (not in classical Unix) E.g., void myPrintf (**arg) { static int loaded = 0; if (!loaded ) { load (“printf”); loaded = 1; printf(arg); } CS-3013 C-term 2008 Linking and Loading

Linker-assisted Dynamic Loading Programmer marks modules as “dynamic” to linker For function call to a dynamic function Call is indirect through a link table Each link table entry is initialized with address of small stub of code to locate and load module. When loaded, loader replaces link table entry with address of loaded function When unloaded, loader restores table entry with stub address Works only for function calls, not static data CS-3013 C-term 2008 Linking and Loading

Example – Linker-assisted loading (before) Your program void main () { printf (…); } Link table Stub void load() { … load(“IOLib”); } CS-3013 C-term 2008 Linking and Loading

Example – Linker-assisted loading (after) Your program void main () { printf (…); } Link table IOLib read() {…} printf() {…} scanf() {…} CS-3013 C-term 2008 Linking and Loading

Shared Libraries Observation – “everyone” links to standard libraries (libc.a, etc.) These consume space in every executable image every process memory at runtime Would it be possible to share the common libraries? Automatically load at runtime? CS-3013 C-term 2008 Linking and Loading

Shared libraries (continued) Libraries designated as “shared” .so, .dll, etc. Supported by corresponding “.a” libraries containing symbol information Linker sets up symbols to be resolved at runtime Loader: Is library already in memory? If yes, map into new process space “map,” an operation to be defined later in course If not, load and then map CS-3013 C-term 2008 Linking and Loading

Run-time Linking/Loading Printf.c Printf.o Shared Library gcc ar Linker Memory Loader Save disk space. Startup faster. Might not need all. Run-time HelloWorld.c HelloWorld.o a.Out (or name of your command) CS-3013 C-term 2008 Linking and Loading

Dynamic Linking Complete linking postponed until execution time. Stub used to locate the appropriate memory-resident library routine. Stub replaces itself with the address of the routine, and executes the routine. Operating system needs to check if routine is in address space of process Dynamic linking is particularly useful for libraries. CS-3013 C-term 2008 Linking and Loading

Dynamic Shared Libraries Static shared libraries requires address space pre-allocation Dynamic shared libraries – address binding at runtime Code must be position independent At runtime, references are resolved as Library_relative_address + library_base_address CS-3013 C-term 2008 Linking and Loading

Overlays (primarily of historical interest) Keep in memory only those instructions and data that are needed at any given time. Needed when process is larger than amount of memory allocated to it. Can be implemented by user no special support needed from operating system, but programming design of overlay structure is complex Can be done with OS help – think about Unix exec system call CS-3013 C-term 2008 Linking and Loading

Linking – Summary Linker – key part of OS – not in kernel Combines object files and libraries into a “standard” format that the OS loader can interpret Resolves references and does static relocation of addresses Creates information for loader to complete binding process Supports dynamic shared libraries CS-3013 C-term 2008 Linking and Loading

Loader An integral part of the OS Resolves addresses and symbols that could not be resolved at link-time May be small or large Small: Classic Unix Large: Linux, Windows XP, etc. May be invoke explicitly or implicitly Explicitly by stub or by program itself Implicitly as part of exec CS-3013 C-term 2008 Linking and Loading

Questions? CS-3013 C-term 2008 Linking and Loading