{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

22 - Linking 1 Outline DynamicLinking (PIC...

Info icon This preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Linking
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Outline Dynamic Linking Position Independent Code (PIC) Suggested reading: 7.10~7.12
Image of page 2
3 Relocation Relocation Merge the input modules Assign runtime address to each symbol Two steps Relocating sections and symbol definitions Relocating symbol references within sections
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 Relocation For each reference to an object with unknown location Assembler generates a relocation entry Relocation entries for code are placed in .rel.text Relocation entries for data are placed in .rel.data
Image of page 4
5 Relocation Relocation Entry  typedef struct { int offset ; int symbol:24,       type:8 ;  } Elf32_Rel ;
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 Relocation 6 e8 fc ff ff ff call 7<main+0x7> swap(); There is a relocation entry in rel.txt offset symbol type 7 swap R_386_PC32
Image of page 6
7 Relocation int *bufp0 = &buf[0] ; 00000000 <bufp0>: 0: 00 00 00 00 There is a relocation entry in rel.data offset symbol type 0 buf R_386_32
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
8 6 e8 fc ff ff ff call 7<main+0x7> swap(); 7: R_386_PC32 swap relocation entry r.offest = 0x7 r.symbol = swap r.type = R_386_PC32 ADDR(main)=ADDR(.text) = 0x80483b4 ADDR(swap)=0x80483c8 refaddr = ADDR(main)+r.offset = 0x80483bb ADDR(r.symbol)=ADDR(swap)=0x80483c8 *refptr = (unsigned) (ADDR(r.symbol) + *refptr – refaddr = (unsigned) (0x80483c8 + (-4) – 0x80483bb) = (unsigned) 0x9 Relocation
Image of page 8
9 int *bufp0 = &buf[0] ; 00000000 <bufp0>: 0: 00 00 00 00 int *bufp0 = &buf[0]; 0: R_386_32 buf relocation entry ADDR(r.symbol) = ADDR(buf) = 0x8049454 *refptr = (unsigned) (ADDR(r.symbol)+ *refptr) = (unsigned) (0x8049454) 0804945c <bufp0>: 0804945c: 54 94 04 08 Relocation
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
10 oreach section s { foreach relocation entry r { refptr = s + r.offset ; /* ptr to reference to be relocated */ /* relocate a PC-relative reference */ if (r.type == R_386_PC32) { refaddr = ADDR(s) + r.offset ; /* ref’s runtime address */ *refptr=(unsigned) ( ADDR(r.symbol) +*refptr –refaddr) ; } Relocation
Image of page 10
11 1 080483b4<main>: 2 080483b4: 55 push %ebp 3 080483b5: 89 e5 mov %esp, %ebp 4 080483b7: 83 ec 08 sub $0x8, %esp 5 080483ba: e8 09 00 00 00 call 80483c8 <swap> 6 080483bf: 31 c0 xor %eax, %eax 7 080483c1: 89 ec mov %ebp, %esp 8 080483c3: 5d pop %ebp 9 080483c4: c3 ret 10 080483c5: 90 nop 11 080483c6: 90 nop 12 080483c7: 90 nop Relocation
Image of page 11

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
12 13 080483c8<swap>: 14 80483c8: 55 push%ebp 15 80483c9: 8b 15 5c 94 04 08 mov 0x804945c, %edx get *bufp0 16 80483cf: a1 58 94 04 08 mov 0x8049458, %edx get buf[1] 17 80483d4: 89 e5 mov %esp, %ebp 18 80483d6: c7 05 48 85 04 08 58 movl $0x8049458, 0x8049548 19 80483dd: 94 04 08 bufp1 = &buf[1] 20 80483e0: 89 ec mov %ebp, %esp 21 80483e2: 8b 0a mov (%edx), %ecx 22 80483e4: 80 02 mov %eax, (%edx) 23 80483e6: a1 48 95 04 08 mov 0x8049548, %eax 24 80483eb: 89 08 mov %ecx, (%eax) 25 80483ed: 5d pop %ebp 26 80483ee: c3 ret Relocation
Image of page 12
13 1 08049454 <buf>: 2 8049454: 01 00 00 00 02 00 00 00 3 0804945c<bufp0>: 4 804945c: 54 94 04 08 Relocation
Image of page 13

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
14 ELF header Segment header table .init section .data section .bss section .symtab .debug Section header table .line .strtab .rodata section .text section EFI object file format
Image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern