LLDB  mainline
ObjectFileELF.cpp
Go to the documentation of this file.
1 //===-- ObjectFileELF.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "ObjectFileELF.h"
10 
11 #include <algorithm>
12 #include <cassert>
13 #include <unordered_map>
14 
15 #include "lldb/Core/FileSpecList.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/ModuleSpec.h"
19 #include "lldb/Core/Progress.h"
20 #include "lldb/Core/Section.h"
21 #include "lldb/Host/FileSystem.h"
22 #include "lldb/Host/LZMA.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Utility/ArchSpec.h"
29 #include "lldb/Utility/Log.h"
30 #include "lldb/Utility/RangeMap.h"
31 #include "lldb/Utility/Status.h"
32 #include "lldb/Utility/Stream.h"
33 #include "lldb/Utility/Timer.h"
34 #include "llvm/ADT/IntervalMap.h"
35 #include "llvm/ADT/PointerUnion.h"
36 #include "llvm/ADT/StringRef.h"
37 #include "llvm/BinaryFormat/ELF.h"
38 #include "llvm/Object/Decompressor.h"
39 #include "llvm/Support/ARMBuildAttributes.h"
40 #include "llvm/Support/CRC.h"
41 #include "llvm/Support/FormatVariadic.h"
42 #include "llvm/Support/MathExtras.h"
43 #include "llvm/Support/MemoryBuffer.h"
44 #include "llvm/Support/MipsABIFlags.h"
45 
46 #define CASE_AND_STREAM(s, def, width) \
47  case def: \
48  s->Printf("%-*s", width, #def); \
49  break;
50 
51 using namespace lldb;
52 using namespace lldb_private;
53 using namespace elf;
54 using namespace llvm::ELF;
55 
57 
58 namespace {
59 
60 // ELF note owner definitions
61 const char *const LLDB_NT_OWNER_FREEBSD = "FreeBSD";
62 const char *const LLDB_NT_OWNER_GNU = "GNU";
63 const char *const LLDB_NT_OWNER_NETBSD = "NetBSD";
64 const char *const LLDB_NT_OWNER_NETBSDCORE = "NetBSD-CORE";
65 const char *const LLDB_NT_OWNER_OPENBSD = "OpenBSD";
66 const char *const LLDB_NT_OWNER_ANDROID = "Android";
67 const char *const LLDB_NT_OWNER_CORE = "CORE";
68 const char *const LLDB_NT_OWNER_LINUX = "LINUX";
69 
70 // ELF note type definitions
71 const elf_word LLDB_NT_FREEBSD_ABI_TAG = 0x01;
72 const elf_word LLDB_NT_FREEBSD_ABI_SIZE = 4;
73 
74 const elf_word LLDB_NT_GNU_ABI_TAG = 0x01;
75 const elf_word LLDB_NT_GNU_ABI_SIZE = 16;
76 
77 const elf_word LLDB_NT_GNU_BUILD_ID_TAG = 0x03;
78 
79 const elf_word LLDB_NT_NETBSD_IDENT_TAG = 1;
80 const elf_word LLDB_NT_NETBSD_IDENT_DESCSZ = 4;
81 const elf_word LLDB_NT_NETBSD_IDENT_NAMESZ = 7;
82 const elf_word LLDB_NT_NETBSD_PROCINFO = 1;
83 
84 // GNU ABI note OS constants
85 const elf_word LLDB_NT_GNU_ABI_OS_LINUX = 0x00;
86 const elf_word LLDB_NT_GNU_ABI_OS_HURD = 0x01;
87 const elf_word LLDB_NT_GNU_ABI_OS_SOLARIS = 0x02;
88 
89 //===----------------------------------------------------------------------===//
90 /// \class ELFRelocation
91 /// Generic wrapper for ELFRel and ELFRela.
92 ///
93 /// This helper class allows us to parse both ELFRel and ELFRela relocation
94 /// entries in a generic manner.
95 class ELFRelocation {
96 public:
97  /// Constructs an ELFRelocation entry with a personality as given by @p
98  /// type.
99  ///
100  /// \param type Either DT_REL or DT_RELA. Any other value is invalid.
101  ELFRelocation(unsigned type);
102 
103  ~ELFRelocation();
104 
105  bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
106 
107  static unsigned RelocType32(const ELFRelocation &rel);
108 
109  static unsigned RelocType64(const ELFRelocation &rel);
110 
111  static unsigned RelocSymbol32(const ELFRelocation &rel);
112 
113  static unsigned RelocSymbol64(const ELFRelocation &rel);
114 
115  static unsigned RelocOffset32(const ELFRelocation &rel);
116 
117  static unsigned RelocOffset64(const ELFRelocation &rel);
118 
119  static unsigned RelocAddend32(const ELFRelocation &rel);
120 
121  static unsigned RelocAddend64(const ELFRelocation &rel);
122 
123 private:
124  typedef llvm::PointerUnion<ELFRel *, ELFRela *> RelocUnion;
125 
126  RelocUnion reloc;
127 };
128 
129 ELFRelocation::ELFRelocation(unsigned type) {
130  if (type == DT_REL || type == SHT_REL)
131  reloc = new ELFRel();
132  else if (type == DT_RELA || type == SHT_RELA)
133  reloc = new ELFRela();
134  else {
135  assert(false && "unexpected relocation type");
136  reloc = static_cast<ELFRel *>(nullptr);
137  }
138 }
139 
140 ELFRelocation::~ELFRelocation() {
141  if (reloc.is<ELFRel *>())
142  delete reloc.get<ELFRel *>();
143  else
144  delete reloc.get<ELFRela *>();
145 }
146 
147 bool ELFRelocation::Parse(const lldb_private::DataExtractor &data,
148  lldb::offset_t *offset) {
149  if (reloc.is<ELFRel *>())
150  return reloc.get<ELFRel *>()->Parse(data, offset);
151  else
152  return reloc.get<ELFRela *>()->Parse(data, offset);
153 }
154 
155 unsigned ELFRelocation::RelocType32(const ELFRelocation &rel) {
156  if (rel.reloc.is<ELFRel *>())
157  return ELFRel::RelocType32(*rel.reloc.get<ELFRel *>());
158  else
159  return ELFRela::RelocType32(*rel.reloc.get<ELFRela *>());
160 }
161 
162 unsigned ELFRelocation::RelocType64(const ELFRelocation &rel) {
163  if (rel.reloc.is<ELFRel *>())
164  return ELFRel::RelocType64(*rel.reloc.get<ELFRel *>());
165  else
166  return ELFRela::RelocType64(*rel.reloc.get<ELFRela *>());
167 }
168 
169 unsigned ELFRelocation::RelocSymbol32(const ELFRelocation &rel) {
170  if (rel.reloc.is<ELFRel *>())
171  return ELFRel::RelocSymbol32(*rel.reloc.get<ELFRel *>());
172  else
173  return ELFRela::RelocSymbol32(*rel.reloc.get<ELFRela *>());
174 }
175 
176 unsigned ELFRelocation::RelocSymbol64(const ELFRelocation &rel) {
177  if (rel.reloc.is<ELFRel *>())
178  return ELFRel::RelocSymbol64(*rel.reloc.get<ELFRel *>());
179  else
180  return ELFRela::RelocSymbol64(*rel.reloc.get<ELFRela *>());
181 }
182 
183 unsigned ELFRelocation::RelocOffset32(const ELFRelocation &rel) {
184  if (rel.reloc.is<ELFRel *>())
185  return rel.reloc.get<ELFRel *>()->r_offset;
186  else
187  return rel.reloc.get<ELFRela *>()->r_offset;
188 }
189 
190 unsigned ELFRelocation::RelocOffset64(const ELFRelocation &rel) {
191  if (rel.reloc.is<ELFRel *>())
192  return rel.reloc.get<ELFRel *>()->r_offset;
193  else
194  return rel.reloc.get<ELFRela *>()->r_offset;
195 }
196 
197 unsigned ELFRelocation::RelocAddend32(const ELFRelocation &rel) {
198  if (rel.reloc.is<ELFRel *>())
199  return 0;
200  else
201  return rel.reloc.get<ELFRela *>()->r_addend;
202 }
203 
204 unsigned ELFRelocation::RelocAddend64(const ELFRelocation &rel) {
205  if (rel.reloc.is<ELFRel *>())
206  return 0;
207  else
208  return rel.reloc.get<ELFRela *>()->r_addend;
209 }
210 
211 } // end anonymous namespace
212 
213 static user_id_t SegmentID(size_t PHdrIndex) {
214  return ~user_id_t(PHdrIndex);
215 }
216 
217 bool ELFNote::Parse(const DataExtractor &data, lldb::offset_t *offset) {
218  // Read all fields.
219  if (data.GetU32(offset, &n_namesz, 3) == nullptr)
220  return false;
221 
222  // The name field is required to be nul-terminated, and n_namesz includes the
223  // terminating nul in observed implementations (contrary to the ELF-64 spec).
224  // A special case is needed for cores generated by some older Linux versions,
225  // which write a note named "CORE" without a nul terminator and n_namesz = 4.
226  if (n_namesz == 4) {
227  char buf[4];
228  if (data.ExtractBytes(*offset, 4, data.GetByteOrder(), buf) != 4)
229  return false;
230  if (strncmp(buf, "CORE", 4) == 0) {
231  n_name = "CORE";
232  *offset += 4;
233  return true;
234  }
235  }
236 
237  const char *cstr = data.GetCStr(offset, llvm::alignTo(n_namesz, 4));
238  if (cstr == nullptr) {
240  LLDB_LOGF(log, "Failed to parse note name lacking nul terminator");
241 
242  return false;
243  }
244  n_name = cstr;
245  return true;
246 }
247 
249  const uint32_t mips_arch = header.e_flags & llvm::ELF::EF_MIPS_ARCH;
250  uint32_t endian = header.e_ident[EI_DATA];
251  uint32_t arch_variant = ArchSpec::eMIPSSubType_unknown;
252  uint32_t fileclass = header.e_ident[EI_CLASS];
253 
254  // If there aren't any elf flags available (e.g core elf file) then return
255  // default
256  // 32 or 64 bit arch (without any architecture revision) based on object file's class.
257  if (header.e_type == ET_CORE) {
258  switch (fileclass) {
259  case llvm::ELF::ELFCLASS32:
260  return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips32el
261  : ArchSpec::eMIPSSubType_mips32;
262  case llvm::ELF::ELFCLASS64:
263  return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips64el
264  : ArchSpec::eMIPSSubType_mips64;
265  default:
266  return arch_variant;
267  }
268  }
269 
270  switch (mips_arch) {
271  case llvm::ELF::EF_MIPS_ARCH_1:
272  case llvm::ELF::EF_MIPS_ARCH_2:
273  case llvm::ELF::EF_MIPS_ARCH_32:
274  return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips32el
275  : ArchSpec::eMIPSSubType_mips32;
276  case llvm::ELF::EF_MIPS_ARCH_32R2:
277  return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips32r2el
278  : ArchSpec::eMIPSSubType_mips32r2;
279  case llvm::ELF::EF_MIPS_ARCH_32R6:
280  return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips32r6el
281  : ArchSpec::eMIPSSubType_mips32r6;
282  case llvm::ELF::EF_MIPS_ARCH_3:
283  case llvm::ELF::EF_MIPS_ARCH_4:
284  case llvm::ELF::EF_MIPS_ARCH_5:
285  case llvm::ELF::EF_MIPS_ARCH_64:
286  return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips64el
287  : ArchSpec::eMIPSSubType_mips64;
288  case llvm::ELF::EF_MIPS_ARCH_64R2:
289  return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips64r2el
290  : ArchSpec::eMIPSSubType_mips64r2;
291  case llvm::ELF::EF_MIPS_ARCH_64R6:
292  return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips64r6el
293  : ArchSpec::eMIPSSubType_mips64r6;
294  default:
295  break;
296  }
297 
298  return arch_variant;
299 }
300 
302  uint32_t fileclass = header.e_ident[EI_CLASS];
303  switch (fileclass) {
304  case llvm::ELF::ELFCLASS32:
305  return ArchSpec::eRISCVSubType_riscv32;
306  case llvm::ELF::ELFCLASS64:
307  return ArchSpec::eRISCVSubType_riscv64;
308  default:
309  return ArchSpec::eRISCVSubType_unknown;
310  }
311 }
312 
314  if (header.e_machine == llvm::ELF::EM_MIPS)
315  return mipsVariantFromElfFlags(header);
316  else if (header.e_machine == llvm::ELF::EM_RISCV)
317  return riscvVariantFromElfFlags(header);
318 
319  return LLDB_INVALID_CPUTYPE;
320 }
321 
322 char ObjectFileELF::ID;
323 
324 // Arbitrary constant used as UUID prefix for core files.
326 
327 // Static methods.
329  PluginManager::RegisterPlugin(GetPluginNameStatic(),
330  GetPluginDescriptionStatic(), CreateInstance,
331  CreateMemoryInstance, GetModuleSpecifications);
332 }
333 
335  PluginManager::UnregisterPlugin(CreateInstance);
336 }
337 
339  static ConstString g_name("elf");
340  return g_name;
341 }
342 
344  return "ELF object file reader.";
345 }
346 
347 ObjectFile *ObjectFileELF::CreateInstance(const lldb::ModuleSP &module_sp,
348  DataBufferSP &data_sp,
349  lldb::offset_t data_offset,
350  const lldb_private::FileSpec *file,
351  lldb::offset_t file_offset,
352  lldb::offset_t length) {
353  if (!data_sp) {
354  data_sp = MapFileData(*file, length, file_offset);
355  if (!data_sp)
356  return nullptr;
357  data_offset = 0;
358  }
359 
360  assert(data_sp);
361 
362  if (data_sp->GetByteSize() <= (llvm::ELF::EI_NIDENT + data_offset))
363  return nullptr;
364 
365  const uint8_t *magic = data_sp->GetBytes() + data_offset;
366  if (!ELFHeader::MagicBytesMatch(magic))
367  return nullptr;
368 
369  // Update the data to contain the entire file if it doesn't already
370  if (data_sp->GetByteSize() < length) {
371  data_sp = MapFileData(*file, length, file_offset);
372  if (!data_sp)
373  return nullptr;
374  data_offset = 0;
375  magic = data_sp->GetBytes();
376  }
377 
378  unsigned address_size = ELFHeader::AddressSizeInBytes(magic);
379  if (address_size == 4 || address_size == 8) {
380  std::unique_ptr<ObjectFileELF> objfile_up(new ObjectFileELF(
381  module_sp, data_sp, data_offset, file, file_offset, length));
382  ArchSpec spec = objfile_up->GetArchitecture();
383  if (spec && objfile_up->SetModulesArchitecture(spec))
384  return objfile_up.release();
385  }
386 
387  return nullptr;
388 }
389 
391  const lldb::ModuleSP &module_sp, DataBufferSP &data_sp,
392  const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) {
393  if (data_sp && data_sp->GetByteSize() > (llvm::ELF::EI_NIDENT)) {
394  const uint8_t *magic = data_sp->GetBytes();
395  if (ELFHeader::MagicBytesMatch(magic)) {
396  unsigned address_size = ELFHeader::AddressSizeInBytes(magic);
397  if (address_size == 4 || address_size == 8) {
398  std::unique_ptr<ObjectFileELF> objfile_up(
399  new ObjectFileELF(module_sp, data_sp, process_sp, header_addr));
400  ArchSpec spec = objfile_up->GetArchitecture();
401  if (spec && objfile_up->SetModulesArchitecture(spec))
402  return objfile_up.release();
403  }
404  }
405  }
406  return nullptr;
407 }
408 
409 bool ObjectFileELF::MagicBytesMatch(DataBufferSP &data_sp,
410  lldb::addr_t data_offset,
411  lldb::addr_t data_length) {
412  if (data_sp &&
413  data_sp->GetByteSize() > (llvm::ELF::EI_NIDENT + data_offset)) {
414  const uint8_t *magic = data_sp->GetBytes() + data_offset;
415  return ELFHeader::MagicBytesMatch(magic);
416  }
417  return false;
418 }
419 
420 static uint32_t calc_crc32(uint32_t init, const DataExtractor &data) {
421  return llvm::crc32(
422  init, llvm::makeArrayRef(data.GetDataStart(), data.GetByteSize()));
423 }
424 
426  const ProgramHeaderColl &program_headers, DataExtractor &object_data) {
427 
428  uint32_t core_notes_crc = 0;
429 
430  for (const ELFProgramHeader &H : program_headers) {
431  if (H.p_type == llvm::ELF::PT_NOTE) {
432  const elf_off ph_offset = H.p_offset;
433  const size_t ph_size = H.p_filesz;
434 
435  DataExtractor segment_data;
436  if (segment_data.SetData(object_data, ph_offset, ph_size) != ph_size) {
437  // The ELF program header contained incorrect data, probably corefile
438  // is incomplete or corrupted.
439  break;
440  }
441 
442  core_notes_crc = calc_crc32(core_notes_crc, segment_data);
443  }
444  }
445 
446  return core_notes_crc;
447 }
448 
449 static const char *OSABIAsCString(unsigned char osabi_byte) {
450 #define _MAKE_OSABI_CASE(x) \
451  case x: \
452  return #x
453  switch (osabi_byte) {
454  _MAKE_OSABI_CASE(ELFOSABI_NONE);
455  _MAKE_OSABI_CASE(ELFOSABI_HPUX);
456  _MAKE_OSABI_CASE(ELFOSABI_NETBSD);
457  _MAKE_OSABI_CASE(ELFOSABI_GNU);
458  _MAKE_OSABI_CASE(ELFOSABI_HURD);
459  _MAKE_OSABI_CASE(ELFOSABI_SOLARIS);
460  _MAKE_OSABI_CASE(ELFOSABI_AIX);
461  _MAKE_OSABI_CASE(ELFOSABI_IRIX);
462  _MAKE_OSABI_CASE(ELFOSABI_FREEBSD);
463  _MAKE_OSABI_CASE(ELFOSABI_TRU64);
464  _MAKE_OSABI_CASE(ELFOSABI_MODESTO);
465  _MAKE_OSABI_CASE(ELFOSABI_OPENBSD);
466  _MAKE_OSABI_CASE(ELFOSABI_OPENVMS);
467  _MAKE_OSABI_CASE(ELFOSABI_NSK);
468  _MAKE_OSABI_CASE(ELFOSABI_AROS);
469  _MAKE_OSABI_CASE(ELFOSABI_FENIXOS);
470  _MAKE_OSABI_CASE(ELFOSABI_C6000_ELFABI);
471  _MAKE_OSABI_CASE(ELFOSABI_C6000_LINUX);
472  _MAKE_OSABI_CASE(ELFOSABI_ARM);
473  _MAKE_OSABI_CASE(ELFOSABI_STANDALONE);
474  default:
475  return "<unknown-osabi>";
476  }
477 #undef _MAKE_OSABI_CASE
478 }
479 
480 //
481 // WARNING : This function is being deprecated
482 // It's functionality has moved to ArchSpec::SetArchitecture This function is
483 // only being kept to validate the move.
484 //
485 // TODO : Remove this function
486 static bool GetOsFromOSABI(unsigned char osabi_byte,
487  llvm::Triple::OSType &ostype) {
488  switch (osabi_byte) {
489  case ELFOSABI_AIX:
490  ostype = llvm::Triple::OSType::AIX;
491  break;
492  case ELFOSABI_FREEBSD:
493  ostype = llvm::Triple::OSType::FreeBSD;
494  break;
495  case ELFOSABI_GNU:
496  ostype = llvm::Triple::OSType::Linux;
497  break;
498  case ELFOSABI_NETBSD:
499  ostype = llvm::Triple::OSType::NetBSD;
500  break;
501  case ELFOSABI_OPENBSD:
502  ostype = llvm::Triple::OSType::OpenBSD;
503  break;
504  case ELFOSABI_SOLARIS:
505  ostype = llvm::Triple::OSType::Solaris;
506  break;
507  default:
508  ostype = llvm::Triple::OSType::UnknownOS;
509  }
510  return ostype != llvm::Triple::OSType::UnknownOS;
511 }
512 
514  const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
515  lldb::offset_t data_offset, lldb::offset_t file_offset,
518 
519  const size_t initial_count = specs.GetSize();
520 
521  if (ObjectFileELF::MagicBytesMatch(data_sp, 0, data_sp->GetByteSize())) {
522  DataExtractor data;
523  data.SetData(data_sp);
524  elf::ELFHeader header;
525  lldb::offset_t header_offset = data_offset;
526  if (header.Parse(data, &header_offset)) {
527  if (data_sp) {
528  ModuleSpec spec(file);
529 
530  const uint32_t sub_type = subTypeFromElfHeader(header);
532  eArchTypeELF, header.e_machine, sub_type, header.e_ident[EI_OSABI]);
533 
534  if (spec.GetArchitecture().IsValid()) {
535  llvm::Triple::OSType ostype;
536  llvm::Triple::VendorType vendor;
537  llvm::Triple::OSType spec_ostype =
538  spec.GetArchitecture().GetTriple().getOS();
539 
540  LLDB_LOGF(log, "ObjectFileELF::%s file '%s' module OSABI: %s",
541  __FUNCTION__, file.GetPath().c_str(),
542  OSABIAsCString(header.e_ident[EI_OSABI]));
543 
544  // SetArchitecture should have set the vendor to unknown
545  vendor = spec.GetArchitecture().GetTriple().getVendor();
546  assert(vendor == llvm::Triple::UnknownVendor);
548 
549  //
550  // Validate it is ok to remove GetOsFromOSABI
551  GetOsFromOSABI(header.e_ident[EI_OSABI], ostype);
552  assert(spec_ostype == ostype);
553  if (spec_ostype != llvm::Triple::OSType::UnknownOS) {
554  LLDB_LOGF(log,
555  "ObjectFileELF::%s file '%s' set ELF module OS type "
556  "from ELF header OSABI.",
557  __FUNCTION__, file.GetPath().c_str());
558  }
559 
560  if (data_sp->GetByteSize() < length)
561  data_sp = MapFileData(file, -1, file_offset);
562  if (data_sp)
563  data.SetData(data_sp);
564  // In case there is header extension in the section #0, the header we
565  // parsed above could have sentinel values for e_phnum, e_shnum, and
566  // e_shstrndx. In this case we need to reparse the header with a
567  // bigger data source to get the actual values.
568  if (header.HasHeaderExtension()) {
569  lldb::offset_t header_offset = data_offset;
570  header.Parse(data, &header_offset);
571  }
572 
573  uint32_t gnu_debuglink_crc = 0;
574  std::string gnu_debuglink_file;
575  SectionHeaderColl section_headers;
576  lldb_private::UUID &uuid = spec.GetUUID();
577 
578  GetSectionHeaderInfo(section_headers, data, header, uuid,
579  gnu_debuglink_file, gnu_debuglink_crc,
580  spec.GetArchitecture());
581 
582  llvm::Triple &spec_triple = spec.GetArchitecture().GetTriple();
583 
584  LLDB_LOGF(log,
585  "ObjectFileELF::%s file '%s' module set to triple: %s "
586  "(architecture %s)",
587  __FUNCTION__, file.GetPath().c_str(),
588  spec_triple.getTriple().c_str(),
590 
591  if (!uuid.IsValid()) {
592  uint32_t core_notes_crc = 0;
593 
594  if (!gnu_debuglink_crc) {
596  "Calculating module crc32 %s with size %" PRIu64 " KiB",
598  (length - file_offset) / 1024);
599 
600  // For core files - which usually don't happen to have a
601  // gnu_debuglink, and are pretty bulky - calculating whole
602  // contents crc32 would be too much of luxury. Thus we will need
603  // to fallback to something simpler.
604  if (header.e_type == llvm::ELF::ET_CORE) {
605  ProgramHeaderColl program_headers;
606  GetProgramHeaderInfo(program_headers, data, header);
607 
608  core_notes_crc =
609  CalculateELFNotesSegmentsCRC32(program_headers, data);
610  } else {
611  gnu_debuglink_crc = calc_crc32(0, data);
612  }
613  }
614  using u32le = llvm::support::ulittle32_t;
615  if (gnu_debuglink_crc) {
616  // Use 4 bytes of crc from the .gnu_debuglink section.
617  u32le data(gnu_debuglink_crc);
618  uuid = UUID::fromData(&data, sizeof(data));
619  } else if (core_notes_crc) {
620  // Use 8 bytes - first 4 bytes for *magic* prefix, mainly to make
621  // it look different form .gnu_debuglink crc followed by 4 bytes
622  // of note segments crc.
623  u32le data[] = {u32le(g_core_uuid_magic), u32le(core_notes_crc)};
624  uuid = UUID::fromData(data, sizeof(data));
625  }
626  }
627 
628  specs.Append(spec);
629  }
630  }
631  }
632  }
633 
634  return specs.GetSize() - initial_count;
635 }
636 
637 // PluginInterface protocol
639  return GetPluginNameStatic();
640 }
641 
642 uint32_t ObjectFileELF::GetPluginVersion() { return m_plugin_version; }
643 // ObjectFile protocol
644 
645 ObjectFileELF::ObjectFileELF(const lldb::ModuleSP &module_sp,
646  DataBufferSP &data_sp, lldb::offset_t data_offset,
647  const FileSpec *file, lldb::offset_t file_offset,
648  lldb::offset_t length)
649  : ObjectFile(module_sp, file, file_offset, length, data_sp, data_offset) {
650  if (file)
651  m_file = *file;
652 }
653 
654 ObjectFileELF::ObjectFileELF(const lldb::ModuleSP &module_sp,
655  DataBufferSP &header_data_sp,
656  const lldb::ProcessSP &process_sp,
657  addr_t header_addr)
658  : ObjectFile(module_sp, process_sp, header_addr, header_data_sp) {}
659 
661  return ((m_header.e_type & ET_EXEC) != 0) || (m_header.e_entry != 0);
662 }
663 
665  bool value_is_offset) {
666  ModuleSP module_sp = GetModule();
667  if (module_sp) {
668  size_t num_loaded_sections = 0;
669  SectionList *section_list = GetSectionList();
670  if (section_list) {
671  if (!value_is_offset) {
673  if (base == LLDB_INVALID_ADDRESS)
674  return false;
675  value -= base;
676  }
677 
678  const size_t num_sections = section_list->GetSize();
679  size_t sect_idx = 0;
680 
681  for (sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
682  // Iterate through the object file sections to find all of the sections
683  // that have SHF_ALLOC in their flag bits.
684  SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
685  if (section_sp->Test(SHF_ALLOC) ||
686  section_sp->GetType() == eSectionTypeContainer) {
687  lldb::addr_t load_addr = section_sp->GetFileAddress();
688  // We don't want to update the load address of a section with type
689  // eSectionTypeAbsoluteAddress as they already have the absolute load
690  // address already specified
691  if (section_sp->GetType() != eSectionTypeAbsoluteAddress)
692  load_addr += value;
693 
694  // On 32-bit systems the load address have to fit into 4 bytes. The
695  // rest of the bytes are the overflow from the addition.
696  if (GetAddressByteSize() == 4)
697  load_addr &= 0xFFFFFFFF;
698 
699  if (target.GetSectionLoadList().SetSectionLoadAddress(section_sp,
700  load_addr))
701  ++num_loaded_sections;
702  }
703  }
704  return num_loaded_sections > 0;
705  }
706  }
707  return false;
708 }
709 
711  if (m_header.e_ident[EI_DATA] == ELFDATA2MSB)
712  return eByteOrderBig;
713  if (m_header.e_ident[EI_DATA] == ELFDATA2LSB)
714  return eByteOrderLittle;
715  return eByteOrderInvalid;
716 }
717 
719  return m_data.GetAddressByteSize();
720 }
721 
723  Symtab *symtab = GetSymtab();
724  if (!symtab)
725  return AddressClass::eUnknown;
726 
727  // The address class is determined based on the symtab. Ask it from the
728  // object file what contains the symtab information.
729  ObjectFile *symtab_objfile = symtab->GetObjectFile();
730  if (symtab_objfile != nullptr && symtab_objfile != this)
731  return symtab_objfile->GetAddressClass(file_addr);
732 
733  auto res = ObjectFile::GetAddressClass(file_addr);
734  if (res != AddressClass::eCode)
735  return res;
736 
737  auto ub = m_address_class_map.upper_bound(file_addr);
738  if (ub == m_address_class_map.begin()) {
739  // No entry in the address class map before the address. Return default
740  // address class for an address in a code section.
741  return AddressClass::eCode;
742  }
743 
744  // Move iterator to the address class entry preceding address
745  --ub;
746 
747  return ub->second;
748 }
749 
751  return std::distance(m_section_headers.begin(), I);
752 }
753 
755  return std::distance(m_section_headers.begin(), I);
756 }
757 
759  lldb::offset_t offset = 0;
760  return m_header.Parse(m_data, &offset);
761 }
762 
764  // Need to parse the section list to get the UUIDs, so make sure that's been
765  // done.
766  if (!ParseSectionHeaders() && GetType() != ObjectFile::eTypeCoreFile)
767  return UUID();
768 
769  if (!m_uuid) {
770  using u32le = llvm::support::ulittle32_t;
771  if (GetType() == ObjectFile::eTypeCoreFile) {
772  uint32_t core_notes_crc = 0;
773 
774  if (!ParseProgramHeaders())
775  return UUID();
776 
777  core_notes_crc =
779 
780  if (core_notes_crc) {
781  // Use 8 bytes - first 4 bytes for *magic* prefix, mainly to make it
782  // look different form .gnu_debuglink crc - followed by 4 bytes of note
783  // segments crc.
784  u32le data[] = {u32le(g_core_uuid_magic), u32le(core_notes_crc)};
785  m_uuid = UUID::fromData(data, sizeof(data));
786  }
787  } else {
788  if (!m_gnu_debuglink_crc)
790  if (m_gnu_debuglink_crc) {
791  // Use 4 bytes of crc from the .gnu_debuglink section.
792  u32le data(m_gnu_debuglink_crc);
793  m_uuid = UUID::fromData(&data, sizeof(data));
794  }
795  }
796  }
797 
798  return m_uuid;
799 }
800 
801 llvm::Optional<FileSpec> ObjectFileELF::GetDebugLink() {
802  if (m_gnu_debuglink_file.empty())
803  return llvm::None;
805 }
806 
808  size_t num_modules = ParseDependentModules();
809  uint32_t num_specs = 0;
810 
811  for (unsigned i = 0; i < num_modules; ++i) {
812  if (files.AppendIfUnique(m_filespec_up->GetFileSpecAtIndex(i)))
813  num_specs++;
814  }
815 
816  return num_specs;
817 }
818 
820  if (!ParseDynamicSymbols())
821  return Address();
822 
823  SectionList *section_list = GetSectionList();
824  if (!section_list)
825  return Address();
826 
827  // Find the SHT_DYNAMIC (.dynamic) section.
828  SectionSP dynsym_section_sp(
830  if (!dynsym_section_sp)
831  return Address();
832  assert(dynsym_section_sp->GetObjectFile() == this);
833 
834  user_id_t dynsym_id = dynsym_section_sp->GetID();
835  const ELFSectionHeaderInfo *dynsym_hdr = GetSectionHeaderByIndex(dynsym_id);
836  if (!dynsym_hdr)
837  return Address();
838 
839  for (size_t i = 0; i < m_dynamic_symbols.size(); ++i) {
840  ELFDynamic &symbol = m_dynamic_symbols[i];
841 
842  if (symbol.d_tag == DT_DEBUG) {
843  // Compute the offset as the number of previous entries plus the size of
844  // d_tag.
845  addr_t offset = i * dynsym_hdr->sh_entsize + GetAddressByteSize();
846  return Address(dynsym_section_sp, offset);
847  }
848  // MIPS executables uses DT_MIPS_RLD_MAP_REL to support PIE. DT_MIPS_RLD_MAP
849  // exists in non-PIE.
850  else if ((symbol.d_tag == DT_MIPS_RLD_MAP ||
851  symbol.d_tag == DT_MIPS_RLD_MAP_REL) &&
852  target) {
853  addr_t offset = i * dynsym_hdr->sh_entsize + GetAddressByteSize();
854  addr_t dyn_base = dynsym_section_sp->GetLoadBaseAddress(target);
855  if (dyn_base == LLDB_INVALID_ADDRESS)
856  return Address();
857 
858  Status error;
859  if (symbol.d_tag == DT_MIPS_RLD_MAP) {
860  // DT_MIPS_RLD_MAP tag stores an absolute address of the debug pointer.
861  Address addr;
862  if (target->ReadPointerFromMemory(dyn_base + offset, error, addr, true))
863  return addr;
864  }
865  if (symbol.d_tag == DT_MIPS_RLD_MAP_REL) {
866  // DT_MIPS_RLD_MAP_REL tag stores the offset to the debug pointer,
867  // relative to the address of the tag.
868  uint64_t rel_offset;
869  rel_offset = target->ReadUnsignedIntegerFromMemory(
870  dyn_base + offset, GetAddressByteSize(), UINT64_MAX, error, true);
871  if (error.Success() && rel_offset != UINT64_MAX) {
872  Address addr;
873  addr_t debug_ptr_address =
874  dyn_base + (offset - GetAddressByteSize()) + rel_offset;
875  addr.SetOffset(debug_ptr_address);
876  return addr;
877  }
878  }
879  }
880  }
881 
882  return Address();
883 }
884 
887  return m_entry_point_address;
888 
889  if (!ParseHeader() || !IsExecutable())
890  return m_entry_point_address;
891 
892  SectionList *section_list = GetSectionList();
893  addr_t offset = m_header.e_entry;
894 
895  if (!section_list)
897  else
899  return m_entry_point_address;
900 }
901 
903  for (const auto &EnumPHdr : llvm::enumerate(ProgramHeaders())) {
904  const ELFProgramHeader &H = EnumPHdr.value();
905  if (H.p_type != PT_LOAD)
906  continue;
907 
908  return Address(
909  GetSectionList()->FindSectionByID(SegmentID(EnumPHdr.index())), 0);
910  }
911  return LLDB_INVALID_ADDRESS;
912 }
913 
914 // ParseDependentModules
916  if (m_filespec_up)
917  return m_filespec_up->GetSize();
918 
919  m_filespec_up = std::make_unique<FileSpecList>();
920 
921  if (!ParseSectionHeaders())
922  return 0;
923 
924  SectionList *section_list = GetSectionList();
925  if (!section_list)
926  return 0;
927 
928  // Find the SHT_DYNAMIC section.
929  Section *dynsym =
931  .get();
932  if (!dynsym)
933  return 0;
934  assert(dynsym->GetObjectFile() == this);
935 
936  const ELFSectionHeaderInfo *header = GetSectionHeaderByIndex(dynsym->GetID());
937  if (!header)
938  return 0;
939  // sh_link: section header index of string table used by entries in the
940  // section.
941  Section *dynstr = section_list->FindSectionByID(header->sh_link).get();
942  if (!dynstr)
943  return 0;
944 
945  DataExtractor dynsym_data;
946  DataExtractor dynstr_data;
947  if (ReadSectionData(dynsym, dynsym_data) &&
948  ReadSectionData(dynstr, dynstr_data)) {
949  ELFDynamic symbol;
950  const lldb::offset_t section_size = dynsym_data.GetByteSize();
951  lldb::offset_t offset = 0;
952 
953  // The only type of entries we are concerned with are tagged DT_NEEDED,
954  // yielding the name of a required library.
955  while (offset < section_size) {
956  if (!symbol.Parse(dynsym_data, &offset))
957  break;
958 
959  if (symbol.d_tag != DT_NEEDED)
960  continue;
961 
962  uint32_t str_index = static_cast<uint32_t>(symbol.d_val);
963  const char *lib_name = dynstr_data.PeekCStr(str_index);
964  FileSpec file_spec(lib_name);
965  FileSystem::Instance().Resolve(file_spec);
966  m_filespec_up->Append(file_spec);
967  }
968  }
969 
970  return m_filespec_up->GetSize();
971 }
972 
973 // GetProgramHeaderInfo
975  DataExtractor &object_data,
976  const ELFHeader &header) {
977  // We have already parsed the program headers
978  if (!program_headers.empty())
979  return program_headers.size();
980 
981  // If there are no program headers to read we are done.
982  if (header.e_phnum == 0)
983  return 0;
984 
985  program_headers.resize(header.e_phnum);
986  if (program_headers.size() != header.e_phnum)
987  return 0;
988 
989  const size_t ph_size = header.e_phnum * header.e_phentsize;
990  const elf_off ph_offset = header.e_phoff;
991  DataExtractor data;
992  if (data.SetData(object_data, ph_offset, ph_size) != ph_size)
993  return 0;
994 
995  uint32_t idx;
996  lldb::offset_t offset;
997  for (idx = 0, offset = 0; idx < header.e_phnum; ++idx) {
998  if (!program_headers[idx].Parse(data, &offset))
999  break;
1000  }
1001 
1002  if (idx < program_headers.size())
1003  program_headers.resize(idx);
1004 
1005  return program_headers.size();
1006 }
1007 
1008 // ParseProgramHeaders
1011 }
1012 
1015  lldb_private::ArchSpec &arch_spec,
1016  lldb_private::UUID &uuid) {
1018  Status error;
1019 
1020  lldb::offset_t offset = 0;
1021 
1022  while (true) {
1023  // Parse the note header. If this fails, bail out.
1024  const lldb::offset_t note_offset = offset;
1025  ELFNote note = ELFNote();
1026  if (!note.Parse(data, &offset)) {
1027  // We're done.
1028  return error;
1029  }
1030 
1031  LLDB_LOGF(log, "ObjectFileELF::%s parsing note name='%s', type=%" PRIu32,
1032  __FUNCTION__, note.n_name.c_str(), note.n_type);
1033 
1034  // Process FreeBSD ELF notes.
1035  if ((note.n_name == LLDB_NT_OWNER_FREEBSD) &&
1036  (note.n_type == LLDB_NT_FREEBSD_ABI_TAG) &&
1037  (note.n_descsz == LLDB_NT_FREEBSD_ABI_SIZE)) {
1038  // Pull out the min version info.
1039  uint32_t version_info;
1040  if (data.GetU32(&offset, &version_info, 1) == nullptr) {
1041  error.SetErrorString("failed to read FreeBSD ABI note payload");
1042  return error;
1043  }
1044 
1045  // Convert the version info into a major/minor number.
1046  const uint32_t version_major = version_info / 100000;
1047  const uint32_t version_minor = (version_info / 1000) % 100;
1048 
1049  char os_name[32];
1050  snprintf(os_name, sizeof(os_name), "freebsd%" PRIu32 ".%" PRIu32,
1051  version_major, version_minor);
1052 
1053  // Set the elf OS version to FreeBSD. Also clear the vendor.
1054  arch_spec.GetTriple().setOSName(os_name);
1055  arch_spec.GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor);
1056 
1057  LLDB_LOGF(log,
1058  "ObjectFileELF::%s detected FreeBSD %" PRIu32 ".%" PRIu32
1059  ".%" PRIu32,
1060  __FUNCTION__, version_major, version_minor,
1061  static_cast<uint32_t>(version_info % 1000));
1062  }
1063  // Process GNU ELF notes.
1064  else if (note.n_name == LLDB_NT_OWNER_GNU) {
1065  switch (note.n_type) {
1066  case LLDB_NT_GNU_ABI_TAG:
1067  if (note.n_descsz == LLDB_NT_GNU_ABI_SIZE) {
1068  // Pull out the min OS version supporting the ABI.
1069  uint32_t version_info[4];
1070  if (data.GetU32(&offset, &version_info[0], note.n_descsz / 4) ==
1071  nullptr) {
1072  error.SetErrorString("failed to read GNU ABI note payload");
1073  return error;
1074  }
1075 
1076  // Set the OS per the OS field.
1077  switch (version_info[0]) {
1078  case LLDB_NT_GNU_ABI_OS_LINUX:
1079  arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
1080  arch_spec.GetTriple().setVendor(
1081  llvm::Triple::VendorType::UnknownVendor);
1082  LLDB_LOGF(log,
1083  "ObjectFileELF::%s detected Linux, min version %" PRIu32
1084  ".%" PRIu32 ".%" PRIu32,
1085  __FUNCTION__, version_info[1], version_info[2],
1086  version_info[3]);
1087  // FIXME we have the minimal version number, we could be propagating
1088  // that. version_info[1] = OS Major, version_info[2] = OS Minor,
1089  // version_info[3] = Revision.
1090  break;
1091  case LLDB_NT_GNU_ABI_OS_HURD:
1092  arch_spec.GetTriple().setOS(llvm::Triple::OSType::UnknownOS);
1093  arch_spec.GetTriple().setVendor(
1094  llvm::Triple::VendorType::UnknownVendor);
1095  LLDB_LOGF(log,
1096  "ObjectFileELF::%s detected Hurd (unsupported), min "
1097  "version %" PRIu32 ".%" PRIu32 ".%" PRIu32,
1098  __FUNCTION__, version_info[1], version_info[2],
1099  version_info[3]);
1100  break;
1101  case LLDB_NT_GNU_ABI_OS_SOLARIS:
1102  arch_spec.GetTriple().setOS(llvm::Triple::OSType::Solaris);
1103  arch_spec.GetTriple().setVendor(
1104  llvm::Triple::VendorType::UnknownVendor);
1105  LLDB_LOGF(log,
1106  "ObjectFileELF::%s detected Solaris, min version %" PRIu32
1107  ".%" PRIu32 ".%" PRIu32,
1108  __FUNCTION__, version_info[1], version_info[2],
1109  version_info[3]);
1110  break;
1111  default:
1112  LLDB_LOGF(log,
1113  "ObjectFileELF::%s unrecognized OS in note, id %" PRIu32
1114  ", min version %" PRIu32 ".%" PRIu32 ".%" PRIu32,
1115  __FUNCTION__, version_info[0], version_info[1],
1116  version_info[2], version_info[3]);
1117  break;
1118  }
1119  }
1120  break;
1121 
1122  case LLDB_NT_GNU_BUILD_ID_TAG:
1123  // Only bother processing this if we don't already have the uuid set.
1124  if (!uuid.IsValid()) {
1125  // 16 bytes is UUID|MD5, 20 bytes is SHA1. Other linkers may produce a
1126  // build-id of a different length. Accept it as long as it's at least
1127  // 4 bytes as it will be better than our own crc32.
1128  if (note.n_descsz >= 4) {
1129  if (const uint8_t *buf = data.PeekData(offset, note.n_descsz)) {
1130  // Save the build id as the UUID for the module.
1131  uuid = UUID::fromData(buf, note.n_descsz);
1132  } else {
1133  error.SetErrorString("failed to read GNU_BUILD_ID note payload");
1134  return error;
1135  }
1136  }
1137  }
1138  break;
1139  }
1140  if (arch_spec.IsMIPS() &&
1141  arch_spec.GetTriple().getOS() == llvm::Triple::OSType::UnknownOS)
1142  // The note.n_name == LLDB_NT_OWNER_GNU is valid for Linux platform
1143  arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
1144  }
1145  // Process NetBSD ELF executables and shared libraries
1146  else if ((note.n_name == LLDB_NT_OWNER_NETBSD) &&
1147  (note.n_type == LLDB_NT_NETBSD_IDENT_TAG) &&
1148  (note.n_descsz == LLDB_NT_NETBSD_IDENT_DESCSZ) &&
1149  (note.n_namesz == LLDB_NT_NETBSD_IDENT_NAMESZ)) {
1150  // Pull out the version info.
1151  uint32_t version_info;
1152  if (data.GetU32(&offset, &version_info, 1) == nullptr) {
1153  error.SetErrorString("failed to read NetBSD ABI note payload");
1154  return error;
1155  }
1156  // Convert the version info into a major/minor/patch number.
1157  // #define __NetBSD_Version__ MMmmrrpp00
1158  //
1159  // M = major version
1160  // m = minor version; a minor number of 99 indicates current.
1161  // r = 0 (since NetBSD 3.0 not used)
1162  // p = patchlevel
1163  const uint32_t version_major = version_info / 100000000;
1164  const uint32_t version_minor = (version_info % 100000000) / 1000000;
1165  const uint32_t version_patch = (version_info % 10000) / 100;
1166  // Set the elf OS version to NetBSD. Also clear the vendor.
1167  arch_spec.GetTriple().setOSName(
1168  llvm::formatv("netbsd{0}.{1}.{2}", version_major, version_minor,
1169  version_patch).str());
1170  arch_spec.GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor);
1171  }
1172  // Process NetBSD ELF core(5) notes
1173  else if ((note.n_name == LLDB_NT_OWNER_NETBSDCORE) &&
1174  (note.n_type == LLDB_NT_NETBSD_PROCINFO)) {
1175  // Set the elf OS version to NetBSD. Also clear the vendor.
1176  arch_spec.GetTriple().setOS(llvm::Triple::OSType::NetBSD);
1177  arch_spec.GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor);
1178  }
1179  // Process OpenBSD ELF notes.
1180  else if (note.n_name == LLDB_NT_OWNER_OPENBSD) {
1181  // Set the elf OS version to OpenBSD. Also clear the vendor.
1182  arch_spec.GetTriple().setOS(llvm::Triple::OSType::OpenBSD);
1183  arch_spec.GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor);
1184  } else if (note.n_name == LLDB_NT_OWNER_ANDROID) {
1185  arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
1186  arch_spec.GetTriple().setEnvironment(
1187  llvm::Triple::EnvironmentType::Android);
1188  } else if (note.n_name == LLDB_NT_OWNER_LINUX) {
1189  // This is sometimes found in core files and usually contains extended
1190  // register info
1191  arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
1192  } else if (note.n_name == LLDB_NT_OWNER_CORE) {
1193  // Parse the NT_FILE to look for stuff in paths to shared libraries As
1194  // the contents look like this in a 64 bit ELF core file: count =
1195  // 0x000000000000000a (10) page_size = 0x0000000000001000 (4096) Index
1196  // start end file_ofs path =====
1197  // 0x0000000000401000 0x0000000000000000 /tmp/a.out [ 1]
1198  // 0x0000000000600000 0x0000000000601000 0x0000000000000000 /tmp/a.out [
1199  // 2] 0x0000000000601000 0x0000000000602000 0x0000000000000001 /tmp/a.out
1200  // [ 3] 0x00007fa79c9ed000 0x00007fa79cba8000 0x0000000000000000
1201  // /lib/x86_64-linux-gnu/libc-2.19.so [ 4] 0x00007fa79cba8000
1202  // 0x00007fa79cda7000 0x00000000000001bb /lib/x86_64-linux-
1203  // gnu/libc-2.19.so [ 5] 0x00007fa79cda7000 0x00007fa79cdab000
1204  // 0x00000000000001ba /lib/x86_64-linux-gnu/libc-2.19.so [ 6]
1205  // 0x00007fa79cdab000 0x00007fa79cdad000 0x00000000000001be /lib/x86_64
1206  // -linux-gnu/libc-2.19.so [ 7] 0x00007fa79cdb2000 0x00007fa79cdd5000
1207  // 0x0000000000000000 /lib/x86_64-linux-gnu/ld-2.19.so [ 8]
1208  // 0x00007fa79cfd4000 0x00007fa79cfd5000 0x0000000000000022 /lib/x86_64
1209  // -linux-gnu/ld-2.19.so [ 9] 0x00007fa79cfd5000 0x00007fa79cfd6000
1210  // 0x0000000000000023 /lib/x86_64-linux-gnu/ld-2.19.so In the 32 bit ELFs
1211  // the count, page_size, start, end, file_ofs are uint32_t For reference:
1212  // see readelf source code (in binutils).
1213  if (note.n_type == NT_FILE) {
1214  uint64_t count = data.GetAddress(&offset);
1215  const char *cstr;
1216  data.GetAddress(&offset); // Skip page size
1217  offset += count * 3 *
1218  data.GetAddressByteSize(); // Skip all start/end/file_ofs
1219  for (size_t i = 0; i < count; ++i) {
1220  cstr = data.GetCStr(&offset);
1221  if (cstr == nullptr) {
1222  error.SetErrorStringWithFormat("ObjectFileELF::%s trying to read "
1223  "at an offset after the end "
1224  "(GetCStr returned nullptr)",
1225  __FUNCTION__);
1226  return error;
1227  }
1228  llvm::StringRef path(cstr);
1229  if (path.contains("/lib/x86_64-linux-gnu") || path.contains("/lib/i386-linux-gnu")) {
1230  arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
1231  break;
1232  }
1233  }
1234  if (arch_spec.IsMIPS() &&
1235  arch_spec.GetTriple().getOS() == llvm::Triple::OSType::UnknownOS)
1236  // In case of MIPSR6, the LLDB_NT_OWNER_GNU note is missing for some
1237  // cases (e.g. compile with -nostdlib) Hence set OS to Linux
1238  arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
1239  }
1240  }
1241 
1242  // Calculate the offset of the next note just in case "offset" has been
1243  // used to poke at the contents of the note data
1244  offset = note_offset + note.GetByteSize();
1245  }
1246 
1247  return error;
1248 }
1249 
1251  ArchSpec &arch_spec) {
1252  lldb::offset_t Offset = 0;
1253 
1254  uint8_t FormatVersion = data.GetU8(&Offset);
1255  if (FormatVersion != llvm::ELFAttrs::Format_Version)
1256  return;
1257 
1258  Offset = Offset + sizeof(uint32_t); // Section Length
1259  llvm::StringRef VendorName = data.GetCStr(&Offset);
1260 
1261  if (VendorName != "aeabi")
1262  return;
1263 
1264  if (arch_spec.GetTriple().getEnvironment() ==
1265  llvm::Triple::UnknownEnvironment)
1266  arch_spec.GetTriple().setEnvironment(llvm::Triple::EABI);
1267 
1268  while (Offset < length) {
1269  uint8_t Tag = data.GetU8(&Offset);
1270  uint32_t Size = data.GetU32(&Offset);
1271 
1272  if (Tag != llvm::ARMBuildAttrs::File || Size == 0)
1273  continue;
1274 
1275  while (Offset < length) {
1276  uint64_t Tag = data.GetULEB128(&Offset);
1277  switch (Tag) {
1278  default:
1279  if (Tag < 32)
1280  data.GetULEB128(&Offset);
1281  else if (Tag % 2 == 0)
1282  data.GetULEB128(&Offset);
1283  else
1284  data.GetCStr(&Offset);
1285 
1286  break;
1287 
1288  case llvm::ARMBuildAttrs::CPU_raw_name:
1289  case llvm::ARMBuildAttrs::CPU_name:
1290  data.GetCStr(&Offset);
1291 
1292  break;
1293 
1294  case llvm::ARMBuildAttrs::ABI_VFP_args: {
1295  uint64_t VFPArgs = data.GetULEB128(&Offset);
1296 
1297  if (VFPArgs == llvm::ARMBuildAttrs::BaseAAPCS) {
1298  if (arch_spec.GetTriple().getEnvironment() ==
1299  llvm::Triple::UnknownEnvironment ||
1300  arch_spec.GetTriple().getEnvironment() == llvm::Triple::EABIHF)
1301  arch_spec.GetTriple().setEnvironment(llvm::Triple::EABI);
1302 
1303  arch_spec.SetFlags(ArchSpec::eARM_abi_soft_float);
1304  } else if (VFPArgs == llvm::ARMBuildAttrs::HardFPAAPCS) {
1305  if (arch_spec.GetTriple().getEnvironment() ==
1306  llvm::Triple::UnknownEnvironment ||
1307  arch_spec.GetTriple().getEnvironment() == llvm::Triple::EABI)
1308  arch_spec.GetTriple().setEnvironment(llvm::Triple::EABIHF);
1309 
1310  arch_spec.SetFlags(ArchSpec::eARM_abi_hard_float);
1311  }
1312 
1313  break;
1314  }
1315  }
1316  }
1317  }
1318 }
1319 
1320 // GetSectionHeaderInfo
1322  DataExtractor &object_data,
1323  const elf::ELFHeader &header,
1324  lldb_private::UUID &uuid,
1325  std::string &gnu_debuglink_file,
1326  uint32_t &gnu_debuglink_crc,
1327  ArchSpec &arch_spec) {
1328  // Don't reparse the section headers if we already did that.
1329  if (!section_headers.empty())
1330  return section_headers.size();
1331 
1332  // Only initialize the arch_spec to okay defaults if they're not already set.
1333  // We'll refine this with note data as we parse the notes.
1334  if (arch_spec.GetTriple().getOS() == llvm::Triple::OSType::UnknownOS) {
1335  llvm::Triple::OSType ostype;
1336  llvm::Triple::OSType spec_ostype;
1337  const uint32_t sub_type = subTypeFromElfHeader(header);
1338  arch_spec.SetArchitecture(eArchTypeELF, header.e_machine, sub_type,
1339  header.e_ident[EI_OSABI]);
1340 
1341  // Validate if it is ok to remove GetOsFromOSABI. Note, that now the OS is
1342  // determined based on EI_OSABI flag and the info extracted from ELF notes
1343  // (see RefineModuleDetailsFromNote). However in some cases that still
1344  // might be not enough: for example a shared library might not have any
1345  // notes at all and have EI_OSABI flag set to System V, as result the OS
1346  // will be set to UnknownOS.
1347  GetOsFromOSABI(header.e_ident[EI_OSABI], ostype);
1348  spec_ostype = arch_spec.GetTriple().getOS();
1349  assert(spec_ostype == ostype);
1350  UNUSED_IF_ASSERT_DISABLED(spec_ostype);
1351  }
1352 
1353  if (arch_spec.GetMachine() == llvm::Triple::mips ||
1354  arch_spec.GetMachine() == llvm::Triple::mipsel ||
1355  arch_spec.GetMachine() == llvm::Triple::mips64 ||
1356  arch_spec.GetMachine() == llvm::Triple::mips64el) {
1357  switch (header.e_flags & llvm::ELF::EF_MIPS_ARCH_ASE) {
1358  case llvm::ELF::EF_MIPS_MICROMIPS:
1359  arch_spec.SetFlags(ArchSpec::eMIPSAse_micromips);
1360  break;
1361  case llvm::ELF::EF_MIPS_ARCH_ASE_M16:
1362  arch_spec.SetFlags(ArchSpec::eMIPSAse_mips16);
1363  break;
1364  case llvm::ELF::EF_MIPS_ARCH_ASE_MDMX:
1365  arch_spec.SetFlags(ArchSpec::eMIPSAse_mdmx);
1366  break;
1367  default:
1368  break;
1369  }
1370  }
1371 
1372  if (arch_spec.GetMachine() == llvm::Triple::arm ||
1373  arch_spec.GetMachine() == llvm::Triple::thumb) {
1374  if (header.e_flags & llvm::ELF::EF_ARM_SOFT_FLOAT)
1375  arch_spec.SetFlags(ArchSpec::eARM_abi_soft_float);
1376  else if (header.e_flags & llvm::ELF::EF_ARM_VFP_FLOAT)
1377  arch_spec.SetFlags(ArchSpec::eARM_abi_hard_float);
1378  }
1379 
1380  // If there are no section headers we are done.
1381  if (header.e_shnum == 0)
1382  return 0;
1383 
1385 
1386  section_headers.resize(header.e_shnum);
1387  if (section_headers.size() != header.e_shnum)
1388  return 0;
1389 
1390  const size_t sh_size = header.e_shnum * header.e_shentsize;
1391  const elf_off sh_offset = header.e_shoff;
1392  DataExtractor sh_data;
1393  if (sh_data.SetData(object_data, sh_offset, sh_size) != sh_size)
1394  return 0;
1395 
1396  uint32_t idx;
1397  lldb::offset_t offset;
1398  for (idx = 0, offset = 0; idx < header.e_shnum; ++idx) {
1399  if (!section_headers[idx].Parse(sh_data, &offset))
1400  break;
1401  }
1402  if (idx < section_headers.size())
1403  section_headers.resize(idx);
1404 
1405  const unsigned strtab_idx = header.e_shstrndx;
1406  if (strtab_idx && strtab_idx < section_headers.size()) {
1407  const ELFSectionHeaderInfo &sheader = section_headers[strtab_idx];
1408  const size_t byte_size = sheader.sh_size;
1409  const Elf64_Off offset = sheader.sh_offset;
1410  lldb_private::DataExtractor shstr_data;
1411 
1412  if (shstr_data.SetData(object_data, offset, byte_size) == byte_size) {
1413  for (SectionHeaderCollIter I = section_headers.begin();
1414  I != section_headers.end(); ++I) {
1415  static ConstString g_sect_name_gnu_debuglink(".gnu_debuglink");
1416  const ELFSectionHeaderInfo &sheader = *I;
1417  const uint64_t section_size =
1418  sheader.sh_type == SHT_NOBITS ? 0 : sheader.sh_size;
1419  ConstString name(shstr_data.PeekCStr(I->sh_name));
1420 
1421  I->section_name = name;
1422 
1423  if (arch_spec.IsMIPS()) {
1424  uint32_t arch_flags = arch_spec.GetFlags();
1425  DataExtractor data;
1426  if (sheader.sh_type == SHT_MIPS_ABIFLAGS) {
1427 
1428  if (section_size && (data.SetData(object_data, sheader.sh_offset,
1429  section_size) == section_size)) {
1430  // MIPS ASE Mask is at offset 12 in MIPS.abiflags section
1431  lldb::offset_t offset = 12; // MIPS ABI Flags Version: 0
1432  arch_flags |= data.GetU32(&offset);
1433 
1434  // The floating point ABI is at offset 7
1435  offset = 7;
1436  switch (data.GetU8(&offset)) {
1437  case llvm::Mips::Val_GNU_MIPS_ABI_FP_ANY:
1439  break;
1440  case llvm::Mips::Val_GNU_MIPS_ABI_FP_DOUBLE:
1442  break;
1443  case llvm::Mips::Val_GNU_MIPS_ABI_FP_SINGLE:
1445  break;
1446  case llvm::Mips::Val_GNU_MIPS_ABI_FP_SOFT:
1448  break;
1449  case llvm::Mips::Val_GNU_MIPS_ABI_FP_OLD_64:
1451  break;
1452  case llvm::Mips::Val_GNU_MIPS_ABI_FP_XX:
1454  break;
1455  case llvm::Mips::Val_GNU_MIPS_ABI_FP_64:
1457  break;
1458  case llvm::Mips::Val_GNU_MIPS_ABI_FP_64A:
1460  break;
1461  }
1462  }
1463  }
1464  // Settings appropriate ArchSpec ABI Flags
1465  switch (header.e_flags & llvm::ELF::EF_MIPS_ABI) {
1466  case llvm::ELF::EF_MIPS_ABI_O32:
1468  break;
1469  case EF_MIPS_ABI_O64:
1471  break;
1472  case EF_MIPS_ABI_EABI32:
1474  break;
1475  case EF_MIPS_ABI_EABI64:
1477  break;
1478  default:
1479  // ABI Mask doesn't cover N32 and N64 ABI.
1480  if (header.e_ident[EI_CLASS] == llvm::ELF::ELFCLASS64)
1482  else if (header.e_flags & llvm::ELF::EF_MIPS_ABI2)
1484  break;
1485  }
1486  arch_spec.SetFlags(arch_flags);
1487  }
1488 
1489  if (arch_spec.GetMachine() == llvm::Triple::arm ||
1490  arch_spec.GetMachine() == llvm::Triple::thumb) {
1491  DataExtractor data;
1492 
1493  if (sheader.sh_type == SHT_ARM_ATTRIBUTES && section_size != 0 &&
1494  data.SetData(object_data, sheader.sh_offset, section_size) == section_size)
1495  ParseARMAttributes(data, section_size, arch_spec);
1496  }
1497 
1498  if (name == g_sect_name_gnu_debuglink) {
1499  DataExtractor data;
1500  if (section_size && (data.SetData(object_data, sheader.sh_offset,
1501  section_size) == section_size)) {
1502  lldb::offset_t gnu_debuglink_offset = 0;
1503  gnu_debuglink_file = data.GetCStr(&gnu_debuglink_offset);
1504  gnu_debuglink_offset = llvm::alignTo(gnu_debuglink_offset, 4);
1505  data.GetU32(&gnu_debuglink_offset, &gnu_debuglink_crc, 1);
1506  }
1507  }
1508 
1509  // Process ELF note section entries.
1510  bool is_note_header = (sheader.sh_type == SHT_NOTE);
1511 
1512  // The section header ".note.android.ident" is stored as a
1513  // PROGBITS type header but it is actually a note header.
1514  static ConstString g_sect_name_android_ident(".note.android.ident");
1515  if (!is_note_header && name == g_sect_name_android_ident)
1516  is_note_header = true;
1517 
1518  if (is_note_header) {
1519  // Allow notes to refine module info.
1520  DataExtractor data;
1521  if (section_size && (data.SetData(object_data, sheader.sh_offset,
1522  section_size) == section_size)) {
1523  Status error = RefineModuleDetailsFromNote(data, arch_spec, uuid);
1524  if (error.Fail()) {
1525  LLDB_LOGF(log, "ObjectFileELF::%s ELF note processing failed: %s",
1526  __FUNCTION__, error.AsCString());
1527  }
1528  }
1529  }
1530  }
1531 
1532  // Make any unknown triple components to be unspecified unknowns.
1533  if (arch_spec.GetTriple().getVendor() == llvm::Triple::UnknownVendor)
1534  arch_spec.GetTriple().setVendorName(llvm::StringRef());
1535  if (arch_spec.GetTriple().getOS() == llvm::Triple::UnknownOS)
1536  arch_spec.GetTriple().setOSName(llvm::StringRef());
1537 
1538  return section_headers.size();
1539  }
1540  }
1541 
1542  section_headers.clear();
1543  return 0;
1544 }
1545 
1546 llvm::StringRef
1547 ObjectFileELF::StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
1548  size_t pos = symbol_name.find('@');
1549  return symbol_name.substr(0, pos);
1550 }
1551 
1552 // ParseSectionHeaders
1556  m_arch_spec);
1557 }
1558 
1561  if (!ParseSectionHeaders())
1562  return nullptr;
1563 
1564  if (id < m_section_headers.size())
1565  return &m_section_headers[id];
1566 
1567  return nullptr;
1568 }
1569 
1571  if (!name || !name[0] || !ParseSectionHeaders())
1572  return 0;
1573  for (size_t i = 1; i < m_section_headers.size(); ++i)
1574  if (m_section_headers[i].section_name == ConstString(name))
1575  return i;
1576  return 0;
1577 }
1578 
1579 static SectionType GetSectionTypeFromName(llvm::StringRef Name) {
1580  if (Name.consume_front(".debug_") || Name.consume_front(".zdebug_")) {
1581  return llvm::StringSwitch<SectionType>(Name)
1582  .Case("abbrev", eSectionTypeDWARFDebugAbbrev)
1583  .Case("abbrev.dwo", eSectionTypeDWARFDebugAbbrevDwo)
1584  .Case("addr", eSectionTypeDWARFDebugAddr)
1585  .Case("aranges", eSectionTypeDWARFDebugAranges)
1586  .Case("cu_index", eSectionTypeDWARFDebugCuIndex)
1587  .Case("frame", eSectionTypeDWARFDebugFrame)
1588  .Case("info", eSectionTypeDWARFDebugInfo)
1589  .Case("info.dwo", eSectionTypeDWARFDebugInfoDwo)
1590  .Cases("line", "line.dwo", eSectionTypeDWARFDebugLine)
1591  .Cases("line_str", "line_str.dwo", eSectionTypeDWARFDebugLineStr)
1592  .Case("loc", eSectionTypeDWARFDebugLoc)
1593  .Case("loc.dwo", eSectionTypeDWARFDebugLocDwo)
1594  .Case("loclists", eSectionTypeDWARFDebugLocLists)
1595  .Case("loclists.dwo", eSectionTypeDWARFDebugLocListsDwo)
1596  .Case("macinfo", eSectionTypeDWARFDebugMacInfo)
1597  .Cases("macro", "macro.dwo", eSectionTypeDWARFDebugMacro)
1598  .Case("names", eSectionTypeDWARFDebugNames)
1599  .Case("pubnames", eSectionTypeDWARFDebugPubNames)
1600  .Case("pubtypes", eSectionTypeDWARFDebugPubTypes)
1601  .Case("ranges", eSectionTypeDWARFDebugRanges)
1602  .Case("rnglists", eSectionTypeDWARFDebugRngLists)
1603  .Case("rnglists.dwo", eSectionTypeDWARFDebugRngListsDwo)
1604  .Case("str", eSectionTypeDWARFDebugStr)
1605  .Case("str.dwo", eSectionTypeDWARFDebugStrDwo)
1606  .Case("str_offsets", eSectionTypeDWARFDebugStrOffsets)
1607  .Case("str_offsets.dwo", eSectionTypeDWARFDebugStrOffsetsDwo)
1608  .Case("tu_index", eSectionTypeDWARFDebugTuIndex)
1609  .Case("types", eSectionTypeDWARFDebugTypes)
1610  .Case("types.dwo", eSectionTypeDWARFDebugTypesDwo)
1611  .Default(eSectionTypeOther);
1612  }
1613  return llvm::StringSwitch<SectionType>(Name)
1614  .Case(".ARM.exidx", eSectionTypeARMexidx)
1615  .Case(".ARM.extab", eSectionTypeARMextab)
1616  .Cases(".bss", ".tbss", eSectionTypeZeroFill)
1617  .Cases(".data", ".tdata", eSectionTypeData)
1618  .Case(".eh_frame", eSectionTypeEHFrame)
1619  .Case(".gnu_debugaltlink", eSectionTypeDWARFGNUDebugAltLink)
1620  .Case(".gosymtab", eSectionTypeGoSymtab)
1621  .Case(".text", eSectionTypeCode)
1622  .Default(eSectionTypeOther);
1623 }
1624 
1626  switch (H.sh_type) {
1627  case SHT_PROGBITS:
1628  if (H.sh_flags & SHF_EXECINSTR)
1629  return eSectionTypeCode;
1630  break;
1631  case SHT_SYMTAB:
1633  case SHT_DYNSYM:
1635  case SHT_RELA:
1636  case SHT_REL:
1638  case SHT_DYNAMIC:
1640  }
1642 }
1643 
1645  switch (Type) {
1646  case eSectionTypeData:
1647  case eSectionTypeZeroFill:
1648  return arch.GetDataByteSize();
1649  case eSectionTypeCode:
1650  return arch.GetCodeByteSize();
1651  default:
1652  return 1;
1653  }
1654 }
1655 
1656 static Permissions GetPermissions(const ELFSectionHeader &H) {
1657  Permissions Perm = Permissions(0);
1658  if (H.sh_flags & SHF_ALLOC)
1659  Perm |= ePermissionsReadable;
1660  if (H.sh_flags & SHF_WRITE)
1661  Perm |= ePermissionsWritable;
1662  if (H.sh_flags & SHF_EXECINSTR)
1663  Perm |= ePermissionsExecutable;
1664  return Perm;
1665 }
1666 
1667 static Permissions GetPermissions(const ELFProgramHeader &H) {
1668  Permissions Perm = Permissions(0);
1669  if (H.p_flags & PF_R)
1670  Perm |= ePermissionsReadable;
1671  if (H.p_flags & PF_W)
1672  Perm |= ePermissionsWritable;
1673  if (H.p_flags & PF_X)
1674  Perm |= ePermissionsExecutable;
1675  return Perm;
1676 }
1677 
1678 namespace {
1679 
1681 
1682 struct SectionAddressInfo {
1683  SectionSP Segment;
1684  VMRange Range;
1685 };
1686 
1687 // (Unlinked) ELF object files usually have 0 for every section address, meaning
1688 // we need to compute synthetic addresses in order for "file addresses" from
1689 // different sections to not overlap. This class handles that logic.
1690 class VMAddressProvider {
1691  using VMMap = llvm::IntervalMap<addr_t, SectionSP, 4,
1692  llvm::IntervalMapHalfOpenInfo<addr_t>>;
1693 
1694  ObjectFile::Type ObjectType;
1695  addr_t NextVMAddress = 0;
1696  VMMap::Allocator Alloc;
1697  VMMap Segments = VMMap(Alloc);
1698  VMMap Sections = VMMap(Alloc);
1700  size_t SegmentCount = 0;
1701  std::string SegmentName;
1702 
1703  VMRange GetVMRange(const ELFSectionHeader &H) {
1704  addr_t Address = H.sh_addr;
1705  addr_t Size = H.sh_flags & SHF_ALLOC ? H.sh_size : 0;
1706  if (ObjectType == ObjectFile::Type::eTypeObjectFile && Segments.empty() && (H.sh_flags & SHF_ALLOC)) {
1707  NextVMAddress =
1708  llvm::alignTo(NextVMAddress, std::max<addr_t>(H.sh_addralign, 1));
1709  Address = NextVMAddress;
1710  NextVMAddress += Size;
1711  }
1712  return VMRange(Address, Size);
1713  }
1714 
1715 public:
1716  VMAddressProvider(ObjectFile::Type Type, llvm::StringRef SegmentName)
1717  : ObjectType(Type), SegmentName(std::string(SegmentName)) {}
1718 
1719  std::string GetNextSegmentName() const {
1720  return llvm::formatv("{0}[{1}]", SegmentName, SegmentCount).str();
1721  }
1722 
1723  llvm::Optional<VMRange> GetAddressInfo(const ELFProgramHeader &H) {
1724  if (H.p_memsz == 0) {
1725  LLDB_LOG(Log, "Ignoring zero-sized {0} segment. Corrupt object file?",
1726  SegmentName);
1727  return llvm::None;
1728  }
1729 
1730  if (Segments.overlaps(H.p_vaddr, H.p_vaddr + H.p_memsz)) {
1731  LLDB_LOG(Log, "Ignoring overlapping {0} segment. Corrupt object file?",
1732  SegmentName);
1733  return llvm::None;
1734  }
1735  return VMRange(H.p_vaddr, H.p_memsz);
1736  }
1737 
1738  llvm::Optional<SectionAddressInfo> GetAddressInfo(const ELFSectionHeader &H) {
1739  VMRange Range = GetVMRange(H);
1740  SectionSP Segment;
1741  auto It = Segments.find(Range.GetRangeBase());
1742  if ((H.sh_flags & SHF_ALLOC) && It.valid()) {
1743  addr_t MaxSize;
1744  if (It.start() <= Range.GetRangeBase()) {
1745  MaxSize = It.stop() - Range.GetRangeBase();
1746  Segment = *It;
1747  } else
1748  MaxSize = It.start() - Range.GetRangeBase();
1749  if (Range.GetByteSize() > MaxSize) {
1750  LLDB_LOG(Log, "Shortening section crossing segment boundaries. "
1751  "Corrupt object file?");
1752  Range.SetByteSize(MaxSize);
1753  }
1754  }
1755  if (Range.GetByteSize() > 0 &&
1756  Sections.overlaps(Range.GetRangeBase(), Range.GetRangeEnd())) {
1757  LLDB_LOG(Log, "Ignoring overlapping section. Corrupt object file?");
1758  return llvm::None;
1759  }
1760  if (Segment)
1761  Range.Slide(-Segment->GetFileAddress());
1762  return SectionAddressInfo{Segment, Range};
1763  }
1764 
1765  void AddSegment(const VMRange &Range, SectionSP Seg) {
1766  Segments.insert(Range.GetRangeBase(), Range.GetRangeEnd(), std::move(Seg));
1767  ++SegmentCount;
1768  }
1769 
1770  void AddSection(SectionAddressInfo Info, SectionSP Sect) {
1771  if (Info.Range.GetByteSize() == 0)
1772  return;
1773  if (Info.Segment)
1774  Info.Range.Slide(Info.Segment->GetFileAddress());
1775  Sections.insert(Info.Range.GetRangeBase(), Info.Range.GetRangeEnd(),
1776  std::move(Sect));
1777  }
1778 };
1779 }
1780 
1781 void ObjectFileELF::CreateSections(SectionList &unified_section_list) {
1782  if (m_sections_up)
1783  return;
1784 
1785  m_sections_up = std::make_unique<SectionList>();
1786  VMAddressProvider regular_provider(GetType(), "PT_LOAD");
1787  VMAddressProvider tls_provider(GetType(), "PT_TLS");
1788 
1789  for (const auto &EnumPHdr : llvm::enumerate(ProgramHeaders())) {
1790  const ELFProgramHeader &PHdr = EnumPHdr.value();
1791  if (PHdr.p_type != PT_LOAD && PHdr.p_type != PT_TLS)
1792  continue;
1793 
1794  VMAddressProvider &provider =
1795  PHdr.p_type == PT_TLS ? tls_provider : regular_provider;
1796  auto InfoOr = provider.GetAddressInfo(PHdr);
1797  if (!InfoOr)
1798  continue;
1799 
1800  uint32_t Log2Align = llvm::Log2_64(std::max<elf_xword>(PHdr.p_align, 1));
1801  SectionSP Segment = std::make_shared<Section>(
1802  GetModule(), this, SegmentID(EnumPHdr.index()),
1803  ConstString(provider.GetNextSegmentName()), eSectionTypeContainer,
1804  InfoOr->GetRangeBase(), InfoOr->GetByteSize(), PHdr.p_offset,
1805  PHdr.p_filesz, Log2Align, /*flags*/ 0);
1806  Segment->SetPermissions(GetPermissions(PHdr));
1807  Segment->SetIsThreadSpecific(PHdr.p_type == PT_TLS);
1808  m_sections_up->AddSection(Segment);
1809 
1810  provider.AddSegment(*InfoOr, std::move(Segment));
1811  }
1812 
1814  if (m_section_headers.empty())
1815  return;
1816 
1817  for (SectionHeaderCollIter I = std::next(m_section_headers.begin());
1818  I != m_section_headers.end(); ++I) {
1819  const ELFSectionHeaderInfo &header = *I;
1820 
1821  ConstString &name = I->section_name;
1822  const uint64_t file_size =
1823  header.sh_type == SHT_NOBITS ? 0 : header.sh_size;
1824 
1825  VMAddressProvider &provider =
1826  header.sh_flags & SHF_TLS ? tls_provider : regular_provider;
1827  auto InfoOr = provider.GetAddressInfo(header);
1828  if (!InfoOr)
1829  continue;
1830 
1831  SectionType sect_type = GetSectionType(header);
1832 
1833  const uint32_t target_bytes_size =
1834  GetTargetByteSize(sect_type, m_arch_spec);
1835 
1836  elf::elf_xword log2align =
1837  (header.sh_addralign == 0) ? 0 : llvm::Log2_64(header.sh_addralign);
1838 
1839  SectionSP section_sp(new Section(
1840  InfoOr->Segment, GetModule(), // Module to which this section belongs.
1841  this, // ObjectFile to which this section belongs and should
1842  // read section data from.
1843  SectionIndex(I), // Section ID.
1844  name, // Section name.
1845  sect_type, // Section type.
1846  InfoOr->Range.GetRangeBase(), // VM address.
1847  InfoOr->Range.GetByteSize(), // VM size in bytes of this section.
1848  header.sh_offset, // Offset of this section in the file.
1849  file_size, // Size of the section as found in the file.
1850  log2align, // Alignment of the section
1851  header.sh_flags, // Flags for this section.
1852  target_bytes_size)); // Number of host bytes per target byte
1853 
1854  section_sp->SetPermissions(GetPermissions(header));
1855  section_sp->SetIsThreadSpecific(header.sh_flags & SHF_TLS);
1856  (InfoOr->Segment ? InfoOr->Segment->GetChildren() : *m_sections_up)
1857  .AddSection(section_sp);
1858  provider.AddSection(std::move(*InfoOr), std::move(section_sp));
1859  }
1860 
1861  // For eTypeDebugInfo files, the Symbol Vendor will take care of updating the
1862  // unified section list.
1863  if (GetType() != eTypeDebugInfo)
1864  unified_section_list = *m_sections_up;
1865 
1866  // If there's a .gnu_debugdata section, we'll try to read the .symtab that's
1867  // embedded in there and replace the one in the original object file (if any).
1868  // If there's none in the orignal object file, we add it to it.
1869  if (auto gdd_obj_file = GetGnuDebugDataObjectFile()) {
1870  if (auto gdd_objfile_section_list = gdd_obj_file->GetSectionList()) {
1871  if (SectionSP symtab_section_sp =
1872  gdd_objfile_section_list->FindSectionByType(
1873  eSectionTypeELFSymbolTable, true)) {
1874  SectionSP module_section_sp = unified_section_list.FindSectionByType(
1876  if (module_section_sp)
1877  unified_section_list.ReplaceSection(module_section_sp->GetID(),
1878  symtab_section_sp);
1879  else
1880  unified_section_list.AddSection(symtab_section_sp);
1881  }
1882  }
1883  }
1884 }
1885 
1886 std::shared_ptr<ObjectFileELF> ObjectFileELF::GetGnuDebugDataObjectFile() {
1887  if (m_gnu_debug_data_object_file != nullptr)
1889 
1890  SectionSP section =
1891  GetSectionList()->FindSectionByName(ConstString(".gnu_debugdata"));
1892  if (!section)
1893  return nullptr;
1894 
1896  GetModule()->ReportWarning(
1897  "No LZMA support found for reading .gnu_debugdata section");
1898  return nullptr;
1899  }
1900 
1901  // Uncompress the data
1902  DataExtractor data;
1903  section->GetSectionData(data);
1904  llvm::SmallVector<uint8_t, 0> uncompressedData;
1905  auto err = lldb_private::lzma::uncompress(data.GetData(), uncompressedData);
1906  if (err) {
1907  GetModule()->ReportWarning(
1908  "An error occurred while decompression the section %s: %s",
1909  section->GetName().AsCString(), llvm::toString(std::move(err)).c_str());
1910  return nullptr;
1911  }
1912 
1913  // Construct ObjectFileELF object from decompressed buffer
1914  DataBufferSP gdd_data_buf(
1915  new DataBufferHeap(uncompressedData.data(), uncompressedData.size()));
1917  llvm::StringRef("gnu_debugdata"));
1919  GetModule(), gdd_data_buf, 0, &fspec, 0, gdd_data_buf->GetByteSize()));
1920 
1921  // This line is essential; otherwise a breakpoint can be set but not hit.
1922  m_gnu_debug_data_object_file->SetType(ObjectFile::eTypeDebugInfo);
1923 
1924  ArchSpec spec = m_gnu_debug_data_object_file->GetArchitecture();
1925  if (spec && m_gnu_debug_data_object_file->SetModulesArchitecture(spec))
1927 
1928  return nullptr;
1929 }
1930 
1931 // Find the arm/aarch64 mapping symbol character in the given symbol name.
1932 // Mapping symbols have the form of "$<char>[.<any>]*". Additionally we
1933 // recognize cases when the mapping symbol prefixed by an arbitrary string
1934 // because if a symbol prefix added to each symbol in the object file with
1935 // objcopy then the mapping symbols are also prefixed.
1936 static char FindArmAarch64MappingSymbol(const char *symbol_name) {
1937  if (!symbol_name)
1938  return '\0';
1939 
1940  const char *dollar_pos = ::strchr(symbol_name, '$');
1941  if (!dollar_pos || dollar_pos[1] == '\0')
1942  return '\0';
1943 
1944  if (dollar_pos[2] == '\0' || dollar_pos[2] == '.')
1945  return dollar_pos[1];
1946  return '\0';
1947 }
1948 
1949 #define STO_MIPS_ISA (3 << 6)
1950 #define STO_MICROMIPS (2 << 6)
1951 #define IS_MICROMIPS(ST_OTHER) (((ST_OTHER)&STO_MIPS_ISA) == STO_MICROMIPS)
1952 
1953 // private
1954 unsigned ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id,
1955  SectionList *section_list,
1956  const size_t num_symbols,
1957  const DataExtractor &symtab_data,
1958  const DataExtractor &strtab_data) {
1959  ELFSymbol symbol;
1960  lldb::offset_t offset = 0;
1961 
1962  static ConstString text_section_name(".text");
1963  static ConstString init_section_name(".init");
1964  static ConstString fini_section_name(".fini");
1965  static ConstString ctors_section_name(".ctors");
1966  static ConstString dtors_section_name(".dtors");
1967 
1968  static ConstString data_section_name(".data");
1969  static ConstString rodata_section_name(".rodata");
1970  static ConstString rodata1_section_name(".rodata1");
1971  static ConstString data2_section_name(".data1");
1972  static ConstString bss_section_name(".bss");
1973  static ConstString opd_section_name(".opd"); // For ppc64
1974 
1975  // On Android the oatdata and the oatexec symbols in the oat and odex files
1976  // covers the full .text section what causes issues with displaying unusable
1977  // symbol name to the user and very slow unwinding speed because the
1978  // instruction emulation based unwind plans try to emulate all instructions
1979  // in these symbols. Don't add these symbols to the symbol list as they have
1980  // no use for the debugger and they are causing a lot of trouble. Filtering
1981  // can't be restricted to Android because this special object file don't
1982  // contain the note section specifying the environment to Android but the
1983  // custom extension and file name makes it highly unlikely that this will
1984  // collide with anything else.
1985  ConstString file_extension = m_file.GetFileNameExtension();
1986  bool skip_oatdata_oatexec =
1987  file_extension == ".oat" || file_extension == ".odex";
1988 
1989  ArchSpec arch = GetArchitecture();
1990  ModuleSP module_sp(GetModule());
1991  SectionList *module_section_list =
1992  module_sp ? module_sp->GetSectionList() : nullptr;
1993 
1994  // Local cache to avoid doing a FindSectionByName for each symbol. The "const
1995  // char*" key must came from a ConstString object so they can be compared by
1996  // pointer
1997  std::unordered_map<const char *, lldb::SectionSP> section_name_to_section;
1998 
1999  unsigned i;
2000  for (i = 0; i < num_symbols; ++i) {
2001  if (!symbol.Parse(symtab_data, &offset))
2002  break;
2003 
2004  const char *symbol_name = strtab_data.PeekCStr(symbol.st_name);
2005  if (!symbol_name)
2006  symbol_name = "";
2007 
2008  // No need to add non-section symbols that have no names
2009  if (symbol.getType() != STT_SECTION &&
2010  (symbol_name == nullptr || symbol_name[0] == '\0'))
2011  continue;
2012 
2013  // Skipping oatdata and oatexec sections if it is requested. See details
2014  // above the definition of skip_oatdata_oatexec for the reasons.
2015  if (skip_oatdata_oatexec && (::strcmp(symbol_name, "oatdata") == 0 ||
2016  ::strcmp(symbol_name, "oatexec") == 0))
2017  continue;
2018 
2019  SectionSP symbol_section_sp;
2020  SymbolType symbol_type = eSymbolTypeInvalid;
2021  Elf64_Half shndx = symbol.st_shndx;
2022 
2023  switch (shndx) {
2024  case SHN_ABS:
2025  symbol_type = eSymbolTypeAbsolute;
2026  break;
2027  case SHN_UNDEF:
2028  symbol_type = eSymbolTypeUndefined;
2029  break;
2030  default:
2031  symbol_section_sp = section_list->FindSectionByID(shndx);
2032  break;
2033  }
2034 
2035  // If a symbol is undefined do not process it further even if it has a STT
2036  // type
2037  if (symbol_type != eSymbolTypeUndefined) {
2038  switch (symbol.getType()) {
2039  default:
2040  case STT_NOTYPE:
2041  // The symbol's type is not specified.
2042  break;
2043 
2044  case STT_OBJECT:
2045  // The symbol is associated with a data object, such as a variable, an
2046  // array, etc.
2047  symbol_type = eSymbolTypeData;
2048  break;
2049 
2050  case STT_FUNC:
2051  // The symbol is associated with a function or other executable code.
2052  symbol_type = eSymbolTypeCode;
2053  break;
2054 
2055  case STT_SECTION:
2056  // The symbol is associated with a section. Symbol table entries of
2057  // this type exist primarily for relocation and normally have STB_LOCAL
2058  // binding.
2059  break;
2060 
2061  case STT_FILE:
2062  // Conventionally, the symbol's name gives the name of the source file
2063  // associated with the object file. A file symbol has STB_LOCAL
2064  // binding, its section index is SHN_ABS, and it precedes the other
2065  // STB_LOCAL symbols for the file, if it is present.
2066  symbol_type = eSymbolTypeSourceFile;
2067  break;
2068 
2069  case STT_GNU_IFUNC:
2070  // The symbol is associated with an indirect function. The actual
2071  // function will be resolved if it is referenced.
2072  symbol_type = eSymbolTypeResolver;
2073  break;
2074  }
2075  }
2076 
2077  if (symbol_type == eSymbolTypeInvalid && symbol.getType() != STT_SECTION) {
2078  if (symbol_section_sp) {
2079  ConstString sect_name = symbol_section_sp->GetName();
2080  if (sect_name == text_section_name || sect_name == init_section_name ||
2081  sect_name == fini_section_name || sect_name == ctors_section_name ||
2082  sect_name == dtors_section_name) {
2083  symbol_type = eSymbolTypeCode;
2084  } else if (sect_name == data_section_name ||
2085  sect_name == data2_section_name ||
2086  sect_name == rodata_section_name ||
2087  sect_name == rodata1_section_name ||
2088  sect_name == bss_section_name) {
2089  symbol_type = eSymbolTypeData;
2090  }
2091  }
2092  }
2093 
2094  int64_t symbol_value_offset = 0;
2095  uint32_t additional_flags = 0;
2096 
2097  if (arch.IsValid()) {
2098  if (arch.GetMachine() == llvm::Triple::arm) {
2099  if (symbol.getBinding() == STB_LOCAL) {
2100  char mapping_symbol = FindArmAarch64MappingSymbol(symbol_name);
2101  if (symbol_type == eSymbolTypeCode) {
2102  switch (mapping_symbol) {
2103  case 'a':
2104  // $a[.<any>]* - marks an ARM instruction sequence
2105  m_address_class_map[symbol.st_value] = AddressClass::eCode;
2106  break;
2107  case 'b':
2108  case 't':
2109  // $b[.<any>]* - marks a THUMB BL instruction sequence
2110  // $t[.<any>]* - marks a THUMB instruction sequence
2111  m_address_class_map[symbol.st_value] =
2112  AddressClass::eCodeAlternateISA;
2113  break;
2114  case 'd':
2115  // $d[.<any>]* - marks a data item sequence (e.g. lit pool)
2116  m_address_class_map[symbol.st_value] = AddressClass::eData;
2117  break;
2118  }
2119  }
2120  if (mapping_symbol)
2121  continue;
2122  }
2123  } else if (arch.GetMachine() == llvm::Triple::aarch64) {
2124  if (symbol.getBinding() == STB_LOCAL) {
2125  char mapping_symbol = FindArmAarch64MappingSymbol(symbol_name);
2126  if (symbol_type == eSymbolTypeCode) {
2127  switch (mapping_symbol) {
2128  case 'x':
2129  // $x[.<any>]* - marks an A64 instruction sequence
2130  m_address_class_map[symbol.st_value] = AddressClass::eCode;
2131  break;
2132  case 'd':
2133  // $d[.<any>]* - marks a data item sequence (e.g. lit pool)
2134  m_address_class_map[symbol.st_value] = AddressClass::eData;
2135  break;
2136  }
2137  }
2138  if (mapping_symbol)
2139  continue;
2140  }
2141  }
2142 
2143  if (arch.GetMachine() == llvm::Triple::arm) {
2144  if (symbol_type == eSymbolTypeCode) {
2145  if (symbol.st_value & 1) {
2146  // Subtracting 1 from the address effectively unsets the low order
2147  // bit, which results in the address actually pointing to the
2148  // beginning of the symbol. This delta will be used below in
2149  // conjunction with symbol.st_value to produce the final
2150  // symbol_value that we store in the symtab.
2151  symbol_value_offset = -1;
2152  m_address_class_map[symbol.st_value ^ 1] =
2153  AddressClass::eCodeAlternateISA;
2154  } else {
2155  // This address is ARM
2156  m_address_class_map[symbol.st_value] = AddressClass::eCode;
2157  }
2158  }
2159  }
2160 
2161  /*
2162  * MIPS:
2163  * The bit #0 of an address is used for ISA mode (1 for microMIPS, 0 for
2164  * MIPS).
2165  * This allows processor to switch between microMIPS and MIPS without any
2166  * need
2167  * for special mode-control register. However, apart from .debug_line,
2168  * none of
2169  * the ELF/DWARF sections set the ISA bit (for symbol or section). Use
2170  * st_other
2171  * flag to check whether the symbol is microMIPS and then set the address
2172  * class
2173  * accordingly.
2174  */
2175  if (arch.IsMIPS()) {
2176  if (IS_MICROMIPS(symbol.st_other))
2177  m_address_class_map[symbol.st_value] = AddressClass::eCodeAlternateISA;
2178  else if ((symbol.st_value & 1) && (symbol_type == eSymbolTypeCode)) {
2179  symbol.st_value = symbol.st_value & (~1ull);
2180  m_address_class_map[symbol.st_value] = AddressClass::eCodeAlternateISA;
2181  } else {
2182  if (symbol_type == eSymbolTypeCode)
2183  m_address_class_map[symbol.st_value] = AddressClass::eCode;
2184  else if (symbol_type == eSymbolTypeData)
2185  m_address_class_map[symbol.st_value] = AddressClass::eData;
2186  else
2187  m_address_class_map[symbol.st_value] = AddressClass::eUnknown;
2188  }
2189  }
2190  }
2191 
2192  // symbol_value_offset may contain 0 for ARM symbols or -1 for THUMB
2193  // symbols. See above for more details.
2194  uint64_t symbol_value = symbol.st_value + symbol_value_offset;
2195 
2196  if (symbol_section_sp == nullptr && shndx == SHN_ABS &&
2197  symbol.st_size != 0) {
2198  // We don't have a section for a symbol with non-zero size. Create a new
2199  // section for it so the address range covered by the symbol is also
2200  // covered by the module (represented through the section list). It is
2201  // needed so module lookup for the addresses covered by this symbol will
2202  // be successfull. This case happens for absolute symbols.
2203  ConstString fake_section_name(std::string(".absolute.") + symbol_name);
2204  symbol_section_sp =
2205  std::make_shared<Section>(module_sp, this, SHN_ABS, fake_section_name,
2206  eSectionTypeAbsoluteAddress, symbol_value,
2207  symbol.st_size, 0, 0, 0, SHF_ALLOC);
2208 
2209  module_section_list->AddSection(symbol_section_sp);
2210  section_list->AddSection(symbol_section_sp);
2211  }
2212 
2213  if (symbol_section_sp &&
2214  CalculateType() != ObjectFile::Type::eTypeObjectFile)
2215  symbol_value -= symbol_section_sp->GetFileAddress();
2216 
2217  if (symbol_section_sp && module_section_list &&
2218  module_section_list != section_list) {
2219  ConstString sect_name = symbol_section_sp->GetName();
2220  auto section_it = section_name_to_section.find(sect_name.GetCString());
2221  if (section_it == section_name_to_section.end())
2222  section_it =
2223  section_name_to_section
2224  .emplace(sect_name.GetCString(),
2225  module_section_list->FindSectionByName(sect_name))
2226  .first;
2227  if (section_it->second)
2228  symbol_section_sp = section_it->second;
2229  }
2230 
2231  bool is_global = symbol.getBinding() == STB_GLOBAL;
2232  uint32_t flags = symbol.st_other << 8 | symbol.st_info | additional_flags;
2233  llvm::StringRef symbol_ref(symbol_name);
2234 
2235  // Symbol names may contain @VERSION suffixes. Find those and strip them
2236  // temporarily.
2237  size_t version_pos = symbol_ref.find('@');
2238  bool has_suffix = version_pos != llvm::StringRef::npos;
2239  llvm::StringRef symbol_bare = symbol_ref.substr(0, version_pos);
2240  Mangled mangled(symbol_bare);
2241 
2242  // Now append the suffix back to mangled and unmangled names. Only do it if
2243  // the demangling was successful (string is not empty).
2244  if (has_suffix) {
2245  llvm::StringRef suffix = symbol_ref.substr(version_pos);
2246 
2247  llvm::StringRef mangled_name = mangled.GetMangledName().GetStringRef();
2248  if (!mangled_name.empty())
2249  mangled.SetMangledName(ConstString((mangled_name + suffix).str()));
2250 
2251  ConstString demangled = mangled.GetDemangledName();
2252  llvm::StringRef demangled_name = demangled.GetStringRef();
2253  if (!demangled_name.empty())
2254  mangled.SetDemangledName(ConstString((demangled_name + suffix).str()));
2255  }
2256 
2257  // In ELF all symbol should have a valid size but it is not true for some
2258  // function symbols coming from hand written assembly. As none of the
2259  // function symbol should have 0 size we try to calculate the size for
2260  // these symbols in the symtab with saying that their original size is not
2261  // valid.
2262  bool symbol_size_valid =
2263  symbol.st_size != 0 || symbol.getType() != STT_FUNC;
2264 
2265  Symbol dc_symbol(
2266  i + start_id, // ID is the original symbol table index.
2267  mangled,
2268  symbol_type, // Type of this symbol
2269  is_global, // Is this globally visible?
2270  false, // Is this symbol debug info?
2271  false, // Is this symbol a trampoline?
2272  false, // Is this symbol artificial?
2273  AddressRange(symbol_section_sp, // Section in which this symbol is
2274  // defined or null.
2275  symbol_value, // Offset in section or symbol value.
2276  symbol.st_size), // Size in bytes of this symbol.
2277  symbol_size_valid, // Symbol size is valid
2278  has_suffix, // Contains linker annotations?
2279  flags); // Symbol flags.
2280  if (symbol.getBinding() == STB_WEAK)
2281  dc_symbol.SetIsWeak(true);
2282  symtab->AddSymbol(dc_symbol);
2283  }
2284  return i;
2285 }
2286 
2288  user_id_t start_id,
2289  lldb_private::Section *symtab) {
2290  if (symtab->GetObjectFile() != this) {
2291  // If the symbol table section is owned by a different object file, have it
2292  // do the parsing.
2293  ObjectFileELF *obj_file_elf =
2294  static_cast<ObjectFileELF *>(symtab->GetObjectFile());
2295  return obj_file_elf->ParseSymbolTable(symbol_table, start_id, symtab);
2296  }
2297 
2298  // Get section list for this object file.
2299  SectionList *section_list = m_sections_up.get();
2300  if (!section_list)
2301  return 0;
2302 
2303  user_id_t symtab_id = symtab->GetID();
2304  const ELFSectionHeaderInfo *symtab_hdr = GetSectionHeaderByIndex(symtab_id);
2305  assert(symtab_hdr->sh_type == SHT_SYMTAB ||
2306  symtab_hdr->sh_type == SHT_DYNSYM);
2307 
2308  // sh_link: section header index of associated string table.
2309  user_id_t strtab_id = symtab_hdr->sh_link;
2310  Section *strtab = section_list->FindSectionByID(strtab_id).get();
2311 
2312  if (symtab && strtab) {
2313  assert(symtab->GetObjectFile() == this);
2314  assert(strtab->GetObjectFile() == this);
2315 
2316  DataExtractor symtab_data;
2317  DataExtractor strtab_data;
2318  if (ReadSectionData(symtab, symtab_data) &&
2319  ReadSectionData(strtab, strtab_data)) {
2320  size_t num_symbols = symtab_data.GetByteSize() / symtab_hdr->sh_entsize;
2321 
2322  return ParseSymbols(symbol_table, start_id, section_list, num_symbols,
2323  symtab_data, strtab_data);
2324  }
2325  }
2326 
2327  return 0;
2328 }
2329 
2331  if (m_dynamic_symbols.size())
2332  return m_dynamic_symbols.size();
2333 
2334  SectionList *section_list = GetSectionList();
2335  if (!section_list)
2336  return 0;
2337 
2338  // Find the SHT_DYNAMIC section.
2339  Section *dynsym =
2341  .get();
2342  if (!dynsym)
2343  return 0;
2344  assert(dynsym->GetObjectFile() == this);
2345 
2346  ELFDynamic symbol;
2347  DataExtractor dynsym_data;
2348  if (ReadSectionData(dynsym, dynsym_data)) {
2349  const lldb::offset_t section_size = dynsym_data.GetByteSize();
2350  lldb::offset_t cursor = 0;
2351 
2352  while (cursor < section_size) {
2353  if (!symbol.Parse(dynsym_data, &cursor))
2354  break;
2355 
2356  m_dynamic_symbols.push_back(symbol);
2357  }
2358  }
2359 
2360  return m_dynamic_symbols.size();
2361 }
2362 
2364  if (!ParseDynamicSymbols())
2365  return nullptr;
2366 
2369  for (; I != E; ++I) {
2370  ELFDynamic *symbol = &*I;
2371 
2372  if (symbol->d_tag == tag)
2373  return symbol;
2374  }
2375 
2376  return nullptr;
2377 }
2378 
2380  // DT_PLTREL
2381  // This member specifies the type of relocation entry to which the
2382  // procedure linkage table refers. The d_val member holds DT_REL or
2383  // DT_RELA, as appropriate. All relocations in a procedure linkage table
2384  // must use the same relocation.
2385  const ELFDynamic *symbol = FindDynamicSymbol(DT_PLTREL);
2386 
2387  if (symbol)
2388  return symbol->d_val;
2389 
2390  return 0;
2391 }
2392 
2393 // Returns the size of the normal plt entries and the offset of the first
2394 // normal plt entry. The 0th entry in the plt table is usually a resolution
2395 // entry which have different size in some architectures then the rest of the
2396 // plt entries.
2397 static std::pair<uint64_t, uint64_t>
2399  const ELFSectionHeader *plt_hdr) {
2400  const elf_xword num_relocations = rel_hdr->sh_size / rel_hdr->sh_entsize;
2401 
2402  // Clang 3.3 sets entsize to 4 for 32-bit binaries, but the plt entries are
2403  // 16 bytes. So round the entsize up by the alignment if addralign is set.
2404  elf_xword plt_entsize =
2405  plt_hdr->sh_addralign
2406  ? llvm::alignTo(plt_hdr->sh_entsize, plt_hdr->sh_addralign)
2407  : plt_hdr->sh_entsize;
2408 
2409  // Some linkers e.g ld for arm, fill plt_hdr->sh_entsize field incorrectly.
2410  // PLT entries relocation code in general requires multiple instruction and
2411  // should be greater than 4 bytes in most cases. Try to guess correct size
2412  // just in case.
2413  if (plt_entsize <= 4) {
2414  // The linker haven't set the plt_hdr->sh_entsize field. Try to guess the
2415  // size of the plt entries based on the number of entries and the size of
2416  // the plt section with the assumption that the size of the 0th entry is at
2417  // least as big as the size of the normal entries and it isn't much bigger
2418  // then that.
2419  if (plt_hdr->sh_addralign)
2420  plt_entsize = plt_hdr->sh_size / plt_hdr->sh_addralign /
2421  (num_relocations + 1) * plt_hdr->sh_addralign;
2422  else
2423  plt_entsize = plt_hdr->sh_size / (num_relocations + 1);
2424  }
2425 
2426  elf_xword plt_offset = plt_hdr->sh_size - num_relocations * plt_entsize;
2427 
2428  return std::make_pair(plt_entsize, plt_offset);
2429 }
2430 
2431 static unsigned ParsePLTRelocations(
2432  Symtab *symbol_table, user_id_t start_id, unsigned rel_type,
2433  const ELFHeader *hdr, const ELFSectionHeader *rel_hdr,
2434  const ELFSectionHeader *plt_hdr, const ELFSectionHeader *sym_hdr,
2435  const lldb::SectionSP &plt_section_sp, DataExtractor &rel_data,
2436  DataExtractor &symtab_data, DataExtractor &strtab_data) {
2437  ELFRelocation rel(rel_type);
2438  ELFSymbol symbol;
2439  lldb::offset_t offset = 0;
2440 
2441  uint64_t plt_offset, plt_entsize;
2442  std::tie(plt_entsize, plt_offset) =
2443  GetPltEntrySizeAndOffset(rel_hdr, plt_hdr);
2444  const elf_xword num_relocations = rel_hdr->sh_size / rel_hdr->sh_entsize;
2445 
2446  typedef unsigned (*reloc_info_fn)(const ELFRelocation &rel);
2447  reloc_info_fn reloc_type;
2448  reloc_info_fn reloc_symbol;
2449 
2450  if (hdr->Is32Bit()) {
2451  reloc_type = ELFRelocation::RelocType32;
2452  reloc_symbol = ELFRelocation::RelocSymbol32;
2453  } else {
2454  reloc_type = ELFRelocation::RelocType64;
2455  reloc_symbol = ELFRelocation::RelocSymbol64;
2456  }
2457 
2458  unsigned slot_type = hdr->GetRelocationJumpSlotType();
2459  unsigned i;
2460  for (i = 0; i < num_relocations; ++i) {
2461  if (!rel.Parse(rel_data, &offset))
2462  break;
2463 
2464  if (reloc_type(rel) != slot_type)
2465  continue;
2466 
2467  lldb::offset_t symbol_offset = reloc_symbol(rel) * sym_hdr->sh_entsize;
2468  if (!symbol.Parse(symtab_data, &symbol_offset))
2469  break;
2470 
2471  const char *symbol_name = strtab_data.PeekCStr(symbol.st_name);
2472  uint64_t plt_index = plt_offset + i * plt_entsize;
2473 
2474  Symbol jump_symbol(
2475  i + start_id, // Symbol table index
2476  symbol_name, // symbol name.
2477  eSymbolTypeTrampoline, // Type of this symbol
2478  false, // Is this globally visible?
2479  false, // Is this symbol debug info?
2480  true, // Is this symbol a trampoline?
2481  true, // Is this symbol artificial?
2482  plt_section_sp, // Section in which this symbol is defined or null.
2483  plt_index, // Offset in section or symbol value.
2484  plt_entsize, // Size in bytes of this symbol.
2485  true, // Size is valid
2486  false, // Contains linker annotations?
2487  0); // Symbol flags.
2488 
2489  symbol_table->AddSymbol(jump_symbol);
2490  }
2491 
2492  return i;
2493 }
2494 
2495 unsigned
2497  const ELFSectionHeaderInfo *rel_hdr,
2498  user_id_t rel_id) {
2499  assert(rel_hdr->sh_type == SHT_RELA || rel_hdr->sh_type == SHT_REL);
2500 
2501  // The link field points to the associated symbol table.
2502  user_id_t symtab_id = rel_hdr->sh_link;
2503 
2504  // If the link field doesn't point to the appropriate symbol name table then
2505  // try to find it by name as some compiler don't fill in the link fields.
2506  if (!symtab_id)
2507  symtab_id = GetSectionIndexByName(".dynsym");
2508 
2509  // Get PLT section. We cannot use rel_hdr->sh_info, since current linkers
2510  // point that to the .got.plt or .got section instead of .plt.
2511  user_id_t plt_id = GetSectionIndexByName(".plt");
2512 
2513  if (!symtab_id || !plt_id)
2514  return 0;
2515 
2516  const ELFSectionHeaderInfo *plt_hdr = GetSectionHeaderByIndex(plt_id);
2517  if (!plt_hdr)
2518  return 0;
2519 
2520  const ELFSectionHeaderInfo *sym_hdr = GetSectionHeaderByIndex(symtab_id);
2521  if (!sym_hdr)
2522  return 0;
2523 
2524  SectionList *section_list = m_sections_up.get();
2525  if (!section_list)
2526  return 0;
2527 
2528  Section *rel_section = section_list->FindSectionByID(rel_id).get();
2529  if (!rel_section)
2530  return 0;
2531 
2532  SectionSP plt_section_sp(section_list->FindSectionByID(plt_id));
2533  if (!plt_section_sp)
2534  return 0;
2535 
2536  Section *symtab = section_list->FindSectionByID(symtab_id).get();
2537  if (!symtab)
2538  return 0;
2539 
2540  // sh_link points to associated string table.
2541  Section *strtab = section_list->FindSectionByID(sym_hdr->sh_link).get();
2542  if (!strtab)
2543  return 0;
2544 
2545  DataExtractor rel_data;
2546  if (!ReadSectionData(rel_section, rel_data))
2547  return 0;
2548 
2549  DataExtractor symtab_data;
2550  if (!ReadSectionData(symtab, symtab_data))
2551  return 0;
2552 
2553  DataExtractor strtab_data;
2554  if (!ReadSectionData(strtab, strtab_data))
2555  return 0;
2556 
2557  unsigned rel_type = PLTRelocationType();
2558  if (!rel_type)
2559  return 0;
2560 
2561  return ParsePLTRelocations(symbol_table, start_id, rel_type, &m_header,
2562  rel_hdr, plt_hdr, sym_hdr, plt_section_sp,
2563  rel_data, symtab_data, strtab_data);
2564 }
2565 
2567  Symtab *symtab, const ELFHeader *hdr, const ELFSectionHeader *rel_hdr,
2568  const ELFSectionHeader *symtab_hdr, const ELFSectionHeader *debug_hdr,
2569  DataExtractor &rel_data, DataExtractor &symtab_data,
2570  DataExtractor &debug_data, Section *rel_section) {
2571  ELFRelocation rel(rel_hdr->sh_type);
2572  lldb::addr_t offset = 0;
2573  const unsigned num_relocations = rel_hdr->sh_size / rel_hdr->sh_entsize;
2574  typedef unsigned (*reloc_info_fn)(const ELFRelocation &rel);
2575  reloc_info_fn reloc_type;
2576  reloc_info_fn reloc_symbol;
2577 
2578  if (hdr->Is32Bit()) {
2579  reloc_type = ELFRelocation::RelocType32;
2580  reloc_symbol = ELFRelocation::RelocSymbol32;
2581  } else {
2582  reloc_type = ELFRelocation::RelocType64;
2583  reloc_symbol = ELFRelocation::RelocSymbol64;
2584  }
2585 
2586  for (unsigned i = 0; i < num_relocations; ++i) {
2587  if (!rel.Parse(rel_data, &offset))
2588  break;
2589 
2590  Symbol *symbol = nullptr;
2591 
2592  if (hdr->Is32Bit()) {
2593  switch (reloc_type(rel)) {
2594  case R_386_32:
2595  case R_386_PC32:
2596  default:
2597  // FIXME: This asserts with this input:
2598  //
2599  // foo.cpp
2600  // int main(int argc, char **argv) { return 0; }
2601  //
2602  // clang++.exe --target=i686-unknown-linux-gnu -g -c foo.cpp -o foo.o
2603  //
2604  // and running this on the foo.o module.
2605  assert(false && "unexpected relocation type");
2606  }
2607  } else {
2608  switch (reloc_type(rel)) {
2609  case R_AARCH64_ABS64:
2610  case R_X86_64_64: {
2611  symbol = symtab->FindSymbolByID(reloc_symbol(rel));
2612  if (symbol) {
2613  addr_t value = symbol->GetAddressRef().GetFileAddress();
2614  DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
2615  uint64_t *dst = reinterpret_cast<uint64_t *>(
2616  data_buffer_sp->GetBytes() + rel_section->GetFileOffset() +
2617  ELFRelocation::RelocOffset64(rel));
2618  uint64_t val_offset = value + ELFRelocation::RelocAddend64(rel);
2619  memcpy(dst, &val_offset, sizeof(uint64_t));
2620  }
2621  break;
2622  }
2623  case R_X86_64_32:
2624  case R_X86_64_32S:
2625  case R_AARCH64_ABS32: {
2626  symbol = symtab->FindSymbolByID(reloc_symbol(rel));
2627  if (symbol) {
2628  addr_t value = symbol->GetAddressRef().GetFileAddress();
2629  value += ELFRelocation::RelocAddend32(rel);
2630  if ((reloc_type(rel) == R_X86_64_32 && (value > UINT32_MAX)) ||
2631  (reloc_type(rel) == R_X86_64_32S &&
2632  ((int64_t)value > INT32_MAX && (int64_t)value < INT32_MIN)) ||
2633  (reloc_type(rel) == R_AARCH64_ABS32 &&
2634  ((int64_t)value > INT32_MAX && (int64_t)value < INT32_MIN))) {
2635  Log *log =
2637  LLDB_LOGF(log, "Failed to apply debug info relocations");
2638  break;
2639  }
2640  uint32_t truncated_addr = (value & 0xFFFFFFFF);
2641  DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer();
2642  uint32_t *dst = reinterpret_cast<uint32_t *>(
2643  data_buffer_sp->GetBytes() + rel_section->GetFileOffset() +
2644  ELFRelocation::RelocOffset32(rel));
2645  memcpy(dst, &truncated_addr, sizeof(uint32_t));
2646  }
2647  break;
2648  }
2649  case R_X86_64_PC32:
2650  default:
2651  assert(false && "unexpected relocation type");
2652  }
2653  }
2654  }
2655 
2656  return 0;
2657 }
2658 
2660  user_id_t rel_id,
2661  lldb_private::Symtab *thetab) {
2662  assert(rel_hdr->sh_type == SHT_RELA || rel_hdr->sh_type == SHT_REL);
2663 
2664  // Parse in the section list if needed.
2665  SectionList *section_list = GetSectionList();
2666  if (!section_list)
2667  return 0;
2668 
2669  user_id_t symtab_id = rel_hdr->sh_link;
2670  user_id_t debug_id = rel_hdr->sh_info;
2671 
2672  const ELFSectionHeader *symtab_hdr = GetSectionHeaderByIndex(symtab_id);
2673  if (!symtab_hdr)
2674  return 0;
2675 
2676  const ELFSectionHeader *debug_hdr = GetSectionHeaderByIndex(debug_id);
2677  if (!debug_hdr)
2678  return 0;
2679 
2680  Section *rel = section_list->FindSectionByID(rel_id).get();
2681  if (!rel)
2682  return 0;
2683 
2684  Section *symtab = section_list->FindSectionByID(symtab_id).get();
2685  if (!symtab)
2686  return 0;
2687 
2688  Section *debug = section_list->FindSectionByID(debug_id).get();
2689  if (!debug)
2690  return 0;
2691 
2692  DataExtractor rel_data;
2693  DataExtractor symtab_data;
2694  DataExtractor debug_data;
2695 
2696  if (GetData(rel->GetFileOffset(), rel->GetFileSize(), rel_data) &&
2697  GetData(symtab->GetFileOffset(), symtab->GetFileSize(), symtab_data) &&
2698  GetData(debug->GetFileOffset(), debug->GetFileSize(), debug_data)) {
2699  ApplyRelocations(thetab, &m_header, rel_hdr, symtab_hdr, debug_hdr,
2700  rel_data, symtab_data, debug_data, debug);
2701  }
2702 
2703  return 0;
2704 }
2705 
2707  ModuleSP module_sp(GetModule());
2708  if (!module_sp)
2709  return nullptr;
2710 
2711  Progress progress(llvm::formatv("Parsing symbol table for {0}",
2712  m_file.GetFilename().AsCString("<Unknown>")));
2713 
2714  // We always want to use the main object file so we (hopefully) only have one
2715  // cached copy of our symtab, dynamic sections, etc.
2716  ObjectFile *module_obj_file = module_sp->GetObjectFile();
2717  if (module_obj_file && module_obj_file != this)
2718  return module_obj_file->GetSymtab();
2719 
2720  if (m_symtab_up == nullptr) {
2721  SectionList *section_list = module_sp->GetSectionList();
2722  if (!section_list)
2723  return nullptr;
2724 
2725  uint64_t symbol_id = 0;
2726  std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
2727 
2728  // Sharable objects and dynamic executables usually have 2 distinct symbol
2729  // tables, one named ".symtab", and the other ".dynsym". The dynsym is a
2730  // smaller version of the symtab that only contains global symbols. The
2731  // information found in the dynsym is therefore also found in the symtab,
2732  // while the reverse is not necessarily true.
2733  Section *symtab =
2734  section_list->FindSectionByType(eSectionTypeELFSymbolTable, true).get();
2735  if (symtab) {
2736  m_symtab_up = std::make_unique<Symtab>(symtab->GetObjectFile());
2737  symbol_id += ParseSymbolTable(m_symtab_up.get(), symbol_id, symtab);
2738  }
2739 
2740  // The symtab section is non-allocable and can be stripped, while the
2741  // .dynsym section which should always be always be there. To support the
2742  // minidebuginfo case we parse .dynsym when there's a .gnu_debuginfo
2743  // section, nomatter if .symtab was already parsed or not. This is because
2744  // minidebuginfo normally removes the .symtab symbols which have their
2745  // matching .dynsym counterparts.
2746  if (!symtab ||
2747  GetSectionList()->FindSectionByName(ConstString(".gnu_debugdata"))) {
2748  Section *dynsym =
2750  .get();
2751  if (dynsym) {
2752  if (!m_symtab_up)
2753  m_symtab_up = std::make_unique<Symtab>(dynsym->GetObjectFile());
2754  symbol_id += ParseSymbolTable(m_symtab_up.get(), symbol_id, dynsym);
2755  }
2756  }
2757 
2758  // DT_JMPREL
2759  // If present, this entry's d_ptr member holds the address of
2760  // relocation
2761  // entries associated solely with the procedure linkage table.
2762  // Separating
2763  // these relocation entries lets the dynamic linker ignore them during
2764  // process initialization, if lazy binding is enabled. If this entry is
2765  // present, the related entries of types DT_PLTRELSZ and DT_PLTREL must
2766  // also be present.
2767  const ELFDynamic *symbol = FindDynamicSymbol(DT_JMPREL);
2768  if (symbol) {
2769  // Synthesize trampoline symbols to help navigate the PLT.
2770  addr_t addr = symbol->d_ptr;
2771  Section *reloc_section =
2772  section_list->FindSectionContainingFileAddress(addr).get();
2773  if (reloc_section) {
2774  user_id_t reloc_id = reloc_section->GetID();
2775  const ELFSectionHeaderInfo *reloc_header =
2776  GetSectionHeaderByIndex(reloc_id);
2777  if (reloc_header) {
2778  if (m_symtab_up == nullptr)
2779  m_symtab_up =
2780  std::make_unique<Symtab>(reloc_section->GetObjectFile());
2781 
2782  ParseTrampolineSymbols(m_symtab_up.get(), symbol_id, reloc_header,
2783  reloc_id);
2784  }
2785  }
2786  }
2787 
2788  if (DWARFCallFrameInfo *eh_frame =
2789  GetModule()->GetUnwindTable().GetEHFrameInfo()) {
2790  if (m_symtab_up == nullptr)
2791  m_symtab_up = std::make_unique<Symtab>(this);
2792  ParseUnwindSymbols(m_symtab_up.get(), eh_frame);
2793  }
2794 
2795  // If we still don't have any symtab then create an empty instance to avoid
2796  // do the section lookup next time.
2797  if (m_symtab_up == nullptr)
2798  m_symtab_up = std::make_unique<Symtab>(this);
2799 
2800  // In the event that there's no symbol entry for the entry point we'll
2801  // artificially create one. We delegate to the symtab object the figuring
2802  // out of the proper size, this will usually make it span til the next
2803  // symbol it finds in the section. This means that if there are missing
2804  // symbols the entry point might span beyond its function definition.
2805  // We're fine with this as it doesn't make it worse than not having a
2806  // symbol entry at all.
2807  if (CalculateType() == eTypeExecutable) {
2808  ArchSpec arch = GetArchitecture();
2809  auto entry_point_addr = GetEntryPointAddress();
2810  bool is_valid_entry_point =
2811  entry_point_addr.IsValid() && entry_point_addr.IsSectionOffset();
2812  addr_t entry_point_file_addr = entry_point_addr.GetFileAddress();
2813  if (is_valid_entry_point && !m_symtab_up->FindSymbolContainingFileAddress(
2814  entry_point_file_addr)) {
2815  uint64_t symbol_id = m_symtab_up->GetNumSymbols();
2816  Symbol symbol(symbol_id,
2817  GetNextSyntheticSymbolName().GetCString(), // Symbol name.
2818  eSymbolTypeCode, // Type of this symbol.
2819  true, // Is this globally visible?
2820  false, // Is this symbol debug info?
2821  false, // Is this symbol a trampoline?
2822  true, // Is this symbol artificial?
2823  entry_point_addr.GetSection(), // Section where this
2824  // symbol is defined.
2825  0, // Offset in section or symbol value.
2826  0, // Size.
2827  false, // Size is valid.
2828  false, // Contains linker annotations?
2829  0); // Symbol flags.
2830  m_symtab_up->AddSymbol(symbol);
2831  // When the entry point is arm thumb we need to explicitly set its
2832  // class address to reflect that. This is important because expression
2833  // evaluation relies on correctly setting a breakpoint at this
2834  // address.
2835  if (arch.GetMachine() == llvm::Triple::arm &&
2836  (entry_point_file_addr & 1))
2837  m_address_class_map[entry_point_file_addr ^ 1] =
2838  AddressClass::eCodeAlternateISA;
2839  else
2840  m_address_class_map[entry_point_file_addr] = AddressClass::eCode;
2841  }
2842  }
2843 
2844  m_symtab_up->CalculateSymbolSizes();
2845  }
2846 
2847  return m_symtab_up.get();
2848 }
2849 
2851 {
2852  static const char *debug_prefix = ".debug";
2853 
2854  // Set relocated bit so we stop getting called, regardless of whether we
2855  // actually relocate.
2856  section->SetIsRelocated(true);
2857 
2858  // We only relocate in ELF relocatable files
2859  if (CalculateType() != eTypeObjectFile)
2860  return;
2861 
2862  const char *section_name = section->GetName().GetCString();
2863  // Can't relocate that which can't be named
2864  if (section_name == nullptr)
2865  return;
2866 
2867  // We don't relocate non-debug sections at the moment
2868  if (strncmp(section_name, debug_prefix, strlen(debug_prefix)))
2869  return;
2870 
2871  // Relocation section names to look for
2872  std::string needle = std::string(".rel") + section_name;
2873  std::string needlea = std::string(".rela") + section_name;
2874 
2875  for (SectionHeaderCollIter I = m_section_headers.begin();
2876  I != m_section_headers.end(); ++I) {
2877  if (I->sh_type == SHT_RELA || I->sh_type == SHT_REL) {
2878  const char *hay_name = I->section_name.GetCString();
2879  if (hay_name == nullptr)
2880  continue;
2881  if (needle == hay_name || needlea == hay_name) {
2882  const ELFSectionHeader &reloc_header = *I;
2883  user_id_t reloc_id = SectionIndex(I);
2884  RelocateDebugSections(&reloc_header, reloc_id, GetSymtab());
2885  break;
2886  }
2887  }
2888  }
2889 }
2890 
2892  DWARFCallFrameInfo *eh_frame) {
2893  SectionList *section_list = GetSectionList();
2894  if (!section_list)
2895  return;
2896 
2897  // First we save the new symbols into a separate list and add them to the
2898  // symbol table after we collected all symbols we want to add. This is
2899  // neccessary because adding a new symbol invalidates the internal index of
2900  // the symtab what causing the next lookup to be slow because it have to
2901  // recalculate the index first.
2902  std::vector<Symbol> new_symbols;
2903 
2904  size_t num_symbols = symbol_table->GetNumSymbols();
2905  uint64_t last_symbol_id =
2906  num_symbols ? symbol_table->SymbolAtIndex(num_symbols - 1)->GetID() : 0;
2907  eh_frame->ForEachFDEEntries([&](lldb::addr_t file_addr, uint32_t size,
2908  dw_offset_t) {
2909  Symbol *symbol = symbol_table->FindSymbolAtFileAddress(file_addr);
2910  if (symbol) {
2911  if (!symbol->GetByteSizeIsValid()) {
2912  symbol->SetByteSize(size);
2913  symbol->SetSizeIsSynthesized(true);
2914  }
2915  } else {
2916  SectionSP section_sp =
2917  section_list->FindSectionContainingFileAddress(file_addr);
2918  if (section_sp) {
2919  addr_t offset = file_addr - section_sp->GetFileAddress();
2920  const char *symbol_name = GetNextSyntheticSymbolName().GetCString();
2921  uint64_t symbol_id = ++last_symbol_id;
2922  Symbol eh_symbol(
2923  symbol_id, // Symbol table index.
2924  symbol_name, // Symbol name.
2925  eSymbolTypeCode, // Type of this symbol.
2926  true, // Is this globally visible?
2927  false, // Is this symbol debug info?
2928  false, // Is this symbol a trampoline?
2929  true, // Is this symbol artificial?
2930  section_sp, // Section in which this symbol is defined or null.
2931  offset, // Offset in section or symbol value.
2932  0, // Size: Don't specify the size as an FDE can
2933  false, // Size is valid: cover multiple symbols.
2934  false, // Contains linker annotations?
2935  0); // Symbol flags.
2936  new_symbols.push_back(eh_symbol);
2937  }
2938  }
2939  return true;
2940  });
2941 
2942  for (const Symbol &s : new_symbols)
2943  symbol_table->AddSymbol(s);
2944 }
2945 
2947  // TODO: determine this for ELF
2948  return false;
2949 }
2950 
2951 //===----------------------------------------------------------------------===//
2952 // Dump
2953 //
2954 // Dump the specifics of the runtime file container (such as any headers
2955 // segments, sections, etc).
2957  ModuleSP module_sp(GetModule());
2958  if (!module_sp) {
2959  return;
2960  }
2961 
2962  std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
2963  s->Printf("%p: ", static_cast<void *>(this));
2964  s->Indent();
2965  s->PutCString("ObjectFileELF");
2966 
2967  ArchSpec header_arch = GetArchitecture();
2968 
2969  *s << ", file = '" << m_file
2970  << "', arch = " << header_arch.GetArchitectureName() << "\n";
2971 
2972  DumpELFHeader(s, m_header);
2973  s->EOL();
2975  s->EOL();
2977  s->EOL();
2978  SectionList *section_list = GetSectionList();
2979  if (section_list)
2980  section_list->Dump(s->AsRawOstream(), s->GetIndentLevel(), nullptr, true,
2981  UINT32_MAX);
2982  Symtab *symtab = GetSymtab();
2983  if (symtab)
2984  symtab->Dump(s, nullptr, eSortOrderNone);
2985  s->EOL();
2987  s->EOL();
2988 }
2989 
2990 // DumpELFHeader
2991 //
2992 // Dump the ELF header to the specified output stream
2994  s->PutCString("ELF Header\n");
2995  s->Printf("e_ident[EI_MAG0 ] = 0x%2.2x\n", header.e_ident[EI_MAG0]);
2996  s->Printf("e_ident[EI_MAG1 ] = 0x%2.2x '%c'\n", header.e_ident[EI_MAG1],
2997  header.e_ident[EI_MAG1]);
2998  s->Printf("e_ident[EI_MAG2 ] = 0x%2.2x '%c'\n", header.e_ident[EI_MAG2],
2999  header.e_ident[EI_MAG2]);
3000  s->Printf("e_ident[EI_MAG3 ] = 0x%2.2x '%c'\n", header.e_ident[EI_MAG3],
3001  header.e_ident[EI_MAG3]);
3002 
3003  s->Printf("e_ident[EI_CLASS ] = 0x%2.2x\n", header.e_ident[EI_CLASS]);
3004  s->Printf("e_ident[EI_DATA ] = 0x%2.2x ", header.e_ident[EI_DATA]);
3005  DumpELFHeader_e_ident_EI_DATA(s, header.e_ident[EI_DATA]);
3006  s->Printf("\ne_ident[EI_VERSION] = 0x%2.2x\n", header.e_ident[EI_VERSION]);
3007  s->Printf("e_ident[EI_PAD ] = 0x%2.2x\n", header.e_ident[EI_PAD]);
3008 
3009  s->Printf("e_type = 0x%4.4x ", header.e_type);
3010  DumpELFHeader_e_type(s, header.e_type);
3011  s->Printf("\ne_machine = 0x%4.4x\n", header.e_machine);
3012  s->Printf("e_version = 0x%8.8x\n", header.e_version);
3013  s->Printf("e_entry = 0x%8.8" PRIx64 "\n", header.e_entry);
3014  s->Printf("e_phoff = 0x%8.8" PRIx64 "\n", header.e_phoff);
3015  s->Printf("e_shoff = 0x%8.8" PRIx64 "\n", header.e_shoff);
3016  s->Printf("e_flags = 0x%8.8x\n", header.e_flags);
3017  s->Printf("e_ehsize = 0x%4.4x\n", header.e_ehsize);
3018  s->Printf("e_phentsize = 0x%4.4x\n", header.e_phentsize);
3019  s->Printf("e_phnum = 0x%8.8x\n", header.e_phnum);
3020  s->Printf("e_shentsize = 0x%4.4x\n", header.e_shentsize);
3021  s->Printf("e_shnum = 0x%8.8x\n", header.e_shnum);
3022  s->Printf("e_shstrndx = 0x%8.8x\n", header.e_shstrndx);
3023 }
3024 
3025 // DumpELFHeader_e_type
3026 //
3027 // Dump an token value for the ELF header member e_type
3029  switch (e_type) {
3030  case ET_NONE:
3031  *s << "ET_NONE";
3032  break;
3033  case ET_REL:
3034  *s << "ET_REL";
3035  break;
3036  case ET_EXEC:
3037  *s << "ET_EXEC";
3038  break;
3039  case ET_DYN:
3040  *s << "ET_DYN";
3041  break;
3042  case ET_CORE:
3043  *s << "ET_CORE";
3044  break;
3045  default:
3046  break;
3047  }
3048 }
3049 
3050 // DumpELFHeader_e_ident_EI_DATA
3051 //
3052 // Dump an token value for the ELF header member e_ident[EI_DATA]
3054  unsigned char ei_data) {
3055  switch (ei_data) {
3056  case ELFDATANONE:
3057  *s << "ELFDATANONE";
3058  break;
3059  case ELFDATA2LSB:
3060  *s << "ELFDATA2LSB - Little Endian";
3061  break;
3062  case ELFDATA2MSB:
3063  *s << "ELFDATA2MSB - Big Endian";
3064  break;
3065  default:
3066  break;
3067  }
3068 }
3069 
3070 // DumpELFProgramHeader
3071 //
3072 // Dump a single ELF program header to the specified output stream
3074  const ELFProgramHeader &ph) {
3076  s->Printf(" %8.8" PRIx64 " %8.8" PRIx64 " %8.8" PRIx64, ph.p_offset,
3077  ph.p_vaddr, ph.p_paddr);
3078  s->Printf(" %8.8" PRIx64 " %8.8" PRIx64 " %8.8x (", ph.p_filesz, ph.p_memsz,
3079  ph.p_flags);
3080 
3082  s->Printf(") %8.8" PRIx64, ph.p_align);
3083 }
3084 
3085 // DumpELFProgramHeader_p_type
3086 //
3087 // Dump an token value for the ELF program header member p_type which describes
3088 // the type of the program header
3090  const int kStrWidth = 15;
3091  switch (p_type) {
3092  CASE_AND_STREAM(s, PT_NULL, kStrWidth);
3093  CASE_AND_STREAM(s, PT_LOAD, kStrWidth);
3094  CASE_AND_STREAM(s, PT_DYNAMIC, kStrWidth);
3095  CASE_AND_STREAM(s, PT_INTERP, kStrWidth);
3096  CASE_AND_STREAM(s, PT_NOTE, kStrWidth);
3097  CASE_AND_STREAM(s, PT_SHLIB, kStrWidth);
3098  CASE_AND_STREAM(s, PT_PHDR, kStrWidth);
3099  CASE_AND_STREAM(s, PT_TLS, kStrWidth);
3100  CASE_AND_STREAM(s, PT_GNU_EH_FRAME, kStrWidth);
3101  default:
3102  s->Printf("0x%8.8x%*s", p_type, kStrWidth - 10, "");
3103  break;
3104  }
3105 }
3106 
3107 // DumpELFProgramHeader_p_flags
3108 //
3109 // Dump an token value for the ELF program header member p_flags
3111  *s << ((p_flags & PF_X) ? "PF_X" : " ")
3112  << (((p_flags & PF_X) && (p_flags & PF_W)) ? '+' : ' ')
3113  << ((p_flags & PF_W) ? "PF_W" : " ")
3114  << (((p_flags & PF_W) && (p_flags & PF_R)) ? '+' : ' ')
3115  << ((p_flags & PF_R) ? "PF_R" : " ");
3116 }
3117 
3118 // DumpELFProgramHeaders
3119 //
3120 // Dump all of the ELF program header to the specified output stream
3122  if (!ParseProgramHeaders())
3123  return;
3124 
3125  s->PutCString("Program Headers\n");
3126  s->PutCString("IDX p_type p_offset p_vaddr p_paddr "
3127  "p_filesz p_memsz p_flags p_align\n");
3128  s->PutCString("==== --------------- -------- -------- -------- "
3129  "-------- -------- ------------------------- --------\n");
3130 
3131  for (const auto &H : llvm::enumerate(m_program_headers)) {
3132  s->Format("[{0,2}] ", H.index());
3134  s->EOL();
3135  }
3136 }
3137 
3138 // DumpELFSectionHeader
3139 //
3140 // Dump a single ELF section header to the specified output stream
3142  const ELFSectionHeaderInfo &sh) {
3143  s->Printf("%8.8x ", sh.sh_name);
3145  s->Printf(" %8.8" PRIx64 " (", sh.sh_flags);
3147  s->Printf(") %8.8" PRIx64 " %8.8" PRIx64 " %8.8" PRIx64, sh.sh_addr,
3148  sh.sh_offset, sh.sh_size);
3149  s->Printf(" %8.8x %8.8x", sh.sh_link, sh.sh_info);
3150  s->Printf(" %8.8" PRIx64 " %8.8" PRIx64, sh.sh_addralign, sh.sh_entsize);
3151 }
3152 
3153 // DumpELFSectionHeader_sh_type
3154 //
3155 // Dump an token value for the ELF section header member sh_type which
3156 // describes the type of the section
3158  const int kStrWidth = 12;
3159  switch (sh_type) {
3160  CASE_AND_STREAM(s, SHT_NULL, kStrWidth);
3161  CASE_AND_STREAM(s, SHT_PROGBITS, kStrWidth);
3162  CASE_AND_STREAM(s, SHT_SYMTAB, kStrWidth);
3163  CASE_AND_STREAM(s, SHT_STRTAB, kStrWidth);
3164  CASE_AND_STREAM(s, SHT_RELA, kStrWidth);
3165  CASE_AND_STREAM(s, SHT_HASH, kStrWidth);
3166  CASE_AND_STREAM(s, SHT_DYNAMIC, kStrWidth);
3167  CASE_AND_STREAM(s, SHT_NOTE, kStrWidth);
3168  CASE_AND_STREAM(s, SHT_NOBITS, kStrWidth);
3169  CASE_AND_STREAM(s, SHT_REL, kStrWidth);
3170  CASE_AND_STREAM(s, SHT_SHLIB, kStrWidth);
3171  CASE_AND_STREAM(s, SHT_DYNSYM, kStrWidth);
3172  CASE_AND_STREAM(s, SHT_LOPROC, kStrWidth);
3173  CASE_AND_STREAM(s, SHT_HIPROC, kStrWidth);
3174  CASE_AND_STREAM(s, SHT_LOUSER, kStrWidth);
3175  CASE_AND_STREAM(s, SHT_HIUSER, kStrWidth);
3176  default:
3177  s->Printf("0x%8.8x%*s", sh_type, kStrWidth - 10, "");
3178  break;
3179  }
3180 }
3181 
3182 // DumpELFSectionHeader_sh_flags
3183 //
3184 // Dump an token value for the ELF section header member sh_flags
3186  elf_xword sh_flags) {
3187  *s << ((sh_flags & SHF_WRITE) ? "WRITE" : " ")
3188  << (((sh_flags & SHF_WRITE) && (sh_flags & SHF_ALLOC)) ? '+' : ' ')
3189  << ((sh_flags & SHF_ALLOC) ? "ALLOC" : " ")
3190  << (((sh_flags & SHF_ALLOC) && (sh_flags & SHF_EXECINSTR)) ? '+' : ' ')
3191  << ((sh_flags & SHF_EXECINSTR) ? "EXECINSTR" : " ");
3192 }
3193 
3194 // DumpELFSectionHeaders
3195 //
3196 // Dump all of the ELF section header to the specified output stream
3198  if (!ParseSectionHeaders())
3199  return;
3200 
3201  s->PutCString("Section Headers\n");
3202  s->PutCString("IDX name type flags "
3203  "addr offset size link info addralgn "
3204  "entsize Name\n");
3205  s->PutCString("==== -------- ------------ -------------------------------- "
3206  "-------- -------- -------- -------- -------- -------- "
3207  "-------- ====================\n");
3208 
3209  uint32_t idx = 0;
3211  I != m_section_headers.end(); ++I, ++idx) {
3212  s->Printf("[%2u] ", idx);
3214  const char *section_name = I->section_name.AsCString("");
3215  if (section_name)
3216  *s << ' ' << section_name << "\n";
3217  }
3218 }
3219 
3221  size_t num_modules = ParseDependentModules();
3222 
3223  if (num_modules > 0) {
3224  s->PutCString("Dependent Modules:\n");
3225  for (unsigned i = 0; i < num_modules; ++i) {
3226  const FileSpec &spec = m_filespec_up->GetFileSpecAtIndex(i);
3227  s->Printf(" %s\n", spec.GetFilename().GetCString());
3228  }
3229  }
3230 }
3231 
3233  if (!ParseHeader())
3234  return ArchSpec();
3235 
3236  if (m_section_headers.empty()) {
3237  // Allow elf notes to be parsed which may affect the detected architecture.
3239  }
3240 
3241  if (CalculateType() == eTypeCoreFile &&
3243  // Core files don't have section headers yet they have PT_NOTE program
3244  // headers that might shed more light on the architecture
3245  for (const elf::ELFProgramHeader &H : ProgramHeaders()) {
3246  if (H.p_type != PT_NOTE || H.p_offset == 0 || H.p_filesz == 0)
3247  continue;
3248  DataExtractor data;
3249  if (data.SetData(m_data, H.p_offset, H.p_filesz) == H.p_filesz) {
3250  UUID uuid;
3252  }
3253  }
3254  }
3255  return m_arch_spec;
3256 }
3257 
3259  switch (m_header.e_type) {
3260  case llvm::ELF::ET_NONE:
3261  // 0 - No file type
3262  return eTypeUnknown;
3263 
3264  case llvm::ELF::ET_REL:
3265  // 1 - Relocatable file
3266  return eTypeObjectFile;
3267 
3268  case llvm::ELF::ET_EXEC:
3269  // 2 - Executable file
3270  return eTypeExecutable;
3271 
3272  case llvm::ELF::ET_DYN:
3273  // 3 - Shared object file
3274  return eTypeSharedLibrary;
3275 
3276  case ET_CORE:
3277  // 4 - Core file
3278  return eTypeCoreFile;
3279 
3280  default:
3281  break;
3282  }
3283  return eTypeUnknown;
3284 }
3285 
3287  switch (m_header.e_type) {
3288  case llvm::ELF::ET_NONE:
3289  // 0 - No file type
3290  return eStrataUnknown;
3291 
3292  case llvm::ELF::ET_REL:
3293  // 1 - Relocatable file
3294  return eStrataUnknown;
3295 
3296  case llvm::ELF::ET_EXEC:
3297  // 2 - Executable file
3298  // TODO: is there any way to detect that an executable is a kernel
3299  // related executable by inspecting the program headers, section headers,
3300  // symbols, or any other flag bits???
3301  return eStrataUser;
3302 
3303  case llvm::ELF::ET_DYN:
3304  // 3 - Shared object file
3305  // TODO: is there any way to detect that an shared library is a kernel
3306  // related executable by inspecting the program headers, section headers,
3307  // symbols, or any other flag bits???
3308  return eStrataUnknown;
3309 
3310  case ET_CORE:
3311  // 4 - Core file
3312  // TODO: is there any way to detect that an core file is a kernel
3313  // related executable by inspecting the program headers, section headers,
3314  // symbols, or any other flag bits???
3315  return eStrataUnknown;
3316 
3317  default:
3318  break;
3319  }
3320  return eStrataUnknown;
3321 }
3322 
3324  lldb::offset_t section_offset, void *dst,
3325  size_t dst_len) {
3326  // If some other objectfile owns this data, pass this to them.
3327  if (section->GetObjectFile() != this)
3328  return section->GetObjectFile()->ReadSectionData(section, section_offset,
3329  dst, dst_len);
3330 
3331  if (!section->Test(SHF_COMPRESSED))
3332  return ObjectFile::ReadSectionData(section, section_offset, dst, dst_len);
3333 
3334  // For compressed sections we need to read to full data to be able to
3335  // decompress.
3336  DataExtractor data;
3337  ReadSectionData(section, data);
3338  return data.CopyData(section_offset, dst_len, dst);
3339 }
3340 
3342  DataExtractor &section_data) {
3343  // If some other objectfile owns this data, pass this to them.
3344  if (section->GetObjectFile() != this)
3345  return section->GetObjectFile()->ReadSectionData(section, section_data);
3346 
3347  size_t result = ObjectFile::ReadSectionData(section, section_data);
3348  if (result == 0 || !llvm::object::Decompressor::isCompressedELFSection(
3349  section->Get(), section->GetName().GetStringRef()))
3350  return result;
3351 
3352  auto Decompressor = llvm::object::Decompressor::create(
3353  section->GetName().GetStringRef(),
3354  {reinterpret_cast<const char *>(section_data.GetDataStart()),
3355  size_t(section_data.GetByteSize())},
3357  if (!Decompressor) {
3358  GetModule()->ReportWarning(
3359  "Unable to initialize decompressor for section '%s': %s",
3360  section->GetName().GetCString(),
3361  llvm::toString(Decompressor.takeError()).c_str());
3362  section_data.Clear();
3363  return 0;
3364  }
3365 
3366  auto buffer_sp =
3367  std::make_shared<DataBufferHeap>(Decompressor->getDecompressedSize(), 0);
3368  if (auto error = Decompressor->decompress(
3369  {reinterpret_cast<char *>(buffer_sp->GetBytes()),
3370  size_t(buffer_sp->GetByteSize())})) {
3371  GetModule()->ReportWarning(
3372  "Decompression of section '%s' failed: %s",
3373  section->GetName().GetCString(),
3374  llvm::toString(std::move(error)).c_str());
3375  section_data.Clear();
3376  return 0;
3377  }
3378 
3379  section_data.SetData(buffer_sp);
3380  return buffer_sp->GetByteSize();
3381 }
3382 
3383 llvm::ArrayRef<ELFProgramHeader> ObjectFileELF::ProgramHeaders() {
3385  return m_program_headers;
3386 }
3387 
3389  return DataExtractor(m_data, H.p_offset, H.p_filesz);
3390 }
3391 
3393  for (const ELFProgramHeader &H : ProgramHeaders()) {
3394  if (H.p_paddr != 0)
3395  return true;
3396  }
3397  return false;
3398 }
3399 
3400 std::vector<ObjectFile::LoadableData>
3402  // Create a list of loadable data from loadable segments, using physical
3403  // addresses if they aren't all null
3404  std::vector<LoadableData> loadables;
3405  bool should_use_paddr = AnySegmentHasPhysicalAddress();
3406  for (const ELFProgramHeader &H : ProgramHeaders()) {
3407  LoadableData loadable;
3408  if (H.p_type != llvm::ELF::PT_LOAD)
3409  continue;
3410  loadable.Dest = should_use_paddr ? H.p_paddr : H.p_vaddr;
3411  if (loadable.Dest == LLDB_INVALID_ADDRESS)
3412  continue;
3413  if (H.p_filesz == 0)
3414  continue;
3415  auto segment_data = GetSegmentData(H);
3416  loadable.Contents = llvm::ArrayRef<uint8_t>(segment_data.GetDataStart(),
3417  segment_data.GetByteSize());
3418  loadables.push_back(loadable);
3419  }
3420  return loadables;
3421 }
ObjectFileELF::StripLinkerSymbolAnnotations
llvm::StringRef StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const override
Definition: ObjectFileELF.cpp:1547
lldb_private::SectionLoadList::SetSectionLoadAddress
bool SetSectionLoadAddress(const lldb::SectionSP &section_sp, lldb::addr_t load_addr, bool warn_multiple=false)
Definition: SectionLoadList.cpp:63
ObjectFileELF::m_filespec_up
std::unique_ptr< lldb_private::FileSpecList > m_filespec_up
List of file specifications corresponding to the modules (shared libraries) on which this object file...
Definition: ObjectFileELF.h:217
ObjectFileELF::m_dynamic_symbols
DynamicSymbolColl m_dynamic_symbols
Collection of symbols from the dynamic table.
Definition: ObjectFileELF.h:209
elf::ELFProgramHeader::p_align
elf_xword p_align
Segment alignment constraint.
Definition: ELFHeader.h:200
lldb_private::SectionList::ReplaceSection
bool ReplaceSection(lldb::user_id_t sect_id, const lldb::SectionSP &section_sp, uint32_t depth=UINT32_MAX)
Definition: Section.cpp:447
lldb_private::Stream::Format
void Format(const char *format, Args &&... args)
Definition: Stream.h:309
lldb_private::UUID
Definition: UUID.h:23
lldb::eSectionTypeDWARFDebugLoc
@ eSectionTypeDWARFDebugLoc
Definition: lldb-enumerations.h:669
lldb_private::DataExtractor::GetSharedDataBuffer
lldb::DataBufferSP & GetSharedDataBuffer()
Definition: DataExtractor.h:796
lldb_private::SectionList::FindSectionContainingFileAddress
lldb::SectionSP FindSectionContainingFileAddress(lldb::addr_t addr, uint32_t depth=UINT32_MAX) const
Definition: Section.cpp:543
lldb_private::DataExtractor::GetULEB128
uint64_t GetULEB128(lldb::offset_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
Definition: DataExtractor.cpp:845
ObjectFileELF::DumpELFSectionHeader_sh_type
static void DumpELFSectionHeader_sh_type(lldb_private::Stream *s, elf::elf_word sh_type)
Definition: ObjectFileELF.cpp:3157
lldb_private::Range::GetRangeBase
BaseType GetRangeBase() const
Definition: RangeMap.h:46
ObjectFileELF::GetSymtab
lldb_private::Symtab * GetSymtab() override
Gets the symbol table for the currently selected architecture (and object for archives).
Definition: ObjectFileELF.cpp:2706
ObjectFileELF::m_gnu_debug_data_object_file
std::shared_ptr< ObjectFileELF > m_gnu_debug_data_object_file
Object file parsed from .gnu_debugdata section (.
Definition: ObjectFileELF.h:213
lldb::eSectionTypeDWARFDebugRngListsDwo
@ eSectionTypeDWARFDebugRngListsDwo
Definition: lldb-enumerations.h:705
lldb_private::FileSpec::GetLastPathComponent
ConstString GetLastPathComponent() const
Definition: FileSpec.cpp:415
ObjectFileELF::Initialize
static void Initialize()
Definition: ObjectFileELF.cpp:328
ObjectFileELF::SectionHeaderCollIter
SectionHeaderColl::iterator SectionHeaderCollIter
Definition: ObjectFileELF.h:178
lldb_private::SectionList::FindSectionByName
lldb::SectionSP FindSectionByName(ConstString section_dstr) const
Definition: Section.cpp:484
ObjectFileELF::CreateMemoryInstance
static lldb_private::ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)
Definition: ObjectFileELF.cpp:390
lldb_private::ArchSpec::eMIPS_ABI_FP_DOUBLE
@ eMIPS_ABI_FP_DOUBLE
Definition: ArchSpec.h:79
ObjectFileELF::GetModuleSpecifications
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)
Definition: ObjectFileELF.cpp:513
elf::ELFSymbol::st_size
elf_xword st_size
Size of the symbol or zero.
Definition: ELFHeader.h:226
LLDB_SCOPED_TIMERF
#define LLDB_SCOPED_TIMERF(...)
Definition: Timer.h:80
lldb_private::ArchSpec
Definition: ArchSpec.h:33
elf::ELFSectionHeader::sh_info
elf_word sh_info
Extra section info (overloaded).
Definition: ELFHeader.h:167
lldb_private::ArchSpec::IsMIPS
bool IsMIPS() const
if MIPS architecture return true.
Definition: ArchSpec.cpp:545
ObjectFileELF::ProgramHeaders
llvm::ArrayRef< elf::ELFProgramHeader > ProgramHeaders()
Definition: ObjectFileELF.cpp:3383
elf::ELFSectionHeader::sh_type
elf_word sh_type
Section type.
Definition: ELFHeader.h:161
lldb_private::ObjectFile::GetFileSpec
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition: ObjectFile.h:290
lldb_private::DataExtractor::GetAddress
uint64_t GetAddress(lldb::offset_t *offset_ptr) const
Extract an address from *offset_ptr.
Definition: DataExtractor.cpp:652
lldb_private::lzma::uncompress
llvm::Error uncompress(llvm::ArrayRef< uint8_t > InputBuffer, llvm::SmallVectorImpl< uint8_t > &Uncompressed)
Definition: LZMA.cpp:28
FileSystem.h
lldb_private::ArchSpec::eMIPSABI_EABI64
@ eMIPSABI_EABI64
Definition: ArchSpec.h:72
UNUSED_IF_ASSERT_DISABLED
#define UNUSED_IF_ASSERT_DISABLED(x)
Definition: lldb-defines.h:136
lldb_private::minidump::MinidumpContext_x86_32_Flags::Segments
@ Segments
lldb_private::Address::IsValid
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:332
lldb::eSymbolTypeCode
@ eSymbolTypeCode
Definition: lldb-enumerations.h:615
lldb_private::SectionList::Dump
void Dump(llvm::raw_ostream &s, unsigned indent, Target *target, bool show_header, uint32_t depth) const
Definition: Section.cpp:570
ObjectFileELF::m_gnu_debuglink_crc
uint32_t m_gnu_debuglink_crc
Definition: ObjectFileELF.h:200
elf::ELFHeader
Definition: ELFHeader.h:56
FindArmAarch64MappingSymbol
static char FindArmAarch64MappingSymbol(const char *symbol_name)
Definition: ObjectFileELF.cpp:1936
ObjectFileELF::GetGnuDebugDataObjectFile
std::shared_ptr< ObjectFileELF > GetGnuDebugDataObjectFile()
Takes the .gnu_debugdata and returns the decompressed object file that is stored within that section.
Definition: ObjectFileELF.cpp:1886
elf::ELFSectionHeader::sh_offset
elf_off sh_offset
Start of section from beginning of file.
Definition: ELFHeader.h:164
lldb_private::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:667
elf::elf_xword
uint64_t elf_xword
Definition: ELFHeader.h:47
ModuleSpec.h
elf::ELFProgramHeader::p_vaddr
elf_addr p_vaddr
Virtual address of segment in memory.
Definition: ELFHeader.h:196
ObjectFileELF::ObjectFileELF
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)
ObjectFileELF::ID
static char ID
Definition: ObjectFileELF.h:93
lldb_private::AddressClass
AddressClass
Definition: lldb-private-enumerations.h:48
elf::ELFHeader::HasHeaderExtension
bool HasHeaderExtension() const
Check if there should be header extension in section header #0.
Definition: ELFHeader.cpp:81
lldb_private::Symbol
Definition: Symbol.h:20
ObjectFileELF::FindDynamicSymbol
const elf::ELFDynamic * FindDynamicSymbol(unsigned tag)
Definition: ObjectFileELF.cpp:2363
elf::ELFHeader::GetRelocationJumpSlotType
unsigned GetRelocationJumpSlotType() const
The jump slot relocation type of this ELF.
Definition: ELFHeader.cpp:176
elf::ELFSymbol::st_shndx
elf_half st_shndx
Section to which this symbol applies.
Definition: ELFHeader.h:230
ObjectFileELF::GetPluginDescriptionStatic
static const char * GetPluginDescriptionStatic()
Definition: ObjectFileELF.cpp:343
lldb::eSymbolTypeInvalid
@ eSymbolTypeInvalid
Definition: lldb-enumerations.h:613
ObjectFileELF::RefineModuleDetailsFromNote
static lldb_private::Status RefineModuleDetailsFromNote(lldb_private::DataExtractor &data, lldb_private::ArchSpec &arch_spec, lldb_private::UUID &uuid)
Definition: ObjectFileELF.cpp:1014
elf::ELFHeader::Parse
bool Parse(lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFHeader entry starting at position offset and update the data extractor with the address s...
Definition: ELFHeader.cpp:114
elf::ELFHeader::e_version
elf_word e_version
Version of object file (always 1).
Definition: ELFHeader.h:62
elf::ELFSectionHeader::sh_flags
elf_xword sh_flags
Section attributes.
Definition: ELFHeader.h:162
ObjectFileELF::ParseProgramHeaders
bool ParseProgramHeaders()
Parses all section headers present in this object file and populates m_program_headers.
Definition: ObjectFileELF.cpp:1009
LIBLLDB_LOG_MODULES
#define LIBLLDB_LOG_MODULES
Definition: Logging.h:35
ObjectFileELF::GetBaseAddress
lldb_private::Address GetBaseAddress() override
Returns base address of this object file.
Definition: ObjectFileELF.cpp:902
lldb_private::ObjectFile::GetSymtab
virtual Symtab * GetSymtab()=0
Gets the symbol table for the currently selected architecture (and object for archives).
lldb_private::ObjectFile::eTypeExecutable
@ eTypeExecutable
A normal executable.
Definition: ObjectFile.h:69
lldb::eSectionTypeDWARFDebugAranges
@ eSectionTypeDWARFDebugAranges
Definition: lldb-enumerations.h:664
lldb_private::UUID::IsValid
bool IsValid() const
Definition: UUID.h:79
elf::ELFHeader::e_ident
unsigned char e_ident[llvm::ELF::EI_NIDENT]
ELF file identification.
Definition: ELFHeader.h:57
lldb_private::SectionList::GetSize
size_t GetSize() const
Definition: Section.h:74
elf::ELFSymbol::Parse
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFSymbol entry from the given DataExtractor starting at position offset.
Definition: ELFHeader.cpp:319
lldb::eSymbolTypeTrampoline
@ eSymbolTypeTrampoline
Definition: lldb-enumerations.h:618
lldb::eSectionTypeELFSymbolTable
@ eSectionTypeELFSymbolTable
Elf SHT_SYMTAB section.
Definition: lldb-enumerations.h:681
lldb_private::ModuleSpecList
Definition: ModuleSpec.h:281
lldb_private::ModuleSpecList::Append
void Append(const ModuleSpec &spec)
Definition: ModuleSpec.h:314
lldb::eSectionTypeDWARFDebugStrOffsetsDwo
@ eSectionTypeDWARFDebugStrOffsetsDwo
Definition: lldb-enumerations.h:703
elf::ELFDynamic::d_val
elf_xword d_val
Integer value of the table entry.
Definition: ELFHeader.h:279
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb::eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugRanges
Definition: lldb-enumerations.h:674
lldb::eSectionTypeDWARFDebugMacro
@ eSectionTypeDWARFDebugMacro
Definition: lldb-enumerations.h:671
LZMA.h
lldb_private::ArchSpec::eMIPS_ABI_FP_XX
@ eMIPS_ABI_FP_XX
Definition: ArchSpec.h:83
elf::ELFHeader::e_flags
elf_word e_flags
Processor specific flags.
Definition: ELFHeader.h:61
ObjectFileELF::ProgramHeaderColl
std::vector< elf::ELFProgramHeader > ProgramHeaderColl
Definition: ObjectFileELF.h:171
lldb::eSectionTypeDWARFDebugInfoDwo
@ eSectionTypeDWARFDebugInfoDwo
Definition: lldb-enumerations.h:701
lldb::eSectionTypeDWARFDebugFrame
@ eSectionTypeDWARFDebugFrame
Definition: lldb-enumerations.h:666
Module.h
lldb::eSectionTypeDWARFDebugLine
@ eSectionTypeDWARFDebugLine
Definition: lldb-enumerations.h:668
lldb_private::ObjectFile::m_symtab_up
std::unique_ptr< lldb_private::Symtab > m_symtab_up
Definition: ObjectFile.h:684
lldb_private::DataExtractor::PeekData
const uint8_t * PeekData(lldb::offset_t offset, lldb::offset_t length) const
Peek at a bytes at offset.
Definition: DataExtractor.h:821
lldb::eSectionTypeDWARFDebugAbbrevDwo
@ eSectionTypeDWARFDebugAbbrevDwo
Definition: lldb-enumerations.h:700
lldb_private::ObjectFile::m_file
FileSpec m_file
Definition: ObjectFile.h:671
ObjectFileELF::SectionHeaderColl
std::vector< ELFSectionHeaderInfo > SectionHeaderColl
Definition: ObjectFileELF.h:177
lldb_private::ObjectFile::GetAddressClass
virtual AddressClass GetAddressClass(lldb::addr_t file_addr)
Get the address type given a file address in an object file.
Definition: ObjectFile.cpp:292
ELFNote::n_name
std::string n_name
Definition: ObjectFileELF.h:29
elf::ELFProgramHeader::p_memsz
elf_xword p_memsz
Byte size of the segment in memory.
Definition: ELFHeader.h:199
ObjectFileELF::GetDependentModules
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override
Definition: ObjectFileELF.cpp:807
GetPermissions
static Permissions GetPermissions(const ELFSectionHeader &H)
Definition: ObjectFileELF.cpp:1656
lldb_private::ArchSpec::GetFlags
uint32_t GetFlags() const
Definition: ArchSpec.h:514
ObjectFileELF::GetAddressByteSize
uint32_t GetAddressByteSize() const override
Gets the address size in bytes for the current object file.
Definition: ObjectFileELF.cpp:718
elf::ELFSectionHeader::sh_size
elf_xword sh_size
Number of bytes occupied in the file.
Definition: ELFHeader.h:165
lldb_private::ArchSpec::SetFlags
void SetFlags(uint32_t flags)
Definition: ArchSpec.h:516
lldb::eSymbolTypeData
@ eSymbolTypeData
Definition: lldb-enumerations.h:617
lldb_private::ObjectFile::ReadSectionData
virtual size_t ReadSectionData(Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len)
Definition: ObjectFile.cpp:471
lldb::eSectionTypeDWARFDebugAddr
@ eSectionTypeDWARFDebugAddr
Definition: lldb-enumerations.h:663
SectionLoadList.h
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:193
IS_MICROMIPS
#define IS_MICROMIPS(ST_OTHER)
Definition: ObjectFileELF.cpp:1951
elf::ELFHeader::e_phnum
elf_word e_phnum
Number of program header entries.
Definition: ELFHeader.h:75
elf::ELFSectionHeader::sh_addr
elf_addr sh_addr
Virtual address of the section in memory.
Definition: ELFHeader.h:163
lldb_private::SectionList
Definition: Section.h:34
lldb_private::Section::GetFileSize
lldb::offset_t GetFileSize() const
Definition: Section.h:146
ObjectFileELF::GetArchitecture
lldb_private::ArchSpec GetArchitecture() override
Get the ArchSpec for this object file.
Definition: ObjectFileELF.cpp:3232
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::Flags::Test
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:96
elf::ELFProgramHeader::p_paddr
elf_addr p_paddr
Physical address (for non-VM systems).
Definition: ELFHeader.h:197
ObjectFileELF::GetSectionType
lldb::SectionType GetSectionType(const ELFSectionHeaderInfo &H) const
Definition: ObjectFileELF.cpp:1625
ObjectFileELF::ELFSectionHeaderInfo::section_name
lldb_private::ConstString section_name
Definition: ObjectFileELF.h:174
lldb_private::ArchSpec::GetCodeByteSize
uint32_t GetCodeByteSize() const
Architecture code byte width accessor.
Definition: ArchSpec.cpp:663
lldb_private::Stream
Definition: Stream.h:28
elf::ELFHeader::e_entry
elf_addr e_entry
Virtual address program entry point.
Definition: ELFHeader.h:58
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:444
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::Symtab::SymbolAtIndex
Symbol * SymbolAtIndex(size_t idx)
Definition: Symtab.cpp:200
elf::ELFSymbol::getType
unsigned char getType() const
Returns the type attribute of the st_info member.
Definition: ELFHeader.h:238
RangeMap.h
LLDB_INVALID_CPUTYPE
#define LLDB_INVALID_CPUTYPE
Definition: lldb-defines.h:105
lldb_private::ObjectFile::Type
Type
Definition: ObjectFile.h:64
lldb_private::DataExtractor::ExtractBytes
size_t ExtractBytes(lldb::offset_t offset, lldb::offset_t length, lldb::ByteOrder dst_byte_order, void *dst) const
Extract an arbitrary number of bytes in the specified byte order.
Definition: DataExtractor.cpp:662
lldb::eSectionTypeDWARFDebugStrOffsets
@ eSectionTypeDWARFDebugStrOffsets
Definition: lldb-enumerations.h:676
LIBLLDB_LOG_SYMBOLS
#define LIBLLDB_LOG_SYMBOLS
Definition: Logging.h:34
GetTargetByteSize
static uint32_t GetTargetByteSize(SectionType Type, const ArchSpec &arch)
Definition: ObjectFileELF.cpp:1644
lldb_private::Target
Definition: Target.h:447
Section.h
lldb_private::eSortOrderNone
@ eSortOrderNone
Definition: lldb-private-enumerations.h:110
lldb_private::DataExtractor::SetData
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
Definition: DataExtractor.cpp:226
lldb_private::Section::SetIsRelocated
void SetIsRelocated(bool b)
Definition: Section.h:237
lldb_private::ObjectFile::eTypeObjectFile
@ eTypeObjectFile
An intermediate object file.
Definition: ObjectFile.h:75
ObjectFileELF::ReadSectionData
size_t ReadSectionData(lldb_private::Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len) override
Definition: ObjectFileELF.cpp:3323
elf::ELFHeader::e_machine
elf_half e_machine
Target architecture.
Definition: ELFHeader.h:64
ObjectFileELF::AnySegmentHasPhysicalAddress
bool AnySegmentHasPhysicalAddress()
Definition: ObjectFileELF.cpp:3392
elf::ELFProgramHeader::p_flags
elf_word p_flags
Segment attributes.
Definition: ELFHeader.h:194
lldb_private::DataExtractor::PeekCStr
const char * PeekCStr(lldb::offset_t offset) const
Peek at a C string at offset.
Definition: DataExtractor.cpp:835
elf::ELFDynamic::d_ptr
elf_addr d_ptr
Pointer value of the table entry.
Definition: ELFHeader.h:280
ObjectFileELF::ParseDynamicSymbols
size_t ParseDynamicSymbols()
Parses the dynamic symbol table and populates m_dynamic_symbols.
Definition: ObjectFileELF.cpp:2330
ELFNote
Definition: ObjectFileELF.h:24
elf::ELFDynamic::Parse
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFDynamic entry from the given DataExtractor starting at position offset.
Definition: ELFHeader.cpp:400
ELFNote::n_type
elf::elf_word n_type
Definition: ObjectFileELF.h:27
Target.h
lldb_private::ModuleSpec::GetUUID
UUID & GetUUID()
Definition: ModuleSpec.h:105
ObjectFileELF::m_arch_spec
lldb_private::ArchSpec m_arch_spec
The architecture detected from parsing elf file contents.
Definition: ObjectFileELF.h:223
ObjectFileELF::ApplyRelocations
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)
Definition: ObjectFileELF.cpp:2566
ELFNote::n_descsz
elf::elf_word n_descsz
Definition: ObjectFileELF.h:26
lldb_private::SectionList::AddSection
size_t AddSection(const lldb::SectionSP &section_sp)
Definition: Section.cpp:407
elf::ELFSymbol::st_name
elf_word st_name
Symbol name string index.
Definition: ELFHeader.h:227
elf::ELFSectionHeader
Definition: ELFHeader.h:159
lldb::eSectionTypeELFRelocationEntries
@ eSectionTypeELFRelocationEntries
Elf SHT_REL or SHT_REL section.
Definition: lldb-enumerations.h:683
GetOsFromOSABI
static bool GetOsFromOSABI(unsigned char osabi_byte, llvm::Triple::OSType &ostype)
Definition: ObjectFileELF.cpp:486
lldb::eSectionTypeDWARFDebugLocDwo
@ eSectionTypeDWARFDebugLocDwo
Definition: lldb-enumerations.h:706
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::ObjectFile::GetSectionList
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
Definition: ObjectFile.cpp:583
lldb::eSectionTypeDWARFDebugLocListsDwo
@ eSectionTypeDWARFDebugLocListsDwo
Definition: lldb-enumerations.h:707
ObjectFileELF::DumpELFProgramHeaders
void DumpELFProgramHeaders(lldb_private::Stream *s)
Definition: ObjectFileELF.cpp:3121
elf::ELFHeader::e_phoff
elf_off e_phoff
File offset of program header table.
Definition: ELFHeader.h:59
elf::ELFSymbol
Definition: ELFHeader.h:224
lldb_private::ObjectFile::LoadableData
Definition: ObjectFile.h:105
lldb_private::Target::ReadUnsignedIntegerFromMemory
uint64_t ReadUnsignedIntegerFromMemory(const Address &addr, size_t integer_byte_size, uint64_t fail_value, Status &error, bool force_live_memory=false)
Definition: Target.cpp:1942
ObjectFileELF::CalculateType
ObjectFile::Type CalculateType() override
The object file should be able to calculate its type by looking at its file header and possibly the s...
Definition: ObjectFileELF.cpp:3258
lldb::eSectionTypeDWARFDebugAbbrev
@ eSectionTypeDWARFDebugAbbrev
Definition: lldb-enumerations.h:662
lldb_private::Stream::Indent
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition: Stream.cpp:130
ObjectFileELF::GetPluginName
lldb_private::ConstString GetPluginName() override
Definition: ObjectFileELF.cpp:638
lldb::eSymbolTypeSourceFile
@ eSymbolTypeSourceFile
Definition: lldb-enumerations.h:621
lldb_private::DataExtractor::GetAddressByteSize
uint32_t GetAddressByteSize() const
Get the current address size.
Definition: DataExtractor.h:253
lldb_private::breakpad::toString
llvm::StringRef toString(Record::Kind K)
Definition: BreakpadRecords.cpp:483
ObjectFileELF::GetEntryPointAddress
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...
Definition: ObjectFileELF.cpp:885
lldb_private::Symtab::Dump
void Dump(Stream *s, Target *target, SortOrder sort_type, Mangled::NamePreference name_preference=Mangled::ePreferDemangled)
Definition: Symtab.cpp:72
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
elf::ELFHeader::e_type
elf_half e_type
Object file type.
Definition: ELFHeader.h:63
ObjectFileELF::CalculateStrata
ObjectFile::Strata CalculateStrata() override
The object file should be able to calculate the strata of the object file.
Definition: ObjectFileELF.cpp:3286
Log.h
lldb::eSymbolTypeUndefined
@ eSymbolTypeUndefined
Definition: lldb-enumerations.h:638
ObjectFileELF::GetUUID
lldb_private::UUID GetUUID() override
Gets the UUID for this object file.
Definition: ObjectFileELF.cpp:763
lldb_private::ObjectFile::LoadableData::Dest
lldb::addr_t Dest
Definition: ObjectFile.h:106
lldb_private::ObjectFile::eStrataUser
@ eStrataUser
Definition: ObjectFile.h:88
lldb::eSectionTypeDWARFDebugStr
@ eSectionTypeDWARFDebugStr
Definition: lldb-enumerations.h:675
ObjectFileELF::GetPluginVersion
uint32_t GetPluginVersion() override
Definition: ObjectFileELF.cpp:642
elf::ELFRel
Definition: ELFHeader.h:305
ObjectFileELF::CreateInstance
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)
Definition: ObjectFileELF.cpp:347
lldb_private::ObjectFile::LoadableData::Contents
llvm::ArrayRef< uint8_t > Contents
Definition: ObjectFile.h:107
ObjectFileELF::m_address_class_map
FileAddressToAddressClassMap m_address_class_map
The address class for each symbol in the elf file.
Definition: ObjectFileELF.h:226
ObjectFileELF::SectionHeaderCollConstIter
SectionHeaderColl::const_iterator SectionHeaderCollConstIter
Definition: ObjectFileELF.h:179
ObjectFileELF::GetPluginNameStatic
static lldb_private::ConstString GetPluginNameStatic()
Definition: ObjectFileELF.cpp:338
Progress.h
lldb_private::ArchSpec::eMIPS_ABI_FP_SOFT
@ eMIPS_ABI_FP_SOFT
Definition: ArchSpec.h:81
ObjectFileELF::ParseHeader
bool ParseHeader() override
Attempts to parse the object header.
Definition: ObjectFileELF.cpp:758
ObjectFileELF::Dump
void Dump(lldb_private::Stream *s) override
Dump a description of this object to a Stream.
Definition: ObjectFileELF.cpp:2956
elf::elf_off
uint64_t elf_off
Definition: ELFHeader.h:42
elf::ELFDynamic
Definition: ELFHeader.h:276
lldb_private::Address::GetFileAddress
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:290
lldb_private::Symbol::GetAddressRef
Address & GetAddressRef()
Definition: Symbol.h:57
GetPltEntrySizeAndOffset
static std::pair< uint64_t, uint64_t > GetPltEntrySizeAndOffset(const ELFSectionHeader *rel_hdr, const ELFSectionHeader *plt_hdr)
Definition: ObjectFileELF.cpp:2398
ObjectFileELF.h
ELFNote::GetByteSize
size_t GetByteSize() const
Definition: ObjectFileELF.h:47
elf::ELFSectionHeader::sh_name
elf_word sh_name
Section name string index.
Definition: ELFHeader.h:160
lldb_private::ObjectFile::eTypeCoreFile
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
Definition: ObjectFile.h:67
lldb_private::DataExtractor::GetDataStart
const uint8_t * GetDataStart() const
Get the data start pointer.
Definition: DataExtractor.h:411
lldb_private::DataExtractor::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
Definition: DataExtractor.h:583
FileSpecList.h
lldb_private::ConstString
Definition: ConstString.h:40
DWARFCallFrameInfo.h
elf::ELFHeader::Is32Bit
bool Is32Bit() const
Returns true if this is a 32 bit ELF file header.
Definition: ELFHeader.h:85
lldb_private::Section::GetName
ConstString GetName() const
Definition: Section.h:170
lldb::eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugInfo
Definition: lldb-enumerations.h:667
lldb_private::DataExtractor::GetU8
uint8_t GetU8(lldb::offset_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
Definition: DataExtractor.cpp:319
subTypeFromElfHeader
static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header)
Definition: ObjectFileELF.cpp:313
ObjectFileELF::DumpELFProgramHeader
static void DumpELFProgramHeader(lldb_private::Stream *s, const elf::ELFProgramHeader &ph)
Definition: ObjectFileELF.cpp:3073
ObjectFileELF::RelocateSection
void RelocateSection(lldb_private::Section *section) override
Perform relocations on the section if necessary.
Definition: ObjectFileELF.cpp:2850
lldb_private::AddressRange
Definition: AddressRange.h:25
ObjectFileELF::ParseUnwindSymbols
void ParseUnwindSymbols(lldb_private::Symtab *symbol_table, lldb_private::DWARFCallFrameInfo *eh_frame)
Definition: ObjectFileELF.cpp:2891
Timer.h
lldb_private::Progress
A Progress indicator helper class.
Definition: Progress.h:55
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
elf
Definition: ELFHeader.h:32
ObjectFileELF::GetAddressClass
lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override
Get the address type given a file address in an object file.
Definition: ObjectFileELF.cpp:722
lldb::eSectionTypeDWARFDebugTypes
@ eSectionTypeDWARFDebugTypes
DWARF .debug_types section.
Definition: lldb-enumerations.h:694
elf::ELFSymbol::st_info
unsigned char st_info
Symbol type and binding attributes.
Definition: ELFHeader.h:228
lldb_private::SectionList::GetSectionAtIndex
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition: Section.cpp:476
lldb::eSectionTypeZeroFill
@ eSectionTypeZeroFill
Definition: lldb-enumerations.h:658
lldb_private::Range
Definition: Process.h:60
elf::ELFProgramHeader::p_type
elf_word p_type
Type of program segment.
Definition: ELFHeader.h:193
lldb_private::ArchSpec::TripleOSWasSpecified
bool TripleOSWasSpecified() const
Definition: ArchSpec.h:351
lldb::eSectionTypeDWARFGNUDebugAltLink
@ eSectionTypeDWARFGNUDebugAltLink
Definition: lldb-enumerations.h:693
lldb_private::Range::Slide
void Slide(BaseType slide)
Definition: RangeMap.h:50
ObjectFileELF::SectionIndex
size_t SectionIndex(const SectionHeaderCollIter &I)
Returns the index of the given section header.
Definition: ObjectFileELF.cpp:750
lldb_private::Stream::GetIndentLevel
unsigned GetIndentLevel() const
Get the current indentation level.
Definition: Stream.cpp:160
lldb::eSectionTypeELFDynamicSymbols
@ eSectionTypeELFDynamicSymbols
Elf SHT_DYNSYM section.
Definition: lldb-enumerations.h:682
lldb_private::ObjectFile::eTypeSharedLibrary
@ eTypeSharedLibrary
A shared library that can be used during execution.
Definition: ObjectFile.h:77
elf::ELFHeader::e_ehsize
elf_half e_ehsize
Byte size of the ELF header.
Definition: ELFHeader.h:65
ObjectFileELF::m_program_headers
ProgramHeaderColl m_program_headers
Collection of program headers.
Definition: ObjectFileELF.h:203
ObjectFileELF::PLTRelocationType
unsigned PLTRelocationType()
Definition: ObjectFileELF.cpp:2379
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
ObjectFileELF::DumpELFHeader_e_type
static void DumpELFHeader_e_type(lldb_private::Stream *s, elf::elf_half e_type)
Definition: ObjectFileELF.cpp:3028
ObjectFileELF::ParseDependentModules
size_t ParseDependentModules()
Scans the dynamic section and locates all dependent modules (shared libraries) populating m_filespec_...
Definition: ObjectFileELF.cpp:915
lldb_private::Symtab::FindSymbolAtFileAddress
Symbol * FindSymbolAtFileAddress(lldb::addr_t file_addr)
Definition: Symtab.cpp:933
lldb_private::ArchSpec::IsValid
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:342
lldb_private::ObjectFile::GetNextSyntheticSymbolName
ConstString GetNextSyntheticSymbolName()
Definition: ObjectFile.cpp:619
lldb::eSectionTypeAbsoluteAddress
@ eSectionTypeAbsoluteAddress
Dummy section for symbols with absolute address.
Definition: lldb-enumerations.h:691
elf::ELFHeader::e_shoff
elf_off e_shoff
File offset of section header table.
Definition: ELFHeader.h:60
elf::ELFHeader::e_phentsize
elf_half e_phentsize
Size of a program header table entry.
Definition: ELFHeader.h:66
lldb::SymbolType
SymbolType
Symbol types.
Definition: lldb-enumerations.h:611
lldb_private::FileSpec::CopyByAppendingPathComponent
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
Definition: FileSpec.cpp:400
lldb_private::ArchSpec::eMIPSABI_N64
@ eMIPSABI_N64
Definition: ArchSpec.h:69
lldb_private::ArchSpec::eMIPSABI_EABI32
@ eMIPSABI_EABI32
Definition: ArchSpec.h:71
ObjectFileELF::GetDebugLink
llvm::Optional< lldb_private::FileSpec > GetDebugLink()
Return the contents of the .gnu_debuglink section, if the object file contains it.
Definition: ObjectFileELF.cpp:801
lldb::eSectionTypeDWARFDebugCuIndex
@ eSectionTypeDWARFDebugCuIndex
Definition: lldb-enumerations.h:665
OSABIAsCString
static const char * OSABIAsCString(unsigned char osabi_byte)
Definition: ObjectFileELF.cpp:449
ObjectFileELF::SetLoadAddress
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...
Definition: ObjectFileELF.cpp:664
lldb::eSectionTypeData
@ eSectionTypeData
Definition: lldb-enumerations.h:649
lldb_private::UserID::GetID
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47
ObjectFileELF::IsExecutable
bool IsExecutable() const override
Tells whether this object file is capable of being the main executable for a process.
Definition: ObjectFileELF.cpp:660
ObjectFileELF::DumpDependentModules
void DumpDependentModules(lldb_private::Stream *s)
ELF dependent module dump routine.
Definition: ObjectFileELF.cpp:3220
lldb_private::Section
Definition: Section.h:96
INT32_MAX
#define INT32_MAX
Definition: lldb-defines.h:27
lldb::eSectionTypeDWARFDebugTuIndex
@ eSectionTypeDWARFDebugTuIndex
Definition: lldb-enumerations.h:708
ObjectFileELF::CreateSections
void CreateSections(lldb_private::SectionList &unified_section_list) override
Definition: ObjectFileELF.cpp:1781
ObjectFileELF::Terminate
static void Terminate()
Definition: ObjectFileELF.cpp:334
lldb_private::ArchSpec::eMIPSABI_O64
@ eMIPSABI_O64
Definition: ArchSpec.h:70
elf::ELFSectionHeader::sh_entsize
elf_xword sh_entsize
Byte size of each section entry.
Definition: ELFHeader.h:169
lldb_private::ObjectFile::eStrataUnknown
@ eStrataUnknown
Definition: ObjectFile.h:87
lldb::eSectionTypeOther
@ eSectionTypeOther
Definition: lldb-enumerations.h:696
lldb_private::Symtab::GetNumSymbols
size_t GetNumSymbols() const
Definition: Symtab.cpp:62
lldb_private::ArchSpec::eMIPS_ABI_FP_OLD_64
@ eMIPS_ABI_FP_OLD_64
Definition: ArchSpec.h:82
lldb::eSectionTypeCode
@ eSectionTypeCode
Definition: lldb-enumerations.h:647
elf::ELFDynamic::d_tag
elf_sxword d_tag
Type of dynamic table entry.
Definition: ELFHeader.h:277
lldb_private::ArchSpec::SetArchitecture
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.
Definition: ArchSpec.cpp:843
lldb_private::SectionList::FindSectionByType
lldb::SectionSP FindSectionByType(lldb::SectionType sect_type, bool check_children, size_t start_idx=0) const
Definition: Section.cpp:524
ObjectFileELF::ParseTrampolineSymbols
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 ...
Definition: ObjectFileELF.cpp:2496
lldb_private::Symbol::GetByteSizeIsValid
bool GetByteSizeIsValid() const
Definition: Symbol.h:174
lldb_private::Symtab::AddSymbol
uint32_t AddSymbol(const Symbol &symbol)
Definition: Symtab.cpp:50
lldb_private::ModuleSpec
Definition: ModuleSpec.h:26
lldb_private::ObjectFile::GetData
size_t GetData(lldb::offset_t offset, size_t length, DataExtractor &data) const
Definition: ObjectFile.cpp:457
elf::ELFHeader::e_shentsize
elf_half e_shentsize
Size of a section header table entry.
Definition: ELFHeader.h:68
lldb_private::Status
Definition: Status.h:44
lldb::eSectionTypeContainer
@ eSectionTypeContainer
The section contains child sections.
Definition: lldb-enumerations.h:648
lldb::eSectionTypeEHFrame
@ eSectionTypeEHFrame
Definition: lldb-enumerations.h:685
lldb::eSectionTypeELFDynamicLinkInfo
@ eSectionTypeELFDynamicLinkInfo
Elf SHT_DYNAMIC section.
Definition: lldb-enumerations.h:684
lldb_private::ArchSpec::GetArchitectureName
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition: ArchSpec.cpp:538
lldb::eByteOrderInvalid
@ eByteOrderInvalid
Definition: lldb-enumerations.h:139
lldb_private::Symtab
Definition: Symtab.h:21
uint32_t
ObjectFileELF::m_section_headers
SectionHeaderColl m_section_headers
Collection of section headers.
Definition: ObjectFileELF.h:206
lldb_private::ArchSpec::eMIPS_ABI_FP_64A
@ eMIPS_ABI_FP_64A
Definition: ArchSpec.h:85
lldb_private::ObjectFile::eTypeDebugInfo
@ eTypeDebugInfo
An object file that contains only debug information.
Definition: ObjectFile.h:71
ObjectFileELF::CalculateELFNotesSegmentsCRC32
static uint32_t CalculateELFNotesSegmentsCRC32(const ProgramHeaderColl &program_headers, lldb_private::DataExtractor &data)
Definition: ObjectFileELF.cpp:425
lldb::SectionType
SectionType
Definition: lldb-enumerations.h:645
lldb_private::Flags::Get
ValueType Get() const
Get accessor for all flags.
Definition: Flags.h:40
_MAKE_OSABI_CASE
#define _MAKE_OSABI_CASE(x)
lldb::eSectionTypeDWARFDebugStrDwo
@ eSectionTypeDWARFDebugStrDwo
Definition: lldb-enumerations.h:702
lldb_private::ArchSpec::eMIPSABI_N32
@ eMIPSABI_N32
Definition: ArchSpec.h:68
lldb_private::Address
Definition: Address.h:59
lldb::eSectionTypeDWARFDebugPubTypes
@ eSectionTypeDWARFDebugPubTypes
Definition: lldb-enumerations.h:673
lldb::eSectionTypeDWARFDebugNames
@ eSectionTypeDWARFDebugNames
DWARF v5 .debug_names.
Definition: lldb-enumerations.h:695
id
void * id
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:20
lldb_private::Stream::EOL
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:128
ObjectFileELF::DumpELFSectionHeader
static void DumpELFSectionHeader(lldb_private::Stream *s, const ELFSectionHeaderInfo &sh)
Definition: ObjectFileELF.cpp:3141
lldb_private::Symtab::GetObjectFile
ObjectFile * GetObjectFile()
Definition: Symtab.h:140
lldb_private::eArchTypeELF
@ eArchTypeELF
Definition: lldb-private-enumerations.h:64
lldb::eSectionTypeARMextab
@ eSectionTypeARMextab
Definition: lldb-enumerations.h:687
lldb::eSectionTypeDWARFDebugPubNames
@ eSectionTypeDWARFDebugPubNames
Definition: lldb-enumerations.h:672
lldb_private::Type
Definition: Type.h:66
lldb_private::Symtab::FindSymbolByID
Symbol * FindSymbolByID(lldb::user_id_t uid) const
Definition: Symtab.cpp:191
ObjectFileELF::MagicBytesMatch
static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, lldb::addr_t length)
Definition: ObjectFileELF.cpp:409
lldb_private::Address::ResolveAddressUsingFileSections
bool ResolveAddressUsingFileSections(lldb::addr_t addr, const SectionList *sections)
Resolve a file virtual address using a section list.
Definition: Address.cpp:247
lldb_private::ArchSpec::eMIPS_ABI_FP_SINGLE
@ eMIPS_ABI_FP_SINGLE
Definition: ArchSpec.h:80
mipsVariantFromElfFlags
static uint32_t mipsVariantFromElfFlags(const elf::ELFHeader &header)
Definition: ObjectFileELF.cpp:248
ArchSpec.h
lldb_private::Range::GetByteSize
SizeType GetByteSize() const
Definition: RangeMap.h:71
lldb_private::Stream::AsRawOstream
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:357
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::ObjectFile::m_data
DataExtractor m_data
The data for this object file so things can be parsed lazily.
Definition: ObjectFile.h:680
elf::ELFProgramHeader
Definition: ELFHeader.h:192
lldb_private::Range::SetByteSize
void SetByteSize(SizeType s)
Definition: RangeMap.h:73
riscvVariantFromElfFlags
static uint32_t riscvVariantFromElfFlags(const elf::ELFHeader &header)
Definition: ObjectFileELF.cpp:301
elf::ELFSymbol::st_value
elf_addr st_value
Absolute or relocatable address.
Definition: ELFHeader.h:225
lldb_private::ModuleChild::GetModule
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
ObjectFileELF::GetSegmentData
lldb_private::DataExtractor GetSegmentData(const elf::ELFProgramHeader &H)
Definition: ObjectFileELF.cpp:3388
uint16_t
ObjectFileELF
Definition: ObjectFileELF.h:57
ObjectFileELF::DumpELFHeader_e_ident_EI_DATA
static void DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s, unsigned char ei_data)
Definition: ObjectFileELF.cpp:3053
lldb_private::DataExtractor::GetU32
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
Definition: DataExtractor.cpp:428
ELFNote::n_namesz
elf::elf_word n_namesz
Definition: ObjectFileELF.h:25
lldb::eSectionTypeDWARFDebugLineStr
@ eSectionTypeDWARFDebugLineStr
DWARF v5 .debug_line_str.
Definition: lldb-enumerations.h:697
lldb_private::DWARFCallFrameInfo::ForEachFDEEntries
void ForEachFDEEntries(const std::function< bool(lldb::addr_t, uint32_t, dw_offset_t)> &callback)
Definition: DWARFCallFrameInfo.cpp:1013
PluginManager.h
lldb_private::Address::SetOffset
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
Definition: Address.h:425
lldb_private::Target::GetSectionLoadList
SectionLoadList & GetSectionLoadList()
Definition: Target.h:1036
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
lldb_private::ModuleSpec::GetArchitecture
ArchSpec & GetArchitecture()
Definition: ModuleSpec.h:95
lldb_private::DWARFCallFrameInfo
Definition: DWARFCallFrameInfo.h:33
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:242
ObjectFileELF::GetProgramHeaderInfo
static size_t GetProgramHeaderInfo(ProgramHeaderColl &program_headers, lldb_private::DataExtractor &object_data, const elf::ELFHeader &header)
Definition: ObjectFileELF.cpp:974
lldb_private::ArchSpec::GetDataByteSize
uint32_t GetDataByteSize() const
Architecture data byte width accessor.
Definition: ArchSpec.cpp:659
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
ObjectFileELF::m_uuid
lldb_private::UUID m_uuid
ELF build ID.
Definition: ObjectFileELF.h:196
ObjectFileELF::DumpELFHeader
static void DumpELFHeader(lldb_private::Stream *s, const elf::ELFHeader &header)
Definition: ObjectFileELF.cpp:2993
ObjectFileELF::ParseSymbolTable
unsigned ParseSymbolTable(lldb_private::Symtab *symbol_table, lldb::user_id_t start_id, lldb_private::Section *symtab)
Populates m_symtab_up will all non-dynamic linker symbols.
Definition: ObjectFileELF.cpp:2287
Status.h
lldb_private::ArchSpec::eMIPS_ABI_FP_64
@ eMIPS_ABI_FP_64
Definition: ArchSpec.h:84
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
SymbolContext.h
ObjectFileELF::m_entry_point_address
lldb_private::Address m_entry_point_address
Cached value of the entry point for this module.
Definition: ObjectFileELF.h:220
ObjectFileELF::GetImageInfoAddress
lldb_private::Address GetImageInfoAddress(lldb_private::Target *target) override
Similar to Process::GetImageInfoAddress().
Definition: ObjectFileELF.cpp:819
lldb_private::DataExtractor::CopyData
lldb::offset_t CopyData(lldb::offset_t offset, lldb::offset_t length, void *dst) const
Copy length bytes from *offset, without swapping bytes.
Definition: DataExtractor.cpp:681
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ArchSpec::eMIPS_ABI_FP_ANY
@ eMIPS_ABI_FP_ANY
Definition: ArchSpec.h:78
ObjectFileELF::g_core_uuid_magic
static const uint32_t g_core_uuid_magic
Definition: ObjectFileELF.h:190
lldb_private::DataExtractor::GetCStr
const char * GetCStr(lldb::offset_t *offset_ptr) const
Extract a C string from *offset_ptr.
Definition: DataExtractor.cpp:787
ObjectFileELF::DumpELFSectionHeader_sh_flags
static void DumpELFSectionHeader_sh_flags(lldb_private::Stream *s, elf::elf_xword sh_flags)
Definition: ObjectFileELF.cpp:3185
CASE_AND_STREAM
#define CASE_AND_STREAM(s, def, width)
Definition: ObjectFileELF.cpp:46
lldb_private::Section::GetFileOffset
lldb::offset_t GetFileOffset() const
Definition: Section.h:140
ObjectFileELF::GetSectionHeaderByIndex
const ELFSectionHeaderInfo * GetSectionHeaderByIndex(lldb::user_id_t id)
Returns the section header with the given id or NULL.
Definition: ObjectFileELF.cpp:1560
lldb::eByteOrderBig
@ eByteOrderBig
Definition: lldb-enumerations.h:140
ObjectFileELF::DynamicSymbolCollIter
DynamicSymbolColl::iterator DynamicSymbolCollIter
Definition: ObjectFileELF.h:182
SegmentID
static user_id_t SegmentID(size_t PHdrIndex)
Definition: ObjectFileELF.cpp:213
lldb_private::DataExtractor::Clear
void Clear()
Clears the object state.
Definition: DataExtractor.cpp:195
elf::ELFSymbol::getBinding
unsigned char getBinding() const
Returns the binding attribute of the st_info member.
Definition: ELFHeader.h:235
ObjectFileELF::GetByteOrder
lldb::ByteOrder GetByteOrder() const override
Gets whether endian swapping should occur when extracting data from this object file.
Definition: ObjectFileELF.cpp:710
lldb_private::DataExtractor::GetData
const void * GetData(lldb::offset_t *offset_ptr, lldb::offset_t length) const
Extract length bytes from *offset_ptr.
Definition: DataExtractor.h:326
elf::ELFProgramHeader::p_filesz
elf_xword p_filesz
Byte size of the segment in file.
Definition: ELFHeader.h:198
ObjectFileELF::RelocateDebugSections
unsigned RelocateDebugSections(const elf::ELFSectionHeader *rel_hdr, lldb::user_id_t rel_id, lldb_private::Symtab *thetab)
Relocates debug sections.
Definition: ObjectFileELF.cpp:2659
ObjectFileELF::DumpELFSectionHeaders
void DumpELFSectionHeaders(lldb_private::Stream *s)
Definition: ObjectFileELF.cpp:3197
lldb_private::ObjectFile::eTypeUnknown
@ eTypeUnknown
Definition: ObjectFile.h:82
lldb_private::ModuleSpecList::GetSize
size_t GetSize() const
Definition: ModuleSpec.h:304
Stream.h
LLDB_PLUGIN_DEFINE
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
lldb_private::Log
Definition: Log.h:49
ObjectFileELF::GetSectionHeaderInfo
static size_t GetSectionHeaderInfo(SectionHeaderColl &section_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.
Definition: ObjectFileELF.cpp:1321
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
ObjectFileELF::ParseARMAttributes
static void ParseARMAttributes(lldb_private::DataExtractor &data, uint64_t length, lldb_private::ArchSpec &arch_spec)
Definition: ObjectFileELF.cpp:1250
ObjectFileELF::IsStripped
bool IsStripped() override
Detect if this object file has been stripped of local symbols.
Definition: ObjectFileELF.cpp:2946
lldb_private::Section::GetObjectFile
ObjectFile * GetObjectFile()
Definition: Section.h:190
lldb::eSymbolTypeResolver
@ eSymbolTypeResolver
Definition: lldb-enumerations.h:616
ObjectFileELF::ParseSectionHeaders
size_t ParseSectionHeaders()
Parses all section headers present in this object file and populates m_section_headers.
Definition: ObjectFileELF.cpp:1553
ObjectFileELF::DumpELFProgramHeader_p_flags
static void DumpELFProgramHeader_p_flags(lldb_private::Stream *s, elf::elf_word p_flags)
Definition: ObjectFileELF.cpp:3110
lldb::eSectionTypeDWARFDebugMacInfo
@ eSectionTypeDWARFDebugMacInfo
Definition: lldb-enumerations.h:670
ObjectFileELF::GetSectionIndexByName
lldb::user_id_t GetSectionIndexByName(const char *name)
Utility method for looking up a section given its name.
Definition: ObjectFileELF.cpp:1570
ObjectFileELF::ParseSymbols
unsigned 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().
Definition: ObjectFileELF.cpp:1954
elf::ELFRela
Definition: ELFHeader.h:346
lldb::eSectionTypeARMexidx
@ eSectionTypeARMexidx
Definition: lldb-enumerations.h:686
lldb::eSymbolTypeAbsolute
@ eSymbolTypeAbsolute
Definition: lldb-enumerations.h:614
lldb_private::FileSpec::GetPath
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:348
lldb_private::lzma::isAvailable
bool isAvailable()
Definition: LZMA.cpp:22
ObjectFileELF::DumpELFProgramHeader_p_type
static void DumpELFProgramHeader_p_type(lldb_private::Stream *s, elf::elf_word p_type)
Definition: ObjectFileELF.cpp:3089
ObjectFileELF::m_header
elf::ELFHeader m_header
ELF file header.
Definition: ObjectFileELF.h:193
lldb_private::DataExtractor::GetByteSize
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
Definition: DataExtractor.h:259
lldb::eByteOrderLittle
@ eByteOrderLittle
Definition: lldb-enumerations.h:142
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
elf::ELFHeader::e_shstrndx
elf_word e_shstrndx
String table section index.
Definition: ELFHeader.h:77
elf::ELFHeader::e_shnum
elf_word e_shnum
Number of section header entries.
Definition: ELFHeader.h:76
lldb::eSectionTypeDWARFDebugTypesDwo
@ eSectionTypeDWARFDebugTypesDwo
Definition: lldb-enumerations.h:704
lldb_private::ObjectFile::Strata
Strata
Definition: ObjectFile.h:85
lldb
Definition: SBAddress.h:15
lldb_private::FileSpec::GetFileNameExtension
ConstString GetFileNameExtension() const
Extract the extension of the file.
Definition: FileSpec.cpp:384
lldb_private::ArchSpec::eMIPSABI_O32
@ eMIPSABI_O32
Definition: ArchSpec.h:67
lldb_private::FileSpec::GetFilename
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:341
elf::ELFSectionHeader::sh_addralign
elf_xword sh_addralign
Power of two alignment constraint.
Definition: ELFHeader.h:168
ObjectFileELF::ELFSectionHeaderInfo
Definition: ObjectFileELF.h:173
lldb::eSectionTypeDWARFDebugLocLists
@ eSectionTypeDWARFDebugLocLists
DWARF v5 .debug_loclists.
Definition: lldb-enumerations.h:699
GetSectionTypeFromName
static SectionType GetSectionTypeFromName(llvm::StringRef Name)
Definition: ObjectFileELF.cpp:1579
lldb::eSectionTypeGoSymtab
@ eSectionTypeGoSymtab
Definition: lldb-enumerations.h:690
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)
Definition: ObjectFileELF.cpp:2431
lldb_private::ObjectFile
Definition: ObjectFile.h:58
calc_crc32
static uint32_t calc_crc32(uint32_t init, const DataExtractor &data)
Definition: ObjectFileELF.cpp:420
DataBufferHeap.h
ELFNote::Parse
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFNote entry from the given DataExtractor starting at position offset.
Definition: ObjectFileELF.cpp:217
UINT64_MAX
#define UINT64_MAX
Definition: lldb-defines.h:35
lldb_private::SectionList::FindSectionByID
lldb::SectionSP FindSectionByID(lldb::user_id_t sect_id) const
Definition: Section.cpp:506
elf::ELFSymbol::st_other
unsigned char st_other
Reserved for future use.
Definition: ELFHeader.h:229
ObjectFileELF::GetLoadableData
std::vector< LoadableData > GetLoadableData(lldb_private::Target &target) override
Loads this objfile to memory.
Definition: ObjectFileELF.cpp:3401
lldb_private::ObjectFile::m_sections_up
std::unique_ptr< lldb_private::SectionList > m_sections_up
Definition: ObjectFile.h:683
ObjectFileELF::m_gnu_debuglink_file
std::string m_gnu_debuglink_file
ELF .gnu_debuglink file and crc data if available.
Definition: ObjectFileELF.h:199
lldb_private::VMRange
Definition: VMRange.h:23
lldb_private::ObjectFile::GetType
Type GetType()
Definition: ObjectFile.h:605
elf::ELFProgramHeader::p_offset
elf_off p_offset
Start of segment from beginning of file.
Definition: ELFHeader.h:195
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138
elf::ELFSectionHeader::sh_link
elf_word sh_link
Index of associated section.
Definition: ELFHeader.h:166
lldb::eSectionTypeDWARFDebugRngLists
@ eSectionTypeDWARFDebugRngLists
DWARF v5 .debug_rnglists.
Definition: lldb-enumerations.h:698
lldb_private::Target::ReadPointerFromMemory
bool ReadPointerFromMemory(const Address &addr, Status &error, Address &pointer_addr, bool force_live_memory=false)
Definition: Target.cpp:1953
lldb_private::Symbol::GetID
uint32_t GetID() const
Definition: Symbol.h:111
lldb_private::Symbol::SetIsWeak
void SetIsWeak(bool b)
Definition: Symbol.h:172
lldb_private::Range::GetRangeEnd
BaseType GetRangeEnd() const
Definition: RangeMap.h:62