memory layout for process n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Memory Layout for Process PowerPoint Presentation
Download Presentation
Memory Layout for Process

Loading in 2 Seconds...

  share
play fullscreen
1 / 8
beau

Memory Layout for Process - PowerPoint PPT Presentation

184 Views
Download Presentation
Memory Layout for Process
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

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

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

  3. 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; intprintf(const char* format, ...) { ... fputc(c, stdout); ... } intscanf(const char* format, ...) { ... c = fgetc(stdin); ... } math.c double sin(double x) { ... } CS 140 Lecture Notes: Linkers

  4. 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); } 0 30 52 60 86 0 14 17 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 symbols “Store the final location of sinat offset 60 in the text section” relocation CS 140 Lecture Notes: Linkers

  5. Object File printf.c printf.o FILE* stdin, stdout; intprintf(const char* format, ...) { ... fputc(c, stdout); ... } intscanf(const char* format, ...) { ... c = fgetc(stdin); ... } ... 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 44 118 232 306 0 8 data section symbols relocation CS 140 Lecture Notes: Linkers

  6. During Pass 2 Memory map: Symbol table: 0 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 main.o text 96 stdio.o text 508 math.o text 720 main.odata 760 stdio.o data 836 CS 140 Lecture Notes: Linkers

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

  8. CS 140 Lecture Notes: Linkers