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 Recitation 8 – 3/25/02 Outline Dynamic Linking Review prior test questions 213 Course Staff 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[]) f4 : 80484f4: 55 push %ebp 80484f5: 89 e5 mov %esp,%ebp 80484f7: 81 ec 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 : 68 b push $0x80485b : 68 ba push $0x80485ba c: e8 07 ff ff ff call : 89 c6 mov %eax,%esi

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

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

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

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

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

10 PLT 1/ : # Invokes dynamic linker : ff 35 e pushl 0x80495e e: ff 25 ec jmp *0x80495ec 80483a4: add %al,(%eax) 80483a6: add %al,(%eax) # Not called from main() 80483a8: ff 25 f jmp *0x80495f ae: push $0x b3: e9 e0 ff ff ff jmp # fflush() 80483b8: ff 25 f jmp *0x80495f be: push $0x c3: e9 d0 ff ff ff jmp

11 PLT 2/3 # puts() 80483c8: ff 25 f jmp *0x80495f ce: push $0x d3: e9 c0 ff ff ff jmp # Not called from main() 80483d8: ff 25 fc jmp *0x80495fc 80483de: push $0x e3: e9 b0 ff ff ff jmp # fgets() 80483e8: ff jmp *0x ee: push $0x f3: e9 a0 ff ff ff jmp

12 PLT 3/3 # Not called from main() 80483f8: ff jmp *0x fe: push $0x : e9 90 ff ff ff jmp #fclose() : ff jmp *0x e: push $0x : e9 80 ff ff ff jmp # fopen() : ff 25 0c jmp *0x804960c e: push $0x : e9 70 ff ff ff jmp

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

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

15 GOT Just after fgets().got (during exeuction of main, just after fgets() ) 0x80495e4 : 0x # end of GOT 0x80495e8 : 0x40013ed0 # library number 0x80495ec : 0x4000a960 # dyn.linker addr 0x80495f0 : 0x400fa530 0x80495f4 : 0x080483be # fflush() 0x80495f8 : 0x080483ce # puts() 0x80495fc : 0x080483de 0x : 0x4006c730 # fgets() 0x : 0x400328cc 0x : 0x e # 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