From Source to Execution:

Similar documents
ECE260: Fundamentals of Computer Engineering

MIPS (SPIM) Assembler Syntax

(Extract from the slides by Terrance E. Boult

Linking. Explain what ELF format is. Explain what an executable is and how it got that way. With huge thanks to Steve Chong for his notes from CS61.

CSCI341. Lecture 22, MIPS Programming: Directives, Linkers, Loaders, Memory

From Code to Program: CALL Con'nued (Linking, and Loading)

Executables and Linking. CS449 Spring 2016

Generating Programs and Linking. Professor Rick Han Department of Computer Science University of Colorado at Boulder

M2 Instruction Set Architecture

Linking and Loading. ICS312 - Spring 2010 Machine-Level and Systems Programming. Henri Casanova

CS 61C: Great Ideas in Computer Architecture CALL continued ( Linking and Loading)

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

Chapter 3 Loaders and Linkers -- Loader Design Options

Outline. Unresolved references

CSE 2421: Systems I Low-Level Programming and Computer Organization. Linking. Presentation N. Introduction to Linkers

A Simplistic Program Translation Scheme

Compiler Drivers = GCC

CIT 595 Spring System Software: Programming Tools. Assembly Process Example: First Pass. Assembly Process Example: Second Pass.

Review C program: foo.c Compiler Assembly program: foo.s Assembler Object(mach lang module): foo.o

Review C program: foo.c Compiler Assembly program: foo.s Assembler Object(mach lang module): foo.o

Lec 13: Linking and Memory. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

3.3 Machine-Independent Loader Features

Loaders. Systems Programming. Outline. Basic Loader Functions

Reviewing gcc, make, gdb, and Linux Editors 1

Chapter 3: Loaders and Linkers

LOADERS AND LINKERS 1. BASIC LOADER FUNCTIONS 2. DESIGN OF AN ABSOLUTE LOADER 3. A SIMPLE BOOTSTRAP LOADER 4. MACHINE DEPENDENT LOADER FEATURES

The Assembly Language Level. Chapter 7

A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp)

ECE 3210 Laboratory 1: Develop an Assembly Program

COS 318: Operating Systems

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

LINKING. Jo, Heeseung

Administrivia. Midterm Exam - You get to bring. What you don t need to bring. Conflicts? DSP accomodations? Head TA

CSCI 2321 (Computer Design), Spring 2018 Homework 3

Making Address Spaces Smaller

Review. Disassembly is simple and starts by decoding opcode field. Lecture #13 Compiling, Assembly, Linking, Loader I

Assembler. #13 Running a Program II

Part I: Translating & Starting a Program: Compiler, Linker, Assembler, Loader. Lecture 4

COS 318: Operating Systems. Overview. Andy Bavier Computer Science Department Princeton University

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

Link 7.A Static Linking

Executables and Linking. CS449 Fall 2017

CS61C : Machine Structures

Chapter 3 Loaders and Linkers

UNIT III LOADERS AND LINKERS PART A

Linking Oct. 15, 2002

2012 LLVM Euro - Michael Spencer. lld. Friday, April 13, The LLVM Linker

Machine Code and Assemblers November 6

Where Are We Now? Linker (1/3) Linker (2/3) Four Types of Addresses we ll discuss. Linker (3/3)

CS2141 Software Development using C/C++ Libraries

UNIT III LOADERS AND LINKERS

The Software Stack: From Assembly Language to Machine Code

CS 110 Computer Architecture Running a Program - CALL (Compiling, Assembling, Linking, and Loading)

ECE 15B COMPUTER ORGANIZATION

CS61C Machine Structures. Lecture 18 - Running a Program I. 3/1/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

Prepared By : Ms. Sanchari Saha ( Asst. Professor) Department : Computer Science & Engineering

Name: Problem 1: (25 points) Short Answers. a) (10 points) Executing a program

[07] SEGMENTATION 1. 1

Lecture 19 CSE August You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii.

CSE 303: Concepts and Tools for Software Development

3. Memory Management

gpio timer uart printf malloc keyboard fb gl console shell

2 Compiling a C program

Compile: compiler. Load: loader. compiler linker loader memory. source object load code module module 2

UCB CS61C : Machine Structures

CS61C : Machine Structures

Compiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

ECE 15B COMPUTER ORGANIZATION

EE458 - Embedded Systems Lecture 4 Embedded Devel.

Incremental Linking with Gold

Software Concepts. It is a translator that converts high level language to machine level language.

Assemblers, Linkers, and Loaders

CSE 333 Interlude - make and build tools

12: Memory Management

C03c: Linkers and Loaders

UNIT III - LOADERS AND LINKERS

If you are on a Mac/Linux box, some commands will differ, but many will be the same.

Exercise Session 7 Computer Architecture and Systems Programming

INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE

Embedded Systems. 2. Software Development. Lothar Thiele. Computer Engineering and Networks Laboratory

UCB CS61C : Machine Structures

Threads. Computer Systems. 5/12/2009 cse threads Perkins, DW Johnson and University of Washington 1

Slide Set 4. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

#include <stdio.h> int main() { printf ("hello class\n"); return 0; }

CSC258: Computer Organization. Functions and the Compiler Tool Chain

Relocating Symbols and Resolving External References. CS429: Computer Organization and Architecture. m.o Relocation Info

Laboratorio di Programmazione. Prof. Marco Bertini

Systems Architecture I

Administrivia. Translation. Interpretation. Compiler. Steps to Starting a Program (translation)

Intermediate Programming, Spring 2017*

CS429: Computer Organization and Architecture

IA-32 Architecture. CS 4440/7440 Malware Analysis and Defense

CPEG421/621 Tutorial

Lecture 10: Program Development versus Execution Environment

Memory Management. Memory Management

Laboratorio di Tecnologie dell'informazione

The A ssembly Assembly Language Level Chapter 7 1

The C standard library

Compiler, Assembler, and Linker

Transcription:

From Source to Execution: Translation and Linking CSE 410, Spring 2009 Computer Systems http://www.cs.washington.edu/410 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 1

Reading Readings and References» Section 2.12, Translating and Starting a Program» Appendix B.1, Introduction» Appendix B.2, Assemblers» Appendix B.3, B3 Linkers» Appendix B.4, Loading 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 2

Starting a Program Two phases from source code to execution Build time» compiler creates assembly code» assembler creates machine code» linker creates an executable (Spim assembles/links when file loaded) Run time» loader moves the executable into memory and starts t the program 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 3

Build Time You re experts on generating assembly language: either by writing high-level h l code that t is compiled, or by hand Two parts to translating from assembly to machine language:» Instruction encoding (including translating pseudoinstructions)» Translating labels to addresses Label translations s go in the symbol table» Symbol table: map from labels (names) to their addresses in the code 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 4

Modular Program Design Small projects might use only one file» Any time any one line changes, recompile and reassemble the whole thing For larger projects, recompilation time and complexity management is significant Solution: split project into modules» compile and assemble modules separately» link the object files 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 5

The Compiler + Assembler Translate source files to object files Object files» Contain machine instructions (1 s & 0 s)» Contain bookkeeping information Procedures and variables the object file defines (globals) lbl) Procedures and variables the object file uses but does not define (unresolved [or external] references) Debugging information associating machine instructions with lines of source code 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 6

The Linker The linker s job is to stitch together the object files: 1. Place the modules in memory space 2. Determine the addresses of data and labels 3. Match up references between modules Creates an executable file 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 7

Determining Addresses Some addresses change during memory layout Modules were compiled/assembled in isolation» Assembler assigns addresses starting at 0 during assembly» Final addresses assigned by linker Absolute addresses must be relocated Object file keeps track of instructions that use absolute addresses textt text 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 8

main.o code: main:a=area(5.0) static data: PI = 3.1415 defined symbols: main, PI undefined symbols: Area Linker Example main.exe area.o code: Area:return PI*r*r static data: defined symbols: Area undefined symbols: PI header code: main:a=area(5.0) area(5.0) Area:return PI*r*r static data: PI = 3.1415 defined symbols: main, PI, Area 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 9

Libraries Some code is used so often, it is bundled into lb libraries for common access Libraries contain most of the code you use but didn t write: e.g., printf(), sqrt() Library code is (often) merged with yours at link time main.o libc.a main.exe 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 10

The Executable End result of compiling, assembling, and linking: the executable» Header, listing the lengths of the other segments» Text (code) segment» Static data segment» Potentially other segments, depending on architecture & OS conventions 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 11

Run Time When a program is started...»some dynamic linking may occur some symbols aren t defined until run time Windows dlls (dynamic link library)» The segments are loaded into memory» The OS transfers control to the program and it runs We ll learn a lot more about this during the OS part of the course 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington 12