I'm studying relocation of ELF for MIPS arch. But I'm a little confused at the calculation of `S`, which is refered in "SYSTEM V APPLICATION BINARAY INTERFACE MIPS RISC Processor Supplement 3rd Edition". For example, I get a relocation ELF executable "a.ex_". mips-elf-objdump -r a.ex_ ---------------------------- RELOCATION RECORDS FOR [.text]: OFFSET TYPE VALUE 00000010 R_MIPS_HI16 .rodata 00000014 R_MIPS_LO16 .rodata ... mips-elf-objdump -dS a.ex_ ---------------------------- static int enc(const int c) { 0: 27bdfff8 addiu sp,sp,-8 4: afbe0000 sw s8,0(sp) 8: 03a0f021 move s8,sp c: afc40008 sw a0,8(s8) return BASE64_ARRAY[c]; 10: 3c020000 lui v0,0x0 14: 2443001c addiu v1,v0,28 ... Here, relocation should be applied to location 0x10 and 0x14. The loader places the segment '.rodata' in 0x00435000 in run time. Intuitively, relocation will be done like this: Original sh_addr Final sh_addr --------------------------------- 0 0x00435000 The location 0x1c will be relocated to 0x0043501c. So the instructions at 0x10 and 0x14 will be fixed as: 10: 3c020043 lui v0,0x0043 14: 2443501c addiu v1,v0,0x501c The document says S Represents the value of the symbol whose index resides in the relocation entry, unless the the symbol is STB_LOCAL and is of type STT_SECTION in which case S represents the original sh_addr minus the final sh_addr. Calculation looks like: S = 0 - 0x00435000 = 0xffbcb000 AHL = 0<<16 + 0x1c = 0x0000001c R_MIPS_HI16=((S+AHL) - (short)(S+AHL)) >> 16 = 0xffbd R_MIPS_LO16=(S+AHL) = 0xb01c The results seem incorrect. The point is, whether S is equal to final_sh_addr-original_sh_addr or S is equal to original_sh_addr-final_sh_addr. Best Regards. Pan Ruochen 2007/8/28