LLDB mainline
Macros | Functions | Variables
ObjectFileELF.cpp File Reference
#include "ObjectFileELF.h"
#include <algorithm>
#include <cassert>
#include <optional>
#include <unordered_map>
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/Progress.h"
#include "lldb/Core/Section.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/LZMA.h"
#include "lldb/Symbol/DWARFCallFrameInfo.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/FileSpecList.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/RangeMap.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/Timer.h"
#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Object/Decompressor.h"
#include "llvm/Support/ARMBuildAttributes.h"
#include "llvm/Support/CRC.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/MipsABIFlags.h"

Go to the source code of this file.

Macros

#define CASE_AND_STREAM(s, def, width)
 
#define _MAKE_OSABI_CASE(x)
 
#define STO_MIPS_ISA   (3 << 6)
 
#define STO_MICROMIPS   (2 << 6)
 
#define IS_MICROMIPS(ST_OTHER)   (((ST_OTHER)&STO_MIPS_ISA) == STO_MICROMIPS)
 

Functions

static user_id_t SegmentID (size_t PHdrIndex)
 
static uint32_t mipsVariantFromElfFlags (const elf::ELFHeader &header)
 
static uint32_t riscvVariantFromElfFlags (const elf::ELFHeader &header)
 
static uint32_t ppc64VariantFromElfFlags (const elf::ELFHeader &header)
 
static uint32_t loongarchVariantFromElfFlags (const elf::ELFHeader &header)
 
static uint32_t subTypeFromElfHeader (const elf::ELFHeader &header)
 
static uint32_t calc_crc32 (uint32_t init, const DataExtractor &data)
 
static const char * OSABIAsCString (unsigned char osabi_byte)
 
static bool GetOsFromOSABI (unsigned char osabi_byte, llvm::Triple::OSType &ostype)
 
static SectionType GetSectionTypeFromName (llvm::StringRef Name)
 
static uint32_t GetTargetByteSize (SectionType Type, const ArchSpec &arch)
 
static Permissions GetPermissions (const ELFSectionHeader &H)
 
static Permissions GetPermissions (const ELFProgramHeader &H)
 
static char FindArmAarch64MappingSymbol (const char *symbol_name)
 
static std::pair< uint64_t, uint64_t > GetPltEntrySizeAndOffset (const ELFSectionHeader *rel_hdr, const ELFSectionHeader *plt_hdr)
 
static unsigned ParsePLTRelocations (Symtab *symbol_table, user_id_t start_id, unsigned rel_type, const ELFHeader *hdr, const ELFSectionHeader *rel_hdr, const ELFSectionHeader *plt_hdr, const ELFSectionHeader *sym_hdr, const lldb::SectionSP &plt_section_sp, DataExtractor &rel_data, DataExtractor &symtab_data, DataExtractor &strtab_data)
 
static void ApplyELF64ABS64Relocation (Symtab *symtab, ELFRelocation &rel, DataExtractor &debug_data, Section *rel_section)
 
static void ApplyELF64ABS32Relocation (Symtab *symtab, ELFRelocation &rel, DataExtractor &debug_data, Section *rel_section, bool is_signed)
 
static void ApplyELF32ABS32RelRelocation (Symtab *symtab, ELFRelocation &rel, DataExtractor &debug_data, Section *rel_section)
 

Variables

static const char *const LLDB_NT_OWNER_FREEBSD = "FreeBSD"
 
static const char *const LLDB_NT_OWNER_GNU = "GNU"
 
static const char *const LLDB_NT_OWNER_NETBSD = "NetBSD"
 
static const char *const LLDB_NT_OWNER_NETBSDCORE = "NetBSD-CORE"
 
static const char *const LLDB_NT_OWNER_OPENBSD = "OpenBSD"
 
static const char *const LLDB_NT_OWNER_ANDROID = "Android"
 
static const char *const LLDB_NT_OWNER_CORE = "CORE"
 
static const char *const LLDB_NT_OWNER_LINUX = "LINUX"
 
static const elf_word LLDB_NT_FREEBSD_ABI_TAG = 0x01
 
static const elf_word LLDB_NT_FREEBSD_ABI_SIZE = 4
 
static const elf_word LLDB_NT_GNU_ABI_TAG = 0x01
 
static const elf_word LLDB_NT_GNU_ABI_SIZE = 16
 
static const elf_word LLDB_NT_GNU_BUILD_ID_TAG = 0x03
 
static const elf_word LLDB_NT_NETBSD_IDENT_TAG = 1
 
static const elf_word LLDB_NT_NETBSD_IDENT_DESCSZ = 4
 
static const elf_word LLDB_NT_NETBSD_IDENT_NAMESZ = 7
 
static const elf_word LLDB_NT_NETBSD_PROCINFO = 1
 
static const elf_word LLDB_NT_GNU_ABI_OS_LINUX = 0x00
 
static const elf_word LLDB_NT_GNU_ABI_OS_HURD = 0x01
 
static const elf_word LLDB_NT_GNU_ABI_OS_SOLARIS = 0x02
 

Macro Definition Documentation

◆ _MAKE_OSABI_CASE

#define _MAKE_OSABI_CASE (   x)
Value:
case x: \
return #x

◆ CASE_AND_STREAM

#define CASE_AND_STREAM (   s,
  def,
  width 
)
Value:
case def: \
s->Printf("%-*s", width, #def); \
break;

Definition at line 48 of file ObjectFileELF.cpp.

◆ IS_MICROMIPS

#define IS_MICROMIPS (   ST_OTHER)    (((ST_OTHER)&STO_MIPS_ISA) == STO_MICROMIPS)

Definition at line 2027 of file ObjectFileELF.cpp.

◆ STO_MICROMIPS

#define STO_MICROMIPS   (2 << 6)

Definition at line 2026 of file ObjectFileELF.cpp.

◆ STO_MIPS_ISA

#define STO_MIPS_ISA   (3 << 6)

Definition at line 2025 of file ObjectFileELF.cpp.

Function Documentation

◆ ApplyELF32ABS32RelRelocation()

static void ApplyELF32ABS32RelRelocation ( Symtab symtab,
ELFRelocation &  rel,
DataExtractor debug_data,
Section rel_section 
)
static

◆ ApplyELF64ABS32Relocation()

static void ApplyELF64ABS32Relocation ( Symtab symtab,
ELFRelocation &  rel,
DataExtractor debug_data,
Section rel_section,
bool  is_signed 
)
static

◆ ApplyELF64ABS64Relocation()

static void ApplyELF64ABS64Relocation ( Symtab symtab,
ELFRelocation &  rel,
DataExtractor debug_data,
Section rel_section 
)
static

◆ calc_crc32()

static uint32_t calc_crc32 ( uint32_t  init,
const DataExtractor data 
)
static

◆ FindArmAarch64MappingSymbol()

static char FindArmAarch64MappingSymbol ( const char *  symbol_name)
static

Definition at line 2012 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::ParseSymbols().

◆ GetOsFromOSABI()

static bool GetOsFromOSABI ( unsigned char  osabi_byte,
llvm::Triple::OSType &  ostype 
)
static

◆ GetPermissions() [1/2]

static Permissions GetPermissions ( const ELFProgramHeader H)
static

Definition at line 1738 of file ObjectFileELF.cpp.

References elf::ELFProgramHeader::p_flags.

◆ GetPermissions() [2/2]

static Permissions GetPermissions ( const ELFSectionHeader H)
static

Definition at line 1727 of file ObjectFileELF.cpp.

References elf::ELFSectionHeader::sh_flags.

Referenced by ObjectFileELF::CreateSections().

◆ GetPltEntrySizeAndOffset()

static std::pair< uint64_t, uint64_t > GetPltEntrySizeAndOffset ( const ELFSectionHeader rel_hdr,
const ELFSectionHeader plt_hdr 
)
static

◆ GetSectionTypeFromName()

static SectionType GetSectionTypeFromName ( llvm::StringRef  Name)
static

Definition at line 1648 of file ObjectFileELF.cpp.

References lldb::eSectionTypeARMexidx, lldb::eSectionTypeARMextab, lldb::eSectionTypeCode, lldb::eSectionTypeData, lldb::eSectionTypeDebug, lldb::eSectionTypeDWARFDebugAbbrev, lldb::eSectionTypeDWARFDebugAbbrevDwo, lldb::eSectionTypeDWARFDebugAddr, lldb::eSectionTypeDWARFDebugAranges, lldb::eSectionTypeDWARFDebugCuIndex, lldb::eSectionTypeDWARFDebugFrame, lldb::eSectionTypeDWARFDebugInfo, lldb::eSectionTypeDWARFDebugInfoDwo, lldb::eSectionTypeDWARFDebugLine, lldb::eSectionTypeDWARFDebugLineStr, lldb::eSectionTypeDWARFDebugLoc, lldb::eSectionTypeDWARFDebugLocDwo, lldb::eSectionTypeDWARFDebugLocLists, lldb::eSectionTypeDWARFDebugLocListsDwo, lldb::eSectionTypeDWARFDebugMacInfo, lldb::eSectionTypeDWARFDebugMacro, lldb::eSectionTypeDWARFDebugNames, lldb::eSectionTypeDWARFDebugPubNames, lldb::eSectionTypeDWARFDebugPubTypes, lldb::eSectionTypeDWARFDebugRanges, lldb::eSectionTypeDWARFDebugRngLists, lldb::eSectionTypeDWARFDebugRngListsDwo, lldb::eSectionTypeDWARFDebugStr, lldb::eSectionTypeDWARFDebugStrDwo, lldb::eSectionTypeDWARFDebugStrOffsets, lldb::eSectionTypeDWARFDebugStrOffsetsDwo, lldb::eSectionTypeDWARFDebugTuIndex, lldb::eSectionTypeDWARFDebugTypes, lldb::eSectionTypeDWARFDebugTypesDwo, lldb::eSectionTypeDWARFGNUDebugAltLink, lldb::eSectionTypeEHFrame, lldb::eSectionTypeGoSymtab, lldb::eSectionTypeOther, lldb::eSectionTypeSwiftModules, and lldb::eSectionTypeZeroFill.

Referenced by lldb_private::wasm::ObjectFileWasm::CreateSections(), and ObjectFileELF::GetSectionType().

◆ GetTargetByteSize()

static uint32_t GetTargetByteSize ( SectionType  Type,
const ArchSpec arch 
)
static

◆ loongarchVariantFromElfFlags()

static uint32_t loongarchVariantFromElfFlags ( const elf::ELFHeader header)
static

◆ mipsVariantFromElfFlags()

static uint32_t mipsVariantFromElfFlags ( const elf::ELFHeader header)
static

◆ OSABIAsCString()

static const char * OSABIAsCString ( unsigned char  osabi_byte)
static

Definition at line 478 of file ObjectFileELF.cpp.

References _MAKE_OSABI_CASE.

Referenced by ObjectFileELF::GetModuleSpecifications().

◆ ParsePLTRelocations()

static unsigned ParsePLTRelocations ( Symtab symbol_table,
user_id_t  start_id,
unsigned  rel_type,
const ELFHeader hdr,
const ELFSectionHeader rel_hdr,
const ELFSectionHeader plt_hdr,
const ELFSectionHeader sym_hdr,
const lldb::SectionSP plt_section_sp,
DataExtractor rel_data,
DataExtractor symtab_data,
DataExtractor strtab_data 
)
static

◆ ppc64VariantFromElfFlags()

static uint32_t ppc64VariantFromElfFlags ( const elf::ELFHeader header)
static

◆ riscvVariantFromElfFlags()

static uint32_t riscvVariantFromElfFlags ( const elf::ELFHeader header)
static

◆ SegmentID()

static user_id_t SegmentID ( size_t  PHdrIndex)
static

◆ subTypeFromElfHeader()

static uint32_t subTypeFromElfHeader ( const elf::ELFHeader header)
static

Variable Documentation

◆ LLDB_NT_FREEBSD_ABI_SIZE

const elf_word LLDB_NT_FREEBSD_ABI_SIZE = 4
static

Definition at line 72 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_FREEBSD_ABI_TAG

const elf_word LLDB_NT_FREEBSD_ABI_TAG = 0x01
static

Definition at line 71 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_GNU_ABI_OS_HURD

const elf_word LLDB_NT_GNU_ABI_OS_HURD = 0x01
static

Definition at line 86 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_GNU_ABI_OS_LINUX

const elf_word LLDB_NT_GNU_ABI_OS_LINUX = 0x00
static

Definition at line 85 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_GNU_ABI_OS_SOLARIS

const elf_word LLDB_NT_GNU_ABI_OS_SOLARIS = 0x02
static

Definition at line 87 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_GNU_ABI_SIZE

const elf_word LLDB_NT_GNU_ABI_SIZE = 16
static

Definition at line 75 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_GNU_ABI_TAG

const elf_word LLDB_NT_GNU_ABI_TAG = 0x01
static

Definition at line 74 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_GNU_BUILD_ID_TAG

const elf_word LLDB_NT_GNU_BUILD_ID_TAG = 0x03
static

Definition at line 77 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_NETBSD_IDENT_DESCSZ

const elf_word LLDB_NT_NETBSD_IDENT_DESCSZ = 4
static

Definition at line 80 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_NETBSD_IDENT_NAMESZ

const elf_word LLDB_NT_NETBSD_IDENT_NAMESZ = 7
static

Definition at line 81 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_NETBSD_IDENT_TAG

const elf_word LLDB_NT_NETBSD_IDENT_TAG = 1
static

Definition at line 79 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_NETBSD_PROCINFO

const elf_word LLDB_NT_NETBSD_PROCINFO = 1
static

Definition at line 82 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_ANDROID

const char* const LLDB_NT_OWNER_ANDROID = "Android"
static

Definition at line 66 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_CORE

const char* const LLDB_NT_OWNER_CORE = "CORE"
static

Definition at line 67 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_FREEBSD

const char* const LLDB_NT_OWNER_FREEBSD = "FreeBSD"
static

Definition at line 61 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_GNU

const char* const LLDB_NT_OWNER_GNU = "GNU"
static

Definition at line 62 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_LINUX

const char* const LLDB_NT_OWNER_LINUX = "LINUX"
static

Definition at line 68 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_NETBSD

const char* const LLDB_NT_OWNER_NETBSD = "NetBSD"
static

Definition at line 63 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_NETBSDCORE

const char* const LLDB_NT_OWNER_NETBSDCORE = "NetBSD-CORE"
static

Definition at line 64 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_OPENBSD

const char* const LLDB_NT_OWNER_OPENBSD = "OpenBSD"
static

Definition at line 65 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().