LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
LIEF::ELF::Relocation Class Reference

Class that represents an ELF relocation. More...

#include <Relocation.hpp>

Inheritance diagram for LIEF::ELF::Relocation:
Collaboration diagram for LIEF::ELF::Relocation:

Public Types

enum class  PURPOSE { NONE = 0 , PLTGOT = 1 , DYNAMIC = 2 , OBJECT = 3 }
 The purpose of a relocation defines how this relocation is used by the loader. More...
 
enum class  ENCODING {
  UNKNOWN = 0 , REL , RELA , RELR ,
  ANDROID_SLEB
}
 
enum class  TYPE : uint32_t {
  UNKNOWN = uint32_t(-1) , ELF_RELOC , ELF_RELOC , ELF_RELOC ,
  ELF_RELOC , ELF_RELOC , ELF_RELOC , ELF_RELOC ,
  ELF_RELOC , ELF_RELOC , ELF_RELOC , ELF_RELOC
}
 The different types of the relocation. More...
 
- Public Types inherited from LIEF::Object
template<class T >
using output_t = add_pointer_t<decay_t<T>>
 
template<class T >
using output_const_t = add_pointer_t<add_const_t<decay_t<T>>>
 

Public Member Functions

 Relocation (uint64_t address, TYPE type, ENCODING enc)
 
 Relocation ()=default
 
 Relocation (ARCH arch)
 
 ~Relocation () override=default
 
Relocationoperator= (Relocation other)
 
 Relocation (const Relocation &other)
 
void swap (Relocation &other)
 
int64_t addend () const
 Additional value that can be involved in the relocation processing.
 
TYPE type () const
 Type of the relocation.
 
bool is_rela () const
 Check if the relocation uses the explicit addend() field (this is usually the case for 64 bits binaries)
 
bool is_rel () const
 Check if the relocation uses the implicit addend (i.e. not present in the ELF structure)
 
bool is_relatively_encoded () const
 True if the relocation is using the relative encoding.
 
bool is_android_packed () const
 True if the relocation is using the Android packed relocation format.
 
uint32_t info () const
 Relocation info which contains, for instance, the symbol index.
 
uint64_t r_info (Header::CLASS clazz) const
 (re)Compute the raw r_info attribute based on the given ELF class
 
ARCH architecture () const
 Target architecture for this relocation.
 
PURPOSE purpose () const
 
ENCODING encoding () const
 The encoding of the relocation.
 
bool is_relative () const
 True if the semantic of the relocation is <ARCH>_RELATIVE
 
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 determined.
 
bool has_symbol () const
 True if the current relocation is associated with a symbol.
 
Symbolsymbol ()
 Symbol associated with the relocation (or a nullptr)
 
const Symbolsymbol () const
 
bool has_section () const
 True if the relocation has an associated section.
 
Sectionsection ()
 The section in which the relocation is applied (or a nullptr)
 
const Sectionsection () const
 
Sectionsymbol_table ()
 The associated symbol table (or a nullptr)
 
const Sectionsymbol_table () const
 
void addend (int64_t addend)
 
void type (TYPE type)
 
void purpose (PURPOSE purpose)
 
void info (uint32_t v)
 
void symbol (Symbol *symbol)
 
void section (Section *section)
 
void symbol_table (Section *section)
 
void accept (Visitor &visitor) const override
 
- Public Member Functions inherited from LIEF::Relocation
 Relocation ()
 
 Relocation (uint64_t address, uint8_t size)
 Constructor from a relocation's address and size.
 
 ~Relocation () override
 
Relocationoperator= (const Relocation &)
 
 Relocation (const Relocation &)
 
void swap (Relocation &other)
 
virtual uint64_t address () const
 Relocation's address.
 
virtual void address (uint64_t address)
 
virtual void size (size_t size)
 
void accept (Visitor &visitor) const override
 Method so that the visitor can visit us.
 
virtual bool operator< (const Relocation &rhs) const
 Comparaison based on the Relocation's address
 
virtual bool operator<= (const Relocation &rhs) const
 Comparaison based on the Relocation's address
 
virtual bool operator> (const Relocation &rhs) const
 Comparaison based on the Relocation's address
 
virtual bool operator>= (const Relocation &rhs) const
 Comparaison based on the Relocation's address
 
- Public Member Functions inherited from LIEF::Object
 Object ()
 
 Object (const Object &other)
 
Objectoperator= (const Object &other)
 
template<class T >
output_t< T > as ()
 
template<class T >
output_const_t< T > as () const
 
virtual bool operator== (const Object &other) const
 
virtual bool operator!= (const Object &other) const
 
virtual ~Object ()
 

Static Public Member Functions

static TYPE type_from (uint32_t value, ARCH arch)
 
static uint32_t to_value (TYPE type)
 

Static Public Attributes

static constexpr uint64_t R_BIT = 27
 
static constexpr uint64_t R_MASK = (uint64_t(1) << R_BIT) - 1
 
static constexpr uint64_t R_X64 = uint64_t(1) << R_BIT
 
static constexpr uint64_t R_AARCH64 = uint64_t(2) << R_BIT
 
static constexpr uint64_t R_ARM = uint64_t(3) << R_BIT
 
static constexpr uint64_t R_HEXAGON = uint64_t(4) << R_BIT
 
static constexpr uint64_t R_X86 = uint64_t(5) << R_BIT
 
static constexpr uint64_t R_LARCH = uint64_t(6) << R_BIT
 
static constexpr uint64_t R_MIPS = uint64_t(7) << R_BIT
 
static constexpr uint64_t R_PPC = uint64_t(8) << R_BIT
 
static constexpr uint64_t R_PPC64 = uint64_t(9) << R_BIT
 
static constexpr uint64_t R_SPARC = uint64_t(10) << R_BIT
 
static constexpr uint64_t R_SYSZ = uint64_t(11) << R_BIT
 

Detailed Description

Class that represents an ELF relocation.

Member Enumeration Documentation

◆ ENCODING

Enumerator
UNKNOWN 
REL 

The relocation is using the regular Elf_Rel structure.

RELA 

The relocation is using the regular Elf_Rela structure.

RELR 

The relocation is using the relative relocation format.

ANDROID_SLEB 

The relocation is using the packed Android-SLEB128 format.

◆ PURPOSE

enum class LIEF::ELF::Relocation::PURPOSE
strong

The purpose of a relocation defines how this relocation is used by the loader.

Enumerator
NONE 
PLTGOT 

The relocation is associated with the PLT/GOT resolution.

DYNAMIC 

The relocation is used for regulard data/code relocation.

OBJECT 

The relocation is used in an object file.

◆ TYPE

enum class LIEF::ELF::Relocation::TYPE : uint32_t
strong

The different types of the relocation.

Enumerator
UNKNOWN 
ELF_RELOC 
ELF_RELOC 
ELF_RELOC 
ELF_RELOC 
ELF_RELOC 
ELF_RELOC 
ELF_RELOC 
ELF_RELOC 
ELF_RELOC 
ELF_RELOC 
ELF_RELOC 

Constructor & Destructor Documentation

◆ Relocation() [1/4]

LIEF::ELF::Relocation::Relocation ( uint64_t address,
TYPE type,
ENCODING enc )

◆ Relocation() [2/4]

LIEF::ELF::Relocation::Relocation ( )
default

◆ Relocation() [3/4]

LIEF::ELF::Relocation::Relocation ( ARCH arch)
inline

◆ ~Relocation()

LIEF::ELF::Relocation::~Relocation ( )
overridedefault

◆ Relocation() [4/4]

LIEF::ELF::Relocation::Relocation ( const Relocation & other)

Member Function Documentation

◆ accept()

void LIEF::ELF::Relocation::accept ( Visitor & visitor) const
overridevirtual

Implements LIEF::Object.

◆ addend() [1/2]

int64_t LIEF::ELF::Relocation::addend ( ) const
inline

Additional value that can be involved in the relocation processing.

◆ addend() [2/2]

void LIEF::ELF::Relocation::addend ( int64_t addend)
inline

◆ architecture()

ARCH LIEF::ELF::Relocation::architecture ( ) const
inline

Target architecture for this relocation.

◆ encoding()

ENCODING LIEF::ELF::Relocation::encoding ( ) const
inline

The encoding of the relocation.

◆ has_section()

bool LIEF::ELF::Relocation::has_section ( ) const
inline

True if the relocation has an associated section.

◆ has_symbol()

bool LIEF::ELF::Relocation::has_symbol ( ) const
inline

True if the current relocation is associated with a symbol.

◆ info() [1/2]

uint32_t LIEF::ELF::Relocation::info ( ) const
inline

Relocation info which contains, for instance, the symbol index.

◆ info() [2/2]

void LIEF::ELF::Relocation::info ( uint32_t v)
inline

◆ is_android_packed()

bool LIEF::ELF::Relocation::is_android_packed ( ) const
inline

True if the relocation is using the Android packed relocation format.

◆ is_rel()

bool LIEF::ELF::Relocation::is_rel ( ) const
inline

Check if the relocation uses the implicit addend (i.e. not present in the ELF structure)

◆ is_rela()

bool LIEF::ELF::Relocation::is_rela ( ) const
inline

Check if the relocation uses the explicit addend() field (this is usually the case for 64 bits binaries)

◆ is_relative()

bool LIEF::ELF::Relocation::is_relative ( ) const
inline

True if the semantic of the relocation is <ARCH>_RELATIVE

◆ is_relatively_encoded()

bool LIEF::ELF::Relocation::is_relatively_encoded ( ) const
inline

True if the relocation is using the relative encoding.

◆ operator=()

Relocation & LIEF::ELF::Relocation::operator= ( Relocation other)

◆ purpose() [1/2]

PURPOSE LIEF::ELF::Relocation::purpose ( ) const
inline

◆ purpose() [2/2]

void LIEF::ELF::Relocation::purpose ( PURPOSE purpose)
inline

◆ r_info()

uint64_t LIEF::ELF::Relocation::r_info ( Header::CLASS clazz) const
inline

(re)Compute the raw r_info attribute based on the given ELF class

◆ section() [1/3]

Section * LIEF::ELF::Relocation::section ( )
inline

The section in which the relocation is applied (or a nullptr)

◆ section() [2/3]

const Section * LIEF::ELF::Relocation::section ( ) const
inline

◆ section() [3/3]

void LIEF::ELF::Relocation::section ( Section * section)
inline

◆ size()

size_t LIEF::ELF::Relocation::size ( ) const
overridevirtual

Return the size (in bits) of the value associated with this relocation Return -1 if the size can't be determined.

Reimplemented from LIEF::Relocation.

◆ swap()

void LIEF::ELF::Relocation::swap ( Relocation & other)

◆ symbol() [1/3]

Symbol * LIEF::ELF::Relocation::symbol ( )
inline

Symbol associated with the relocation (or a nullptr)

◆ symbol() [2/3]

const Symbol * LIEF::ELF::Relocation::symbol ( ) const
inline

◆ symbol() [3/3]

void LIEF::ELF::Relocation::symbol ( Symbol * symbol)
inline

◆ symbol_table() [1/3]

Section * LIEF::ELF::Relocation::symbol_table ( )
inline

The associated symbol table (or a nullptr)

◆ symbol_table() [2/3]

const Section * LIEF::ELF::Relocation::symbol_table ( ) const
inline

◆ symbol_table() [3/3]

void LIEF::ELF::Relocation::symbol_table ( Section * section)
inline

◆ to_value()

static uint32_t LIEF::ELF::Relocation::to_value ( TYPE type)
inlinestatic

◆ type() [1/2]

TYPE LIEF::ELF::Relocation::type ( ) const
inline

Type of the relocation.

◆ type() [2/2]

void LIEF::ELF::Relocation::type ( TYPE type)
inline

◆ type_from()

static TYPE LIEF::ELF::Relocation::type_from ( uint32_t value,
ARCH arch )
static

Member Data Documentation

◆ R_AARCH64

uint64_t LIEF::ELF::Relocation::R_AARCH64 = uint64_t(2) << R_BIT
staticconstexpr

◆ R_ARM

uint64_t LIEF::ELF::Relocation::R_ARM = uint64_t(3) << R_BIT
staticconstexpr

◆ R_BIT

uint64_t LIEF::ELF::Relocation::R_BIT = 27
staticconstexpr

◆ R_HEXAGON

uint64_t LIEF::ELF::Relocation::R_HEXAGON = uint64_t(4) << R_BIT
staticconstexpr

◆ R_LARCH

uint64_t LIEF::ELF::Relocation::R_LARCH = uint64_t(6) << R_BIT
staticconstexpr

◆ R_MASK

uint64_t LIEF::ELF::Relocation::R_MASK = (uint64_t(1) << R_BIT) - 1
staticconstexpr

◆ R_MIPS

uint64_t LIEF::ELF::Relocation::R_MIPS = uint64_t(7) << R_BIT
staticconstexpr

◆ R_PPC

uint64_t LIEF::ELF::Relocation::R_PPC = uint64_t(8) << R_BIT
staticconstexpr

◆ R_PPC64

uint64_t LIEF::ELF::Relocation::R_PPC64 = uint64_t(9) << R_BIT
staticconstexpr

◆ R_SPARC

uint64_t LIEF::ELF::Relocation::R_SPARC = uint64_t(10) << R_BIT
staticconstexpr

◆ R_SYSZ

uint64_t LIEF::ELF::Relocation::R_SYSZ = uint64_t(11) << R_BIT
staticconstexpr

◆ R_X64

uint64_t LIEF::ELF::Relocation::R_X64 = uint64_t(1) << R_BIT
staticconstexpr

◆ R_X86

uint64_t LIEF::ELF::Relocation::R_X86 = uint64_t(5) << R_BIT
staticconstexpr

The documentation for this class was generated from the following file: