ELF files contain two structures to handle relocations:
Elf64_Rel
:
typedef struct { Elf64_Addr r_offset; Uint64_t r_info; } Elf64_Rel;
and Elf64_Rela
:
typedef struct { Elf64_Addr r_offset; uint64_t r_info; int64_t r_addend; } Elf64_Rela;
I want to take peek at the relocation entries but I’m not sure which one to use. The manual pages are quite cryptic about this. Is there a specific usage for each?
Advertisement
Answer
This depends on the target. Most targets use only one of the two forms. The Relocation chapter in the System V Application Binary Interface (the ELF specification) says this:
As specified previously, only
Elf32_Rela
andElf64_Rela
entries contain an explicit addend. Entries of typeElf32_Rel
andElf64_Rel
store an implicit addend in the location to be modified. Depending on the processor architecture, one form or the other might be necessary or more convenient. Consequently, an implementation for a particular machine may use one form exclusively or either form depending on context.
The ELF format is self-describing in the sense that it shows whether REL or RELA relocations are used (SHT_REL
or SHT_RELA
for section type; DT_REL
, DT_RELSZ
, DT_RELENT
or DT_RELA
, DT_RELASZ
, DT_RELAENT
in the dynamic section). But relocation-processing itself is very target-specific.