16#ifndef LIEF_ELF_RELOCATION_H
17#define LIEF_ELF_RELOCATION_H
64 static constexpr uint64_t
R_BIT = 27;
65 static constexpr uint64_t
R_MASK = (uint64_t(1) <<
R_BIT) - 1;
83 enum class TYPE : uint32_t {
84 UNKNOWN = uint32_t(-1),
86#define ELF_RELOC(name, value) name = (value | R_X64),
90#define ELF_RELOC(name, value) name = (value | R_AARCH64),
94#define ELF_RELOC(name, value) name = (value | R_ARM),
98#define ELF_RELOC(name, value) name = (value | R_HEXAGON),
102#define ELF_RELOC(name, value) name = (value | R_X86),
106#define ELF_RELOC(name, value) name = (value | R_LARCH),
110#define ELF_RELOC(name, value) name = (value | R_MIPS),
114#define ELF_RELOC(name, value) name = (value | R_PPC),
118#define ELF_RELOC(name, value) name = (value | R_PPC64),
122#define ELF_RELOC(name, value) name = (value | R_SPARC),
126#define ELF_RELOC(name, value) name = (value | R_SYSZ),
130#define ELF_RELOC(name, value) name = (value | R_RISCV),
134#define ELF_RELOC(name, value) name = (value | R_BPF),
138#define ELF_RELOC(name, value) name = (value | R_SH4),
153 architecture_ = arch;
166 addend_{other.addend_},
167 encoding_{other.encoding_},
168 architecture_{other.architecture_} {}
179 std::swap(address_, other.address_);
180 std::swap(type_, other.type_);
181 std::swap(addend_, other.addend_);
182 std::swap(encoding_, other.encoding_);
183 std::swap(symbol_, other.symbol_);
184 std::swap(architecture_, other.architecture_);
185 std::swap(purpose_, other.purpose_);
186 std::swap(section_, other.section_);
187 std::swap(symbol_table_, other.symbol_table_);
188 std::swap(info_, other.info_);
189 std::swap(binary_, other.binary_);
241 return architecture_;
267 return symbol_ !=
nullptr;
295 return symbol_table_;
299 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:225
TYPE
The different types of the relocation.
Definition ELF/Relocation.hpp:83
@ PPC64_RELATIVE
Definition ELF/Relocation.hpp:970
@ UNKNOWN
Definition ELF/Relocation.hpp:84
@ X86_64_RELATIVE
Definition ELF/Relocation.hpp:101
@ AARCH64_RELATIVE
Definition ELF/Relocation.hpp:284
@ HEX_RELATIVE
Definition ELF/Relocation.hpp:486
@ ARM_RELATIVE
Definition ELF/Relocation.hpp:324
@ PPC_RELATIVE
Definition ELF/Relocation.hpp:904
@ X86_RELATIVE
Definition ELF/Relocation.hpp:564
static constexpr uint64_t R_PPC64
Definition ELF/Relocation.hpp:75
friend std::ostream & operator<<(std::ostream &os, const Relocation &entry)
TYPE type() const
Type of the relocation.
Definition ELF/Relocation.hpp:198
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:71
static uint32_t to_value(TYPE type)
Definition ELF/Relocation.hpp:145
Symbol * symbol()
Symbol associated with the relocation (or a nullptr).
Definition ELF/Relocation.hpp:271
Section * symbol_table()
The associated symbol table (or a nullptr).
Definition ELF/Relocation.hpp:294
static TYPE type_from(uint32_t value, ARCH arch)
void accept(Visitor &visitor) const override
void swap(Relocation &other)
Definition ELF/Relocation.hpp:178
ENCODING encoding() const
The encoding of the relocation.
Definition ELF/Relocation.hpp:249
Relocation & operator=(Relocation other)
Copy assignment operator.
Definition ELF/Relocation.hpp:173
int64_t addend() const
Additional value that can be involved in the relocation processing.
Definition ELF/Relocation.hpp:193
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:244
bool is_relative() const
True if the semantic of the relocation is <ARCH>_RELATIVE.
Definition ELF/Relocation.hpp:254
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:220
static constexpr uint64_t R_MASK
Definition ELF/Relocation.hpp:65
static constexpr uint64_t R_BPF
Definition ELF/Relocation.hpp:79
bool has_symbol() const
True if the current relocation is associated with a symbol.
Definition ELF/Relocation.hpp:266
static constexpr uint64_t R_RISCV
Definition ELF/Relocation.hpp:78
bool has_section() const
True if the relocation has an associated section.
Definition ELF/Relocation.hpp:280
const Section * symbol_table() const
Definition ELF/Relocation.hpp:298
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:204
static constexpr uint64_t R_SPARC
Definition ELF/Relocation.hpp:76
friend class Binary
Definition ELF/Relocation.hpp:43
static constexpr uint64_t R_HEXAGON
Definition ELF/Relocation.hpp:70
static constexpr uint64_t R_SYSZ
Definition ELF/Relocation.hpp:77
bool is_rel() const
Check if the relocation uses the implicit addend (i.e. not present in the ELF structure).
Definition ELF/Relocation.hpp:210
ARCH architecture() const
Target architecture for this relocation.
Definition ELF/Relocation.hpp:240
Relocation(uint64_t address, TYPE type, ENCODING enc)
static constexpr uint64_t R_SH4
Definition ELF/Relocation.hpp:80
friend class Parser
Definition ELF/Relocation.hpp:42
static constexpr uint64_t R_BIT
Definition ELF/Relocation.hpp:64
Section * section()
The section in which the relocation is applied (or a nullptr).
Definition ELF/Relocation.hpp:285
static constexpr uint64_t R_ARM
Definition ELF/Relocation.hpp:69
static constexpr uint64_t R_MIPS
Definition ELF/Relocation.hpp:73
static constexpr uint64_t R_PPC
Definition ELF/Relocation.hpp:74
static constexpr uint64_t R_X64
Definition ELF/Relocation.hpp:67
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:230
static constexpr uint64_t R_LARCH
Definition ELF/Relocation.hpp:72
void addend(int64_t addend)
Definition ELF/Relocation.hpp:302
static constexpr uint64_t R_AARCH64
Definition ELF/Relocation.hpp:68
ENCODING
Definition ELF/Relocation.hpp:56
@ ANDROID_SLEB
The relocation is using the packed Android-SLEB128 format.
Definition ELF/Relocation.hpp:61
@ RELR
The relocation is using the relative relocation format.
Definition ELF/Relocation.hpp:60
@ UNKNOWN
Definition ELF/Relocation.hpp:57
@ RELA
The relocation is using the regular Elf_Rela structure.
Definition ELF/Relocation.hpp:59
@ REL
The relocation is using the regular Elf_Rel structure.
Definition ELF/Relocation.hpp:58
bool is_relatively_encoded() const
True if the relocation is using the relative encoding.
Definition ELF/Relocation.hpp:215
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
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:43
#define LIEF_LOCAL
Definition visibility.h:44