21 - Linking 1 Outline Relocation ExecutableObjectFiles...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Linking
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Outline Relocation Executable Object Files Loading Dynamic Linking Suggested reading: 7.7~7.11
Background 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
Background image of page 3

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

View Full DocumentRight 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
Background image of page 4
5 Relocation Relocation Entry  typedef struct { int offset ; int symbol:24,       type:8 ;  } Elf32_Rel ;
Background image of page 5

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

View Full DocumentRight 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
Background 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
Background image of page 7

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

View Full DocumentRight 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
Background 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
Background image of page 9

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

View Full DocumentRight 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
Background 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
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/19/2011 for the course CS 000 taught by Professor Jing during the Fall '10 term at Fudan University.

Page1 / 35

21 - Linking 1 Outline Relocation ExecutableObjectFiles...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online