Download presentation
Presentation is loading. Please wait.
Published byMelinda Dorsey Modified over 9 years ago
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 Code 0 ∞ Data Stack 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
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 int printf(char *fmt,...) {... } int scanf(char *fmt,...) {... } int printf(char *fmt,...) {... } int scanf(char *fmt,...) {... } stdio.c double sin(double x) { static double res, lastx; if (x != lastx) { lastx = x; … compute sin(x) … } return res; } double sin(double x) { static double res, lastx; if (x != lastx) { lastx = x; … compute sin(x) … } return res; } 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 20 32 40 56... 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... 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 symbols relocation
5
CS 140 Lecture Notes: LinkersSlide 5 Object File double sin(double x) { static double res, lastx; if (x != lastx) { lastx = x; … compute sin(x) … } return res; } double sin(double x) { static double res, lastx; if (x != lastx) { lastx = x; … compute sin(x) … } return res; } math.cmath.o 8 20 204 0 8... 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... 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 data segment relocation symbols
6
CS 140 Lecture Notes: LinkersSlide 6 After Pass 1 main.o text 0 64 276 700 math.o text stdio.o text math.o data 708 stdio.o data 836 main:0 sin:64 lastx:700 result:708 printf:314 scanf:508 Memory map:Symbol table:
7
CS 140 Lecture Notes: LinkersSlide 7 Relocation text segment in main.o 40... call 0... ref: sin@T:40 relocation record in main.o sin: 64 symbol table text segment in a.out 40... call 64...
8
CS 140 Lecture Notes: LinkersSlide 8
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.