Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CS 140 Lecture Notes: LinkersSlide 1 Memory Layout for Process Code 0 ∞ Data Stack."— Presentation transcript:

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

2 CS 140 Lecture Notes: LinkersSlide 2 Creating a Process 10101010 10101010 10101010 ccx.cx.sasx.o 10101010 10101010 10101010 ccy.cy.sasy.o 10101010 10101010 10101010 ccz.cz.sasz.o 10101010 10101010 10101010 Source Code Assembly Code Object Code Executable a.out CompilerAssemblerLinkerLoader ld OS Code 0 ∞ Data Stack

3 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

4 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 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] 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

5 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 44 118 232 306 0 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]... 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

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

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

8 CS 140 Lecture Notes: LinkersSlide 8


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

Similar presentations


Ads by Google