Meaning of ELF64_R_SYM(rela->r_info)
Nick Clifton
nickc@redhat.com
Wed Apr 21 14:54:42 GMT 2021
Hi Peng,
> I see ELF64_R_SYM(rela->r_info) are 00000005 and 0000000b
> respectively. I don't find what they refer to.
You have already discovered this:
> "r_info contains both a symbol table index and a relocation type. The
> symbol table index identifies the symbol whose value should be used in
> the relocation."
So a value of 00000005 refers to the 5th entry in the symbol table
associated with the relocation section that contains the reloc.
Similarly 0000000b refers to the 11th entry in the symbol table.
> Offset Info Type Symbol's
> Value Symbol's Name + Addend
> 0000000000000007 0000000500000002 R_X86_64_PC32
> 0000000000000000 .rodata - 4
> 000000000000000c 0000000b00000004 R_X86_64_PLT32
> 0000000000000000 puts - 4
So readelf has decoded symbol index 5 and displayed ".rodata" and symbol
index 11 and displayed "puts".
> But I checked the symbol table and I don't think 00000005 and 0000000b
> have anything to do with this table.
But they do:
> 5: 0000000000000000 0 SECTION LOCAL DEFAULT 5
Symbol 5 is a section symbol, so its name is the section name, ie .rodata.
> 11: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND puts
And here is the "puts" symbol.
> Also for 00000002 and 00000004 (the lower half of Info), they just
> refer to R_X86_64_PC32 and R_X86_64_PLT32. Why showing the same info
> twice in the output of readelf -rW? Why not just show it once?
It is done this way in order to help debug problems. The raw value of
the info field is displayed so that users can see the actual value, and
then the decoded data (symbol name + relocation name + offset) is
displayed so that the value can be easily interpreted. Users *could*
interpret the raw value themselves, but it can be a chore, and it is
simple for readelf to perform that task.
Cheers
Nick
PS. A very recent update to readelf has changed the display of section
symbols in the symbol table. so that they now show the section name,
instead of just a blank space.
More information about the Binutils
mailing list