ddn.elf.reloc

ELF relocation handling functionality.

This module provides utilities for reading, searching, and building ELF relocation entries. Relocations describe how to modify the code and data when linking or loading an ELF file.

Types 4

Represents a relocation entry in an ELF file.

This struct provides unified access to both REL (without addend) and RELA (with addend) relocation formats.

Fields
const(ubyte)[] _data
size_t _index
bool _hasAddend
Methods
size_t index() pure nothrow @nogc @safe constGet the relocation's index in the table.
bool hasAddend() pure nothrow @nogc @safe constCheck if this relocation has an addend (RELA format).
ulong getOffset()Get the offset where the relocation should be applied.
uint getSymbol()Get the symbol table index this relocation refers to.
uint getType()Get the relocation type.
long getAddend()Get the addend value (only for RELA entries).
bool isUndefined()Check if this is an undefined symbol relocation.
Constructors
this(const(ubyte)[] data, size_t index, bool hasAddend, types.ElfClass elfClass)Constructor from raw relocation table data.

Range for iterating over relocations in a relocation table.

Implements the D InputRange interface.

Fields
const(ubyte)[] _data
size_t _currentIndex
size_t _totalRelocations
bool _hasAddend
Methods
bool empty() pure nothrow @nogc @safe constCheck if the range is empty.
ElfRelocation front()Get the current relocation.
void popFront()Advance to the next relocation.
typeof(this) save()Save the current state of the range.
Constructors
this()Default constructor for creating an empty range.
this(const(ubyte)[] data, size_t totalRelocations, bool hasAddend, types.ElfClass elfClass)Constructor from relocation table data.
this(const(ubyte)[] data, size_t currentIndex, size_t totalRelocations, bool hasAddend, types.ElfClass elfClass)Private constructor for creating saved copies.

Represents an ELF relocation table (.rel or .rela section).

This struct provides access to relocations that modify code and data when linking or loading an ELF file.

Fields
const(ubyte)[] _data
size_t _numRelocations
bool _hasAddend
size_t _appliesToSection
Methods
size_t numRelocations() pure nothrow @nogc @safe constGet the number of relocations in the table.
bool hasAddend() pure nothrow @nogc @safe constCheck if this is a RELA section (with addend).
ElfRelocation getRelocation(size_t index)Get a relocation by its index.
RelocationRange relocations()Iterate over all relocations.
RelocationRange getRelocationsForSection(size_t sectionIndex)Get relocations that apply to a specific section.
Constructors
this(ElfFile file, size_t sectionIndex)Constructor from an ELF file and section index.

Builder for creating ELF relocation tables.

This struct allows incremental construction of a relocation table.

Fields
gelf.Relocation[] _relEntries
Methods
RelocationTableBuilder create()Create a new empty relocation table builder.
size_t addRelRelocation(ulong offset, uint symbolIndex, uint type)Add a REL relocation (without addend).
size_t addRelaRelocation(ulong offset, uint symbolIndex, uint type, long addend)Add a RELA relocation (with addend).
size_t relCount() pure nothrow @nogc @safe constGet the number of REL entries.
size_t relaCount() pure nothrow @nogc @safe constGet the number of RELA entries.
bool hasRelEntries() pure nothrow @nogc @safe constCheck if this builder has any REL entries.
bool hasRelaEntries() pure nothrow @nogc @safe constCheck if this builder has any RELA entries.
ubyte[] buildRel()Build the REL relocation table byte array.
ubyte[] buildRela()Build the RELA relocation table byte array.
void clear()Clear all relocations from the builder.
Constructors
this(gelf.Relocation[] relEntries, gelf.RelocationWithAddend[] relaEntries)Private constructor with entry arrays.

Functions 1

fnElfRelocationTable getRelocationTableByName(ElfFile file, string name)Get a relocation table by section name from an ELF file.