Memory Layout for Process

Slides:



Advertisements
Similar presentations
Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Advertisements

Copyright 2013 – Noah Mendelsohn Compiling C Programs Noah Mendelsohn Tufts University Web:
Compilation (Semester A, 2013/14) Lecture 14: Compiling Object Oriented Programs Noam Rinetzky Slides credit: Mooly Sagiv 1.
Week 4 – Functions Introduction. Functions: Purpose Breaking a large problem into a series of smaller problems is a common problem- solving technique.
Compiler construction in4020 – lecture 10 Koen Langendoen Delft University of Technology The Netherlands.
Linking & Loading CS-502 Operating Systems
Linker and Loader. Program building into four stages (C Program) Preprocessing (Preprocessor) It processes include files, conditional compilation instructions.
Linkers and Loaders 1 Linkers & Loaders – A Programmers Perspective.
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
CS 140 Lecture Notes: LinkersSlide 1 Memory Layout for Process Code 0 ∞ Data Stack.
Chapter 3 Memory Management. 3.1 From Programs To Address Space 3 steps to run the programs of an application – A Compiler translates the source code.
Generating Programs and Linking Professor Rick Han Department of Computer Science University of Colorado at Boulder.
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
CS2422 Assembly Language & System Programming January 2, 2007.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management - 2 CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
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.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
CS 140 Lecture Notes: LinkersSlide 1 Memory Layout for Process Code 0 ∞ Data Stack.
CS 140 Lecture Notes: LinkersSlide 1 Memory Layout for Process Code 0 ∞ Data Stack.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
Lec 4Systems Architecture1 Systems Architecture Lecture 4: Compilers, Assemblers, Linkers & Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan.
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.
Basic I/O in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Stream Model of I/O header file: A stream provides a connection.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Minimal standard C program int main(void) { return 0 ; }
WEEK 5 LINKING AND LOADING MEMORY MANAGEMENT PAGING AND SEGMENTATION Operating Systems CS3013 / CS502.
1 Linking. 2 Outline What is linking and why linking Complier driver Static linking Symbols & Symbol Table Suggested reading: 7.1~7.5.
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
Program Translation and Execution I: Linking Sept. 29, 1998 Topics object files linkers class11.ppt Introduction to Computer Systems.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
Program Execution and ELF Files Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014 Abed Asi.
Object Files & Linking. Object Sections Compiled code store as object files – Linux : ELF : Extensible Linking Format – Windows : PE : Portable Execution.
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
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
Slides adapted from Bryant and O’Hallaron
System Programming and administration
Functions, Part 2 of 2 Topics Functions That Return a Value
Memory Layout for Process
Linking & Loading.
Program Execution in Linux
CS-3013 Operating Systems C-term 2008
Computer Systems and Networks
Administrative things
CS 140 Lecture Notes: Virtual Memory
Today’s Topic Breakdown of CC script.
CALL & Pthread.
Jeremy R. Johnson Wed. Apr. 5, 2000
CS 140 Lecture Notes: Virtual Memory
The Assembly Language Level
Linking & Loading CS-502 Operating Systems
Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan
Systems Architecture I
Program Execution in Linux
Loaders and Linkers.
Assemblers, Linkers, and Loaders
10/6: Lecture Topics C Brainteaser More on Procedure Call
Linking & Loading CS-502 Operating Systems
Memory Layout for Process
CS 140 Lecture Notes: Virtual Memory
Introduction to C Programming
Program Assembly.
Memory Management (Ch 4: )
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
Presentation transcript:

Memory Layout for Process ∞ Stack Data Code CS 140 Lecture Notes: Linkers

CS 140 Lecture Notes: Linkers Creating a Process Source Code Assembly Code Object Code Executable 101010101010101010101010101010101010101010101010 x.c cc x.s as x.o Code ∞ Data Stack 101010101010101010101010101010101010101010101010 101010101010101010101010101010101010101010101010 OS y.c cc y.s as y.o ld a.out 101010101010101010101010101010101010101010101010 z.c cc z.s as z.o Compiler Assembler Linker Loader CS 140 Lecture Notes: Linkers

CS 140 Lecture Notes: Linkers A Simple Example main.c stdio.c 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); } FILE* stdin, stdout; int printf(const char* format,...) { ... fputc(c, stdout); } int scanf(const char* format,...) { c = fgetc(stdin); math.c double sin(double x) { ... } CS 140 Lecture Notes: Linkers

main.o Object File main.c main.o 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); } 30 52 60 86 14 17 main: ... call printf call scanf call sin _s1: "Type number: " _s2: "%f" _s3: "Sine is %f\n" main T[0] _s1 D[0] _s2 D[14] _s3 D[17] printf T[30] printf T[86] scanf T[52] sin T[60] _s1 T[24] _s2 T[54] _s3 T[80] text section data section symbols “Store the final location of sin at offset 60 in the text section” relocation CS 140 Lecture Notes: Linkers

CS 140 Lecture Notes: Linkers printf.o Object File printf.c printf.o FILE* stdin, stdout; int printf(const char* format, ...) { ... fputc(c, stdout); } int scanf(const char* format, c = fgetc(stdin); 44 118 232 306 8 ... printf: load stdout scanf: load stdin stdin: stdout: printf T[44] scanf T[232] stdin D[0] stdout D[8] stdout T[118] stdin T[306] text section data section symbols relocation CS 140 Lecture Notes: Linkers

CS 140 Lecture Notes: Linkers After Pass 2 Memory map: Symbol table: 836 stdio.o data Name File Sec Offset Addr main: main T 0 0 _s1: main D 0 720 _s2: main D 14 734 _s3: main D 17 737 printf: stdio T 38 134 scanf: stdio T 232 328 stdin: stdio D 0 760 stdout: stdio D 8 768 sin: math T 0 508 760 main.o data 720 math.o text 508 stdio.o text 96 main.o text CS 140 Lecture Notes: Linkers

Relocation text section in main.o relocation record in main.o 30 ... call 0 text section in main.o printf T[30] relocation record in main.o printf: 134 symbol table 30 ... call 134 text section in a.out CS 140 Lecture Notes: Linkers