2.3 struct relocation

A relocation has the following structure:
 
struct relocation {
        Elf32_Rela rela;
        struct relocation *next;
};

rela holds the relocation information. And next points to the next relocation structure.

rela is of type Elf32_Rela (defined in sys/elf.h) that has the following structure:
 
typedef struct {
        Elf32_Addr      r_offset;
        Elf32_Word      r_info;
        Elf32_Sword     r_addend;
} Elf32_Rela;

r_offset

This member gives the location at which to apply the relocation action. The value is the byte offset from the beginning of the section's object code to the instruction affected by the relocation.
r_info
This member gives both the sequence number of the symbol, with respect to which the relocation must be made, and the type of relocation to apply. Table 2.3.1 shows four basic relocation types (defined in sys/elf_SPARC.h) and the instructions to apply to. For the complete set of relocation types, see Object File Format from docs.sun.com. Table 2.3.2 shows how to manipulate the value of r_info with macros (defined in sys/elf.h):

Table 2.3.1 Relocation Types

Type
Instruction
R_SPARC_WDISP30
call label
R_SPARC_WDISP22
branch label 
R_SPARC_HI22
sethi %hi(label), %o0
R_SPARC_LO10
or %o0, %lo(label), %o0

Table 2.3.2 r_info Macros

Macro
Meaning
ELF32_R_SYM(i)
Extract symbol sequence number from r_info i
ELF32_R_TYPE(i)
Extract relocation type from r_info i
ELF32_R_INFO(s, t)
Compose r_info with symbol sequence nubmer s and relocation type t

r_addend

This member is always 0.
table of content