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

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:
Buffer Overflow Prabhaker Mateti Wright State University.
Cosc 2150 Arrays in assembly code. Variables and addresses Uncompiled ld [a], %r1 addcc %r1, 2, %r3 ARC has three addressing modes —immediate, direct,
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.
TDBA66, VT-03 Lecture - Ch. 21 A complete C-program Display Fig. 2.1 and comment on different things such as Preprocessor directives Header files Identifiers.
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
CS2422 Assembly Language & System Programming January 2, 2007.
Lectures on Numerical Methods1 An Example zCompute Squares çPrints a table of squares as shown below /* Compute Squares.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
Disassembly תרגול 9 ניתוח קוד. How to - Disassembly of code Compilation of code:  gcc code.c  We get the file: a.out Disassembly:  objdump -d a.out.
1 CSE1301 Computer Programming: Lecture 9 Input/Output.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
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,
A simple C program: Printing a line of text #include main() { printf(“hello, world\n”); } Program output: hello, world.
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.
CMPE13 Cyrus Bazeghi Chapter 18 I/O in C. CMPE Standard C Library I/O commands are not included as part of the C language. Instead, they are part.
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.
Chapter 18 I/O in C.
1 Lecture09: File I/O 5/6/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
CMSC 1041 Functions II Functions that return a value.
1 Lecture09: File I/O 11/19/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
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.
CSE1301 Computer Programming: Lecture 6 Input/Output.
1 Homework Done the reading? –K&R –Glass Chapters 1 and 2 Applied for cs240? (If not, keep at it!) Gotten a UNIX account? (If not, keep at it!)
Minimal standard C program int main(void) { return 0 ; }
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
Files A collection of related data treated as a unit. Two types Text
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
IO revisited CSE 2451 Rong Shi. stdio.h Functions – printf – scanf(normally stops at whitespace) – fgets – sscanf Standard streams – stdin(defaults to.
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.
Chapter 18 I/O in C Original slides from Gregory Byrd, North Carolina State University Modified slides by C. Wilcox, Y. Malaiya Colorado State University.
 Dynamic Memory Allocation  Linked Lists  void main() {{ ◦ FILE *file; ◦ char file_name[] = “file.txt”; ◦ if ((file = fopen(file_name, "w")) ==
Lecture 3 Translation.
Lecture2.
Dawson Engler Stanford CS department
CS 140 Lecture Notes: Virtual Memory
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
A bit of C programming Lecture 3 Uli Raich.
System Programming and administration
Chapter 7 Text Input/Output Objectives
Functions, Part 2 of 2 Topics Functions That Return a Value
Memory Layout for Process
Chapter 18 I/O in C.
Computer Systems and Networks
CS 140 Lecture Notes: Virtual Memory
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CSI 121 Structured Programming Language Lecture 7: Input/Output
Jeremy R. Johnson Wed. Apr. 5, 2000
Memory Layout for Process
CS 140 Lecture Notes: Virtual Memory
Program Requirements.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Systems Architecture I
Program Execution in Linux
Loaders and Linkers.
10/6: Lecture Topics C Brainteaser More on Procedure Call
Memory Layout for Process
CS 140 Lecture Notes: Virtual Memory
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 ccx.cx.sasx.o ccy.cy.sasy.o ccz.cz.sasz.o Source Code Assembly Code Object Code Executable a.out CompilerAssemblerLinkerLoader ld OS Code 0 ∞ Data Stack

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 FILE* stdin, stdout; int printf(const char* format,...) {... fputc(c, stdout);... } int scanf(const char* format,...) {... c = fgetc(stdin);... } FILE* stdin, stdout; int printf(const char* format,...) {... fputc(c, stdout);... } int scanf(const char* format,...) {... c = fgetc(stdin);... } stdio.c double sin(double x) {... } double sin(double x) {... } 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 main:... call printf... call scanf... call sin... call printf _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] main:... call printf... call scanf... call sin... call printf _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 relocation “Store the final location of sin at offset 60 in the text section” symbols

CS 140 Lecture Notes: LinkersSlide 5 Object File FILE* stdin, stdout; int printf(const char* format,...) {... fputc(c, stdout);... } int scanf(const char* format,...) {... c = fgetc(stdin);... } FILE* stdin, stdout; int printf(const char* format,...) {... fputc(c, stdout);... } int scanf(const char* format,...) {... c = fgetc(stdin);... } printf.cprintf.o 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]... 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 relocation symbols

CS 140 Lecture Notes: LinkersSlide 6 During Pass 2 NameFileSecOffsetAddr main:mainT00 _s1:mainD0720 _s2:mainD14734 _s3:mainD17737 printf:stdioT38134 scanf:stdioT stdin:stdioD0760 stdout:stdioD8768 sin:mathT0508 Memory map:Symbol table: main.o text math.o text stdio.o text main.o data stdio.o data

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

CS 140 Lecture Notes: LinkersSlide 8