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
structElfRelocation
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
private const(ubyte)[] _dataprivate size_t _indexprivate bool _hasAddendprivate types.ElfClass _classprivate ElfEndian _endianMethods
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.private
gelf.Relocation decodeRel()private
gelf.RelocationWithAddend decodeRela()Constructors
this(const(ubyte)[] data, size_t index, bool hasAddend,
types.ElfClass elfClass, ElfEndian endianness)Constructor from raw relocation table data.structRelocationRange
Range for iterating over relocations in a relocation table.
Implements the D InputRange interface.
Fields
private const(ubyte)[] _dataprivate size_t _currentIndexprivate size_t _totalRelocationsprivate bool _hasAddendprivate types.ElfClass _classprivate ElfEndian _endianMethods
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, ElfEndian endianness)Constructor from relocation table data.this(const(ubyte)[] data, size_t currentIndex, size_t totalRelocations,
bool hasAddend, types.ElfClass elfClass, ElfEndian endianness)Private constructor for creating saved copies.structElfRelocationTable
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
private const(ubyte)[] _dataprivate size_t _numRelocationsprivate bool _hasAddendprivate types.ElfClass _classprivate ElfEndian _endianprivate size_t _appliesToSectionMethods
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.structRelocationTableBuilder
Builder for creating ELF relocation tables.
This struct allows incremental construction of a relocation table.
Methods
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).ubyte[] buildRel(types.ElfClass cls = types.ElfClass.CLASS64,
io.ElfEndian endian = io.ElfEndian.LITTLE)Build the REL relocation table byte array.ubyte[] buildRela(types.ElfClass cls = types.ElfClass.CLASS64,
io.ElfEndian endian = io.ElfEndian.LITTLE)Build the RELA relocation table byte array for the specified ELF class and byte order.size_t relEntrySize(types.ElfClass cls = types.ElfClass.CLASS64) const pure nothrow @nogc @safeGet the size of a REL entry for the given class.size_t relaEntrySize(types.ElfClass cls = types.ElfClass.CLASS64) const pure nothrow @nogc @safeGet the size of a RELA entry for the given class.void clear()Clear all relocations from the builder.Constructors
this(gelf.Relocation[] relEntries, gelf.RelocationWithAddend[] relaEntries)Private constructor with entry arrays.Functions 1
fn
ElfRelocationTable getRelocationTableByName(ElfFile file, string name)Get a relocation table by section name from an ELF file.