LLDB mainline
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | List of all members
elf::ELFHeader Class Reference

Generic representation of an ELF file header. More...

#include <ELFHeader.h>

Public Member Functions

 ELFHeader ()
 
bool Is32Bit () const
 Returns true if this is a 32 bit ELF file header.
 
bool Is64Bit () const
 Returns true if this is a 64 bit ELF file header.
 
lldb::ByteOrder GetByteOrder () const
 The byte order of this ELF file header.
 
unsigned GetRelocationJumpSlotType () const
 The jump slot relocation type of this ELF.
 
bool HasHeaderExtension () const
 Check if there should be header extension in section header #0.
 
bool Parse (lldb_private::DataExtractor &data, lldb::offset_t *offset)
 Parse an ELFHeader entry starting at position offset and update the data extractor with the address size and byte order attributes as defined by the header.
 

Static Public Member Functions

static bool MagicBytesMatch (const uint8_t *magic)
 Examines at most EI_NIDENT bytes starting from the given pointer and determines if the magic ELF identification exists.
 
static unsigned AddressSizeInBytes (const uint8_t *magic)
 Examines at most EI_NIDENT bytes starting from the given address and determines the address size of the underlying ELF file.
 

Public Attributes

unsigned char e_ident [llvm::ELF::EI_NIDENT]
 ELF file identification.
 
elf_addr e_entry
 Virtual address program entry point.
 
elf_off e_phoff
 File offset of program header table.
 
elf_off e_shoff
 File offset of section header table.
 
elf_word e_flags
 Processor specific flags.
 
elf_word e_version
 Version of object file (always 1).
 
elf_half e_type
 Object file type.
 
elf_half e_machine
 Target architecture.
 
elf_half e_ehsize
 Byte size of the ELF header.
 
elf_half e_phentsize
 Size of a program header table entry.
 
elf_half e_phnum_hdr
 Number of program header entries.
 
elf_half e_shentsize
 Size of a section header table entry.
 
elf_half e_shnum_hdr
 Number of section header entries.
 
elf_half e_shstrndx_hdr
 String table section index.
 
elf_word e_phnum
 Number of program header entries.
 
elf_word e_shnum
 Number of section header entries.
 
elf_word e_shstrndx
 String table section index.
 

Private Member Functions

void ParseHeaderExtension (lldb_private::DataExtractor &data)
 Parse an ELFHeader header extension entry.
 

Detailed Description

Generic representation of an ELF file header.

This object is used to identify the general attributes on an ELF file and to locate additional sections within the file.

Definition at line 56 of file ELFHeader.h.

Constructor & Destructor Documentation

◆ ELFHeader()

ELFHeader::ELFHeader ( )

Definition at line 71 of file ELFHeader.cpp.

Member Function Documentation

◆ AddressSizeInBytes()

unsigned ELFHeader::AddressSizeInBytes ( const uint8_t *  magic)
static

Examines at most EI_NIDENT bytes starting from the given address and determines the address size of the underlying ELF file.

This function should only be called on an pointer for which MagicBytesMatch returns true.

Returns
The number of bytes forming an address in the ELF file (either 4 or 8), else zero if the address size could not be determined.

Definition at line 161 of file ELFHeader.cpp.

Referenced by ObjectFileELF::CreateInstance(), and ObjectFileELF::CreateMemoryInstance().

◆ GetByteOrder()

ByteOrder ELFHeader::GetByteOrder ( ) const

The byte order of this ELF file header.

Returns
The byte order of this ELF file as described by the header.

Definition at line 73 of file ELFHeader.cpp.

References e_ident, lldb::eByteOrderBig, lldb::eByteOrderInvalid, and lldb::eByteOrderLittle.

Referenced by Parse().

◆ GetRelocationJumpSlotType()

unsigned ELFHeader::GetRelocationJumpSlotType ( ) const

The jump slot relocation type of this ELF.

Definition at line 176 of file ELFHeader.cpp.

References e_machine.

Referenced by ParsePLTRelocations().

◆ HasHeaderExtension()

bool ELFHeader::HasHeaderExtension ( ) const

Check if there should be header extension in section header #0.

Returns
True if parsing the ELFHeader requires reading header extension and false otherwise.

Definition at line 81 of file ELFHeader.cpp.

References e_phnum_hdr, e_shnum_hdr, e_shoff, and e_shstrndx_hdr.

Referenced by ObjectFileELF::GetModuleSpecifications(), and Parse().

◆ Is32Bit()

bool elf::ELFHeader::Is32Bit ( ) const
inline

Returns true if this is a 32 bit ELF file header.

Returns
True if this is a 32 bit ELF file header.

Definition at line 85 of file ELFHeader.h.

References e_ident.

Referenced by ObjectFileELF::ApplyRelocations(), Parse(), and ParsePLTRelocations().

◆ Is64Bit()

bool elf::ELFHeader::Is64Bit ( ) const
inline

Returns true if this is a 64 bit ELF file header.

Returns
True if this is a 64 bit ELF file header.

Definition at line 93 of file ELFHeader.h.

References e_ident.

◆ MagicBytesMatch()

bool ELFHeader::MagicBytesMatch ( const uint8_t *  magic)
static

Examines at most EI_NIDENT bytes starting from the given pointer and determines if the magic ELF identification exists.

Returns
True if the given sequence of bytes identifies an ELF file.

Definition at line 157 of file ELFHeader.cpp.

Referenced by ObjectFileELF::CreateInstance(), ProcessElfCore::CreateInstance(), ObjectFileELF::CreateMemoryInstance(), and ObjectFileELF::MagicBytesMatch().

◆ Parse()

bool ELFHeader::Parse ( lldb_private::DataExtractor data,
lldb::offset_t offset 
)

Parse an ELFHeader entry starting at position offset and update the data extractor with the address size and byte order attributes as defined by the header.

Parameters
[in,out]dataThe DataExtractor to read from. Updated with the address size and byte order attributes appropriate to this header.
[in,out]offsetPointer to an offset in the data. On return the offset will be advanced by the number of bytes read.
Returns
True if the ELFHeader was successfully read and false otherwise.

Definition at line 114 of file ELFHeader.cpp.

References e_ehsize, e_entry, e_flags, e_ident, e_phnum, e_phnum_hdr, e_shnum, e_shnum_hdr, e_shstrndx, e_shstrndx_hdr, e_type, e_version, GetByteOrder(), GetMaxU64(), lldb_private::DataExtractor::GetU16(), lldb_private::DataExtractor::GetU32(), lldb_private::DataExtractor::GetU8(), HasHeaderExtension(), Is32Bit(), ParseHeaderExtension(), lldb_private::DataExtractor::SetAddressByteSize(), and lldb_private::DataExtractor::SetByteOrder().

Referenced by ProcessElfCore::CreateInstance(), ObjectFileELF::GetModuleSpecifications(), and ObjectFileELF::ParseHeader().

◆ ParseHeaderExtension()

void ELFHeader::ParseHeaderExtension ( lldb_private::DataExtractor data)
private

Parse an ELFHeader header extension entry.

This method is called by Parse().

Parameters
[in]dataThe DataExtractor to read from.

Definition at line 96 of file ELFHeader.cpp.

References e_phnum, e_phnum_hdr, e_shentsize, e_shnum, e_shnum_hdr, e_shoff, e_shstrndx, e_shstrndx_hdr, elf::ELFSectionHeader::Parse(), elf::ELFSectionHeader::sh_info, elf::ELFSectionHeader::sh_link, and elf::ELFSectionHeader::sh_size.

Referenced by Parse().

Member Data Documentation

◆ e_ehsize

elf_half elf::ELFHeader::e_ehsize

Byte size of the ELF header.

Definition at line 65 of file ELFHeader.h.

Referenced by ObjectFileELF::DumpELFHeader(), and Parse().

◆ e_entry

elf_addr elf::ELFHeader::e_entry

Virtual address program entry point.

Definition at line 58 of file ELFHeader.h.

Referenced by ObjectFileELF::DumpELFHeader(), ObjectFileELF::GetEntryPointAddress(), ObjectFileELF::IsExecutable(), and Parse().

◆ e_flags

elf_word elf::ELFHeader::e_flags

Processor specific flags.

Definition at line 61 of file ELFHeader.h.

Referenced by ObjectFileELF::DumpELFHeader(), ObjectFileELF::GetSectionHeaderInfo(), mipsVariantFromElfFlags(), and Parse().

◆ e_ident

unsigned char elf::ELFHeader::e_ident[llvm::ELF::EI_NIDENT]

◆ e_machine

elf_half elf::ELFHeader::e_machine

◆ e_phentsize

elf_half elf::ELFHeader::e_phentsize

Size of a program header table entry.

Definition at line 66 of file ELFHeader.h.

Referenced by ObjectFileELF::DumpELFHeader(), and ObjectFileELF::GetProgramHeaderInfo().

◆ e_phnum

elf_word elf::ELFHeader::e_phnum

Number of program header entries.

Definition at line 75 of file ELFHeader.h.

Referenced by ObjectFileELF::DumpELFHeader(), ObjectFileELF::GetProgramHeaderInfo(), Parse(), and ParseHeaderExtension().

◆ e_phnum_hdr

elf_half elf::ELFHeader::e_phnum_hdr

Number of program header entries.

Definition at line 67 of file ELFHeader.h.

Referenced by HasHeaderExtension(), Parse(), and ParseHeaderExtension().

◆ e_phoff

elf_off elf::ELFHeader::e_phoff

File offset of program header table.

Definition at line 59 of file ELFHeader.h.

Referenced by ObjectFileELF::DumpELFHeader(), and ObjectFileELF::GetProgramHeaderInfo().

◆ e_shentsize

elf_half elf::ELFHeader::e_shentsize

Size of a section header table entry.

Definition at line 68 of file ELFHeader.h.

Referenced by ObjectFileELF::DumpELFHeader(), ObjectFileELF::GetSectionHeaderInfo(), and ParseHeaderExtension().

◆ e_shnum

elf_word elf::ELFHeader::e_shnum

Number of section header entries.

Definition at line 76 of file ELFHeader.h.

Referenced by ObjectFileELF::DumpELFHeader(), ObjectFileELF::GetSectionHeaderInfo(), Parse(), and ParseHeaderExtension().

◆ e_shnum_hdr

elf_half elf::ELFHeader::e_shnum_hdr

Number of section header entries.

Definition at line 69 of file ELFHeader.h.

Referenced by HasHeaderExtension(), Parse(), and ParseHeaderExtension().

◆ e_shoff

elf_off elf::ELFHeader::e_shoff

File offset of section header table.

Definition at line 60 of file ELFHeader.h.

Referenced by ObjectFileELF::DumpELFHeader(), ObjectFileELF::GetSectionHeaderInfo(), HasHeaderExtension(), and ParseHeaderExtension().

◆ e_shstrndx

elf_word elf::ELFHeader::e_shstrndx

String table section index.

Definition at line 77 of file ELFHeader.h.

Referenced by ObjectFileELF::DumpELFHeader(), ObjectFileELF::GetSectionHeaderInfo(), Parse(), and ParseHeaderExtension().

◆ e_shstrndx_hdr

elf_half elf::ELFHeader::e_shstrndx_hdr

String table section index.

Definition at line 70 of file ELFHeader.h.

Referenced by HasHeaderExtension(), Parse(), and ParseHeaderExtension().

◆ e_type

elf_half elf::ELFHeader::e_type

◆ e_version

elf_word elf::ELFHeader::e_version

Version of object file (always 1).

Definition at line 62 of file ELFHeader.h.

Referenced by ProcessElfCore::CreateInstance(), ObjectFileELF::DumpELFHeader(), and Parse().


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