1 / 8

Memory Layout for Process

Memory Layout for Process. ∞. Stack. Data. Code. 0. ∞. Stack. Data. Code. 0. x.c. y.c. cc. cc. y.s. x.s. as. as. y.o. x.o. 101010101010101010101010101010101010101010101010. z.c. cc. z.s. as. z.o. 101010101010101010101010101010101010101010101010.

bao
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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Stack Data Code 0 x.c y.c cc cc y.s x.s as as y.o x.o 101010101010101010101010101010101010101010101010 z.c cc z.s as z.o 101010101010101010101010101010101010101010101010 101010101010101010101010101010101010101010101010 101010101010101010101010101010101010101010101010 Creating a Process SourceCode Assembly Code Object Code Executable 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); } int printf(char *fmt, ...) { ... } int scanf(char *fmt, ...) { ... } math.c double sin(double x) { static double res, lastx; if (x != lastx) { lastx = x; … compute sin(x)… } return res; } 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); } ... call printf ... call scanf ... call sin ... call printf def: main@T:0 ref: printf@T:20, T:56 ref: scanf@T:32 ref: sin@T:40 text segment 20 32 40 56 symbols relocation CS 140 Lecture Notes: Linkers

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

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

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

  8. CS 140 Lecture Notes: Linkers

More Related