Assembler/Linker/Loader Mooly Sagiv html://www.cs.tau.ac.il/~msagiv/courses/wcc04.html Chapter 4.3.

Slides:



Advertisements
Similar presentations
Chapter 11 Implementing an Assembler and a Linker Using C++ and Java.
Advertisements

Compiler construction in4020 – lecture 10 Koen Langendoen Delft University of Technology The Netherlands.
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
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.
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.
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++
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
Compilation (Semester A, 2013/14) Lecture 13: Assembler, Linker & Loader Noam Rinetzky Slides credit: Eli Bendersky, Mooly Sagiv & Sanjeev Setia.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object Code.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Code Generation for Basic Blocks Introduction Mooly Sagiv html:// Chapter
MIPS Assembler Programming
An introduction to systems programming
Compiler Summary Mooly Sagiv html://
Memory management. Instruction execution cycle Fetch instruction from main memory Decode instruction Fetch operands (if needed0 Execute instruction Store.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
A Simple Two-Pass Assembler
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:
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.
Assemblers.
Chapter 1 Computer architecture Languages: machine, assembly, high
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 4.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
1 Assemblers System Programming by Leland L. Beck Chapter 2.
Computer Science 210 Computer Organization More on Assembler.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.
The Assembly Process Computer Organization and Assembly Language: Module 10.
Compilation Lecture 13: Course summary: Advanced Topics Noam Rinetzky 1.
CSc 453 Linking and Loading
CHAPTER 3-1, 3-2 MEMORY MANAGEMENT. MEMORY HIERARCHY Small amount of expensive, fast, volatile cache Larger amount of still fast, but slower, volatile.
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.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
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.
Assemblers, linkers, loaders
Computer Architecture & Operations I
Memory management.
Computer Science 210 Computer Organization
System Programming and administration
The University of Adelaide, School of Computer Science
Program Execution in Linux
Computer Science 210 Computer Organization
Chapter 7 LC-2 Assembly Language.
Computer Organization & Compilation Process
CALL & Pthread.
Loaders and Linkers: Features
ECEG-3202 Computer Architecture and Organization
A Simple Two-Pass Assembler
Computer Architecture
System Programming by Leland L. Beck Chapter 2
Program Execution in Linux
Chapter 1 Computer architecture Languages: machine, assembly, high
10/6: Lecture Topics C Brainteaser More on Procedure Call
An introduction to systems programming
Program Assembly.
Presentation transcript:

Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3

Outline Where does it fit into the compiler Functionality “Backward” description Assembler design issues Linker design issues

A More Realistic Compiler

Assembler Generate executable code from assembly Yet another compiler One-to one translation Resolve external references Relocate code How does it fit together? Is it really part of the compiler?

Program Runtime State Code segment Stack segment Data Segment Machine Registers

Program Run Code segment Stack segment Data Segment Machine Registers Operating System Loader.EXE Code segment Data Segment Initial stack size Start address Debug

Program Run Code segment Stack segment Data Segment Machine Registers.EXE Code segment Data Segment Initial stack size Start address

Loader (Summary) Part of the operating system Does not depend on the programming language Privileged mode Initializes the runtime state Invisible activation record

Linker Code Segment Data Segment Code Segment Data Segment Relocation Bits External Symbol Table

Linker Merge several executables Resolve external references Relocate addresses User mode Provided by the operating system But can be specific for the compiler –More secure code –Better error diagnosis

Relocation information How to change internal addresses Positions in the code which contains addresses (data/code) Two implementations –Bitmap –Linked-lists

External References The code may include references to external names (identifiers) –Library calls –External data Stored in external symbol table

Example

Recap Assembler generates binary code –Unresolved addresses –Relocatable addresses Linker generates executable code Loader generates runtime states (images)

Assembler Design Issues Converts symbolic machine code to binary One to one conversion addl %edx, %ecx  = 01 D1 (Hex) Some assemblers support overloading –Different opcodes based on types Format conversions Handling internal addresses

Handling Internal Addresses

Resolving Internal Addresses Two scans of the code –Construct a table label  address –Replace labels with values Backpatching –One scan of the code –Simultaneously construct the table and resolve symbolic addresses – Maintains list of unresolved labels –Useful beyond assemblers

Backpatching

Handling External Addresses Record symbol table in external table Produce binary version together with the code and relocation bits Output of the assembly –Code segment –Data segment –Relocation bits –External table

Example of External Symbol Table

Example

Linker Design Issues Append –Code segments –Data segments –Relocation bit maps –External symbol tables Retain information about static length Real life complications –Aggregate initializations –Object file formats –Large library –Efficient search procedures

Summary Code generation yields code which is still far from executable –Delegate to existing assembler Assembler translates symbolic instructions into binary and creates relocation bits Linker creates executable from several files produced by the assembly Loader creates an image from executable