Unformatted text preview:

Memory Layout for ProcessCreating a ProcessA Simple ExampleObject FileSlide 5After Pass 1RelocationSlide 8CS 140 Lecture Notes: Linkers Slide 1Memory Layout for ProcessCode0∞DataStackCS 140 Lecture Notes: Linkers Slide 2Creating a ProcessCode0∞DataStack101010101010101010101010101010101010101010101010ccx.c x.s as x.o101010101010101010101010101010101010101010101010ccy.c y.s as y.o101010101010101010101010101010101010101010101010ccz.c z.s as z.o101010101010101010101010101010101010101010101010SourceCodeAssemblyCodeObjectCodeExecutablea.outCompiler Assembler Linker LoaderldOSCS 140 Lecture Notes: Linkers Slide 3A Simple Exampleextern 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.cint printf(char *fmt, ...) { ...}int scanf(char *fmt, ...) { ...}int printf(char *fmt, ...) { ...}int scanf(char *fmt, ...) { ...}stdio.cdouble 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.cCS 140 Lecture Notes: Linkers Slide 4Object Fileextern 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 main.o20324056...call printf...call scanf...call sin...call printfdef: main@T:0ref: printf@T:20, T:56ref: scanf@T:32ref: sin@T:40...call printf...call scanf...call sin...call printfdef: main@T:0ref: printf@T:20, T:56ref: scanf@T:32ref: sin@T:40text segmentsymbolsrelocationCS 140 Lecture Notes: Linkers Slide 5Object Filedouble 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 math.o 8 20204 0 8...load lastx...store lastx...load resres:lastx:def: sin@T:0def: lastx@D:0def: res@D:8ref: lastx@T:8, T:20ref: res@T:204...load lastx...store lastx...load resres:lastx:def: sin@T:0def: lastx@D:0def: res@D:8ref: lastx@T:8, T:20ref: res@T:204text segmentdata segmentrelocationsymbolsCS 140 Lecture Notes: Linkers Slide 6After Pass 1main.o text064276700math.o textstdio.o textmath.o data708stdio.o data836main: 0sin: 64lastx: 700result: 708printf: 314scanf: 508Memory map: Symbol table:CS 140 Lecture Notes: Linkers Slide 7Relocationtext segment in main.o40...call 0...ref: sin@T:40relocation record in main.osin: 64symbol tabletext segment in a.out40...call 64...CS 140 Lecture Notes: Linkers Slide


View Full Document

Stanford CS 140 - Memory Layout for Process

Documents in this Course
Homework

Homework

25 pages

Notes

Notes

8 pages

Load more
Download Memory Layout for Process
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Memory Layout for Process and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Memory Layout for Process 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?