Object Files & Linking. Object Sections Compiled code store as object files – Linux : ELF : Extensible Linking Format – Windows : PE : Portable Execution.

Slides:



Advertisements
Similar presentations
Hand-Held Devices and Embedded Systems Course Student: Tomás Sánchez López Student ID:
Advertisements

Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Part IV: Memory Management
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.
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
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.
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
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.
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
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++
Loaders and Linkers Object Program contains the information:
Compilation (Semester A, 2013/14) Lecture 13: Assembler, Linker & Loader Noam Rinetzky Slides credit: Eli Bendersky, Mooly Sagiv & Sanjeev Setia.
Linking and Loading Fred Prussack CS 518. L&L: Overview Wake-up Questions Terms and Definitions / General Information LoadingLinking –Static vs. Dynamic.
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3.
Software Development and Software Loading in Embedded Systems.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
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.
Separate Assembly allows a program to be built from modules rather than a single source file.
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:
Runtime Environments Compiler Construction Chapter 7.
CSU System Programming, NTNU CSIE1 / 99 Linkers and Libraries Advisor: Dr. Gwan-Hwan Hwang Lecturer: Che-Sheng Lin.
Lecture-1 Compilation process
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
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.
Topic 2d High-Level languages and Systems Software
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.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Buffer Overflow Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
Linking Ⅱ.
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Paradyn Project Paradyn / Dyninst Week Madison, Wisconsin April 12-14, 2010 Binary Rewriting with Dyninst Madhavi Krishnan and Dan McNulty.
Different Types of Libraries
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 31 Memory Management.
The Development Process Compilation. Compilation - Dr. Craig A. Struble 2 Programming Process Problem Solving Phase We will spend significant time on.
1 Linking. 2 Outline What is linking and why linking Complier driver Static linking Symbols & Symbol Table Suggested reading: 7.1~7.5.
CSc 453 Linking and Loading
Linking I Topics Assembly and symbol resolution Static linking Systems I.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Студенческая лаборатория МФТИ-Intel Assembler, Linker, MIPS Simulator Andrey Rodchenko
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Lecture 3 Translation.
Assemblers, linkers, loaders
The University of Adelaide, School of Computer Science
Linking & Loading.
Linux Userspace Process Memory Layout
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
Computer Science 210 Computer Organization
Topic 2e High-Level languages and Systems Software
Computer Science 210 Computer Organization
Linking & Loading CS-502 Operating Systems
Program Execution in Linux
Loaders and Linkers.
Linking & Loading CS-502 Operating Systems
Program Assembly.
OPERATING SYSTEMS MEMORY MANAGEMENT BY DR.V.R.ELANGOVAN.
Run-time environments
Presentation transcript:

Object Files & Linking

Object Sections Compiled code store as object files – Linux : ELF : Extensible Linking Format – Windows : PE : Portable Execution

Object Sections ELF sections.text : Executable code read/executable.rodata : Read Only Data read.data : Data read/write.bss : Uninitialized Data read/write

Object at Runtime At runtime segments loaded into process address space

Object at Runtime Addresses need to be relocatable – Linker needs to move as it combines objects

Relocation Addresses stored as offset in section Address = section start + offset Mov instruction = Code start + Offset = 0xXXXXF xXXXX0080

Relocation Code sample: – Array in.data – getNum accesses – getBiggerNum calls others

Relocation Offsets

Relocation Do not have final addresses for branches & loads

Relocation Table Relocation Table stores addresses that need fixing at link time: Offset of item Address it needs

Relocation Linker fixes up

Static Libraries Static Libraries: – Collection of 1+ object files designed to bake into executable at compile time – Windows : mylibrary.lib – Linux mylibrary.a

Static Libraries Static Issues: – All library code included in every executable – Every running program has own copies of in memory – Need to recompile to use new library code

Static Libraries Dynamic Libraries: – Collection of 1+ object files designed to be linked at run time – Windows : mylibrary.dll (dynamically linked library) – Linux mylibrary.so (shared object)

Static Libraries Dynamic Wins: – Executable does not need lib code – Every running program can share one copy of library – May not need to recompile to use new library code

Static Libraries Dynamic Wins: – Every running program can share one copy of library Library code must not be modifiable in.text

Static Libraries Dynamic Wins: – May not need to recompile to use new library code As long as no features removed/reordered

Dynamic Sample Program to make use of dynamic library:

Dynamic Sample Program to make use of dynamic library: – Function calls now go to

Dynamic Sample Program to make use of dynamic library: – Function calls now go to

PLT Procedure Linkage Table Jump table in.data used to look up dynamic functions

PLT First call, Global Offset Table points back to code to dynamic loader

PLT Loader replaces GOT record with

Other Dynamic Tricks Can load library at run time:

Other Dynamic Tricks Can load library at run time:

Other Dynamic Tricks Can hijack dynamic library calls – Hacking – Debugging