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.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
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
Chapter 3 Loaders and Linkers. Purpose and Function Places object program in memory Linking – Combines 2 or more obj programs Relocation – Allows loading.
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.
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.
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 Machine-Independent Features Automatic Library Search automatically incorporate routines from a subprogram library Loading Options.
Multiprocessing Memory Management
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.
An introduction to systems programming
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
A. Frank - P. Weisberg Operating Systems Real Memory Management.
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.
UNIX ELF File Format. Elf File Format The a.out format served the Unix community well for over 10 years. However, to better support cross-compilation,
CHP - 9 File Structures. INTRODUCTION In some of the previous chapters, we have discussed representations of and operations on data structures. These.
Separate Assembly allows a program to be built from modules rather than a single source file.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
MIPS coding. SPIM Some links can be found such as:
Chapter 10 - Memory Management –Memory management can have a large influence on the performance of a program. –Operating system handles allocation of memory.
© 2004, D. J. Foreman 1 Memory Management. © 2004, D. J. Foreman 2 Building a Module -1  Compiler ■ generates references for function addresses may be.
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
Topic 2d High-Level languages and Systems Software
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
Different Types of Libraries
Memory Management: Overlays and Virtual Memory. Agenda Overview of Virtual Memory –Review material based on Computer Architecture and OS concepts Credits.
NETW3005 Memory Management. Reading For this lecture, you should have read Chapter 8 (Sections 1-6). NETW3005 (Operating Systems) Lecture 07 – Memory.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
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.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
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.
CHP - 9 File Structures.
System Programming and administration
The University of Adelaide, School of Computer Science
Linking & Loading.
Memory Management © 2004, D. J. Foreman.
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
Page Replacement.
Loaders and Linkers: Features
Machine Independent Features
Memory Management Tasks
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Memory Management Overview
Computer Organization and Design Assembly & Compilation
Linking & Loading CS-502 Operating Systems
File-System Structure
Memory management Explain how memory is managed in a typical modern computer system (virtual memory, paging and segmentation should be described.
Program Execution in Linux
10/6: Lecture Topics C Brainteaser More on Procedure Call
Linking & Loading CS-502 Operating Systems
An introduction to systems programming
Presentation transcript:

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 a lot of time. (e.g., the printf() in the C library) However, if a library is not shared among many programs, but instead a copy is included in every program that uses it, the size of each linked program will be large. Also, a lot of disk and memory space will be wasted by these programs that uses non-shared libraries. This motivates the concept of shared library.

How Does It Work? At link time, the linker searches through libraries to find modules that resolve undefined external symbols. Rather than copying the contents of the module into the output file, the linker makes a note of what library the module come from and puts a list of the libraries in the executable. When the program is loaded, startup code finds those libraries and maps them into the program’s address space before the program starts. Standard operating system file-mapping semantics automatically share pages that are mapped read-only or copy-on-write.

An Example Program #include main() { printf("exponential value %d\n", exp(-1)); }

Its Shared Library Usage Information Program Header: PHDR off 0x vaddr 0x paddr 0x align 2**2 filesz 0x000000c0 memsz 0x000000c0 flags r-x DYNAMIC off 0x000005f4 vaddr 0x080495f4 paddr 0x080495f4 align 2**2 filesz 0x memsz 0x flags rw- Dynamic Section: NEEDED libm.so.2 NEEDED libc.so.4

Linking Shared Libraries The most difficult aspect of static shared libraries is address space management. Each shared library occupies a fixed piece of address space in each program in which it is used. Different libraries have to use non-overlapping addresses if they can be used in the same program. Assigning address space to libraries is a black art. –On one hand, you want to leave some space in between them to allow version updates. –On the other hand, you like to put popular libraries as close together as possible to minimize the number of page tables needed.

Address Space Allocation Example shieyuan3# ldd a.out a.out: libm.so.2 => /usr/lib/libm.so.2 (0x ) libc.so.4 => /usr/lib/libc.so.4 (0x )

Address Space Management Generally both the code and the data addresses for each library are explicitly defined, with the data area starting on a page boundary a page or two after the end of the code. This makes it possible to create minor version updates, because updates frequently do not change the data layout, but just add or change code.

Techniques for Minor Updates Each individual shared library exports symbols, both code and data, and usually also imports symbols if the library depends on other libraries. To allow library updates, we need a method to update a library without changing the addresses of exported symbols. For code addresses, rather than exporting the address of each routine, the library contains a table of jump instructions that jump to all of the routines, with the addresses of the jump instructions exported as the addresses of the routines. The performance cost is one extra jump. Normally this is acceptable.

Techniques for Minor Updates For exported data, the situation is more difficult, because there is no easy way to add a level of indirection like to one for code addresses. In practice, however, exported data tend to be tables (e.g., the File structure for the C library) of known size or a single word value like errno. We can collect these data and place them at the beginning of the data section to precede any anonymous data that are part of individual routines.

Binding Time Shared libraries raise binding time issues that do not apply to conventionally linked program. A program that uses a shared library depends on having that shared library available when the program is run. One kind of error occurs when the required libraries are not present. In such a case, there is no much we can do. An error message is usually printed.

Binding Time (cont’d) What will happen if the library is present but the library has changed since the program was linked? With static shared libraries, symbols are still bound to addresses at link time, but library code is not bound to the executable code until run time. A static shared library cannot change very much without breaking the programs that it is bound to. –If we change the addresses of routine and data in the new version of library, then the program will crash.

Binding Time (cont’d) A static shared library can sometimes be updated without breaking the program that uses it, if the updates can be made in a way that does not move any address in the library. This permits minor version updates, typically for small bug fixes. Larger changes unavoidably change program addresses, which means that a system needs multiple versions of the library. –E.g., libc.so.4

Structure of Shared Library The shared library is an executable format file. The jump table is considered to be text, because it is executable code.