Meaning of ELF64_R_SYM(rela->r_info)

Peng Yu pengyu.ut@gmail.com
Wed Apr 21 14:02:07 GMT 2021


Hi,

I see ELF64_R_SYM(rela->r_info) are 00000005 and 0000000b
respectively. I don't find what they refer to.

The 64-bit ELF spec (https://uclibc.org/docs/elf-64-gen.pdf) says

"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."

$ cat a.c
#include <stdio.h>
int main() { puts("Hello World!"); }
$ gcc -c a.c
$ readelf -rW a.o

Relocation section '.rela.text' at offset 0x210 contains 2 entries:
    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

Relocation section '.rela.eh_frame' at offset 0x240 contains 1 entry:
    Offset             Info             Type               Symbol's
Value  Symbol's Name + Addend
0000000000000020  0000000200000002 R_X86_64_PC32
0000000000000000 .text + 0

But I checked the symbol table and I don't think 00000005 and 0000000b
have anything to do with this table.

Could anybody help me understand what they refer to?

$ readelf -s a.o

Symbol table '.symtab' contains 12 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS a.c
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    1
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    3
     4: 0000000000000000     0 SECTION LOCAL  DEFAULT    4
     5: 0000000000000000     0 SECTION LOCAL  DEFAULT    5
     6: 0000000000000000     0 SECTION LOCAL  DEFAULT    7
     7: 0000000000000000     0 SECTION LOCAL  DEFAULT    8
     8: 0000000000000000     0 SECTION LOCAL  DEFAULT    6
     9: 0000000000000000    23 FUNC    GLOBAL DEFAULT    1 main
    10: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _GLOBAL_OFFSET_TABLE_
    11: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND puts

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?

https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/elf.h#l3423
https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/elf.h#l3425

-- 
Regards,
Peng


More information about the Binutils mailing list