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.

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); } intprintf(char *fmt, ...) { ... } intscanf(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 ref: printf@T:56 ref: scanf@T:32 ref: sin@T:40 text section 20 32 40 56 symbols relocation “Store the final location of printfat offset 20 in the text section” 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:8 def: res@D:0 ref: lastx@T:8 ref: lastx@T:20 ref: res@T:204 text section 8 20 204 0 8 data section symbols relocation CS 140 Lecture Notes: Linkers

  6. After Pass 1 Memory map: Symbol table: main: 0 sin: 64 lastx: 700 result: 708 printf: 314 scanf: 508 836 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 section in main.o ref: sin@T:40 relocation record in main.o sin: 64 symbol table ... call 64 ... 40 text section in a.out CS 140 Lecture Notes: Linkers

  8. CS 140 Lecture Notes: Linkers

More Related