16#ifndef LIEF_ELF_RELOCATION_H
17#define LIEF_ELF_RELOCATION_H
65 static constexpr uint64_t
R_BIT = 27;
66 static constexpr uint64_t
R_MASK = (uint64_t(1) <<
R_BIT) - 1;
84 enum class TYPE : uint32_t {
87 #define ELF_RELOC(name, value) name = (value | R_X64),
91 #define ELF_RELOC(name, value) name = (value | R_AARCH64),
95 #define ELF_RELOC(name, value) name = (value | R_ARM),
99 #define ELF_RELOC(name, value) name = (value | R_HEXAGON),
103 #define ELF_RELOC(name, value) name = (value | R_X86),
107 #define ELF_RELOC(name, value) name = (value | R_LARCH),
111 #define ELF_RELOC(name, value) name = (value | R_MIPS),
115 #define ELF_RELOC(name, value) name = (value | R_PPC),
119 #define ELF_RELOC(name, value) name = (value | R_PPC64),
123 #define ELF_RELOC(name, value) name = (value | R_SPARC),
127 #define ELF_RELOC(name, value) name = (value | R_SYSZ),
131 #define ELF_RELOC(name, value) name = (value | R_RISCV),
135 #define ELF_RELOC(name, value) name = (value | R_BPF),
139 #define ELF_RELOC(name, value) name = (value | R_SH4),
154 architecture_ = arch;
167 addend_{other.addend_},
168 encoding_{other.encoding_},
169 architecture_{other.architecture_}
181 std::swap(address_, other.address_);
182 std::swap(type_, other.type_);
183 std::swap(addend_, other.addend_);
184 std::swap(encoding_, other.encoding_);
185 std::swap(symbol_, other.symbol_);
186 std::swap(architecture_, other.architecture_);
187 std::swap(purpose_, other.purpose_);
188 std::swap(section_, other.section_);
189 std::swap(symbol_table_, other.symbol_table_);
190 std::swap(info_, other.info_);
191 std::swap(binary_, other.binary_);
243 return architecture_;
269 return symbol_ !=
nullptr;
297 return symbol_table_;
301 return symbol_table_;
Class which represents an ELF binary.
Definition ELF/Binary.hpp:59
Class which takes an ELF::Binary object and reconstructs a valid binary.
Definition ELF/Builder.hpp:48
Class which parses and transforms an ELF file into a ELF::Binary object.
Definition ELF/Parser.hpp:45
uint32_t info() const
Relocation info which contains, for instance, the symbol index.
Definition ELF/Relocation.hpp:227
TYPE
The different types of the relocation.
Definition ELF/Relocation.hpp:84
@ PPC64_RELATIVE
Definition ELF/Relocation.hpp:971
@ UNKNOWN
Definition ELF/Relocation.hpp:85
@ X86_64_RELATIVE
Definition ELF/Relocation.hpp:102
@ AARCH64_RELATIVE
Definition ELF/Relocation.hpp:285
@ HEX_RELATIVE
Definition ELF/Relocation.hpp:487
@ ARM_RELATIVE
Definition ELF/Relocation.hpp:325
@ PPC_RELATIVE
Definition ELF/Relocation.hpp:905
@ X86_RELATIVE
Definition ELF/Relocation.hpp:565
static constexpr uint64_t R_PPC64
Definition ELF/Relocation.hpp:76
friend std::ostream & operator<<(std::ostream &os, const Relocation &entry)
TYPE type() const
Type of the relocation.
Definition ELF/Relocation.hpp:200
PURPOSE
The purpose of a relocation defines how this relocation is used by the loader.
Definition ELF/Relocation.hpp:50
@ DYNAMIC
The relocation is used for regulard data/code relocation.
Definition ELF/Relocation.hpp:53
@ OBJECT
The relocation is used in an object file.
Definition ELF/Relocation.hpp:54
@ PLTGOT
The relocation is associated with the PLT/GOT resolution.
Definition ELF/Relocation.hpp:52
@ NONE
Definition ELF/Relocation.hpp:51
static constexpr uint64_t R_X86
Definition ELF/Relocation.hpp:72
static uint32_t to_value(TYPE type)
Definition ELF/Relocation.hpp:146
Symbol * symbol()
Symbol associated with the relocation (or a nullptr).
Definition ELF/Relocation.hpp:273
Section * symbol_table()
The associated symbol table (or a nullptr).
Definition ELF/Relocation.hpp:296
static TYPE type_from(uint32_t value, ARCH arch)
void accept(Visitor &visitor) const override
void swap(Relocation &other)
Definition ELF/Relocation.hpp:180
ENCODING encoding() const
The encoding of the relocation.
Definition ELF/Relocation.hpp:251
Relocation & operator=(Relocation other)
Copy assignment operator.
Definition ELF/Relocation.hpp:175
int64_t addend() const
Additional value that can be involved in the relocation processing.
Definition ELF/Relocation.hpp:195
result< uint64_t > resolve(uint64_t base_address=0) const
Try to resolve the value of the relocation such as *address() = resolve().
PURPOSE purpose() const
Definition ELF/Relocation.hpp:246
bool is_relative() const
True if the semantic of the relocation is <ARCH>_RELATIVE.
Definition ELF/Relocation.hpp:256
size_t size() const override
Return the size (in bits) of the value associated with this relocation Return -1 if the size can't be...
bool is_android_packed() const
True if the relocation is using the Android packed relocation format.
Definition ELF/Relocation.hpp:222
static constexpr uint64_t R_MASK
Definition ELF/Relocation.hpp:66
static constexpr uint64_t R_BPF
Definition ELF/Relocation.hpp:80
bool has_symbol() const
True if the current relocation is associated with a symbol.
Definition ELF/Relocation.hpp:268
static constexpr uint64_t R_RISCV
Definition ELF/Relocation.hpp:79
bool has_section() const
True if the relocation has an associated section.
Definition ELF/Relocation.hpp:282
const Section * symbol_table() const
Definition ELF/Relocation.hpp:300
friend class Builder
Definition ELF/Relocation.hpp:44
bool is_rela() const
Check if the relocation uses the explicit addend() field (this is usually the case for 64 bits binari...
Definition ELF/Relocation.hpp:206
const Section * section() const
Definition ELF/Relocation.hpp:291
static constexpr uint64_t R_SPARC
Definition ELF/Relocation.hpp:77
friend class Binary
Definition ELF/Relocation.hpp:43
static constexpr uint64_t R_HEXAGON
Definition ELF/Relocation.hpp:71
static constexpr uint64_t R_SYSZ
Definition ELF/Relocation.hpp:78
bool is_rel() const
Check if the relocation uses the implicit addend (i.e. not present in the ELF structure).
Definition ELF/Relocation.hpp:212
ARCH architecture() const
Target architecture for this relocation.
Definition ELF/Relocation.hpp:242
Relocation(uint64_t address, TYPE type, ENCODING enc)
static constexpr uint64_t R_SH4
Definition ELF/Relocation.hpp:81
friend class Parser
Definition ELF/Relocation.hpp:42
static constexpr uint64_t R_BIT
Definition ELF/Relocation.hpp:65
Section * section()
The section in which the relocation is applied (or a nullptr).
Definition ELF/Relocation.hpp:287
static constexpr uint64_t R_ARM
Definition ELF/Relocation.hpp:70
static constexpr uint64_t R_MIPS
Definition ELF/Relocation.hpp:74
static constexpr uint64_t R_PPC
Definition ELF/Relocation.hpp:75
static constexpr uint64_t R_X64
Definition ELF/Relocation.hpp:68
uint64_t r_info(Header::CLASS clazz) const
(re)Compute the raw r_info attribute based on the given ELF class
Definition ELF/Relocation.hpp:232
static constexpr uint64_t R_LARCH
Definition ELF/Relocation.hpp:73
void addend(int64_t addend)
Definition ELF/Relocation.hpp:304
static constexpr uint64_t R_AARCH64
Definition ELF/Relocation.hpp:69
ENCODING
Definition ELF/Relocation.hpp:57
@ ANDROID_SLEB
The relocation is using the packed Android-SLEB128 format.
Definition ELF/Relocation.hpp:62
@ RELR
The relocation is using the relative relocation format.
Definition ELF/Relocation.hpp:61
@ UNKNOWN
Definition ELF/Relocation.hpp:58
@ RELA
The relocation is using the regular Elf_Rela structure.
Definition ELF/Relocation.hpp:60
@ REL
The relocation is using the regular Elf_Rel structure.
Definition ELF/Relocation.hpp:59
bool is_relatively_encoded() const
True if the relocation is using the relative encoding.
Definition ELF/Relocation.hpp:217
Class which represents an ELF Section.
Definition ELF/Section.hpp:48
Class which represents an ELF symbol.
Definition ELF/Symbol.hpp:35
Class which represents an abstracted Relocation.
Definition Abstract/Relocation.hpp:27
virtual uint64_t address() const
Relocation's address.
Definition Abstract/Relocation.hpp:48
Definition Visitor.hpp:210
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:75
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
const char * to_string(DynamicEntry::TAG e)
ARCH
Definition ELF/enums.hpp:30
@ NONE
Definition ELF/enums.hpp:31
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42