14#include <unordered_map>
37#include "llvm/ADT/IntervalMap.h"
38#include "llvm/ADT/PointerUnion.h"
39#include "llvm/ADT/StringRef.h"
40#include "llvm/BinaryFormat/ELF.h"
41#include "llvm/Object/Decompressor.h"
42#include "llvm/Support/ARMBuildAttributes.h"
43#include "llvm/Support/CRC.h"
44#include "llvm/Support/FormatVariadic.h"
45#include "llvm/Support/MathExtras.h"
46#include "llvm/Support/MemoryBuffer.h"
47#include "llvm/Support/MipsABIFlags.h"
49#define CASE_AND_STREAM(s, def, width) \
51 s->Printf("%-*s", width, #def); \
57using namespace llvm::ELF;
104 ELFRelocation(
unsigned type);
110 static unsigned RelocType32(
const ELFRelocation &rel);
112 static unsigned RelocType64(
const ELFRelocation &rel);
114 static unsigned RelocSymbol32(
const ELFRelocation &rel);
116 static unsigned RelocSymbol64(
const ELFRelocation &rel);
118 static elf_addr RelocOffset32(
const ELFRelocation &rel);
120 static elf_addr RelocOffset64(
const ELFRelocation &rel);
122 static elf_sxword RelocAddend32(
const ELFRelocation &rel);
124 static elf_sxword RelocAddend64(
const ELFRelocation &rel);
126 bool IsRela() {
return (llvm::isa<ELFRela *>(reloc)); }
129 typedef llvm::PointerUnion<ELFRel *, ELFRela *> RelocUnion;
139 assert(lhs_module_parent && rhs_module_parent);
142 if (lhs->GetFileAddress() != rhs->GetFileAddress())
143 lhs_module_parent->ReportWarning(
144 "Mismatch addresses for section {0} when "
145 "merging with {1}, expected: {2:x}, "
147 lhs->GetTypeAsCString(),
148 rhs_module_parent->GetFileSpec().GetPathAsConstString().GetCString(),
149 lhs->GetByteSize(), rhs->GetByteSize());
154 return rhs->GetFileSize() > lhs->GetFileSize() ? rhs : lhs;
158ELFRelocation::ELFRelocation(
unsigned type) {
159 if (type == DT_REL || type == SHT_REL)
160 reloc =
new ELFRel();
161 else if (type == DT_RELA || type == SHT_RELA)
162 reloc =
new ELFRela();
164 assert(
false &&
"unexpected relocation type");
165 reloc =
static_cast<ELFRel *
>(
nullptr);
169ELFRelocation::~ELFRelocation() {
170 if (
auto *elfrel = llvm::dyn_cast<ELFRel *>(reloc))
173 delete llvm::cast<ELFRela *>(reloc);
176bool ELFRelocation::Parse(
const lldb_private::DataExtractor &data,
178 if (
auto *elfrel = llvm::dyn_cast<ELFRel *>(reloc))
179 return elfrel->Parse(data, offset);
181 return llvm::cast<ELFRela *>(reloc)->Parse(data, offset);
184unsigned ELFRelocation::RelocType32(
const ELFRelocation &rel) {
185 if (
auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
191unsigned ELFRelocation::RelocType64(
const ELFRelocation &rel) {
192 if (
auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
198unsigned ELFRelocation::RelocSymbol32(
const ELFRelocation &rel) {
199 if (
auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
205unsigned ELFRelocation::RelocSymbol64(
const ELFRelocation &rel) {
206 if (
auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
212elf_addr ELFRelocation::RelocOffset32(
const ELFRelocation &rel) {
213 if (
auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
214 return elfrel->r_offset;
216 return llvm::cast<ELFRela *>(rel.reloc)->r_offset;
219elf_addr ELFRelocation::RelocOffset64(
const ELFRelocation &rel) {
220 if (
auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
221 return elfrel->r_offset;
223 return llvm::cast<ELFRela *>(rel.reloc)->r_offset;
226elf_sxword ELFRelocation::RelocAddend32(
const ELFRelocation &rel) {
227 if (llvm::isa<ELFRel *>(rel.reloc))
230 return llvm::cast<ELFRela *>(rel.reloc)->r_addend;
233elf_sxword ELFRelocation::RelocAddend64(
const ELFRelocation &rel) {
234 if (llvm::isa<ELFRel *>(rel.reloc))
237 return llvm::cast<ELFRela *>(rel.reloc)->r_addend;
257 if (strncmp(buf,
"CORE", 4) == 0) {
265 if (cstr ==
nullptr) {
267 LLDB_LOGF(log,
"Failed to parse note name lacking nul terminator");
276 const uint32_t mips_arch = header.
e_flags & llvm::ELF::EF_MIPS_ARCH;
279 uint32_t fileclass = header.
e_ident[EI_CLASS];
284 if (header.
e_type == ET_CORE) {
286 case llvm::ELF::ELFCLASS32:
289 case llvm::ELF::ELFCLASS64:
298 case llvm::ELF::EF_MIPS_ARCH_1:
299 case llvm::ELF::EF_MIPS_ARCH_2:
300 case llvm::ELF::EF_MIPS_ARCH_32:
303 case llvm::ELF::EF_MIPS_ARCH_32R2:
306 case llvm::ELF::EF_MIPS_ARCH_32R6:
309 case llvm::ELF::EF_MIPS_ARCH_3:
310 case llvm::ELF::EF_MIPS_ARCH_4:
311 case llvm::ELF::EF_MIPS_ARCH_5:
312 case llvm::ELF::EF_MIPS_ARCH_64:
315 case llvm::ELF::EF_MIPS_ARCH_64R2:
318 case llvm::ELF::EF_MIPS_ARCH_64R6:
329 uint32_t fileclass = header.
e_ident[EI_CLASS];
331 case llvm::ELF::ELFCLASS32:
333 case llvm::ELF::ELFCLASS64:
342 if (
endian == ELFDATA2LSB)
349 uint32_t fileclass = header.
e_ident[EI_CLASS];
351 case llvm::ELF::ELFCLASS32:
353 case llvm::ELF::ELFCLASS64:
361 if (header.
e_machine == llvm::ELF::EM_MIPS)
363 else if (header.
e_machine == llvm::ELF::EM_PPC64)
365 else if (header.
e_machine == llvm::ELF::EM_RISCV)
367 else if (header.
e_machine == llvm::ELF::EM_LOONGARCH)
395 bool mapped_writable =
false;
401 mapped_writable =
true;
406 if (data_sp->GetByteSize() <= (llvm::ELF::EI_NIDENT + data_offset))
409 const uint8_t *magic = data_sp->GetBytes() + data_offset;
414 if (data_sp->GetByteSize() < length) {
419 mapped_writable =
true;
420 magic = data_sp->GetBytes();
424 if (!mapped_writable) {
425 data_sp = std::make_shared<DataBufferHeap>(data_sp->GetBytes(),
426 data_sp->GetByteSize());
428 magic = data_sp->GetBytes();
432 if (address_size == 4 || address_size == 8) {
434 module_sp, data_sp, data_offset, file, file_offset, length));
435 ArchSpec spec = objfile_up->GetArchitecture();
436 if (spec && objfile_up->SetModulesArchitecture(spec))
437 return objfile_up.release();
446 if (!data_sp || data_sp->GetByteSize() < (llvm::ELF::EI_NIDENT))
448 const uint8_t *magic = data_sp->GetBytes();
457 if (!hdr.
Parse(data, &offset))
466 if (end_phdrs > data_sp->GetByteSize())
467 data_sp =
ReadMemory(process_sp, header_addr, end_phdrs);
469 std::unique_ptr<ObjectFileELF> objfile_up(
470 new ObjectFileELF(module_sp, data_sp, process_sp, header_addr));
471 ArchSpec spec = objfile_up->GetArchitecture();
472 if (spec && objfile_up->SetModulesArchitecture(spec))
473 return objfile_up.release();
482 data_sp->GetByteSize() > (llvm::ELF::EI_NIDENT + data_offset)) {
483 const uint8_t *magic = data_sp->GetBytes() + data_offset;
490 return llvm::crc32(init,
497 uint32_t core_notes_crc = 0;
500 if (H.p_type == llvm::ELF::PT_NOTE) {
501 const elf_off ph_offset = H.p_offset;
502 const size_t ph_size = H.p_filesz;
505 if (segment_data.
SetData(object_data, ph_offset, ph_size) != ph_size) {
511 core_notes_crc =
calc_crc32(core_notes_crc, segment_data);
515 return core_notes_crc;
519#define _MAKE_OSABI_CASE(x) \
522 switch (osabi_byte) {
544 return "<unknown-osabi>";
546#undef _MAKE_OSABI_CASE
556 llvm::Triple::OSType &ostype) {
557 switch (osabi_byte) {
559 ostype = llvm::Triple::OSType::AIX;
561 case ELFOSABI_FREEBSD:
562 ostype = llvm::Triple::OSType::FreeBSD;
565 ostype = llvm::Triple::OSType::Linux;
567 case ELFOSABI_NETBSD:
568 ostype = llvm::Triple::OSType::NetBSD;
570 case ELFOSABI_OPENBSD:
571 ostype = llvm::Triple::OSType::OpenBSD;
573 case ELFOSABI_SOLARIS:
574 ostype = llvm::Triple::OSType::Solaris;
577 ostype = llvm::Triple::OSType::UnknownOS;
579 return ostype != llvm::Triple::OSType::UnknownOS;
588 const size_t initial_count = specs.
GetSize();
595 if (header.
Parse(data, &header_offset)) {
612 llvm::Triple::OSType ostype;
613 llvm::Triple::VendorType vendor;
614 llvm::Triple::OSType spec_ostype =
617 LLDB_LOGF(log,
"ObjectFileELF::%s file '%s' module OSABI: %s",
618 __FUNCTION__, file.
GetPath().c_str(),
623 assert(vendor == llvm::Triple::UnknownVendor);
629 assert(spec_ostype == ostype);
630 if (spec_ostype != llvm::Triple::OSType::UnknownOS) {
632 "ObjectFileELF::%s file '%s' set ELF module OS type "
633 "from ELF header OSABI.",
634 __FUNCTION__, file.
GetPath().c_str());
641 if (data_sp->GetByteSize() < length)
651 header.
Parse(data, &header_offset);
654 uint32_t gnu_debuglink_crc = 0;
655 std::string gnu_debuglink_file;
660 gnu_debuglink_file, gnu_debuglink_crc,
666 "ObjectFileELF::%s file '%s' module set to triple: %s "
668 __FUNCTION__, file.
GetPath().c_str(),
669 spec_triple.getTriple().c_str(),
673 uint32_t core_notes_crc = 0;
675 if (!gnu_debuglink_crc) {
677 "Calculating module crc32 %s with size %" PRIu64
" KiB",
679 (length - file_offset) / 1024);
685 if (header.
e_type == llvm::ELF::ET_CORE) {
695 using u32le = llvm::support::ulittle32_t;
696 if (gnu_debuglink_crc) {
698 u32le data(gnu_debuglink_crc);
699 uuid =
UUID(&data,
sizeof(data));
700 }
else if (core_notes_crc) {
705 uuid =
UUID(data,
sizeof(data));
715 return specs.
GetSize() - initial_count;
724 :
ObjectFile(module_sp, file, file_offset, length, data_sp, data_offset) {
733 :
ObjectFile(module_sp, process_sp, header_addr, header_data_sp) {}
740 bool value_is_offset) {
743 size_t num_loaded_sections = 0;
746 if (!value_is_offset) {
753 const size_t num_sections = section_list->
GetSize();
756 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
772 if (section_sp->IsThreadSpecific())
774 if (section_sp->Test(SHF_ALLOC) ||
786 load_addr &= 0xFFFFFFFF;
789 ++num_loaded_sections;
792 return num_loaded_sections > 0;
799 if (
m_header.e_ident[EI_DATA] == ELFDATA2MSB)
801 if (
m_header.e_ident[EI_DATA] == ELFDATA2LSB)
807 return m_data.GetAddressByteSize();
818 if (symtab_objfile !=
nullptr && symtab_objfile !=
this)
859 if (H.p_type == llvm::ELF::PT_NOTE) {
876 using u32le = llvm::support::ulittle32_t;
878 uint32_t core_notes_crc = 0;
886 if (core_notes_crc) {
915 uint32_t num_specs = 0;
917 for (
unsigned i = 0; i < num_modules; ++i) {
936 if (symbol.
d_tag != DT_DEBUG && symbol.
d_tag != DT_MIPS_RLD_MAP &&
937 symbol.
d_tag != DT_MIPS_RLD_MAP_REL)
947 if (symbol.
d_tag == DT_DEBUG)
952 if ((symbol.
d_tag == DT_MIPS_RLD_MAP ||
953 symbol.
d_tag == DT_MIPS_RLD_MAP_REL) &&
960 if (symbol.
d_tag == DT_MIPS_RLD_MAP) {
966 if (symbol.
d_tag == DT_MIPS_RLD_MAP_REL) {
974 addr_t debug_ptr_address =
1032 if (entry.symbol.d_tag != DT_NEEDED)
1034 if (!entry.name.empty()) {
1049 if (!program_headers.empty())
1050 return program_headers.size();
1056 program_headers.resize(header.
e_phnum);
1057 if (program_headers.size() != header.
e_phnum)
1063 if (data.
SetData(object_data, ph_offset, ph_size) != ph_size)
1068 for (idx = 0, offset = 0; idx < header.
e_phnum; ++idx) {
1069 if (!program_headers[idx].Parse(data, &offset))
1073 if (idx < program_headers.size())
1074 program_headers.resize(idx);
1076 return program_headers.size();
1097 if (!
note.Parse(data, &offset)) {
1102 LLDB_LOGF(log,
"ObjectFileELF::%s parsing note name='%s', type=%" PRIu32,
1103 __FUNCTION__,
note.n_name.c_str(),
note.n_type);
1110 uint32_t version_info;
1111 if (data.
GetU32(&offset, &version_info, 1) ==
nullptr) {
1118 const uint32_t version_major = version_info / 100000;
1119 const uint32_t version_minor = (version_info / 1000) % 100;
1122 snprintf(os_name,
sizeof(os_name),
"freebsd%" PRIu32
".%" PRIu32,
1123 version_major, version_minor);
1126 arch_spec.
GetTriple().setOSName(os_name);
1127 arch_spec.
GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor);
1130 "ObjectFileELF::%s detected FreeBSD %" PRIu32
".%" PRIu32
1132 __FUNCTION__, version_major, version_minor,
1133 static_cast<uint32_t
>(version_info % 1000));
1137 switch (
note.n_type) {
1141 uint32_t version_info[4];
1142 if (data.
GetU32(&offset, &version_info[0],
note.n_descsz / 4) ==
1150 switch (version_info[0]) {
1152 arch_spec.
GetTriple().setOS(llvm::Triple::OSType::Linux);
1154 llvm::Triple::VendorType::UnknownVendor);
1156 "ObjectFileELF::%s detected Linux, min version %" PRIu32
1157 ".%" PRIu32
".%" PRIu32,
1158 __FUNCTION__, version_info[1], version_info[2],
1165 arch_spec.
GetTriple().setOS(llvm::Triple::OSType::UnknownOS);
1167 llvm::Triple::VendorType::UnknownVendor);
1169 "ObjectFileELF::%s detected Hurd (unsupported), min "
1170 "version %" PRIu32
".%" PRIu32
".%" PRIu32,
1171 __FUNCTION__, version_info[1], version_info[2],
1175 arch_spec.
GetTriple().setOS(llvm::Triple::OSType::Solaris);
1177 llvm::Triple::VendorType::UnknownVendor);
1179 "ObjectFileELF::%s detected Solaris, min version %" PRIu32
1180 ".%" PRIu32
".%" PRIu32,
1181 __FUNCTION__, version_info[1], version_info[2],
1186 "ObjectFileELF::%s unrecognized OS in note, id %" PRIu32
1187 ", min version %" PRIu32
".%" PRIu32
".%" PRIu32,
1188 __FUNCTION__, version_info[0], version_info[1],
1189 version_info[2], version_info[3]);
1201 if (
note.n_descsz >= 4) {
1202 if (
const uint8_t *buf = data.
PeekData(offset,
note.n_descsz)) {
1207 "failed to read GNU_BUILD_ID note payload");
1214 if (arch_spec.
IsMIPS() &&
1215 arch_spec.
GetTriple().getOS() == llvm::Triple::OSType::UnknownOS)
1217 arch_spec.
GetTriple().setOS(llvm::Triple::OSType::Linux);
1225 uint32_t version_info;
1226 if (data.
GetU32(&offset, &version_info, 1) ==
nullptr) {
1238 const uint32_t version_major = version_info / 100000000;
1239 const uint32_t version_minor = (version_info % 100000000) / 1000000;
1240 const uint32_t version_patch = (version_info % 10000) / 100;
1243 llvm::formatv(
"netbsd{0}.{1}.{2}", version_major, version_minor,
1244 version_patch).str());
1245 arch_spec.
GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor);
1251 arch_spec.
GetTriple().setOS(llvm::Triple::OSType::NetBSD);
1252 arch_spec.
GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor);
1257 arch_spec.
GetTriple().setOS(llvm::Triple::OSType::OpenBSD);
1258 arch_spec.
GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor);
1260 arch_spec.
GetTriple().setOS(llvm::Triple::OSType::Linux);
1262 llvm::Triple::EnvironmentType::Android);
1266 arch_spec.
GetTriple().setOS(llvm::Triple::OSType::Linux);
1290 if (
note.n_type == NT_FILE) {
1294 offset += count * 3 *
1296 for (
size_t i = 0; i < count; ++i) {
1298 if (cstr ==
nullptr) {
1300 "ObjectFileELF::%s trying to read "
1301 "at an offset after the end "
1302 "(GetCStr returned nullptr)",
1306 llvm::StringRef path(cstr);
1307 if (path.contains(
"/lib/x86_64-linux-gnu") || path.contains(
"/lib/i386-linux-gnu")) {
1308 arch_spec.
GetTriple().setOS(llvm::Triple::OSType::Linux);
1312 if (arch_spec.
IsMIPS() &&
1313 arch_spec.
GetTriple().getOS() == llvm::Triple::OSType::UnknownOS)
1316 arch_spec.
GetTriple().setOS(llvm::Triple::OSType::Linux);
1322 offset = note_offset +
note.GetByteSize();
1332 uint8_t FormatVersion = data.
GetU8(&Offset);
1333 if (FormatVersion != llvm::ELFAttrs::Format_Version)
1336 Offset = Offset +
sizeof(uint32_t);
1337 llvm::StringRef VendorName = data.
GetCStr(&Offset);
1339 if (VendorName !=
"aeabi")
1342 if (arch_spec.
GetTriple().getEnvironment() ==
1343 llvm::Triple::UnknownEnvironment)
1344 arch_spec.
GetTriple().setEnvironment(llvm::Triple::EABI);
1346 while (Offset < length) {
1347 uint8_t Tag = data.
GetU8(&Offset);
1348 uint32_t Size = data.
GetU32(&Offset);
1350 if (Tag != llvm::ARMBuildAttrs::File || Size == 0)
1353 while (Offset < length) {
1359 else if (Tag % 2 == 0)
1366 case llvm::ARMBuildAttrs::CPU_raw_name:
1367 case llvm::ARMBuildAttrs::CPU_name:
1372 case llvm::ARMBuildAttrs::ABI_VFP_args: {
1375 if (VFPArgs == llvm::ARMBuildAttrs::BaseAAPCS) {
1376 if (arch_spec.
GetTriple().getEnvironment() ==
1377 llvm::Triple::UnknownEnvironment ||
1378 arch_spec.
GetTriple().getEnvironment() == llvm::Triple::EABIHF)
1379 arch_spec.
GetTriple().setEnvironment(llvm::Triple::EABI);
1382 }
else if (VFPArgs == llvm::ARMBuildAttrs::HardFPAAPCS) {
1383 if (arch_spec.
GetTriple().getEnvironment() ==
1384 llvm::Triple::UnknownEnvironment ||
1385 arch_spec.
GetTriple().getEnvironment() == llvm::Triple::EABI)
1386 arch_spec.
GetTriple().setEnvironment(llvm::Triple::EABIHF);
1403 std::string &gnu_debuglink_file,
1404 uint32_t &gnu_debuglink_crc,
1407 if (!section_headers.empty())
1408 return section_headers.size();
1412 if (arch_spec.
GetTriple().getOS() == llvm::Triple::OSType::UnknownOS) {
1413 llvm::Triple::OSType ostype;
1414 llvm::Triple::OSType spec_ostype;
1426 spec_ostype = arch_spec.
GetTriple().getOS();
1427 assert(spec_ostype == ostype);
1431 if (arch_spec.
GetMachine() == llvm::Triple::mips ||
1432 arch_spec.
GetMachine() == llvm::Triple::mipsel ||
1433 arch_spec.
GetMachine() == llvm::Triple::mips64 ||
1434 arch_spec.
GetMachine() == llvm::Triple::mips64el) {
1435 switch (header.
e_flags & llvm::ELF::EF_MIPS_ARCH_ASE) {
1436 case llvm::ELF::EF_MIPS_MICROMIPS:
1439 case llvm::ELF::EF_MIPS_ARCH_ASE_M16:
1442 case llvm::ELF::EF_MIPS_ARCH_ASE_MDMX:
1450 if (arch_spec.
GetMachine() == llvm::Triple::arm ||
1451 arch_spec.
GetMachine() == llvm::Triple::thumb) {
1452 if (header.
e_flags & llvm::ELF::EF_ARM_SOFT_FLOAT)
1454 else if (header.
e_flags & llvm::ELF::EF_ARM_VFP_FLOAT)
1458 if (arch_spec.
GetMachine() == llvm::Triple::riscv32 ||
1459 arch_spec.
GetMachine() == llvm::Triple::riscv64) {
1460 uint32_t flags = arch_spec.
GetFlags();
1462 if (header.
e_flags & llvm::ELF::EF_RISCV_RVC)
1464 if (header.
e_flags & llvm::ELF::EF_RISCV_RVE)
1467 if ((header.
e_flags & llvm::ELF::EF_RISCV_FLOAT_ABI_SINGLE) ==
1468 llvm::ELF::EF_RISCV_FLOAT_ABI_SINGLE)
1470 else if ((header.
e_flags & llvm::ELF::EF_RISCV_FLOAT_ABI_DOUBLE) ==
1471 llvm::ELF::EF_RISCV_FLOAT_ABI_DOUBLE)
1473 else if ((header.
e_flags & llvm::ELF::EF_RISCV_FLOAT_ABI_QUAD) ==
1474 llvm::ELF::EF_RISCV_FLOAT_ABI_QUAD)
1480 if (arch_spec.
GetMachine() == llvm::Triple::loongarch32 ||
1481 arch_spec.
GetMachine() == llvm::Triple::loongarch64) {
1482 uint32_t flags = arch_spec.
GetFlags();
1483 switch (header.
e_flags & llvm::ELF::EF_LOONGARCH_ABI_MODIFIER_MASK) {
1484 case llvm::ELF::EF_LOONGARCH_ABI_SINGLE_FLOAT:
1487 case llvm::ELF::EF_LOONGARCH_ABI_DOUBLE_FLOAT:
1490 case llvm::ELF::EF_LOONGARCH_ABI_SOFT_FLOAT:
1503 section_headers.resize(header.
e_shnum);
1504 if (section_headers.size() != header.
e_shnum)
1510 if (sh_data.
SetData(object_data, sh_offset, sh_size) != sh_size)
1515 for (idx = 0, offset = 0; idx < header.
e_shnum; ++idx) {
1516 if (!section_headers[idx].Parse(sh_data, &offset))
1519 if (idx < section_headers.size())
1520 section_headers.resize(idx);
1522 const unsigned strtab_idx = header.
e_shstrndx;
1523 if (strtab_idx && strtab_idx < section_headers.size()) {
1525 const size_t byte_size = sheader.
sh_size;
1526 const Elf64_Off offset = sheader.
sh_offset;
1529 if (shstr_data.
SetData(object_data, offset, byte_size) == byte_size) {
1531 I != section_headers.end(); ++I) {
1532 static ConstString g_sect_name_gnu_debuglink(
".gnu_debuglink");
1534 const uint64_t section_size =
1538 I->section_name = name;
1540 if (arch_spec.
IsMIPS()) {
1541 uint32_t arch_flags = arch_spec.
GetFlags();
1543 if (sheader.
sh_type == SHT_MIPS_ABIFLAGS) {
1546 section_size) == section_size)) {
1549 arch_flags |= data.
GetU32(&offset);
1553 switch (data.
GetU8(&offset)) {
1554 case llvm::Mips::Val_GNU_MIPS_ABI_FP_ANY:
1557 case llvm::Mips::Val_GNU_MIPS_ABI_FP_DOUBLE:
1560 case llvm::Mips::Val_GNU_MIPS_ABI_FP_SINGLE:
1563 case llvm::Mips::Val_GNU_MIPS_ABI_FP_SOFT:
1566 case llvm::Mips::Val_GNU_MIPS_ABI_FP_OLD_64:
1569 case llvm::Mips::Val_GNU_MIPS_ABI_FP_XX:
1572 case llvm::Mips::Val_GNU_MIPS_ABI_FP_64:
1575 case llvm::Mips::Val_GNU_MIPS_ABI_FP_64A:
1582 switch (header.
e_flags & llvm::ELF::EF_MIPS_ABI) {
1583 case llvm::ELF::EF_MIPS_ABI_O32:
1586 case EF_MIPS_ABI_O64:
1589 case EF_MIPS_ABI_EABI32:
1592 case EF_MIPS_ABI_EABI64:
1597 if (header.
e_ident[EI_CLASS] == llvm::ELF::ELFCLASS64)
1599 else if (header.
e_flags & llvm::ELF::EF_MIPS_ABI2)
1606 if (arch_spec.
GetMachine() == llvm::Triple::arm ||
1607 arch_spec.
GetMachine() == llvm::Triple::thumb) {
1610 if (sheader.
sh_type == SHT_ARM_ATTRIBUTES && section_size != 0 &&
1611 data.
SetData(object_data, sheader.
sh_offset, section_size) == section_size)
1615 if (name == g_sect_name_gnu_debuglink) {
1618 section_size) == section_size)) {
1620 gnu_debuglink_file = data.
GetCStr(&gnu_debuglink_offset);
1621 gnu_debuglink_offset = llvm::alignTo(gnu_debuglink_offset, 4);
1622 data.
GetU32(&gnu_debuglink_offset, &gnu_debuglink_crc, 1);
1627 bool is_note_header = (sheader.
sh_type == SHT_NOTE);
1631 static ConstString g_sect_name_android_ident(
".note.android.ident");
1632 if (!is_note_header && name == g_sect_name_android_ident)
1633 is_note_header =
true;
1635 if (is_note_header) {
1639 section_size) == section_size)) {
1642 LLDB_LOGF(log,
"ObjectFileELF::%s ELF note processing failed: %s",
1643 __FUNCTION__,
error.AsCString());
1650 if (arch_spec.
GetTriple().getVendor() == llvm::Triple::UnknownVendor)
1651 arch_spec.
GetTriple().setVendorName(llvm::StringRef());
1652 if (arch_spec.
GetTriple().getOS() == llvm::Triple::UnknownOS)
1653 arch_spec.
GetTriple().setOSName(llvm::StringRef());
1655 return section_headers.size();
1659 section_headers.clear();
1665 size_t pos = symbol_name.find(
'@');
1666 return symbol_name.substr(0, pos);
1697 if (Name.consume_front(
".debug_"))
1700 return llvm::StringSwitch<SectionType>(Name)
1751 Permissions Perm = Permissions(0);
1753 Perm |= ePermissionsReadable;
1755 Perm |= ePermissionsWritable;
1757 Perm |= ePermissionsExecutable;
1762 Permissions Perm = Permissions(0);
1764 Perm |= ePermissionsReadable;
1766 Perm |= ePermissionsWritable;
1768 Perm |= ePermissionsExecutable;
1776struct SectionAddressInfo {
1784class VMAddressProvider {
1786 llvm::IntervalMapHalfOpenInfo<addr_t>>;
1789 addr_t NextVMAddress = 0;
1790 VMMap::Allocator Alloc;
1791 VMMap Segments{Alloc};
1792 VMMap Sections{Alloc};
1793 lldb_private::Log *Log =
GetLog(LLDBLog::Modules);
1794 size_t SegmentCount = 0;
1795 std::string SegmentName;
1797 VMRange GetVMRange(
const ELFSectionHeader &H) {
1803 if ((ObjectType == ObjectFile::Type::eTypeObjectFile ||
1804 (ObjectType == ObjectFile::Type::eTypeDebugInfo && H.
sh_addr == 0)) &&
1805 Segments.empty() && (H.
sh_flags & SHF_ALLOC)) {
1807 llvm::alignTo(NextVMAddress, std::max<addr_t>(H.
sh_addralign, 1));
1808 Address = NextVMAddress;
1809 NextVMAddress += Size;
1811 return VMRange(Address, Size);
1816 : ObjectType(
Type), SegmentName(std::string(SegmentName)) {}
1818 std::string GetNextSegmentName()
const {
1819 return llvm::formatv(
"{0}[{1}]", SegmentName, SegmentCount).str();
1822 std::optional<VMRange> GetAddressInfo(
const ELFProgramHeader &H) {
1824 LLDB_LOG(Log,
"Ignoring zero-sized {0} segment. Corrupt object file?",
1826 return std::nullopt;
1830 LLDB_LOG(Log,
"Ignoring overlapping {0} segment. Corrupt object file?",
1832 return std::nullopt;
1837 std::optional<SectionAddressInfo> GetAddressInfo(
const ELFSectionHeader &H) {
1838 VMRange Range = GetVMRange(H);
1840 auto It = Segments.find(Range.GetRangeBase());
1841 if ((H.
sh_flags & SHF_ALLOC) && It.valid()) {
1843 if (It.start() <= Range.GetRangeBase()) {
1844 MaxSize = It.stop() - Range.GetRangeBase();
1847 MaxSize = It.start() - Range.GetRangeBase();
1849 LLDB_LOG(Log,
"Shortening section crossing segment boundaries. "
1850 "Corrupt object file?");
1855 Sections.overlaps(Range.GetRangeBase(), Range.GetRangeEnd())) {
1856 LLDB_LOG(Log,
"Ignoring overlapping section. Corrupt object file?");
1857 return std::nullopt;
1860 Range.Slide(-Segment->GetFileAddress());
1861 return SectionAddressInfo{Segment, Range};
1864 void AddSegment(
const VMRange &Range,
SectionSP Seg) {
1865 Segments.insert(Range.GetRangeBase(), Range.GetRangeEnd(), std::move(Seg));
1869 void AddSection(SectionAddressInfo Info,
SectionSP Sect) {
1870 if (Info.Range.GetByteSize() == 0)
1873 Info.Range.Slide(Info.Segment->GetFileAddress());
1874 Sections.insert(Info.Range.GetRangeBase(), Info.Range.GetRangeEnd(),
1888 addr_t vm_addr = section->GetFileAddress();
1890 offset_t byte_size = section->GetByteSize();
1891 bool thread_specific = section->IsThreadSpecific();
1892 uint32_t permissions = section->GetPermissions();
1893 uint32_t alignment = section->GetLog2Align();
1895 for (
auto sect : section_list) {
1896 if (sect->GetName() == name &&
1897 sect->IsThreadSpecific() == thread_specific &&
1898 sect->GetPermissions() == permissions &&
1899 sect->GetByteSize() == byte_size && sect->GetFileAddress() == vm_addr &&
1900 sect->GetLog2Align() == alignment) {
1918 VMAddressProvider regular_provider(
GetType(),
"PT_LOAD");
1919 VMAddressProvider tls_provider(
GetType(),
"PT_TLS");
1926 VMAddressProvider &provider =
1927 PHdr.
p_type == PT_TLS ? tls_provider : regular_provider;
1928 auto InfoOr = provider.GetAddressInfo(PHdr);
1932 uint32_t Log2Align = llvm::Log2_64(std::max<elf_xword>(PHdr.
p_align, 1));
1933 SectionSP Segment = std::make_shared<Section>(
1936 InfoOr->GetRangeBase(), InfoOr->GetByteSize(), PHdr.
p_offset,
1939 Segment->SetIsThreadSpecific(PHdr.
p_type == PT_TLS);
1942 provider.AddSegment(*InfoOr, std::move(Segment));
1954 const uint64_t file_size =
1957 VMAddressProvider &provider =
1958 header.
sh_flags & SHF_TLS ? tls_provider : regular_provider;
1959 auto InfoOr = provider.GetAddressInfo(header);
1965 const uint32_t target_bytes_size =
1978 InfoOr->Range.GetRangeBase(),
1979 InfoOr->Range.GetByteSize(),
1984 target_bytes_size));
1987 section_sp->SetIsThreadSpecific(header.
sh_flags & SHF_TLS);
1988 (InfoOr->Segment ? InfoOr->Segment->GetChildren() : *
m_sections_up)
1989 .AddSection(section_sp);
1990 provider.AddSection(std::move(*InfoOr), std::move(section_sp));
1995 unified_section_list =
2002 if (
auto gdd_objfile_section_list = gdd_obj_file->GetSectionList()) {
2004 gdd_objfile_section_list->FindSectionByType(
2008 if (module_section_sp)
2012 unified_section_list.
AddSection(symtab_section_sp);
2029 "No LZMA support found for reading .gnu_debugdata section");
2035 section->GetSectionData(data);
2036 llvm::SmallVector<uint8_t, 0> uncompressedData;
2040 "An error occurred while decompression the section {0}: {1}",
2041 section->GetName().AsCString(), llvm::toString(std::move(err)).c_str());
2047 new DataBufferHeap(uncompressedData.data(), uncompressedData.size()));
2049 llvm::StringRef(
"gnu_debugdata"));
2051 GetModule(), gdd_data_buf, 0, &fspec, 0, gdd_data_buf->GetByteSize()));
2072 const char *dollar_pos = ::strchr(symbol_name,
'$');
2073 if (!dollar_pos || dollar_pos[1] ==
'\0')
2076 if (dollar_pos[2] ==
'\0' || dollar_pos[2] ==
'.')
2077 return dollar_pos[1];
2085 if (strcmp(symbol_name,
"$d") == 0) {
2088 if (strcmp(symbol_name,
"$x") == 0) {
2094#define STO_MIPS_ISA (3 << 6)
2095#define STO_MICROMIPS (2 << 6)
2096#define IS_MICROMIPS(ST_OTHER) (((ST_OTHER)&STO_MIPS_ISA) == STO_MICROMIPS)
2099std::pair<unsigned, ObjectFileELF::FileAddressToAddressClassMap>
2101 SectionList *section_list,
const size_t num_symbols,
2118 static ConstString rodata_section_name(
".rodata");
2119 static ConstString rodata1_section_name(
".rodata1");
2134 llvm::StringRef file_extension =
m_file.GetFileNameExtension();
2135 bool skip_oatdata_oatexec =
2136 file_extension ==
".oat" || file_extension ==
".odex";
2141 module_sp ? module_sp->GetSectionList() :
nullptr;
2148 std::unordered_map<lldb::SectionSP, lldb::SectionSP> section_map;
2151 for (i = 0; i < num_symbols; ++i) {
2152 if (!symbol.
Parse(symtab_data, &offset))
2163 if (llvm::StringRef(symbol_name).starts_with(
".L"))
2166 if (symbol.
getType() != STT_SECTION &&
2167 (symbol_name ==
nullptr || symbol_name[0] ==
'\0'))
2172 if (skip_oatdata_oatexec && (::strcmp(symbol_name,
"oatdata") == 0 ||
2173 ::strcmp(symbol_name,
"oatexec") == 0))
2178 Elf64_Half shndx = symbol.
st_shndx;
2235 if (symbol_section_sp) {
2236 ConstString sect_name = symbol_section_sp->GetName();
2237 if (sect_name == text_section_name || sect_name == init_section_name ||
2238 sect_name == fini_section_name || sect_name == ctors_section_name ||
2239 sect_name == dtors_section_name) {
2241 }
else if (sect_name == data_section_name ||
2242 sect_name == data2_section_name ||
2243 sect_name == rodata_section_name ||
2244 sect_name == rodata1_section_name ||
2245 sect_name == bss_section_name) {
2251 int64_t symbol_value_offset = 0;
2252 uint32_t additional_flags = 0;
2254 if (arch.
GetMachine() == llvm::Triple::arm) {
2258 switch (mapping_symbol) {
2267 address_class_map[symbol.
st_value] =
2279 }
else if (arch.
GetMachine() == llvm::Triple::aarch64) {
2283 switch (mapping_symbol) {
2297 }
else if (arch.
GetTriple().isRISCV()) {
2304 switch (mapping_symbol) {
2320 if (arch.
GetMachine() == llvm::Triple::arm) {
2328 symbol_value_offset = -1;
2329 address_class_map[symbol.
st_value ^ 1] =
2371 uint64_t symbol_value = symbol.
st_value + symbol_value_offset;
2373 if (symbol_section_sp &&
2375 symbol_value -= symbol_section_sp->GetFileAddress();
2377 if (symbol_section_sp && module_section_list &&
2378 module_section_list != section_list) {
2379 auto section_it = section_map.find(symbol_section_sp);
2380 if (section_it == section_map.end()) {
2381 section_it = section_map
2382 .emplace(symbol_section_sp,
2387 if (section_it->second)
2388 symbol_section_sp = section_it->second;
2391 bool is_global = symbol.
getBinding() == STB_GLOBAL;
2392 uint32_t flags = symbol.
st_other << 8 | symbol.
st_info | additional_flags;
2393 llvm::StringRef symbol_ref(symbol_name);
2397 size_t version_pos = symbol_ref.find(
'@');
2398 bool has_suffix = version_pos != llvm::StringRef::npos;
2399 llvm::StringRef symbol_bare = symbol_ref.substr(0, version_pos);
2405 llvm::StringRef suffix = symbol_ref.substr(version_pos);
2408 if (!mangled_name.empty())
2412 llvm::StringRef demangled_name = demangled.
GetStringRef();
2413 if (!demangled_name.empty())
2422 bool symbol_size_valid =
2425 bool is_trampoline =
false;
2434 if (trampoline_name.starts_with(
"__AArch64ADRPThunk_") ||
2435 trampoline_name.starts_with(
"__AArch64AbsLongThunk_")) {
2437 is_trampoline =
true;
2463 return {i, address_class_map};
2466std::pair<unsigned, ObjectFileELF::FileAddressToAddressClassMap>
2474 auto [num_symbols, address_class_map] =
2481 return {num_symbols, address_class_map};
2491 assert(symtab_hdr->
sh_type == SHT_SYMTAB ||
2492 symtab_hdr->
sh_type == SHT_DYNSYM);
2498 if (symtab && strtab) {
2508 return ParseSymbols(symbol_table, start_id, section_list, num_symbols,
2509 symtab_data, strtab_data);
2531 if (std::optional<DataExtractor> dynstr_data =
GetDynstrData()) {
2533 switch (entry.symbol.d_tag) {
2541 const char *name = dynstr_data->GetCStr(&cursor);
2543 entry.name = std::string(name);
2558 if (entry.symbol.d_tag == tag)
2559 return &entry.symbol;
2573 return symbol->
d_val;
2582static std::pair<uint64_t, uint64_t>
2598 if (plt_entsize <= 4) {
2608 plt_entsize = plt_hdr->
sh_size / (num_relocations + 1);
2613 return std::make_pair(plt_entsize, plt_offset);
2622 ELFRelocation rel(rel_type);
2626 uint64_t plt_offset, plt_entsize;
2627 std::tie(plt_entsize, plt_offset) =
2631 typedef unsigned (*reloc_info_fn)(
const ELFRelocation &rel);
2632 reloc_info_fn reloc_type;
2633 reloc_info_fn reloc_symbol;
2636 reloc_type = ELFRelocation::RelocType32;
2637 reloc_symbol = ELFRelocation::RelocSymbol32;
2639 reloc_type = ELFRelocation::RelocType64;
2640 reloc_symbol = ELFRelocation::RelocSymbol64;
2645 for (i = 0; i < num_relocations; ++i) {
2646 if (!rel.Parse(rel_data, &offset))
2649 if (reloc_type(rel) != slot_type)
2653 if (!symbol.
Parse(symtab_data, &symbol_offset))
2657 uint64_t plt_index = plt_offset + i * plt_entsize;
2684 assert(rel_hdr->
sh_type == SHT_RELA || rel_hdr->
sh_type == SHT_REL);
2698 if (!symtab_id || !plt_id)
2718 if (!plt_section_sp)
2747 rel_hdr, plt_hdr, sym_hdr, plt_section_sp,
2748 rel_data, symtab_data, strtab_data);
2760 llvm::cast<WritableDataBuffer>(data_buffer_sp.get());
2762 ELFRelocation::RelocOffset64(rel);
2763 uint64_t val_offset = value + ELFRelocation::RelocAddend64(rel);
2764 memcpy(dst, &val_offset,
sizeof(uint64_t));
2770 Section *rel_section,
bool is_signed) {
2774 value += ELFRelocation::RelocAddend32(rel);
2777 ((int64_t)value >
INT32_MAX || (int64_t)value < INT32_MIN))) {
2779 LLDB_LOGF(log,
"Failed to apply debug info relocations");
2782 uint32_t truncated_addr = (value & 0xFFFFFFFF);
2786 llvm::cast<WritableDataBuffer>(data_buffer_sp.get());
2788 ELFRelocation::RelocOffset32(rel);
2789 memcpy(dst, &truncated_addr,
sizeof(uint32_t));
2802 LLDB_LOGF(log,
"Debug info symbol invalid: %s", name);
2805 assert(llvm::isUInt<32>(value) &&
"Valid addresses are 32-bit");
2809 llvm::cast<WritableDataBuffer>(data_buffer_sp.get());
2811 ELFRelocation::RelocOffset32(rel);
2814 memcpy(&addend, dst,
sizeof(int32_t));
2817 if (addend < 0 &&
static_cast<uint32_t
>(-addend) > value) {
2818 LLDB_LOGF(log,
"Debug info relocation overflow: 0x%" PRIx64,
2819 static_cast<int64_t
>(value) + addend);
2822 if (!llvm::isUInt<32>(value + addend)) {
2823 LLDB_LOGF(log,
"Debug info relocation out of range: 0x%" PRIx64, value);
2826 uint32_t addr = value + addend;
2827 memcpy(dst, &addr,
sizeof(uint32_t));
2836 ELFRelocation rel(rel_hdr->
sh_type);
2839 typedef unsigned (*reloc_info_fn)(
const ELFRelocation &rel);
2840 reloc_info_fn reloc_type;
2841 reloc_info_fn reloc_symbol;
2844 reloc_type = ELFRelocation::RelocType32;
2845 reloc_symbol = ELFRelocation::RelocSymbol32;
2847 reloc_type = ELFRelocation::RelocType64;
2848 reloc_symbol = ELFRelocation::RelocSymbol64;
2851 for (
unsigned i = 0; i < num_relocations; ++i) {
2852 if (!rel.Parse(rel_data, &offset)) {
2853 GetModule()->ReportError(
".rel{0}[{1:d}] failed to parse relocation",
2857 Symbol *symbol =
nullptr;
2861 case llvm::ELF::EM_ARM:
2862 switch (reloc_type(rel)) {
2867 GetModule()->ReportError(
"unsupported AArch32 relocation:"
2868 " .rel{0}[{1}], type {2}",
2873 assert(
false &&
"unexpected relocation type");
2876 case llvm::ELF::EM_386:
2877 switch (reloc_type(rel)) {
2882 rel_section->
GetFileOffset() + ELFRelocation::RelocOffset32(rel);
2886 llvm::cast<WritableDataBuffer>(data_buffer_sp.get());
2887 uint32_t *dst =
reinterpret_cast<uint32_t *
>(
2888 data_buffer->
GetBytes() + f_offset);
2892 value += ELFRelocation::RelocAddend32(rel);
2898 GetModule()->ReportError(
".rel{0}[{1}] unknown symbol id: {2:d}",
2905 GetModule()->ReportError(
"unsupported i386 relocation:"
2906 " .rel{0}[{1}], type {2}",
2911 assert(
false &&
"unexpected relocation type");
2916 GetModule()->ReportError(
"unsupported 32-bit ELF machine arch: {0}", hdr->
e_machine);
2921 case llvm::ELF::EM_AARCH64:
2922 switch (reloc_type(rel)) {
2923 case R_AARCH64_ABS64:
2926 case R_AARCH64_ABS32:
2930 assert(
false &&
"unexpected relocation type");
2933 case llvm::ELF::EM_LOONGARCH:
2934 switch (reloc_type(rel)) {
2942 assert(
false &&
"unexpected relocation type");
2945 case llvm::ELF::EM_X86_64:
2946 switch (reloc_type(rel)) {
2959 assert(
false &&
"unexpected relocation type");
2963 GetModule()->ReportError(
"unsupported 64-bit ELF machine arch: {0}", hdr->
e_machine);
2975 assert(rel_hdr->
sh_type == SHT_RELA || rel_hdr->
sh_type == SHT_REL);
3013 rel_data, symtab_data, debug_data, debug);
3024 Progress progress(
"Parsing symbol table",
3025 m_file.GetFilename().AsCString(
"<Unknown>"));
3030 ObjectFile *module_obj_file = module_sp->GetObjectFile();
3031 if (module_obj_file && module_obj_file !=
this)
3034 SectionList *section_list = module_sp->GetSectionList();
3038 uint64_t symbol_id = 0;
3048 auto [num_symbols, address_class_map] =
3051 symbol_id += num_symbols;
3066 auto [num_symbols, address_class_map] =
3068 symbol_id += num_symbols;
3072 uint32_t dynamic_num_symbols = 0;
3073 std::optional<DataExtractor> symtab_data =
3076 if (symtab_data && strtab_data) {
3077 auto [num_symbols_parsed, address_class_map] =
ParseSymbols(
3078 &lldb_symtab, symbol_id, section_list, dynamic_num_symbols,
3079 symtab_data.value(), strtab_data.value());
3080 symbol_id += num_symbols_parsed;
3101 if (reloc_section) {
3111 GetModule()->GetUnwindTable().GetEHFrameInfo()) {
3125 bool is_valid_entry_point =
3126 entry_point_addr.IsValid() && entry_point_addr.IsSectionOffset();
3127 addr_t entry_point_file_addr = entry_point_addr.GetFileAddress();
3129 entry_point_file_addr)) {
3134 SectionSP section_sp = entry_point_addr.GetSection();
3153 if (arch.
GetMachine() == llvm::Triple::arm &&
3154 (entry_point_file_addr & 1)) {
3168 static const char *debug_prefix =
".debug";
3180 if (section_name ==
nullptr)
3184 if (strncmp(section_name, debug_prefix, strlen(debug_prefix)))
3188 std::string needle = std::string(
".rel") + section_name;
3189 std::string needlea = std::string(
".rela") + section_name;
3193 if (I->sh_type == SHT_RELA || I->sh_type == SHT_REL) {
3194 const char *hay_name = I->section_name.GetCString();
3195 if (hay_name ==
nullptr)
3197 if (needle == hay_name || needlea == hay_name) {
3218 std::vector<Symbol> new_symbols;
3221 uint64_t last_symbol_id =
3235 addr_t offset = file_addr - section_sp->GetFileAddress();
3236 uint64_t symbol_id = ++last_symbol_id;
3254 new_symbols.push_back(eh_symbol);
3260 for (
const Symbol &s : new_symbols)
3280 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
3281 s->
Printf(
"%p: ",
static_cast<void *
>(
this));
3287 *s <<
", file = '" <<
m_file
3312 if (image_info_addr.
IsValid())
3313 s->
Printf(
"image_info_address = %#16.16" PRIx64
"\n",
3322 s->
Printf(
"e_ident[EI_MAG0 ] = 0x%2.2x\n", header.
e_ident[EI_MAG0]);
3323 s->
Printf(
"e_ident[EI_MAG1 ] = 0x%2.2x '%c'\n", header.
e_ident[EI_MAG1],
3325 s->
Printf(
"e_ident[EI_MAG2 ] = 0x%2.2x '%c'\n", header.
e_ident[EI_MAG2],
3327 s->
Printf(
"e_ident[EI_MAG3 ] = 0x%2.2x '%c'\n", header.
e_ident[EI_MAG3],
3330 s->
Printf(
"e_ident[EI_CLASS ] = 0x%2.2x\n", header.
e_ident[EI_CLASS]);
3331 s->
Printf(
"e_ident[EI_DATA ] = 0x%2.2x ", header.
e_ident[EI_DATA]);
3333 s->
Printf(
"\ne_ident[EI_VERSION] = 0x%2.2x\n", header.
e_ident[EI_VERSION]);
3334 s->
Printf(
"e_ident[EI_PAD ] = 0x%2.2x\n", header.
e_ident[EI_PAD]);
3381 unsigned char ei_data) {
3384 *s <<
"ELFDATANONE";
3387 *s <<
"ELFDATA2LSB - Little Endian";
3390 *s <<
"ELFDATA2MSB - Big Endian";
3403 s->
Printf(
" %8.8" PRIx64
" %8.8" PRIx64
" %8.8" PRIx64, ph.
p_offset,
3417 const int kStrWidth = 15;
3429 s->
Printf(
"0x%8.8x%*s", p_type, kStrWidth - 10,
"");
3438 *s << ((p_flags & PF_X) ?
"PF_X" :
" ")
3439 << (((p_flags & PF_X) && (p_flags & PF_W)) ?
'+' :
' ')
3440 << ((p_flags & PF_W) ?
"PF_W" :
" ")
3441 << (((p_flags & PF_W) && (p_flags & PF_R)) ?
'+' :
' ')
3442 << ((p_flags & PF_R) ?
"PF_R" :
" ");
3453 s->
PutCString(
"IDX p_type p_offset p_vaddr p_paddr "
3454 "p_filesz p_memsz p_flags p_align\n");
3455 s->
PutCString(
"==== --------------- -------- -------- -------- "
3456 "-------- -------- ------------------------- --------\n");
3459 s->
Format(
"[{0,2}] ", H.index());
3474 s->
Printf(
") %8.8" PRIx64
" %8.8" PRIx64
" %8.8" PRIx64, sh.
sh_addr,
3485 const int kStrWidth = 12;
3504 s->
Printf(
"0x%8.8x%*s", sh_type, kStrWidth - 10,
"");
3514 *s << ((sh_flags & SHF_WRITE) ?
"WRITE" :
" ")
3515 << (((sh_flags & SHF_WRITE) && (sh_flags & SHF_ALLOC)) ?
'+' :
' ')
3516 << ((sh_flags & SHF_ALLOC) ?
"ALLOC" :
" ")
3517 << (((sh_flags & SHF_ALLOC) && (sh_flags & SHF_EXECINSTR)) ?
'+' :
' ')
3518 << ((sh_flags & SHF_EXECINSTR) ?
"EXECINSTR" :
" ");
3530 "addr offset size link info addralgn "
3532 s->
PutCString(
"==== -------- ------------ -------------------------------- "
3533 "-------- -------- -------- -------- -------- -------- "
3534 "-------- ====================\n");
3539 s->
Printf(
"[%2u] ", idx);
3541 const char *section_name = I->section_name.AsCString(
"");
3543 *s <<
' ' << section_name <<
"\n";
3550 if (num_modules > 0) {
3552 for (
unsigned i = 0; i < num_modules; ++i) {
3560#define DYNAMIC_STRINGIFY_ENUM(tag, value) \
3564#define DYNAMIC_TAG(n, v)
3566 case llvm::ELF::EM_AARCH64:
3568#define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
3569#include "llvm/BinaryFormat/DynamicTags.def"
3570#undef AARCH64_DYNAMIC_TAG
3574 case llvm::ELF::EM_HEXAGON:
3576#define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
3577#include "llvm/BinaryFormat/DynamicTags.def"
3578#undef HEXAGON_DYNAMIC_TAG
3582 case llvm::ELF::EM_MIPS:
3584#define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
3585#include "llvm/BinaryFormat/DynamicTags.def"
3586#undef MIPS_DYNAMIC_TAG
3590 case llvm::ELF::EM_PPC:
3592#define PPC_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
3593#include "llvm/BinaryFormat/DynamicTags.def"
3594#undef PPC_DYNAMIC_TAG
3598 case llvm::ELF::EM_PPC64:
3600#define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
3601#include "llvm/BinaryFormat/DynamicTags.def"
3602#undef PPC64_DYNAMIC_TAG
3606 case llvm::ELF::EM_RISCV:
3608#define RISCV_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
3609#include "llvm/BinaryFormat/DynamicTags.def"
3610#undef RISCV_DYNAMIC_TAG
3617#define AARCH64_DYNAMIC_TAG(name, value)
3618#define MIPS_DYNAMIC_TAG(name, value)
3619#define HEXAGON_DYNAMIC_TAG(name, value)
3620#define PPC_DYNAMIC_TAG(name, value)
3621#define PPC64_DYNAMIC_TAG(name, value)
3622#define RISCV_DYNAMIC_TAG(name, value)
3624#define DYNAMIC_TAG_MARKER(name, value)
3625#define DYNAMIC_TAG(name, value) \
3628#include "llvm/BinaryFormat/DynamicTags.def"
3630#undef AARCH64_DYNAMIC_TAG
3631#undef MIPS_DYNAMIC_TAG
3632#undef HEXAGON_DYNAMIC_TAG
3633#undef PPC_DYNAMIC_TAG
3634#undef PPC64_DYNAMIC_TAG
3635#undef RISCV_DYNAMIC_TAG
3636#undef DYNAMIC_TAG_MARKER
3637#undef DYNAMIC_STRINGIFY_ENUM
3639 return "<unknown:>0x" + llvm::utohexstr(
Type,
true);
3650 s->
PutCString(
"==== ---------------- ------------------\n");
3653 s->
Printf(
"[%2u] ", idx++);
3655 "%-16s 0x%16.16" PRIx64,
3657 entry.symbol.d_ptr);
3658 if (!entry.name.empty())
3659 s->
Printf(
" \"%s\"", entry.name.c_str());
3678 if (H.p_type != PT_NOTE || H.p_offset == 0 || H.p_filesz == 0)
3681 if (data.
SetData(
m_data, H.p_offset, H.p_filesz) == H.p_filesz) {
3692 case llvm::ELF::ET_NONE:
3696 case llvm::ELF::ET_REL:
3700 case llvm::ELF::ET_EXEC:
3704 case llvm::ELF::ET_DYN:
3720 case llvm::ELF::ET_NONE:
3724 case llvm::ELF::ET_REL:
3728 case llvm::ELF::ET_EXEC:
3733 static ConstString loader_section_name(
".interp");
3736 if (loader_section) {
3744 llvm::StringRef loader_name(buffer, read_size - 1);
3745 llvm::StringRef freebsd_kernel_loader_name(
"/red/herring");
3746 if (loader_name == freebsd_kernel_loader_name)
3753 case llvm::ELF::ET_DYN:
3781 if (!section->
Test(SHF_COMPRESSED))
3788 return data.
CopyData(section_offset, dst_len, dst);
3798 if (result == 0 || !(section->
Get() & llvm::ELF::SHF_COMPRESSED))
3801 auto Decompressor = llvm::object::Decompressor::create(
3803 {reinterpret_cast<const char *>(section_data.GetDataStart()),
3804 size_t(section_data.GetByteSize())},
3806 if (!Decompressor) {
3808 "Unable to initialize decompressor for section '{0}': {1}",
3810 llvm::toString(Decompressor.takeError()).c_str());
3811 section_data.
Clear();
3816 std::make_shared<DataBufferHeap>(Decompressor->getDecompressedSize(), 0);
3817 if (
auto error = Decompressor->decompress(
3818 {buffer_sp->GetBytes(), size_t(buffer_sp->GetByteSize())})) {
3819 GetModule()->ReportWarning(
"Decompression of section '{0}' failed: {1}",
3821 llvm::toString(std::move(
error)).c_str());
3822 section_data.
Clear();
3826 section_data.
SetData(buffer_sp);
3827 return buffer_sp->GetByteSize();
3864std::vector<ObjectFile::LoadableData>
3868 std::vector<LoadableData> loadables;
3872 if (H.p_type != llvm::ELF::PT_LOAD)
3874 loadable.
Dest = should_use_paddr ? H.p_paddr : H.p_vaddr;
3877 if (H.p_filesz == 0)
3880 loadable.
Contents = llvm::ArrayRef<uint8_t>(segment_data.GetDataStart(),
3881 segment_data.GetByteSize());
3882 loadables.push_back(loadable);
3894std::optional<DataExtractor>
3911 return std::nullopt;
3917 return std::nullopt;
3927 assert(dynamic->GetObjectFile() ==
this);
3933 section_list->FindSectionByID(header->sh_link).get()) {
3952 if (strtab ==
nullptr || strsz ==
nullptr)
3953 return std::nullopt;
3964 if (H.p_type == llvm::ELF::PT_DYNAMIC) {
3979 assert(dynamic->GetObjectFile() ==
this);
3986 return std::nullopt;
3991 if (hash ==
nullptr)
3992 return std::nullopt;
3995 struct DtHashHeader {
4002 offset_t offset = offsetof(DtHashHeader, nchain);
4003 return data->
GetU32(&offset);
4006 return std::nullopt;
4011 if (gnu_hash ==
nullptr)
4012 return std::nullopt;
4016 struct DtGnuHashHeader {
4017 uint32_t nbuckets = 0;
4018 uint32_t symoffset = 0;
4019 uint32_t bloom_size = 0;
4020 uint32_t bloom_shift = 0;
4022 uint32_t num_symbols = 0;
4026 DtGnuHashHeader header;
4027 header.nbuckets = data->
GetU32(&offset);
4028 header.symoffset = data->
GetU32(&offset);
4029 header.bloom_size = data->
GetU32(&offset);
4030 header.bloom_shift = data->
GetU32(&offset);
4032 const addr_t buckets_offset =
4033 sizeof(DtGnuHashHeader) + addr_size * header.bloom_size;
4034 std::vector<uint32_t> buckets;
4038 for (uint32_t i = 0; i < header.nbuckets; ++i)
4039 buckets.push_back(bucket_data->GetU32(&offset));
4041 uint32_t last_symbol = 0;
4042 for (uint32_t bucket_value : buckets)
4043 last_symbol = std::max(bucket_value, last_symbol);
4044 if (last_symbol < header.symoffset) {
4045 num_symbols = header.symoffset;
4048 const addr_t chains_base_offset = buckets_offset + header.nbuckets * 4;
4052 chains_base_offset + (last_symbol - header.symoffset) * 4)) {
4054 uint32_t chain_entry = chain_entry_data->GetU32(&offset);
4057 if (chain_entry & 1)
4063 num_symbols = last_symbol;
4067 if (num_symbols > 0)
4070 return std::nullopt;
4073std::optional<DataExtractor>
4091 if (symtab ==
nullptr || syment ==
nullptr)
4092 return std::nullopt;
4095 num_symbols = *syms;
4097 num_symbols = *syms;
4099 return std::nullopt;
4100 if (num_symbols == 0)
4101 return std::nullopt;
static llvm::raw_ostream & error(Stream &strm)
static llvm::raw_ostream & note(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
static void ApplyELF64ABS32Relocation(Symtab *symtab, ELFRelocation &rel, DataExtractor &debug_data, Section *rel_section, bool is_signed)
static const elf_word LLDB_NT_NETBSD_IDENT_DESCSZ
static const char *const LLDB_NT_OWNER_NETBSDCORE
static const elf_word LLDB_NT_FREEBSD_ABI_TAG
static std::string getDynamicTagAsString(uint16_t Arch, uint64_t Type)
static uint32_t riscvVariantFromElfFlags(const elf::ELFHeader &header)
static const elf_word LLDB_NT_GNU_ABI_OS_LINUX
static uint32_t ppc64VariantFromElfFlags(const elf::ELFHeader &header)
static bool GetOsFromOSABI(unsigned char osabi_byte, llvm::Triple::OSType &ostype)
#define _MAKE_OSABI_CASE(x)
static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header)
static uint32_t calc_crc32(uint32_t init, const DataExtractor &data)
static char FindArmAarch64MappingSymbol(const char *symbol_name)
static const char *const LLDB_NT_OWNER_CORE
static const elf_word LLDB_NT_NETBSD_IDENT_TAG
static const elf_word LLDB_NT_GNU_ABI_OS_SOLARIS
static std::pair< uint64_t, uint64_t > GetPltEntrySizeAndOffset(const ELFSectionHeader *rel_hdr, const ELFSectionHeader *plt_hdr)
static SectionType GetSectionTypeFromName(llvm::StringRef Name)
static const elf_word LLDB_NT_FREEBSD_ABI_SIZE
static const elf_word LLDB_NT_GNU_ABI_TAG
static char FindRISCVMappingSymbol(const char *symbol_name)
static SectionSP FindMatchingSection(const SectionList §ion_list, SectionSP section)
static const char *const LLDB_NT_OWNER_GNU
static const elf_word LLDB_NT_NETBSD_PROCINFO
#define CASE_AND_STREAM(s, def, width)
static user_id_t SegmentID(size_t PHdrIndex)
static void ApplyELF32ABS32RelRelocation(Symtab *symtab, ELFRelocation &rel, DataExtractor &debug_data, Section *rel_section)
static const elf_word LLDB_NT_GNU_ABI_SIZE
static uint32_t GetTargetByteSize(SectionType Type, const ArchSpec &arch)
static const char *const LLDB_NT_OWNER_OPENBSD
static const char *const LLDB_NT_OWNER_FREEBSD
static const char *const LLDB_NT_OWNER_LINUX
static const char * OSABIAsCString(unsigned char osabi_byte)
static Permissions GetPermissions(const ELFSectionHeader &H)
static const char *const LLDB_NT_OWNER_ANDROID
#define IS_MICROMIPS(ST_OTHER)
static const elf_word LLDB_NT_NETBSD_IDENT_NAMESZ
static uint32_t loongarchVariantFromElfFlags(const elf::ELFHeader &header)
static const elf_word LLDB_NT_GNU_ABI_OS_HURD
static uint32_t mipsVariantFromElfFlags(const elf::ELFHeader &header)
static const char *const LLDB_NT_OWNER_NETBSD
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 const elf_word LLDB_NT_GNU_BUILD_ID_TAG
#define LLDB_PLUGIN_DEFINE(PluginName)
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
#define LLDB_SCOPED_TIMERF(...)
Generic COFF object file reader.
static size_t GetSectionHeaderInfo(SectionHeaderColl §ion_headers, lldb_private::DataExtractor &object_data, const elf::ELFHeader &header, lldb_private::UUID &uuid, std::string &gnu_debuglink_file, uint32_t &gnu_debuglink_crc, lldb_private::ArchSpec &arch_spec)
Parses the elf section headers and returns the uuid, debug link name, crc, archspec.
std::vector< elf::ELFProgramHeader > ProgramHeaderColl
static void DumpELFHeader(lldb_private::Stream *s, const elf::ELFHeader &header)
unsigned ParseTrampolineSymbols(lldb_private::Symtab *symbol_table, lldb::user_id_t start_id, const ELFSectionHeaderInfo *rela_hdr, lldb::user_id_t section_id)
Scans the relocation entries and adds a set of artificial symbols to the given symbol table for each ...
lldb_private::ArchSpec m_arch_spec
The architecture detected from parsing elf file contents.
static void DumpELFSectionHeader_sh_type(lldb_private::Stream *s, elf::elf_word sh_type)
std::shared_ptr< ObjectFileELF > m_gnu_debug_data_object_file
Object file parsed from .gnu_debugdata section (.
SectionHeaderColl::iterator SectionHeaderCollIter
uint32_t m_gnu_debuglink_crc
unsigned RelocateDebugSections(const elf::ELFSectionHeader *rel_hdr, lldb::user_id_t rel_id, lldb_private::Symtab *thetab)
Relocates debug sections.
bool AnySegmentHasPhysicalAddress()
static void DumpELFProgramHeader(lldb_private::Stream *s, const elf::ELFProgramHeader &ph)
lldb_private::Address m_entry_point_address
Cached value of the entry point for this module.
size_t ReadSectionData(lldb_private::Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len) override
llvm::StringRef StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const override
static void ParseARMAttributes(lldb_private::DataExtractor &data, uint64_t length, lldb_private::ArchSpec &arch_spec)
lldb_private::DataExtractor GetSegmentData(const elf::ELFProgramHeader &H)
void RelocateSection(lldb_private::Section *section) override
Perform relocations on the section if necessary.
FileAddressToAddressClassMap m_address_class_map
The address class for each symbol in the elf file.
static llvm::StringRef GetPluginDescriptionStatic()
static const uint32_t g_core_uuid_magic
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, lldb::offset_t file_offset, lldb::offset_t length, lldb_private::ModuleSpecList &specs)
bool IsExecutable() const override
Tells whether this object file is capable of being the main executable for a process.
void DumpDependentModules(lldb_private::Stream *s)
ELF dependent module dump routine.
static void DumpELFHeader_e_type(lldb_private::Stream *s, elf::elf_half e_type)
static size_t GetProgramHeaderInfo(ProgramHeaderColl &program_headers, lldb_private::DataExtractor &object_data, const elf::ELFHeader &header)
static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, lldb::addr_t length)
std::optional< lldb_private::DataExtractor > GetDynsymDataFromDynamic(uint32_t &num_symbols)
Get the bytes that represent the dynamic symbol table from the .dynamic section from process memory.
DynamicSymbolColl m_dynamic_symbols
Collection of symbols from the dynamic table.
static void DumpELFSectionHeader(lldb_private::Stream *s, const ELFSectionHeaderInfo &sh)
std::vector< ELFSectionHeaderInfo > SectionHeaderColl
static void DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s, unsigned char ei_data)
lldb_private::ArchSpec GetArchitecture() override
Get the ArchSpec for this object file.
std::optional< lldb_private::FileSpec > GetDebugLink()
Return the contents of the .gnu_debuglink section, if the object file contains it.
lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override
Get the address type given a file address in an object file.
static void DumpELFSectionHeader_sh_flags(lldb_private::Stream *s, elf::elf_xword sh_flags)
lldb_private::UUID GetUUID() override
Gets the UUID for this object file.
std::optional< uint32_t > GetNumSymbolsFromDynamicGnuHash()
Get the number of symbols from the DT_GNU_HASH dynamic entry.
std::optional< lldb_private::DataExtractor > ReadDataFromDynamic(const elf::ELFDynamic *dyn, uint64_t length, uint64_t offset=0)
Read the bytes pointed to by the dyn dynamic entry.
ObjectFileELF(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t offset, lldb::offset_t length)
static void DumpELFProgramHeader_p_type(lldb_private::Stream *s, elf::elf_word p_type)
static lldb_private::Status RefineModuleDetailsFromNote(lldb_private::DataExtractor &data, lldb_private::ArchSpec &arch_spec, lldb_private::UUID &uuid)
size_t SectionIndex(const SectionHeaderCollIter &I)
Returns the index of the given section header.
static void DumpELFProgramHeader_p_flags(lldb_private::Stream *s, elf::elf_word p_flags)
static llvm::StringRef GetPluginNameStatic()
size_t ParseDependentModules()
Scans the dynamic section and locates all dependent modules (shared libraries) populating m_filespec_...
void DumpELFSectionHeaders(lldb_private::Stream *s)
std::shared_ptr< ObjectFileELF > GetGnuDebugDataObjectFile()
Takes the .gnu_debugdata and returns the decompressed object file that is stored within that section.
static lldb::WritableDataBufferSP MapFileDataWritable(const lldb_private::FileSpec &file, uint64_t Size, uint64_t Offset)
void Dump(lldb_private::Stream *s) override
Dump a description of this object to a Stream.
static uint32_t CalculateELFNotesSegmentsCRC32(const ProgramHeaderColl &program_headers, lldb_private::DataExtractor &data)
lldb_private::UUID m_uuid
ELF build ID.
void DumpELFProgramHeaders(lldb_private::Stream *s)
std::pair< unsigned, FileAddressToAddressClassMap > ParseSymbolTable(lldb_private::Symtab *symbol_table, lldb::user_id_t start_id, lldb_private::Section *symtab)
Populates the symbol table with all non-dynamic linker symbols.
size_t ParseDynamicSymbols()
Parses the dynamic symbol table and populates m_dynamic_symbols.
static lldb_private::ObjectFile * CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
std::optional< lldb_private::DataExtractor > GetDynamicData()
Get the bytes that represent the .dynamic section.
ObjectFile::Type CalculateType() override
The object file should be able to calculate its type by looking at its file header and possibly the s...
lldb::SectionType GetSectionType(const ELFSectionHeaderInfo &H) const
bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, bool value_is_offset) override
Sets the load address for an entire module, assuming a rigid slide of sections, if possible in the im...
std::unique_ptr< lldb_private::FileSpecList > m_filespec_up
List of file specifications corresponding to the modules (shared libraries) on which this object file...
std::optional< uint32_t > GetNumSymbolsFromDynamicHash()
Get the number of symbols from the DT_HASH dynamic entry.
bool ParseProgramHeaders()
Parses all section headers present in this object file and populates m_program_headers.
std::vector< LoadableData > GetLoadableData(lldb_private::Target &target) override
Loads this objfile to memory.
const ELFSectionHeaderInfo * GetSectionHeaderByIndex(lldb::user_id_t id)
Returns the section header with the given id or NULL.
void CreateSections(lldb_private::SectionList &unified_section_list) override
lldb::user_id_t GetSectionIndexByName(const char *name)
Utility method for looking up a section given its name.
uint32_t GetAddressByteSize() const override
Gets the address size in bytes for the current object file.
SectionHeaderColl::const_iterator SectionHeaderCollConstIter
ProgramHeaderColl m_program_headers
Collection of program headers.
void DumpELFDynamic(lldb_private::Stream *s)
ELF dump the .dynamic section.
unsigned ApplyRelocations(lldb_private::Symtab *symtab, const elf::ELFHeader *hdr, const elf::ELFSectionHeader *rel_hdr, const elf::ELFSectionHeader *symtab_hdr, const elf::ELFSectionHeader *debug_hdr, lldb_private::DataExtractor &rel_data, lldb_private::DataExtractor &symtab_data, lldb_private::DataExtractor &debug_data, lldb_private::Section *rel_section)
lldb::ByteOrder GetByteOrder() const override
Gets whether endian swapping should occur when extracting data from this object file.
bool ParseHeader() override
Attempts to parse the object header.
elf::ELFHeader m_header
ELF file header.
std::string m_gnu_debuglink_file
ELF .gnu_debuglink file and crc data if available.
void ParseUnwindSymbols(lldb_private::Symtab *symbol_table, lldb_private::DWARFCallFrameInfo *eh_frame)
std::pair< unsigned, FileAddressToAddressClassMap > ParseSymbols(lldb_private::Symtab *symbol_table, lldb::user_id_t start_id, lldb_private::SectionList *section_list, const size_t num_symbols, const lldb_private::DataExtractor &symtab_data, const lldb_private::DataExtractor &strtab_data)
Helper routine for ParseSymbolTable().
SectionHeaderColl m_section_headers
Collection of section headers.
lldb_private::Address GetEntryPointAddress() override
Returns the address of the Entry Point in this object file - if the object file doesn't have an entry...
ObjectFile::Strata CalculateStrata() override
The object file should be able to calculate the strata of the object file.
void ParseSymtab(lldb_private::Symtab &symtab) override
Parse the symbol table into the provides symbol table object.
unsigned PLTRelocationType()
static lldb_private::ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)
lldb::addr_t m_dynamic_base_addr
The file address of the .dynamic section.
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override
Extract the dependent modules from an object file.
size_t ParseSectionHeaders()
Parses all section headers present in this object file and populates m_section_headers.
lldb_private::Address GetBaseAddress() override
Returns base address of this object file.
bool IsStripped() override
Detect if this object file has been stripped of local symbols.
const elf::ELFDynamic * FindDynamicSymbol(unsigned tag)
std::map< lldb::addr_t, lldb_private::AddressClass > FileAddressToAddressClassMap
An ordered map of file address to address class.
llvm::ArrayRef< elf::ELFProgramHeader > ProgramHeaders()
std::optional< lldb_private::DataExtractor > GetDynstrData()
Get the bytes that represent the dynamic string table data.
lldb_private::Address GetImageInfoAddress(lldb_private::Target *target) override
Similar to Process::GetImageInfoAddress().
A section + offset based address range class.
A section + offset based address class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
bool ResolveAddressUsingFileSections(lldb::addr_t addr, const SectionList *sections)
Resolve a file virtual address using a section list.
lldb::SectionSP GetSection() const
Get const accessor for the section.
lldb::addr_t GetFileAddress() const
Get the file address.
bool IsValid() const
Check if the object state is valid.
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
An architecture specification class.
@ eLoongArchSubType_loongarch64
@ eLoongArchSubType_unknown
@ eLoongArchSubType_loongarch32
uint32_t GetCodeByteSize() const
Architecture code byte width accessor.
bool IsValid() const
Tests if this ArchSpec is valid.
llvm::Triple & GetTriple()
Architecture triple accessor.
void SetFlags(uint32_t flags)
bool SetArchitecture(ArchitectureType arch_type, uint32_t cpu, uint32_t sub, uint32_t os=0)
Change the architecture object type, CPU type and OS type.
@ eLoongArch_abi_single_float
soft float
@ eLoongArch_abi_double_float
single precision floating point, +f
bool IsMIPS() const
if MIPS architecture return true.
uint32_t GetDataByteSize() const
Architecture data byte width accessor.
uint32_t GetFlags() const
@ eMIPSSubType_mips32r6el
@ eMIPSSubType_mips64r6el
@ eMIPSSubType_mips64r2el
@ eMIPSSubType_mips32r2el
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
@ eRISCV_float_abi_double
single precision floating point, +f
@ eRISCV_float_abi_quad
double precision floating point, +d
@ eRISCV_float_abi_single
soft float
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
void ForEachFDEEntries(const std::function< bool(lldb::addr_t, uint32_t, dw_offset_t)> &callback)
A subclass of DataBuffer that stores a data buffer on the heap.
A class that measures elapsed time in an exception safe way.
bool AppendIfUnique(const FileSpec &file)
Append a FileSpec object if unique.
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
const ConstString & GetFilename() const
Filename string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
std::shared_ptr< WritableDataBuffer > CreateWritableDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
static FileSystem & Instance()
ValueType Get() const
Get accessor for all flags.
bool Test(ValueType bit) const
Test a single flag bit.
A class that handles mangled names.
void SetDemangledName(ConstString name)
ConstString GetMangledName() const
Mangled name get accessor.
ConstString GetDemangledName() const
Demangled name get accessor.
void SetMangledName(ConstString name)
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
void Append(const ModuleSpec &spec)
void SetObjectSize(uint64_t object_size)
ArchSpec & GetArchitecture()
void SetObjectOffset(uint64_t object_offset)
DataExtractor m_data
The data for this object file so things can be parsed lazily.
std::unique_ptr< lldb_private::SectionList > m_sections_up
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset)
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, lldb::offset_t file_offset, lldb::offset_t length, lldb::DataBufferSP data_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
const lldb::addr_t m_memory_addr
Set if the object file only exists in memory.
static lldb::SectionType GetDWARFSectionTypeFromName(llvm::StringRef name)
Parses the section type from a section name for DWARF sections.
virtual void ParseSymtab(Symtab &symtab)=0
Parse the symbol table into the provides symbol table object.
virtual AddressClass GetAddressClass(lldb::addr_t file_addr)
Get the address type given a file address in an object file.
Symtab * GetSymtab(bool can_create=true)
Gets the symbol table for the currently selected architecture (and object for archives).
static lldb::WritableDataBufferSP ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size)
size_t GetData(lldb::offset_t offset, size_t length, DataExtractor &data) const
@ eTypeExecutable
A normal executable.
@ eTypeDebugInfo
An object file that contains only debug information.
@ eTypeObjectFile
An intermediate object file.
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
@ eTypeSharedLibrary
A shared library that can be used during execution.
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
bool IsInMemory() const
Returns true if the object file exists only in memory.
lldb::ProcessWP m_process_wp
virtual size_t ReadSectionData(Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len)
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A Progress indicator helper class.
lldb::SectionSP FindSectionByName(ConstString section_dstr) const
static SectionList Merge(SectionList &lhs, SectionList &rhs, MergeCallback filter)
lldb::SectionSP FindSectionByID(lldb::user_id_t sect_id) const
lldb::SectionSP FindSectionContainingFileAddress(lldb::addr_t addr, uint32_t depth=UINT32_MAX) const
size_t AddSection(const lldb::SectionSP §ion_sp)
bool ReplaceSection(lldb::user_id_t sect_id, const lldb::SectionSP §ion_sp, uint32_t depth=UINT32_MAX)
lldb::SectionSP FindSectionByType(lldb::SectionType sect_type, bool check_children, size_t start_idx=0) const
void Dump(llvm::raw_ostream &s, unsigned indent, Target *target, bool show_header, uint32_t depth) const
lldb::SectionSP GetSectionAtIndex(size_t idx) const
ConstString GetName() const
void SetIsRelocated(bool b)
lldb::offset_t GetFileOffset() const
ObjectFile * GetObjectFile()
lldb::offset_t GetFileSize() const
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
A stream class that can stream formatted output to a file.
void Format(const char *format, Args &&... args)
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t EOL()
Output and End of Line character to the stream.
unsigned GetIndentLevel() const
Get the current indentation level.
void SetSizeIsSynthesized(bool b)
bool GetByteSizeIsValid() const
Address & GetAddressRef()
ConstString GetName() const
void SetByteSize(lldb::addr_t size)
Symbol * FindSymbolByID(lldb::user_id_t uid) const
Symbol * SymbolAtIndex(size_t idx)
Symbol * FindSymbolAtFileAddress(lldb::addr_t file_addr)
Symbol * FindSymbolContainingFileAddress(lldb::addr_t file_addr)
uint32_t AddSymbol(const Symbol &symbol)
void Dump(Stream *s, Target *target, SortOrder sort_type, Mangled::NamePreference name_preference=Mangled::ePreferDemangled)
ObjectFile * GetObjectFile() const
size_t GetNumSymbols() const
bool ReadPointerFromMemory(const Address &addr, Status &error, Address &pointer_addr, bool force_live_memory=false)
uint64_t ReadUnsignedIntegerFromMemory(const Address &addr, size_t integer_byte_size, uint64_t fail_value, Status &error, bool force_live_memory=false)
bool SetSectionLoadAddress(const lldb::SectionSP §ion, lldb::addr_t load_addr, bool warn_multiple=false)
Represents UUID's of various sizes.
lldb::addr_t GetByteSize() const
void SetByteSize(lldb::addr_t byte_size)
uint8_t * GetBytes()
Get a pointer to the data.
#define LLDB_INVALID_CPUTYPE
#define UNUSED_IF_ASSERT_DISABLED(x)
#define LLDB_INVALID_ADDRESS
llvm::Error uncompress(llvm::ArrayRef< uint8_t > InputBuffer, llvm::SmallVectorImpl< uint8_t > &Uncompressed)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::Process > ProcessSP
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
@ eSectionTypeELFDynamicSymbols
Elf SHT_DYNSYM section.
@ eSectionTypeContainer
The section contains child sections.
@ eSectionTypeELFDynamicLinkInfo
Elf SHT_DYNAMIC section.
@ eSectionTypeAbsoluteAddress
Dummy section for symbols with absolute address.
@ eSectionTypeELFRelocationEntries
Elf SHT_REL or SHT_REL section.
@ eSectionTypeLLDBFormatters
@ eSectionTypeLLDBTypeSummaries
@ eSectionTypeSwiftModules
@ eSectionTypeDWARFGNUDebugAltLink
@ eSectionTypeELFSymbolTable
Elf SHT_SYMTAB section.
std::shared_ptr< lldb_private::Module > ModuleSP
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFNote entry from the given DataExtractor starting at position offset.
Represents an entry in an ELF dynamic table.
elf_addr d_ptr
Pointer value of the table entry.
elf_xword d_val
Integer value of the table entry.
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFDynamic entry from the given DataExtractor starting at position offset.
elf_sxword d_tag
Type of dynamic table entry.
static unsigned RelocSymbol64(const ELFRel &rel)
Returns the symbol index when the given entry represents a 64-bit relocation.
static unsigned RelocType64(const ELFRel &rel)
Returns the type when the given entry represents a 64-bit relocation.
static unsigned RelocType32(const ELFRel &rel)
Returns the type when the given entry represents a 32-bit relocation.
static unsigned RelocSymbol32(const ELFRel &rel)
Returns the symbol index when the given entry represents a 32-bit relocation.
static unsigned RelocSymbol64(const ELFRela &rela)
Returns the symbol index when the given entry represents a 64-bit relocation.
static unsigned RelocType64(const ELFRela &rela)
Returns the type when the given entry represents a 64-bit relocation.
static unsigned RelocType32(const ELFRela &rela)
Returns the type when the given entry represents a 32-bit relocation.
static unsigned RelocSymbol32(const ELFRela &rela)
Returns the symbol index when the given entry represents a 32-bit relocation.
Represents a symbol within an ELF symbol table.
unsigned char getType() const
Returns the type attribute of the st_info member.
elf_half st_shndx
Section to which this symbol applies.
unsigned char st_info
Symbol type and binding attributes.
unsigned char getBinding() const
Returns the binding attribute of the st_info member.
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFSymbol entry from the given DataExtractor starting at position offset.
elf_addr st_value
Absolute or relocatable address.
elf_word st_name
Symbol name string index.
elf_xword st_size
Size of the symbol or zero.
unsigned char st_other
Reserved for future use.
llvm::ArrayRef< uint8_t > Contents
lldb::user_id_t GetID() const
Get accessor for the user ID.