CS 140 Lecture Notes: LinkersSlide 1 Memory Layout for Process Code 0 ∞ Data Stack.

Slides:



Advertisements
Similar presentations
Copyright 2013 – Noah Mendelsohn Compiling C Programs Noah Mendelsohn Tufts University Web:
Advertisements

Cosc 2150 Arrays in assembly code. Variables and addresses Uncompiled ld [a], %r1 addcc %r1, 2, %r3 ARC has three addressing modes —immediate, direct,
Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Compiler construction in4020 – lecture 10 Koen Langendoen Delft University of Technology The Netherlands.
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
1 Computer Architecture MIPS Simulator and Assembly language.
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.
CS 140 Lecture Notes: LinkersSlide 1 Memory Layout for Process Code 0 ∞ Data Stack.
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
CS2422 Assembly Language & System Programming January 2, 2007.
1 Simple C Programs. 2 Goals for this Lecture Help you learn about: Simple C programs Program structure Defining symbolic constants Detecting and reporting.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management - 2 CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent.
1 Assemblers and Linkers CS Goals of This Lecture Compilation process  Compile, assemble, archive, link, execute Assembling  Representing instructions.
1 Functions (covered by Chapter 5 in ABC). 2 Type function_name( parameter list ) { Declarations Statements } Function Definition Header body Partitioning.
An introduction to systems programming
CS 61C L14Introduction to MIPS: Instruction Representation II (1) Garcia, Spring 2004 © UCB Roy Wang inst.eecs.berkeley.edu/~cs61c-tf inst.eecs.berkeley.edu/~cs61c.
C and Data Structures Baojian Hua
CS 140 Lecture Notes: Virtual MemorySlide 1 Load-Time Relocation Process 1 0 ∞ Process 3 Operating System Process 6.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
CS 140 Lecture Notes: LinkersSlide 1 Memory Layout for Process Code 0 ∞ Data Stack.
Program Compilation and Execution. Today’s Objectives Explain why runtime stack needed for C Explain why runtime stack needed for C Draw logical division.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
1 Compilers Modern Compiler Design Supplementary Note 2 SPIM Overview NCYU C. H. Wang.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
ECE 103 Engineering Programming Chapter 36 C Storage Classes Herbert G. Mayer, PSU CS Status 8/4/2014 Initial content copied verbatim from ECE 103 material.
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
Oct 2001ANSI C Under Unix (v1.0)1 UNIX C Programming under Unix written and presented by M.T.Stanhope.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Program Translation and Execution I: Linking Sept. 29, 1998 Topics object files linkers class11.ppt Introduction to Computer Systems.
CS 140 Lecture Notes: Virtual MemorySlide 1 Load-Time Relocation Process 1 0 ∞ Process 3 Operating System Process 6.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
“Success consists of going from failure to failure without loss of enthusiasm.” Winston Churchill.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Lecture 3 Translation.
Lecture2.
Dawson Engler Stanford CS department
CS 140 Lecture Notes: Virtual Memory
Computer Architecture & Operations I
System Programming and administration
The University of Adelaide, School of Computer Science
Memory Layout for Process
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
Program Execution in Linux
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
CSC 253 Lecture 8.
CS 140 Lecture Notes: Virtual Memory
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CSC 253 Lecture 8.
Computer Organization & Compilation Process
Stack Memory 2 (also called Call Stack)
Memory Layout for Process
Loaders and Linkers.
Memory Allocation CS 217.
CS 140 Lecture Notes: Virtual Memory
Memory Physical and Virtual
The Assembly Language Level
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CS-401 Assembly Language Programming
C (and C++) Pointers April 4, 2019.
Program Execution in Linux
Loaders and Linkers.
Assemblers, Linkers, and Loaders
10/6: Lecture Topics C Brainteaser More on Procedure Call
An introduction to systems programming
Memory Layout for Process
CS 140 Lecture Notes: Virtual Memory
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Presentation transcript:

CS 140 Lecture Notes: LinkersSlide 1 Memory Layout for Process Code 0 ∞ Data Stack

CS 140 Lecture Notes: LinkersSlide 2 Creating a Process Code 0 ∞ Data Stack ccx.cx.sasx.o ccy.cy.sasy.o ccz.cz.sasz.o Source Code Assembly Code Object Code Executable a.out CompilerAssemblerLinkerLoader ld OS

CS 140 Lecture Notes: LinkersSlide 3 A Simple Example extern float sin(); extern printf(), scanf(); main() { double x, result; printf("Type number: "); scanf("%f", &x); result = sin(x); printf("Sine is %f\n", result); } extern float sin(); extern printf(), scanf(); main() { double x, result; printf("Type number: "); scanf("%f", &x); result = sin(x); printf("Sine is %f\n", result); } main.c int printf(char *fmt,...) {... } int scanf(char *fmt,...) {... } int printf(char *fmt,...) {... } int scanf(char *fmt,...) {... } stdio.c double sin(double x) { static double res, lastx; if (x != lastx) { lastx = x; … compute sin(x) … } return res; } double sin(double x) { static double res, lastx; if (x != lastx) { lastx = x; … compute sin(x) … } return res; } math.c

CS 140 Lecture Notes: LinkersSlide 4 Object File extern float sin(); extern printf(), scanf(); main() { double x, result; printf("Type number: "); scanf("%f", &x); result = sin(x); printf("Sine is %f\n", result); } extern float sin(); extern printf(), scanf(); main() { double x, result; printf("Type number: "); scanf("%f", &x); result = sin(x); printf("Sine is %f\n", result); } main.cmain.o call printf... call scanf... call sin... call printf def: ref: T:56 ref: ref: call printf... call scanf... call sin... call printf def: ref: T:56 ref: ref: text segment symbols relocation

CS 140 Lecture Notes: LinkersSlide 5 Object File double sin(double x) { static double res, lastx; if (x != lastx) { lastx = x; … compute sin(x) … } return res; } double sin(double x) { static double res, lastx; if (x != lastx) { lastx = x; … compute sin(x) … } return res; } math.cmath.o load lastx... store lastx... load res res: lastx: def: def: def: ref: T:20 ref: load lastx... store lastx... load res res: lastx: def: def: def: ref: T:20 ref: text segment data segment relocation symbols

CS 140 Lecture Notes: LinkersSlide 6 After Pass 1 main.o text math.o text stdio.o text math.o data 708 stdio.o data 836 main:0 sin:64 lastx:700 result:708 printf:314 scanf:508 Memory map:Symbol table:

CS 140 Lecture Notes: LinkersSlide 7 Relocation text segment in main.o call 0... ref: relocation record in main.o sin: 64 symbol table text segment in a.out call 64...

CS 140 Lecture Notes: LinkersSlide 8