Unformatted text preview: . Relocating PC-Relative References
Recall from our running example in Figure 7.1(a) that the main routine in the .text section of main.o calls the swap routine, which is deﬁned in swap.o. Here is the disassembled listing for the call instruction, as generated by the GNU OBJDUMP tool:
6: e8 fc ff ff ff call 7 <main+0x7> 7: R_386_PC32 swap
swap(); relocation entry 368 CHAPTER 7. LINKING From this listing we see that the call instruction begins at section offset 0x6 and consists of the 1-byte opcode 0xe8, followed by the 32-bit reference 0xfffffffc ( decimal), which is stored in little-endian byte order. We also see a relocation entry for this reference displayed on the following line. (Recall that relocation entries and instructions are actually stored in different sections of the object ﬁle. The OBJDUMP tool displays them together for convenience.) The relocation entry r consists of three ﬁelds:
r.offset = 0x7 r.symbol = swap r.type = R_386_PC32 that tell the linker to modify the 32-bit PC-relative reference starting at offset 0x7 so that it w...
View Full Document