10
CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile- Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE UNIVERSITY, WILBERFORCE, OH 1

CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE

Embed Size (px)

Citation preview

Page 1: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE

CPS3340 COMPUTER

ARCHITECTURE Fall Semester, 2013

CPS3340 COMPUTER

ARCHITECTURE Fall Semester, 2013

10/29/2013

Lecture 13: Compile-Link-Load

Instructor: Ashraf YaseenDEPARTMENT OF MATH & COMPUTER SCIENCECENTRAL STATE UNIVERSITY, WILBERFORCE, OH

1

Page 2: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE

Review

Last Class Procedures Handling Character Data

This Class Starting and Loading a Program Linking Dynamic Linking

Next Class Quiz

2

Page 3: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE

Translation and Startup

Many compilers produce object modules directly

Static linking

3

Page 4: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE

Assembler Pseudoinstructions

Most assembler instructions represent machine instructions one-to-one

Pseudoinstructions: figments of the assembler’s imaginationmove $t0, $t1 → add $t0, $zero, $t1

blt $t0, $t1, L → slt $at, $t0, $t1bne $at, $zero, L

$at (register 1): assembler temporary

4

Page 5: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE

Producing an Object Module

Assembler (or compiler) translates program into machine instructions

Provides information for building a complete program from the pieces Header: described contents of object module Text segment: translated instructions Static data segment: data allocated for the life of

the program Relocation info: for contents that depend on

absolute location of loaded program Symbol table: global definitions and external refs Debug info: for associating with source code

5

Page 6: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE

Linking Object Modules

Produces an executable image1. Merges segments2. Resolve labels (determine their

addresses)3. Patch location-dependent and

external refs Could leave location dependencies for

fixing by a relocating loader

6

Page 7: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE

Loading a Program

Load from image file on disk into memory1. Read header to determine segment sizes2. Create virtual address space3. Copy text and initialized data into memory

Or set page table entries so they can be faulted in

4. Set up arguments on stack5. Initialize registers (including $sp, $fp, $gp)6. Jump to startup routine

Copies arguments to $a0, … and calls main When main returns, do exit syscall

7

Page 8: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE

Dynamic Linking

Only link/load library procedure when it is called Requires procedure code to be relocatable Avoids image bloat caused by static linking

of all (transitively) referenced libraries Automatically picks up new library versions

8

Page 9: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE

Summary

Handling Character Data Starting a program Loading a program Dynamic linking

9

Page 10: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE

What I want you to do

Review Chapter 2 Prepare for Midterm II

10