16#ifndef LIEF_ELF_RELOCATION_H
17#define LIEF_ELF_RELOCATION_H
77 static constexpr uint64_t
R_BIT = 27;
78 static constexpr uint64_t
R_MASK = (uint64_t(1) <<
R_BIT) - 1;
98 enum class TYPE : uint32_t {
99 UNKNOWN = uint32_t(-1),
101#define ELF_RELOC(name, value) name = (value | R_X64),
105#define ELF_RELOC(name, value) name = (value | R_AARCH64),
109#define ELF_RELOC(name, value) name = (value | R_ARM),
113#define ELF_RELOC(name, value) name = (value | R_HEXAGON),
117#define ELF_RELOC(name, value) name = (value | R_X86),
121#define ELF_RELOC(name, value) name = (value | R_LARCH),
125#define ELF_RELOC(name, value) name = (value | R_MIPS),
129#define ELF_RELOC(name, value) name = (value | R_PPC),
133#define ELF_RELOC(name, value) name = (value | R_PPC64),
137#define ELF_RELOC(name, value) name = (value | R_SPARC),
141#define ELF_RELOC(name, value) name = (value | R_SYSZ),
145#define ELF_RELOC(name, value) name = (value | R_RISCV),
149#define ELF_RELOC(name, value) name = (value | R_BPF),
153#define ELF_RELOC(name, value) name = (value | R_SH4),
168 architecture_(arch) {}
180 addend_{other.addend_},
181 encoding_{other.encoding_},
182 architecture_{other.architecture_} {}
193 std::swap(address_, other.address_);
194 std::swap(type_, other.type_);
195 std::swap(addend_, other.addend_);
196 std::swap(encoding_, other.encoding_);
197 std::swap(symbol_, other.symbol_);
198 std::swap(architecture_, other.architecture_);
199 std::swap(purpose_, other.purpose_);
200 std::swap(section_, other.section_);
201 std::swap(symbol_table_, other.symbol_table_);
202 std::swap(info_, other.info_);
203 std::swap(binary_, other.binary_);
255 return architecture_;
281 return symbol_ !=
nullptr;
309 return symbol_table_;
313 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:44
uint32_t info() const
Relocation info which contains, for instance, the symbol index.
Definition ELF/Relocation.hpp:239
TYPE
The different types of the relocation.
Definition ELF/Relocation.hpp:98
@ PPC64_RELATIVE
Definition ELF/Relocation.hpp:985
@ UNKNOWN
Definition ELF/Relocation.hpp:99
@ X86_64_RELATIVE
Definition ELF/Relocation.hpp:116
@ AARCH64_RELATIVE
Definition ELF/Relocation.hpp:299
@ HEX_RELATIVE
Definition ELF/Relocation.hpp:501
@ ARM_RELATIVE
Definition ELF/Relocation.hpp:339
@ PPC_RELATIVE
Definition ELF/Relocation.hpp:919
@ X86_RELATIVE
Definition ELF/Relocation.hpp:579
static constexpr uint64_t R_PPC64
Definition ELF/Relocation.hpp:89
friend std::ostream & operator<<(std::ostream &os, const Relocation &entry)
TYPE type() const
Type of the relocation.
Definition ELF/Relocation.hpp:212
PURPOSE
The purpose of a relocation defines how this relocation is used by the loader.
Definition ELF/Relocation.hpp:49
@ NONE
Definition ELF/Relocation.hpp:50
static constexpr uint64_t R_X86
Definition ELF/Relocation.hpp:85
static uint32_t to_value(TYPE type)
Definition ELF/Relocation.hpp:160
Symbol * symbol()
Symbol associated with the relocation (or a nullptr).
Definition ELF/Relocation.hpp:285
Section * symbol_table()
The associated symbol table (or a nullptr).
Definition ELF/Relocation.hpp:308
static TYPE type_from(uint32_t value, ARCH arch)
void accept(Visitor &visitor) const override
void swap(Relocation &other)
Definition ELF/Relocation.hpp:192
ENCODING encoding() const
The encoding of the relocation.
Definition ELF/Relocation.hpp:263
Relocation & operator=(Relocation other)
Copy assignment operator.
Definition ELF/Relocation.hpp:187
int64_t addend() const
Additional value that can be involved in the relocation processing.
Definition ELF/Relocation.hpp:207
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:258
bool is_relative() const
True if the semantic of the relocation is <ARCH>_RELATIVE.
Definition ELF/Relocation.hpp:268
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:234
static constexpr uint64_t R_MASK
Definition ELF/Relocation.hpp:78
static constexpr uint64_t R_BPF
Definition ELF/Relocation.hpp:93
bool has_symbol() const
True if the current relocation is associated with a symbol.
Definition ELF/Relocation.hpp:280
static constexpr uint64_t R_RISCV
Definition ELF/Relocation.hpp:92
bool has_section() const
True if the relocation has an associated section.
Definition ELF/Relocation.hpp:294
const Section * symbol_table() const
Definition ELF/Relocation.hpp:312
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:218
static constexpr uint64_t R_SPARC
Definition ELF/Relocation.hpp:90
friend class Binary
Definition ELF/Relocation.hpp:43
static constexpr uint64_t R_HEXAGON
Definition ELF/Relocation.hpp:84
static constexpr uint64_t R_SYSZ
Definition ELF/Relocation.hpp:91
bool is_rel() const
Check if the relocation uses the implicit addend (i.e. not present in the ELF structure).
Definition ELF/Relocation.hpp:224
ARCH architecture() const
Target architecture for this relocation.
Definition ELF/Relocation.hpp:254
Relocation(uint64_t address, TYPE type, ENCODING enc)
static constexpr uint64_t R_SH4
Definition ELF/Relocation.hpp:94
friend class Parser
Definition ELF/Relocation.hpp:42
const Symbol * symbol() const
Definition ELF/Relocation.hpp:289
static constexpr uint64_t R_BIT
Definition ELF/Relocation.hpp:77
Section * section()
The section in which the relocation is applied (or a nullptr).
Definition ELF/Relocation.hpp:299
static constexpr uint64_t R_ARM
Definition ELF/Relocation.hpp:83
static constexpr uint64_t R_MIPS
Definition ELF/Relocation.hpp:87
static constexpr uint64_t R_PPC
Definition ELF/Relocation.hpp:88
static constexpr uint64_t R_X64
Definition ELF/Relocation.hpp:81
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:244
static constexpr uint64_t R_LARCH
Definition ELF/Relocation.hpp:86
void addend(int64_t addend)
Definition ELF/Relocation.hpp:316
static constexpr uint64_t R_AARCH64
Definition ELF/Relocation.hpp:82
ENCODING
Definition ELF/Relocation.hpp:61
@ ANDROID_SLEB
The relocation is using the packed Android-SLEB128 format.
Definition ELF/Relocation.hpp:74
@ RELR
The relocation is using the relative relocation format.
Definition ELF/Relocation.hpp:71
@ UNKNOWN
Definition ELF/Relocation.hpp:62
@ RELA
The relocation is using the regular Elf_Rela structure.
Definition ELF/Relocation.hpp:68
@ REL
The relocation is using the regular Elf_Rel structure.
Definition ELF/Relocation.hpp:65
bool is_relatively_encoded() const
True if the relocation is using the relative encoding.
Definition ELF/Relocation.hpp:229
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:47
Definition Visitor.hpp:212
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:77
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
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:45
#define LIEF_LOCAL
Definition visibility.h:46