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