Presentation is loading. Please wait.

Presentation is loading. Please wait.

15-213 Recitation 8 – 3/25/02 Outline Dynamic Linking Review prior test questions 213 Course Staff Office Hours: See Posting.

Similar presentations


Presentation on theme: "15-213 Recitation 8 – 3/25/02 Outline Dynamic Linking Review prior test questions 213 Course Staff Office Hours: See Posting."— Presentation transcript:

1 15-213 Recitation 8 – 3/25/02 Outline Dynamic Linking Review prior test questions 213 Course Staff e-mail: staff-213@cs.cmu.edu Office Hours: See Posting on Web

2 Example Program #include int main (int argc, char *argv) { FILE *fp; char buffer [1024]; fp = fopen ("lines.txt", "r"); fgets (buffer, 1024, fp); puts (buffer); fflush (stdout); fclose (fp); }

3 Example Program (Asm) 1/7 int main (int argc, char *argv[]) 080484f4 : 80484f4: 55 push %ebp 80484f5: 89 e5 mov %esp,%ebp 80484f7: 81 ec 10 04 00 00 sub $0x410,%esp 80484fd: 56 push %esi 80484fe: 53 push %ebx {

4 Example Program (Asm) 2/7 FILE *fp; char buffer [1024]; fp = fopen ("lines.txt", "r"); 80484ff: 83 c4 f8 add $0xfffffff8,%esp 8048502: 68 b8 85 04 08 push $0x80485b8 8048507: 68 ba 85 04 08 push $0x80485ba 804850c: e8 07 ff ff ff call 8048418 8048511: 89 c6 mov %eax,%esi

5 Example Program (ASM) 3/7 fgets (buffer, 1024, fp); 8048513: 83 c4 fc add $0xfffffffc,%esp 8048516: 56 push %esi 8048517: 68 00 04 00 00 push $0x400 804851c: 8d 9d 00 fc ff ff lea 0xfffffc00(%ebp),%ebx 8048522: 53 push %ebx 8048523: e8 c0 fe ff ff call 80483e8

6 Example Program (ASM) 4/7 puts (buffer); 8048528: 83 c4 20 add $0x20,%esp 804852b: 83 c4 f4 add $0xfffffff4,%esp 804852e: 53 push %ebx 804852f: e8 94 fe ff ff call 80483c8

7 Example Program (ASM) 5/7 fflush (stdout); 8048534: a1 b4 96 04 08 mov 0x80496b4,%eax 8048539: 83 c4 f4 add $0xfffffff4,%esp 804853c: 50 push %eax 804853d: e8 76 fe ff ff call 80483b8

8 Example Program (ASM) 6/7 fclose (fp); 8048542: 83 c4 20 add $0x20,%esp 8048545: 83 c4 f4 add $0xfffffff4,%esp 8048548: 56 push %esi 8048549: e8 ba fe ff ff call 8048408

9 Example Program (Asm) 7/7 } 804854e: 8d a5 e8 fb ff ff lea 0xfffffbe8(%ebp),%esp 8048554: 5b pop %ebx 8048555: 5e pop %esi 8048556: 89 ec mov %ebp,%esp 8048558: 5d pop %ebp 8048559: c3 ret

10 PLT 1/3 08048398 : # Invokes dynamic linker 8048398: ff 35 e8 95 04 08 pushl 0x80495e8 804839e: ff 25 ec 95 04 08 jmp *0x80495ec 80483a4: 00 00 add %al,(%eax) 80483a6: 00 00 add %al,(%eax) # Not called from main() 80483a8: ff 25 f0 95 04 08 jmp *0x80495f0 80483ae: 68 00 00 00 00 push $0x0 80483b3: e9 e0 ff ff ff jmp 8048398 # fflush() 80483b8: ff 25 f4 95 04 08 jmp *0x80495f4 80483be: 68 08 00 00 00 push $0x8 80483c3: e9 d0 ff ff ff jmp 8048398

11 PLT 2/3 # puts() 80483c8: ff 25 f8 95 04 08 jmp *0x80495f8 80483ce: 68 10 00 00 00 push $0x10 80483d3: e9 c0 ff ff ff jmp 8048398 # Not called from main() 80483d8: ff 25 fc 95 04 08 jmp *0x80495fc 80483de: 68 18 00 00 00 push $0x18 80483e3: e9 b0 ff ff ff jmp 8048398 # fgets() 80483e8: ff 25 00 96 04 08 jmp *0x8049600 80483ee: 68 20 00 00 00 push $0x20 80483f3: e9 a0 ff ff ff jmp 8048398

12 PLT 3/3 # Not called from main() 80483f8: ff 25 04 96 04 08 jmp *0x8049604 80483fe: 68 28 00 00 00 push $0x28 8048403: e9 90 ff ff ff jmp 8048398 #fclose() 8048408: ff 25 08 96 04 08 jmp *0x8049608 804840e: 68 30 00 00 00 push $0x30 8048413: e9 80 ff ff ff jmp 8048398 # fopen() 8048418: ff 25 0c 96 04 08 jmp *0x804960c 804841e: 68 38 00 00 00 push $0x38 8048423: e9 70 ff ff ff jmp 8048398

13 GOT Before Execution.got (before program executes) 0x80495e4 : 0x08049614 # End of GOT 0x80495e8 : 0x00000000 # library number 0x80495ec : 0x00000000 # dyn.linker addr 0x80495f0 : 0x080483ae 0x80495f4 : 0x080483be # fflush() 0x80495f8 : 0x080483ce # puts() 0x80495fc : 0x080483de 0x8049600 : 0x080483ee # fgets() 0x8049604 : 0x080483fe 0x8049608 : 0x0804840e # fclose() 0x804960c : 0x0804841e # fopen()...

14 GOT After Init, Before Main.got (before main executes, but after initialization) 0x80495e4 : 0x08049614 # end of GOT 0x80495e8 : 0x40013ed0 # library number 0x80495ec : 0x4000a960 # dyn.linker addr 0x80495f0 : 0x400fa530 0x80495f4 : 0x080483be # fflush() 0x80495f8 : 0x080483ce # puts() 0x80495fc : 0x080483de 0x8049600 : 0x080483ee # fgets() 0x8049604 : 0x400328cc 0x8049608 : 0x0804840e # fclose() 0x804960c : 0x0804841e # fopen()...

15 GOT Just after fgets().got (during exeuction of main, just after fgets() ) 0x80495e4 : 0x08049614 # end of GOT 0x80495e8 : 0x40013ed0 # library number 0x80495ec : 0x4000a960 # dyn.linker addr 0x80495f0 : 0x400fa530 0x80495f4 : 0x080483be # fflush() 0x80495f8 : 0x080483ce # puts() 0x80495fc : 0x080483de 0x8049600 : 0x4006c730 # fgets() 0x8049604 : 0x400328cc 0x8049608 : 0x0804840e # fclose() 0x804960c : 0x4006c800 # fopen()...


Download ppt "15-213 Recitation 8 – 3/25/02 Outline Dynamic Linking Review prior test questions 213 Course Staff Office Hours: See Posting."

Similar presentations


Ads by Google