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/Process.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"
#include "llvm/BinaryFormat/DynamicTags.def"

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)
 
#define DYNAMIC_STRINGIFY_ENUM(tag, value)
 
#define DYNAMIC_TAG(n, v)
 
#define AARCH64_DYNAMIC_TAG(name, value)   DYNAMIC_STRINGIFY_ENUM(name, value)
 
#define HEXAGON_DYNAMIC_TAG(name, value)   DYNAMIC_STRINGIFY_ENUM(name, value)
 
#define MIPS_DYNAMIC_TAG(name, value)   DYNAMIC_STRINGIFY_ENUM(name, value)
 
#define PPC_DYNAMIC_TAG(name, value)   DYNAMIC_STRINGIFY_ENUM(name, value)
 
#define PPC64_DYNAMIC_TAG(name, value)   DYNAMIC_STRINGIFY_ENUM(name, value)
 
#define RISCV_DYNAMIC_TAG(name, value)   DYNAMIC_STRINGIFY_ENUM(name, value)
 
#define AARCH64_DYNAMIC_TAG(name, value)
 
#define MIPS_DYNAMIC_TAG(name, value)
 
#define HEXAGON_DYNAMIC_TAG(name, value)
 
#define PPC_DYNAMIC_TAG(name, value)
 
#define PPC64_DYNAMIC_TAG(name, value)
 
#define RISCV_DYNAMIC_TAG(name, value)
 
#define DYNAMIC_TAG_MARKER(name, value)
 
#define DYNAMIC_TAG(name, value)
 

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 SectionSP FindMatchingSection (const SectionList &section_list, SectionSP section)
 
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)
 
static std::string getDynamicTagAsString (uint16_t Arch, uint64_t Type)
 

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

◆ AARCH64_DYNAMIC_TAG [1/2]

#define AARCH64_DYNAMIC_TAG (   name,
  value 
)    DYNAMIC_STRINGIFY_ENUM(name, value)

◆ AARCH64_DYNAMIC_TAG [2/2]

#define AARCH64_DYNAMIC_TAG (   name,
  value 
)

◆ CASE_AND_STREAM

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

Definition at line 49 of file ObjectFileELF.cpp.

◆ DYNAMIC_STRINGIFY_ENUM

#define DYNAMIC_STRINGIFY_ENUM (   tag,
  value 
)
Value:
case value: \
return #tag;

◆ DYNAMIC_TAG [1/2]

#define DYNAMIC_TAG (   n,
 
)

◆ DYNAMIC_TAG [2/2]

#define DYNAMIC_TAG (   name,
  value 
)
Value:
case value: \
return #name;

◆ DYNAMIC_TAG_MARKER

#define DYNAMIC_TAG_MARKER (   name,
  value 
)

◆ HEXAGON_DYNAMIC_TAG [1/2]

#define HEXAGON_DYNAMIC_TAG (   name,
  value 
)    DYNAMIC_STRINGIFY_ENUM(name, value)

◆ HEXAGON_DYNAMIC_TAG [2/2]

#define HEXAGON_DYNAMIC_TAG (   name,
  value 
)

◆ IS_MICROMIPS

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

Definition at line 2073 of file ObjectFileELF.cpp.

◆ MIPS_DYNAMIC_TAG [1/2]

#define MIPS_DYNAMIC_TAG (   name,
  value 
)    DYNAMIC_STRINGIFY_ENUM(name, value)

◆ MIPS_DYNAMIC_TAG [2/2]

#define MIPS_DYNAMIC_TAG (   name,
  value 
)

◆ PPC64_DYNAMIC_TAG [1/2]

#define PPC64_DYNAMIC_TAG (   name,
  value 
)    DYNAMIC_STRINGIFY_ENUM(name, value)

◆ PPC64_DYNAMIC_TAG [2/2]

#define PPC64_DYNAMIC_TAG (   name,
  value 
)

◆ PPC_DYNAMIC_TAG [1/2]

#define PPC_DYNAMIC_TAG (   name,
  value 
)    DYNAMIC_STRINGIFY_ENUM(name, value)

◆ PPC_DYNAMIC_TAG [2/2]

#define PPC_DYNAMIC_TAG (   name,
  value 
)

◆ RISCV_DYNAMIC_TAG [1/2]

#define RISCV_DYNAMIC_TAG (   name,
  value 
)    DYNAMIC_STRINGIFY_ENUM(name, value)

◆ RISCV_DYNAMIC_TAG [2/2]

#define RISCV_DYNAMIC_TAG (   name,
  value 
)

◆ STO_MICROMIPS

#define STO_MICROMIPS   (2 << 6)

Definition at line 2072 of file ObjectFileELF.cpp.

◆ STO_MIPS_ISA

#define STO_MIPS_ISA   (3 << 6)

Definition at line 2071 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 2058 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::ParseSymbols().

◆ FindMatchingSection()

static SectionSP FindMatchingSection ( const SectionList section_list,
SectionSP  section 
)
static

Definition at line 1874 of file ObjectFileELF.cpp.

References FindMatchingSection().

Referenced by FindMatchingSection(), and ObjectFileELF::ParseSymbols().

◆ getDynamicTagAsString()

static std::string getDynamicTagAsString ( uint16_t  Arch,
uint64_t  Type 
)
static

Definition at line 3512 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::DumpELFDynamic().

◆ 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 1751 of file ObjectFileELF.cpp.

References elf::ELFProgramHeader::p_flags.

◆ GetPermissions() [2/2]

static Permissions GetPermissions ( const ELFSectionHeader H)
static

Definition at line 1740 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 1656 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::eSectionTypeLLDBFormatters, lldb::eSectionTypeLLDBTypeSummaries, lldb::eSectionTypeOther, and lldb::eSectionTypeSwiftModules.

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 495 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 73 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 72 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 87 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 86 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 88 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 76 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 75 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 78 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 81 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 82 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 80 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_NETBSD_PROCINFO

const elf_word LLDB_NT_NETBSD_PROCINFO = 1
static

Definition at line 83 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_ANDROID

const char* const LLDB_NT_OWNER_ANDROID = "Android"
static

Definition at line 67 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_CORE

const char* const LLDB_NT_OWNER_CORE = "CORE"
static

Definition at line 68 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_FREEBSD

const char* const LLDB_NT_OWNER_FREEBSD = "FreeBSD"
static

Definition at line 62 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_GNU

const char* const LLDB_NT_OWNER_GNU = "GNU"
static

Definition at line 63 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_LINUX

const char* const LLDB_NT_OWNER_LINUX = "LINUX"
static

Definition at line 69 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_NETBSD

const char* const LLDB_NT_OWNER_NETBSD = "NetBSD"
static

Definition at line 64 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 65 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().

◆ LLDB_NT_OWNER_OPENBSD

const char* const LLDB_NT_OWNER_OPENBSD = "OpenBSD"
static

Definition at line 66 of file ObjectFileELF.cpp.

Referenced by ObjectFileELF::RefineModuleDetailsFromNote().