LLVM  8.0.0svn
COFFObjectFile.cpp
Go to the documentation of this file.
1 //===- COFFObjectFile.cpp - COFF object file implementation ---------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the COFFObjectFile class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/ADT/Triple.h"
18 #include "llvm/BinaryFormat/COFF.h"
19 #include "llvm/Object/Binary.h"
20 #include "llvm/Object/COFF.h"
21 #include "llvm/Object/Error.h"
22 #include "llvm/Object/ObjectFile.h"
24 #include "llvm/Support/Endian.h"
25 #include "llvm/Support/Error.h"
29 #include <algorithm>
30 #include <cassert>
31 #include <cstddef>
32 #include <cstdint>
33 #include <cstring>
34 #include <limits>
35 #include <memory>
36 #include <system_error>
37 
38 using namespace llvm;
39 using namespace object;
40 
45 
46 // Returns false if size is greater than the buffer size. And sets ec.
47 static bool checkSize(MemoryBufferRef M, std::error_code &EC, uint64_t Size) {
48  if (M.getBufferSize() < Size) {
50  return false;
51  }
52  return true;
53 }
54 
55 // Sets Obj unless any bytes in [addr, addr + size) fall outsize of m.
56 // Returns unexpected_eof if error.
57 template <typename T>
58 static std::error_code getObject(const T *&Obj, MemoryBufferRef M,
59  const void *Ptr,
60  const uint64_t Size = sizeof(T)) {
61  uintptr_t Addr = uintptr_t(Ptr);
62  if (std::error_code EC = Binary::checkOffset(M, Addr, Size))
63  return EC;
64  Obj = reinterpret_cast<const T *>(Addr);
65  return std::error_code();
66 }
67 
68 // Decode a string table entry in base 64 (//AAAAAA). Expects \arg Str without
69 // prefixed slashes.
70 static bool decodeBase64StringEntry(StringRef Str, uint32_t &Result) {
71  assert(Str.size() <= 6 && "String too long, possible overflow.");
72  if (Str.size() > 6)
73  return true;
74 
75  uint64_t Value = 0;
76  while (!Str.empty()) {
77  unsigned CharVal;
78  if (Str[0] >= 'A' && Str[0] <= 'Z') // 0..25
79  CharVal = Str[0] - 'A';
80  else if (Str[0] >= 'a' && Str[0] <= 'z') // 26..51
81  CharVal = Str[0] - 'a' + 26;
82  else if (Str[0] >= '0' && Str[0] <= '9') // 52..61
83  CharVal = Str[0] - '0' + 52;
84  else if (Str[0] == '+') // 62
85  CharVal = 62;
86  else if (Str[0] == '/') // 63
87  CharVal = 63;
88  else
89  return true;
90 
91  Value = (Value * 64) + CharVal;
92  Str = Str.substr(1);
93  }
94 
96  return true;
97 
98  Result = static_cast<uint32_t>(Value);
99  return false;
100 }
101 
102 template <typename coff_symbol_type>
103 const coff_symbol_type *COFFObjectFile::toSymb(DataRefImpl Ref) const {
104  const coff_symbol_type *Addr =
105  reinterpret_cast<const coff_symbol_type *>(Ref.p);
106 
107  assert(!checkOffset(Data, uintptr_t(Addr), sizeof(*Addr)));
108 #ifndef NDEBUG
109  // Verify that the symbol points to a valid entry in the symbol table.
110  uintptr_t Offset = uintptr_t(Addr) - uintptr_t(base());
111 
112  assert((Offset - getPointerToSymbolTable()) % sizeof(coff_symbol_type) == 0 &&
113  "Symbol did not point to the beginning of a symbol");
114 #endif
115 
116  return Addr;
117 }
118 
119 const coff_section *COFFObjectFile::toSec(DataRefImpl Ref) const {
120  const coff_section *Addr = reinterpret_cast<const coff_section*>(Ref.p);
121 
122 #ifndef NDEBUG
123  // Verify that the section points to a valid entry in the section table.
124  if (Addr < SectionTable || Addr >= (SectionTable + getNumberOfSections()))
125  report_fatal_error("Section was outside of section table.");
126 
127  uintptr_t Offset = uintptr_t(Addr) - uintptr_t(SectionTable);
128  assert(Offset % sizeof(coff_section) == 0 &&
129  "Section did not point to the beginning of a section");
130 #endif
131 
132  return Addr;
133 }
134 
136  auto End = reinterpret_cast<uintptr_t>(StringTable);
137  if (SymbolTable16) {
138  const coff_symbol16 *Symb = toSymb<coff_symbol16>(Ref);
139  Symb += 1 + Symb->NumberOfAuxSymbols;
140  Ref.p = std::min(reinterpret_cast<uintptr_t>(Symb), End);
141  } else if (SymbolTable32) {
142  const coff_symbol32 *Symb = toSymb<coff_symbol32>(Ref);
143  Symb += 1 + Symb->NumberOfAuxSymbols;
144  Ref.p = std::min(reinterpret_cast<uintptr_t>(Symb), End);
145  } else {
146  llvm_unreachable("no symbol table pointer!");
147  }
148 }
149 
151  COFFSymbolRef Symb = getCOFFSymbol(Ref);
152  StringRef Result;
153  if (std::error_code EC = getSymbolName(Symb, Result))
154  return errorCodeToError(EC);
155  return Result;
156 }
157 
159  return getCOFFSymbol(Ref).getValue();
160 }
161 
163  // MSVC/link.exe seems to align symbols to the next-power-of-2
164  // up to 32 bytes.
165  COFFSymbolRef Symb = getCOFFSymbol(Ref);
166  return std::min(uint64_t(32), PowerOf2Ceil(Symb.getValue()));
167 }
168 
170  uint64_t Result = getSymbolValue(Ref);
171  COFFSymbolRef Symb = getCOFFSymbol(Ref);
172  int32_t SectionNumber = Symb.getSectionNumber();
173 
174  if (Symb.isAnyUndefined() || Symb.isCommon() ||
175  COFF::isReservedSectionNumber(SectionNumber))
176  return Result;
177 
178  const coff_section *Section = nullptr;
179  if (std::error_code EC = getSection(SectionNumber, Section))
180  return errorCodeToError(EC);
181  Result += Section->VirtualAddress;
182 
183  // The section VirtualAddress does not include ImageBase, and we want to
184  // return virtual addresses.
185  Result += getImageBase();
186 
187  return Result;
188 }
189 
191  COFFSymbolRef Symb = getCOFFSymbol(Ref);
192  int32_t SectionNumber = Symb.getSectionNumber();
193 
195  return SymbolRef::ST_Function;
196  if (Symb.isAnyUndefined())
197  return SymbolRef::ST_Unknown;
198  if (Symb.isCommon())
199  return SymbolRef::ST_Data;
200  if (Symb.isFileRecord())
201  return SymbolRef::ST_File;
202 
203  // TODO: perhaps we need a new symbol type ST_Section.
204  if (SectionNumber == COFF::IMAGE_SYM_DEBUG || Symb.isSectionDefinition())
205  return SymbolRef::ST_Debug;
206 
207  if (!COFF::isReservedSectionNumber(SectionNumber))
208  return SymbolRef::ST_Data;
209 
210  return SymbolRef::ST_Other;
211 }
212 
214  COFFSymbolRef Symb = getCOFFSymbol(Ref);
215  uint32_t Result = SymbolRef::SF_None;
216 
217  if (Symb.isExternal() || Symb.isWeakExternal())
218  Result |= SymbolRef::SF_Global;
219 
220  if (const coff_aux_weak_external *AWE = Symb.getWeakExternal()) {
221  Result |= SymbolRef::SF_Weak;
222  if (AWE->Characteristics != COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS)
223  Result |= SymbolRef::SF_Undefined;
224  }
225 
227  Result |= SymbolRef::SF_Absolute;
228 
229  if (Symb.isFileRecord())
231 
232  if (Symb.isSectionDefinition())
234 
235  if (Symb.isCommon())
236  Result |= SymbolRef::SF_Common;
237 
238  if (Symb.isUndefined())
239  Result |= SymbolRef::SF_Undefined;
240 
241  return Result;
242 }
243 
245  COFFSymbolRef Symb = getCOFFSymbol(Ref);
246  return Symb.getValue();
247 }
248 
251  COFFSymbolRef Symb = getCOFFSymbol(Ref);
253  return section_end();
254  const coff_section *Sec = nullptr;
255  if (std::error_code EC = getSection(Symb.getSectionNumber(), Sec))
256  return errorCodeToError(EC);
258  Ret.p = reinterpret_cast<uintptr_t>(Sec);
259  return section_iterator(SectionRef(Ret, this));
260 }
261 
264  return Symb.getSectionNumber();
265 }
266 
268  const coff_section *Sec = toSec(Ref);
269  Sec += 1;
270  Ref.p = reinterpret_cast<uintptr_t>(Sec);
271 }
272 
273 std::error_code COFFObjectFile::getSectionName(DataRefImpl Ref,
274  StringRef &Result) const {
275  const coff_section *Sec = toSec(Ref);
276  return getSectionName(Sec, Result);
277 }
278 
280  const coff_section *Sec = toSec(Ref);
281  uint64_t Result = Sec->VirtualAddress;
282 
283  // The section VirtualAddress does not include ImageBase, and we want to
284  // return virtual addresses.
285  Result += getImageBase();
286  return Result;
287 }
288 
290  return toSec(Sec) - SectionTable;
291 }
292 
293 uint64_t COFFObjectFile::getSectionSize(DataRefImpl Ref) const {
294  return getSectionSize(toSec(Ref));
295 }
296 
298  StringRef &Result) const {
299  const coff_section *Sec = toSec(Ref);
300  ArrayRef<uint8_t> Res;
301  std::error_code EC = getSectionContents(Sec, Res);
302  Result = StringRef(reinterpret_cast<const char*>(Res.data()), Res.size());
303  return EC;
304 }
305 
307  const coff_section *Sec = toSec(Ref);
308  return Sec->getAlignment();
309 }
310 
312  return false;
313 }
314 
316  const coff_section *Sec = toSec(Ref);
318 }
319 
321  const coff_section *Sec = toSec(Ref);
323 }
324 
326  const coff_section *Sec = toSec(Ref);
330  return (Sec->Characteristics & BssFlags) == BssFlags;
331 }
332 
334  uintptr_t Offset =
335  uintptr_t(Sec.getRawDataRefImpl().p) - uintptr_t(SectionTable);
336  assert((Offset % sizeof(coff_section)) == 0);
337  return (Offset / sizeof(coff_section)) + 1;
338 }
339 
341  const coff_section *Sec = toSec(Ref);
342  // In COFF, a virtual section won't have any in-file
343  // content, so the file pointer to the content will be zero.
344  return Sec->PointerToRawData == 0;
345 }
346 
347 static uint32_t getNumberOfRelocations(const coff_section *Sec,
348  MemoryBufferRef M, const uint8_t *base) {
349  // The field for the number of relocations in COFF section table is only
350  // 16-bit wide. If a section has more than 65535 relocations, 0xFFFF is set to
351  // NumberOfRelocations field, and the actual relocation count is stored in the
352  // VirtualAddress field in the first relocation entry.
353  if (Sec->hasExtendedRelocations()) {
354  const coff_relocation *FirstReloc;
355  if (getObject(FirstReloc, M, reinterpret_cast<const coff_relocation*>(
356  base + Sec->PointerToRelocations)))
357  return 0;
358  // -1 to exclude this first relocation entry.
359  return FirstReloc->VirtualAddress - 1;
360  }
361  return Sec->NumberOfRelocations;
362 }
363 
364 static const coff_relocation *
365 getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base) {
366  uint64_t NumRelocs = getNumberOfRelocations(Sec, M, Base);
367  if (!NumRelocs)
368  return nullptr;
369  auto begin = reinterpret_cast<const coff_relocation *>(
370  Base + Sec->PointerToRelocations);
371  if (Sec->hasExtendedRelocations()) {
372  // Skip the first relocation entry repurposed to store the number of
373  // relocations.
374  begin++;
375  }
376  if (Binary::checkOffset(M, uintptr_t(begin),
377  sizeof(coff_relocation) * NumRelocs))
378  return nullptr;
379  return begin;
380 }
381 
383  const coff_section *Sec = toSec(Ref);
384  const coff_relocation *begin = getFirstReloc(Sec, Data, base());
385  if (begin && Sec->VirtualAddress != 0)
386  report_fatal_error("Sections with relocations should have an address of 0");
388  Ret.p = reinterpret_cast<uintptr_t>(begin);
389  return relocation_iterator(RelocationRef(Ret, this));
390 }
391 
393  const coff_section *Sec = toSec(Ref);
394  const coff_relocation *I = getFirstReloc(Sec, Data, base());
395  if (I)
396  I += getNumberOfRelocations(Sec, Data, base());
398  Ret.p = reinterpret_cast<uintptr_t>(I);
399  return relocation_iterator(RelocationRef(Ret, this));
400 }
401 
402 // Initialize the pointer to the symbol table.
403 std::error_code COFFObjectFile::initSymbolTablePtr() {
404  if (COFFHeader)
405  if (std::error_code EC = getObject(
406  SymbolTable16, Data, base() + getPointerToSymbolTable(),
408  return EC;
409 
410  if (COFFBigObjHeader)
411  if (std::error_code EC = getObject(
412  SymbolTable32, Data, base() + getPointerToSymbolTable(),
414  return EC;
415 
416  // Find string table. The first four byte of the string table contains the
417  // total size of the string table, including the size field itself. If the
418  // string table is empty, the value of the first four byte would be 4.
421  const uint8_t *StringTableAddr = base() + StringTableOffset;
422  const ulittle32_t *StringTableSizePtr;
423  if (std::error_code EC = getObject(StringTableSizePtr, Data, StringTableAddr))
424  return EC;
425  StringTableSize = *StringTableSizePtr;
426  if (std::error_code EC =
427  getObject(StringTable, Data, StringTableAddr, StringTableSize))
428  return EC;
429 
430  // Treat table sizes < 4 as empty because contrary to the PECOFF spec, some
431  // tools like cvtres write a size of 0 for an empty table instead of 4.
432  if (StringTableSize < 4)
433  StringTableSize = 4;
434 
435  // Check that the string table is null terminated if has any in it.
436  if (StringTableSize > 4 && StringTable[StringTableSize - 1] != 0)
438  return std::error_code();
439 }
440 
442  if (PE32Header)
443  return PE32Header->ImageBase;
444  else if (PE32PlusHeader)
445  return PE32PlusHeader->ImageBase;
446  // This actually comes up in practice.
447  return 0;
448 }
449 
450 // Returns the file offset for the given VA.
451 std::error_code COFFObjectFile::getVaPtr(uint64_t Addr, uintptr_t &Res) const {
452  uint64_t ImageBase = getImageBase();
453  uint64_t Rva = Addr - ImageBase;
454  assert(Rva <= UINT32_MAX);
455  return getRvaPtr((uint32_t)Rva, Res);
456 }
457 
458 // Returns the file offset for the given RVA.
459 std::error_code COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const {
460  for (const SectionRef &S : sections()) {
461  const coff_section *Section = getCOFFSection(S);
462  uint32_t SectionStart = Section->VirtualAddress;
463  uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
464  if (SectionStart <= Addr && Addr < SectionEnd) {
465  uint32_t Offset = Addr - SectionStart;
466  Res = uintptr_t(base()) + Section->PointerToRawData + Offset;
467  return std::error_code();
468  }
469  }
471 }
472 
473 std::error_code
475  ArrayRef<uint8_t> &Contents) const {
476  for (const SectionRef &S : sections()) {
477  const coff_section *Section = getCOFFSection(S);
478  uint32_t SectionStart = Section->VirtualAddress;
479  // Check if this RVA is within the section bounds. Be careful about integer
480  // overflow.
481  uint32_t OffsetIntoSection = RVA - SectionStart;
482  if (SectionStart <= RVA && OffsetIntoSection < Section->VirtualSize &&
483  Size <= Section->VirtualSize - OffsetIntoSection) {
484  uintptr_t Begin =
485  uintptr_t(base()) + Section->PointerToRawData + OffsetIntoSection;
486  Contents =
487  ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(Begin), Size);
488  return std::error_code();
489  }
490  }
492 }
493 
494 // Returns hint and name fields, assuming \p Rva is pointing to a Hint/Name
495 // table entry.
496 std::error_code COFFObjectFile::getHintName(uint32_t Rva, uint16_t &Hint,
497  StringRef &Name) const {
498  uintptr_t IntPtr = 0;
499  if (std::error_code EC = getRvaPtr(Rva, IntPtr))
500  return EC;
501  const uint8_t *Ptr = reinterpret_cast<const uint8_t *>(IntPtr);
502  Hint = *reinterpret_cast<const ulittle16_t *>(Ptr);
503  Name = StringRef(reinterpret_cast<const char *>(Ptr + 2));
504  return std::error_code();
505 }
506 
507 std::error_code
509  const codeview::DebugInfo *&PDBInfo,
510  StringRef &PDBFileName) const {
511  ArrayRef<uint8_t> InfoBytes;
512  if (std::error_code EC = getRvaAndSizeAsBytes(
513  DebugDir->AddressOfRawData, DebugDir->SizeOfData, InfoBytes))
514  return EC;
515  if (InfoBytes.size() < sizeof(*PDBInfo) + 1)
517  PDBInfo = reinterpret_cast<const codeview::DebugInfo *>(InfoBytes.data());
518  InfoBytes = InfoBytes.drop_front(sizeof(*PDBInfo));
519  PDBFileName = StringRef(reinterpret_cast<const char *>(InfoBytes.data()),
520  InfoBytes.size());
521  // Truncate the name at the first null byte. Ignore any padding.
522  PDBFileName = PDBFileName.split('\0').first;
523  return std::error_code();
524 }
525 
526 std::error_code
528  StringRef &PDBFileName) const {
529  for (const debug_directory &D : debug_directories())
531  return getDebugPDBInfo(&D, PDBInfo, PDBFileName);
532  // If we get here, there is no PDB info to return.
533  PDBInfo = nullptr;
534  PDBFileName = StringRef();
535  return std::error_code();
536 }
537 
538 // Find the import table.
539 std::error_code COFFObjectFile::initImportTablePtr() {
540  // First, we get the RVA of the import table. If the file lacks a pointer to
541  // the import table, do nothing.
542  const data_directory *DataEntry;
543  if (getDataDirectory(COFF::IMPORT_TABLE, DataEntry))
544  return std::error_code();
545 
546  // Do nothing if the pointer to import table is NULL.
547  if (DataEntry->RelativeVirtualAddress == 0)
548  return std::error_code();
549 
550  uint32_t ImportTableRva = DataEntry->RelativeVirtualAddress;
551 
552  // Find the section that contains the RVA. This is needed because the RVA is
553  // the import table's memory address which is different from its file offset.
554  uintptr_t IntPtr = 0;
555  if (std::error_code EC = getRvaPtr(ImportTableRva, IntPtr))
556  return EC;
557  if (std::error_code EC = checkOffset(Data, IntPtr, DataEntry->Size))
558  return EC;
559  ImportDirectory = reinterpret_cast<
560  const coff_import_directory_table_entry *>(IntPtr);
561  return std::error_code();
562 }
563 
564 // Initializes DelayImportDirectory and NumberOfDelayImportDirectory.
565 std::error_code COFFObjectFile::initDelayImportTablePtr() {
566  const data_directory *DataEntry;
568  return std::error_code();
569  if (DataEntry->RelativeVirtualAddress == 0)
570  return std::error_code();
571 
572  uint32_t RVA = DataEntry->RelativeVirtualAddress;
573  NumberOfDelayImportDirectory = DataEntry->Size /
575 
576  uintptr_t IntPtr = 0;
577  if (std::error_code EC = getRvaPtr(RVA, IntPtr))
578  return EC;
579  DelayImportDirectory = reinterpret_cast<
580  const delay_import_directory_table_entry *>(IntPtr);
581  return std::error_code();
582 }
583 
584 // Find the export table.
585 std::error_code COFFObjectFile::initExportTablePtr() {
586  // First, we get the RVA of the export table. If the file lacks a pointer to
587  // the export table, do nothing.
588  const data_directory *DataEntry;
589  if (getDataDirectory(COFF::EXPORT_TABLE, DataEntry))
590  return std::error_code();
591 
592  // Do nothing if the pointer to export table is NULL.
593  if (DataEntry->RelativeVirtualAddress == 0)
594  return std::error_code();
595 
596  uint32_t ExportTableRva = DataEntry->RelativeVirtualAddress;
597  uintptr_t IntPtr = 0;
598  if (std::error_code EC = getRvaPtr(ExportTableRva, IntPtr))
599  return EC;
600  ExportDirectory =
601  reinterpret_cast<const export_directory_table_entry *>(IntPtr);
602  return std::error_code();
603 }
604 
605 std::error_code COFFObjectFile::initBaseRelocPtr() {
606  const data_directory *DataEntry;
608  return std::error_code();
609  if (DataEntry->RelativeVirtualAddress == 0)
610  return std::error_code();
611 
612  uintptr_t IntPtr = 0;
613  if (std::error_code EC = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr))
614  return EC;
615  BaseRelocHeader = reinterpret_cast<const coff_base_reloc_block_header *>(
616  IntPtr);
617  BaseRelocEnd = reinterpret_cast<coff_base_reloc_block_header *>(
618  IntPtr + DataEntry->Size);
619  // FIXME: Verify the section containing BaseRelocHeader has at least
620  // DataEntry->Size bytes after DataEntry->RelativeVirtualAddress.
621  return std::error_code();
622 }
623 
624 std::error_code COFFObjectFile::initDebugDirectoryPtr() {
625  // Get the RVA of the debug directory. Do nothing if it does not exist.
626  const data_directory *DataEntry;
627  if (getDataDirectory(COFF::DEBUG_DIRECTORY, DataEntry))
628  return std::error_code();
629 
630  // Do nothing if the RVA is NULL.
631  if (DataEntry->RelativeVirtualAddress == 0)
632  return std::error_code();
633 
634  // Check that the size is a multiple of the entry size.
635  if (DataEntry->Size % sizeof(debug_directory) != 0)
637 
638  uintptr_t IntPtr = 0;
639  if (std::error_code EC = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr))
640  return EC;
641  DebugDirectoryBegin = reinterpret_cast<const debug_directory *>(IntPtr);
642  DebugDirectoryEnd = reinterpret_cast<const debug_directory *>(
643  IntPtr + DataEntry->Size);
644  // FIXME: Verify the section containing DebugDirectoryBegin has at least
645  // DataEntry->Size bytes after DataEntry->RelativeVirtualAddress.
646  return std::error_code();
647 }
648 
649 std::error_code COFFObjectFile::initLoadConfigPtr() {
650  // Get the RVA of the debug directory. Do nothing if it does not exist.
651  const data_directory *DataEntry;
653  return std::error_code();
654 
655  // Do nothing if the RVA is NULL.
656  if (DataEntry->RelativeVirtualAddress == 0)
657  return std::error_code();
658  uintptr_t IntPtr = 0;
659  if (std::error_code EC = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr))
660  return EC;
661 
662  LoadConfig = (const void *)IntPtr;
663  return std::error_code();
664 }
665 
667  : ObjectFile(Binary::ID_COFF, Object), COFFHeader(nullptr),
668  COFFBigObjHeader(nullptr), PE32Header(nullptr), PE32PlusHeader(nullptr),
669  DataDirectory(nullptr), SectionTable(nullptr), SymbolTable16(nullptr),
670  SymbolTable32(nullptr), StringTable(nullptr), StringTableSize(0),
671  ImportDirectory(nullptr),
672  DelayImportDirectory(nullptr), NumberOfDelayImportDirectory(0),
673  ExportDirectory(nullptr), BaseRelocHeader(nullptr), BaseRelocEnd(nullptr),
674  DebugDirectoryBegin(nullptr), DebugDirectoryEnd(nullptr) {
675  // Check that we at least have enough room for a header.
676  if (!checkSize(Data, EC, sizeof(coff_file_header)))
677  return;
678 
679  // The current location in the file where we are looking at.
680  uint64_t CurPtr = 0;
681 
682  // PE header is optional and is present only in executables. If it exists,
683  // it is placed right after COFF header.
684  bool HasPEHeader = false;
685 
686  // Check if this is a PE/COFF file.
687  if (checkSize(Data, EC, sizeof(dos_header) + sizeof(COFF::PEMagic))) {
688  // PE/COFF, seek through MS-DOS compatibility stub and 4-byte
689  // PE signature to find 'normal' COFF header.
690  const auto *DH = reinterpret_cast<const dos_header *>(base());
691  if (DH->Magic[0] == 'M' && DH->Magic[1] == 'Z') {
692  CurPtr = DH->AddressOfNewExeHeader;
693  // Check the PE magic bytes. ("PE\0\0")
694  if (memcmp(base() + CurPtr, COFF::PEMagic, sizeof(COFF::PEMagic)) != 0) {
696  return;
697  }
698  CurPtr += sizeof(COFF::PEMagic); // Skip the PE magic bytes.
699  HasPEHeader = true;
700  }
701  }
702 
703  if ((EC = getObject(COFFHeader, Data, base() + CurPtr)))
704  return;
705 
706  // It might be a bigobj file, let's check. Note that COFF bigobj and COFF
707  // import libraries share a common prefix but bigobj is more restrictive.
708  if (!HasPEHeader && COFFHeader->Machine == COFF::IMAGE_FILE_MACHINE_UNKNOWN &&
709  COFFHeader->NumberOfSections == uint16_t(0xffff) &&
710  checkSize(Data, EC, sizeof(coff_bigobj_file_header))) {
711  if ((EC = getObject(COFFBigObjHeader, Data, base() + CurPtr)))
712  return;
713 
714  // Verify that we are dealing with bigobj.
715  if (COFFBigObjHeader->Version >= COFF::BigObjHeader::MinBigObjectVersion &&
716  std::memcmp(COFFBigObjHeader->UUID, COFF::BigObjMagic,
717  sizeof(COFF::BigObjMagic)) == 0) {
718  COFFHeader = nullptr;
719  CurPtr += sizeof(coff_bigobj_file_header);
720  } else {
721  // It's not a bigobj.
722  COFFBigObjHeader = nullptr;
723  }
724  }
725  if (COFFHeader) {
726  // The prior checkSize call may have failed. This isn't a hard error
727  // because we were just trying to sniff out bigobj.
728  EC = std::error_code();
729  CurPtr += sizeof(coff_file_header);
730 
731  if (COFFHeader->isImportLibrary())
732  return;
733  }
734 
735  if (HasPEHeader) {
736  const pe32_header *Header;
737  if ((EC = getObject(Header, Data, base() + CurPtr)))
738  return;
739 
740  const uint8_t *DataDirAddr;
741  uint64_t DataDirSize;
742  if (Header->Magic == COFF::PE32Header::PE32) {
743  PE32Header = Header;
744  DataDirAddr = base() + CurPtr + sizeof(pe32_header);
745  DataDirSize = sizeof(data_directory) * PE32Header->NumberOfRvaAndSize;
746  } else if (Header->Magic == COFF::PE32Header::PE32_PLUS) {
747  PE32PlusHeader = reinterpret_cast<const pe32plus_header *>(Header);
748  DataDirAddr = base() + CurPtr + sizeof(pe32plus_header);
749  DataDirSize = sizeof(data_directory) * PE32PlusHeader->NumberOfRvaAndSize;
750  } else {
751  // It's neither PE32 nor PE32+.
753  return;
754  }
755  if ((EC = getObject(DataDirectory, Data, DataDirAddr, DataDirSize)))
756  return;
757  }
758 
759  if (COFFHeader)
760  CurPtr += COFFHeader->SizeOfOptionalHeader;
761 
762  if ((EC = getObject(SectionTable, Data, base() + CurPtr,
763  (uint64_t)getNumberOfSections() * sizeof(coff_section))))
764  return;
765 
766  // Initialize the pointer to the symbol table.
767  if (getPointerToSymbolTable() != 0) {
768  if ((EC = initSymbolTablePtr())) {
769  SymbolTable16 = nullptr;
770  SymbolTable32 = nullptr;
771  StringTable = nullptr;
772  StringTableSize = 0;
773  }
774  } else {
775  // We had better not have any symbols if we don't have a symbol table.
776  if (getNumberOfSymbols() != 0) {
778  return;
779  }
780  }
781 
782  // Initialize the pointer to the beginning of the import table.
783  if ((EC = initImportTablePtr()))
784  return;
785  if ((EC = initDelayImportTablePtr()))
786  return;
787 
788  // Initialize the pointer to the export table.
789  if ((EC = initExportTablePtr()))
790  return;
791 
792  // Initialize the pointer to the base relocation table.
793  if ((EC = initBaseRelocPtr()))
794  return;
795 
796  // Initialize the pointer to the export table.
797  if ((EC = initDebugDirectoryPtr()))
798  return;
799 
800  if ((EC = initLoadConfigPtr()))
801  return;
802 
803  EC = std::error_code();
804 }
805 
808  Ret.p = getSymbolTable();
809  return basic_symbol_iterator(SymbolRef(Ret, this));
810 }
811 
813  // The symbol table ends where the string table begins.
815  Ret.p = reinterpret_cast<uintptr_t>(StringTable);
816  return basic_symbol_iterator(SymbolRef(Ret, this));
817 }
818 
820  if (!ImportDirectory)
821  return import_directory_end();
822  if (ImportDirectory->isNull())
823  return import_directory_end();
825  ImportDirectoryEntryRef(ImportDirectory, 0, this));
826 }
827 
830  ImportDirectoryEntryRef(nullptr, -1, this));
831 }
832 
836  DelayImportDirectoryEntryRef(DelayImportDirectory, 0, this));
837 }
838 
843  DelayImportDirectory, NumberOfDelayImportDirectory, this));
844 }
845 
848  ExportDirectoryEntryRef(ExportDirectory, 0, this));
849 }
850 
852  if (!ExportDirectory)
853  return export_directory_iterator(ExportDirectoryEntryRef(nullptr, 0, this));
854  ExportDirectoryEntryRef Ref(ExportDirectory,
855  ExportDirectory->AddressTableEntries, this);
856  return export_directory_iterator(Ref);
857 }
858 
861  Ret.p = reinterpret_cast<uintptr_t>(SectionTable);
862  return section_iterator(SectionRef(Ret, this));
863 }
864 
867  int NumSections =
868  COFFHeader && COFFHeader->isImportLibrary() ? 0 : getNumberOfSections();
869  Ret.p = reinterpret_cast<uintptr_t>(SectionTable + NumSections);
870  return section_iterator(SectionRef(Ret, this));
871 }
872 
874  return base_reloc_iterator(BaseRelocRef(BaseRelocHeader, this));
875 }
876 
878  return base_reloc_iterator(BaseRelocRef(BaseRelocEnd, this));
879 }
880 
882  return getArch() == Triple::x86_64 || getArch() == Triple::aarch64 ? 8 : 4;
883 }
884 
886  switch(getMachine()) {
888  return "COFF-i386";
890  return "COFF-x86-64";
892  return "COFF-ARM";
894  return "COFF-ARM64";
895  default:
896  return "COFF-<unknown arch>";
897  }
898 }
899 
901  switch (getMachine()) {
903  return Triple::x86;
905  return Triple::x86_64;
907  return Triple::thumb;
909  return Triple::aarch64;
910  default:
911  return Triple::UnknownArch;
912  }
913 }
914 
916  if (PE32Header)
917  return PE32Header->AddressOfEntryPoint;
918  return 0;
919 }
920 
924 }
925 
930 }
931 
935 }
936 
939 }
940 
941 std::error_code
943  Res = COFFHeader;
944  return std::error_code();
945 }
946 
947 std::error_code
949  Res = COFFBigObjHeader;
950  return std::error_code();
951 }
952 
953 std::error_code COFFObjectFile::getPE32Header(const pe32_header *&Res) const {
954  Res = PE32Header;
955  return std::error_code();
956 }
957 
958 std::error_code
960  Res = PE32PlusHeader;
961  return std::error_code();
962 }
963 
964 std::error_code
966  const data_directory *&Res) const {
967  // Error if there's no data directory or the index is out of range.
968  if (!DataDirectory) {
969  Res = nullptr;
971  }
972  assert(PE32Header || PE32PlusHeader);
973  uint32_t NumEnt = PE32Header ? PE32Header->NumberOfRvaAndSize
974  : PE32PlusHeader->NumberOfRvaAndSize;
975  if (Index >= NumEnt) {
976  Res = nullptr;
978  }
979  Res = &DataDirectory[Index];
980  return std::error_code();
981 }
982 
983 std::error_code COFFObjectFile::getSection(int32_t Index,
984  const coff_section *&Result) const {
985  Result = nullptr;
987  return std::error_code();
988  if (static_cast<uint32_t>(Index) <= getNumberOfSections()) {
989  // We already verified the section table data, so no need to check again.
990  Result = SectionTable + (Index - 1);
991  return std::error_code();
992  }
994 }
995 
997  const coff_section *&Result) const {
998  Result = nullptr;
999  StringRef SecName;
1000  for (const SectionRef &Section : sections()) {
1001  if (std::error_code E = Section.getName(SecName))
1002  return E;
1003  if (SecName == SectionName) {
1004  Result = getCOFFSection(Section);
1005  return std::error_code();
1006  }
1007  }
1009 }
1010 
1011 std::error_code COFFObjectFile::getString(uint32_t Offset,
1012  StringRef &Result) const {
1013  if (StringTableSize <= 4)
1014  // Tried to get a string from an empty string table.
1016  if (Offset >= StringTableSize)
1018  Result = StringRef(StringTable + Offset);
1019  return std::error_code();
1020 }
1021 
1023  StringRef &Res) const {
1024  return getSymbolName(Symbol.getGeneric(), Res);
1025 }
1026 
1028  StringRef &Res) const {
1029  // Check for string table entry. First 4 bytes are 0.
1030  if (Symbol->Name.Offset.Zeroes == 0) {
1031  if (std::error_code EC = getString(Symbol->Name.Offset.Offset, Res))
1032  return EC;
1033  return std::error_code();
1034  }
1035 
1036  if (Symbol->Name.ShortName[COFF::NameSize - 1] == 0)
1037  // Null terminated, let ::strlen figure out the length.
1038  Res = StringRef(Symbol->Name.ShortName);
1039  else
1040  // Not null terminated, use all 8 bytes.
1041  Res = StringRef(Symbol->Name.ShortName, COFF::NameSize);
1042  return std::error_code();
1043 }
1044 
1047  const uint8_t *Aux = nullptr;
1048 
1049  size_t SymbolSize = getSymbolTableEntrySize();
1050  if (Symbol.getNumberOfAuxSymbols() > 0) {
1051  // AUX data comes immediately after the symbol in COFF
1052  Aux = reinterpret_cast<const uint8_t *>(Symbol.getRawPtr()) + SymbolSize;
1053 #ifndef NDEBUG
1054  // Verify that the Aux symbol points to a valid entry in the symbol table.
1055  uintptr_t Offset = uintptr_t(Aux) - uintptr_t(base());
1056  if (Offset < getPointerToSymbolTable() ||
1057  Offset >=
1058  getPointerToSymbolTable() + (getNumberOfSymbols() * SymbolSize))
1059  report_fatal_error("Aux Symbol data was outside of symbol table.");
1060 
1061  assert((Offset - getPointerToSymbolTable()) % SymbolSize == 0 &&
1062  "Aux Symbol data did not point to the beginning of a symbol");
1063 #endif
1064  }
1065  return makeArrayRef(Aux, Symbol.getNumberOfAuxSymbols() * SymbolSize);
1066 }
1067 
1069  uintptr_t Offset =
1070  reinterpret_cast<uintptr_t>(Symbol.getRawPtr()) - getSymbolTable();
1071  assert(Offset % getSymbolTableEntrySize() == 0 &&
1072  "Symbol did not point to the beginning of a symbol");
1073  size_t Index = Offset / getSymbolTableEntrySize();
1074  assert(Index < getNumberOfSymbols());
1075  return Index;
1076 }
1077 
1079  StringRef &Res) const {
1080  StringRef Name;
1081  if (Sec->Name[COFF::NameSize - 1] == 0)
1082  // Null terminated, let ::strlen figure out the length.
1083  Name = Sec->Name;
1084  else
1085  // Not null terminated, use all 8 bytes.
1086  Name = StringRef(Sec->Name, COFF::NameSize);
1087 
1088  // Check for string table entry. First byte is '/'.
1089  if (Name.startswith("/")) {
1090  uint32_t Offset;
1091  if (Name.startswith("//")) {
1092  if (decodeBase64StringEntry(Name.substr(2), Offset))
1094  } else {
1095  if (Name.substr(1).getAsInteger(10, Offset))
1097  }
1098  if (std::error_code EC = getString(Offset, Name))
1099  return EC;
1100  }
1101 
1102  Res = Name;
1103  return std::error_code();
1104 }
1105 
1106 uint64_t COFFObjectFile::getSectionSize(const coff_section *Sec) const {
1107  // SizeOfRawData and VirtualSize change what they represent depending on
1108  // whether or not we have an executable image.
1109  //
1110  // For object files, SizeOfRawData contains the size of section's data;
1111  // VirtualSize should be zero but isn't due to buggy COFF writers.
1112  //
1113  // For executables, SizeOfRawData *must* be a multiple of FileAlignment; the
1114  // actual section size is in VirtualSize. It is possible for VirtualSize to
1115  // be greater than SizeOfRawData; the contents past that point should be
1116  // considered to be zero.
1117  if (getDOSHeader())
1118  return std::min(Sec->VirtualSize, Sec->SizeOfRawData);
1119  return Sec->SizeOfRawData;
1120 }
1121 
1122 std::error_code
1124  ArrayRef<uint8_t> &Res) const {
1125  // In COFF, a virtual section won't have any in-file
1126  // content, so the file pointer to the content will be zero.
1127  if (Sec->PointerToRawData == 0)
1128  return std::error_code();
1129  // The only thing that we need to verify is that the contents is contained
1130  // within the file bounds. We don't need to make sure it doesn't cover other
1131  // data, as there's nothing that says that is not allowed.
1132  uintptr_t ConStart = uintptr_t(base()) + Sec->PointerToRawData;
1134  if (checkOffset(Data, ConStart, SectionSize))
1136  Res = makeArrayRef(reinterpret_cast<const uint8_t *>(ConStart), SectionSize);
1137  return std::error_code();
1138 }
1139 
1140 const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
1141  return reinterpret_cast<const coff_relocation*>(Rel.p);
1142 }
1143 
1145  Rel.p = reinterpret_cast<uintptr_t>(
1146  reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
1147 }
1148 
1150  const coff_relocation *R = toRel(Rel);
1151  return R->VirtualAddress;
1152 }
1153 
1155  const coff_relocation *R = toRel(Rel);
1156  DataRefImpl Ref;
1158  return symbol_end();
1159  if (SymbolTable16)
1160  Ref.p = reinterpret_cast<uintptr_t>(SymbolTable16 + R->SymbolTableIndex);
1161  else if (SymbolTable32)
1162  Ref.p = reinterpret_cast<uintptr_t>(SymbolTable32 + R->SymbolTableIndex);
1163  else
1164  llvm_unreachable("no symbol table pointer!");
1165  return symbol_iterator(SymbolRef(Ref, this));
1166 }
1167 
1169  const coff_relocation* R = toRel(Rel);
1170  return R->Type;
1171 }
1172 
1173 const coff_section *
1175  return toSec(Section.getRawDataRefImpl());
1176 }
1177 
1179  if (SymbolTable16)
1180  return toSymb<coff_symbol16>(Ref);
1181  if (SymbolTable32)
1182  return toSymb<coff_symbol32>(Ref);
1183  llvm_unreachable("no symbol table pointer!");
1184 }
1185 
1187  return getCOFFSymbol(Symbol.getRawDataRefImpl());
1188 }
1189 
1190 const coff_relocation *
1192  return toRel(Reloc.getRawDataRefImpl());
1193 }
1194 
1197  return {getFirstReloc(Sec, Data, base()),
1198  getNumberOfRelocations(Sec, Data, base())};
1199 }
1200 
1201 #define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(reloc_type) \
1202  case COFF::reloc_type: \
1203  return #reloc_type;
1204 
1206  switch (getMachine()) {
1208  switch (Type) {
1226  default:
1227  return "Unknown";
1228  }
1229  break;
1231  switch (Type) {
1247  default:
1248  return "Unknown";
1249  }
1250  break;
1252  switch (Type) {
1270  default:
1271  return "Unknown";
1272  }
1273  break;
1275  switch (Type) {
1287  default:
1288  return "Unknown";
1289  }
1290  break;
1291  default:
1292  return "Unknown";
1293  }
1294 }
1295 
1296 #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
1297 
1299  DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
1300  const coff_relocation *Reloc = toRel(Rel);
1301  StringRef Res = getRelocationTypeName(Reloc->Type);
1302  Result.append(Res.begin(), Res.end());
1303 }
1304 
1306  return !DataDirectory;
1307 }
1308 
1311  .Case("eh_fram", "eh_frame")
1312  .Default(Name);
1313 }
1314 
1317  return ImportTable == Other.ImportTable && Index == Other.Index;
1318 }
1319 
1321  ++Index;
1322  if (ImportTable[Index].isNull()) {
1323  Index = -1;
1324  ImportTable = nullptr;
1325  }
1326 }
1327 
1329  const coff_import_directory_table_entry *&Result) const {
1330  return getObject(Result, OwningObject->Data, ImportTable + Index);
1331 }
1332 
1335  uintptr_t Ptr, int Index) {
1336  if (Object->getBytesInAddress() == 4) {
1337  auto *P = reinterpret_cast<const import_lookup_table_entry32 *>(Ptr);
1338  return imported_symbol_iterator(ImportedSymbolRef(P, Index, Object));
1339  }
1340  auto *P = reinterpret_cast<const import_lookup_table_entry64 *>(Ptr);
1341  return imported_symbol_iterator(ImportedSymbolRef(P, Index, Object));
1342 }
1343 
1346  uintptr_t IntPtr = 0;
1347  Object->getRvaPtr(RVA, IntPtr);
1348  return makeImportedSymbolIterator(Object, IntPtr, 0);
1349 }
1350 
1353  uintptr_t IntPtr = 0;
1354  Object->getRvaPtr(RVA, IntPtr);
1355  // Forward the pointer to the last entry which is null.
1356  int Index = 0;
1357  if (Object->getBytesInAddress() == 4) {
1358  auto *Entry = reinterpret_cast<ulittle32_t *>(IntPtr);
1359  while (*Entry++)
1360  ++Index;
1361  } else {
1362  auto *Entry = reinterpret_cast<ulittle64_t *>(IntPtr);
1363  while (*Entry++)
1364  ++Index;
1365  }
1366  return makeImportedSymbolIterator(Object, IntPtr, Index);
1367 }
1368 
1371  return importedSymbolBegin(ImportTable[Index].ImportAddressTableRVA,
1372  OwningObject);
1373 }
1374 
1377  return importedSymbolEnd(ImportTable[Index].ImportAddressTableRVA,
1378  OwningObject);
1379 }
1380 
1383  return make_range(imported_symbol_begin(), imported_symbol_end());
1384 }
1385 
1387  return importedSymbolBegin(ImportTable[Index].ImportLookupTableRVA,
1388  OwningObject);
1389 }
1390 
1392  return importedSymbolEnd(ImportTable[Index].ImportLookupTableRVA,
1393  OwningObject);
1394 }
1395 
1398  return make_range(lookup_table_begin(), lookup_table_end());
1399 }
1400 
1401 std::error_code ImportDirectoryEntryRef::getName(StringRef &Result) const {
1402  uintptr_t IntPtr = 0;
1403  if (std::error_code EC =
1404  OwningObject->getRvaPtr(ImportTable[Index].NameRVA, IntPtr))
1405  return EC;
1406  Result = StringRef(reinterpret_cast<const char *>(IntPtr));
1407  return std::error_code();
1408 }
1409 
1410 std::error_code
1412  Result = ImportTable[Index].ImportLookupTableRVA;
1413  return std::error_code();
1414 }
1415 
1416 std::error_code
1418  Result = ImportTable[Index].ImportAddressTableRVA;
1419  return std::error_code();
1420 }
1421 
1424  return Table == Other.Table && Index == Other.Index;
1425 }
1426 
1428  ++Index;
1429 }
1430 
1433  return importedSymbolBegin(Table[Index].DelayImportNameTable,
1434  OwningObject);
1435 }
1436 
1439  return importedSymbolEnd(Table[Index].DelayImportNameTable,
1440  OwningObject);
1441 }
1442 
1445  return make_range(imported_symbol_begin(), imported_symbol_end());
1446 }
1447 
1448 std::error_code DelayImportDirectoryEntryRef::getName(StringRef &Result) const {
1449  uintptr_t IntPtr = 0;
1450  if (std::error_code EC = OwningObject->getRvaPtr(Table[Index].Name, IntPtr))
1451  return EC;
1452  Result = StringRef(reinterpret_cast<const char *>(IntPtr));
1453  return std::error_code();
1454 }
1455 
1456 std::error_code DelayImportDirectoryEntryRef::
1458  Result = Table;
1459  return std::error_code();
1460 }
1461 
1462 std::error_code DelayImportDirectoryEntryRef::
1463 getImportAddress(int AddrIndex, uint64_t &Result) const {
1464  uint32_t RVA = Table[Index].DelayImportAddressTable +
1465  AddrIndex * (OwningObject->is64() ? 8 : 4);
1466  uintptr_t IntPtr = 0;
1467  if (std::error_code EC = OwningObject->getRvaPtr(RVA, IntPtr))
1468  return EC;
1469  if (OwningObject->is64())
1470  Result = *reinterpret_cast<const ulittle64_t *>(IntPtr);
1471  else
1472  Result = *reinterpret_cast<const ulittle32_t *>(IntPtr);
1473  return std::error_code();
1474 }
1475 
1478  return ExportTable == Other.ExportTable && Index == Other.Index;
1479 }
1480 
1482  ++Index;
1483 }
1484 
1485 // Returns the name of the current export symbol. If the symbol is exported only
1486 // by ordinal, the empty string is set as a result.
1487 std::error_code ExportDirectoryEntryRef::getDllName(StringRef &Result) const {
1488  uintptr_t IntPtr = 0;
1489  if (std::error_code EC =
1490  OwningObject->getRvaPtr(ExportTable->NameRVA, IntPtr))
1491  return EC;
1492  Result = StringRef(reinterpret_cast<const char *>(IntPtr));
1493  return std::error_code();
1494 }
1495 
1496 // Returns the starting ordinal number.
1497 std::error_code
1499  Result = ExportTable->OrdinalBase;
1500  return std::error_code();
1501 }
1502 
1503 // Returns the export ordinal of the current export symbol.
1504 std::error_code ExportDirectoryEntryRef::getOrdinal(uint32_t &Result) const {
1505  Result = ExportTable->OrdinalBase + Index;
1506  return std::error_code();
1507 }
1508 
1509 // Returns the address of the current export symbol.
1510 std::error_code ExportDirectoryEntryRef::getExportRVA(uint32_t &Result) const {
1511  uintptr_t IntPtr = 0;
1512  if (std::error_code EC =
1513  OwningObject->getRvaPtr(ExportTable->ExportAddressTableRVA, IntPtr))
1514  return EC;
1516  reinterpret_cast<const export_address_table_entry *>(IntPtr);
1517  Result = entry[Index].ExportRVA;
1518  return std::error_code();
1519 }
1520 
1521 // Returns the name of the current export symbol. If the symbol is exported only
1522 // by ordinal, the empty string is set as a result.
1523 std::error_code
1525  uintptr_t IntPtr = 0;
1526  if (std::error_code EC =
1527  OwningObject->getRvaPtr(ExportTable->OrdinalTableRVA, IntPtr))
1528  return EC;
1529  const ulittle16_t *Start = reinterpret_cast<const ulittle16_t *>(IntPtr);
1530 
1531  uint32_t NumEntries = ExportTable->NumberOfNamePointers;
1532  int Offset = 0;
1533  for (const ulittle16_t *I = Start, *E = Start + NumEntries;
1534  I < E; ++I, ++Offset) {
1535  if (*I != Index)
1536  continue;
1537  if (std::error_code EC =
1538  OwningObject->getRvaPtr(ExportTable->NamePointerRVA, IntPtr))
1539  return EC;
1540  const ulittle32_t *NamePtr = reinterpret_cast<const ulittle32_t *>(IntPtr);
1541  if (std::error_code EC = OwningObject->getRvaPtr(NamePtr[Offset], IntPtr))
1542  return EC;
1543  Result = StringRef(reinterpret_cast<const char *>(IntPtr));
1544  return std::error_code();
1545  }
1546  Result = "";
1547  return std::error_code();
1548 }
1549 
1550 std::error_code ExportDirectoryEntryRef::isForwarder(bool &Result) const {
1551  const data_directory *DataEntry;
1552  if (auto EC = OwningObject->getDataDirectory(COFF::EXPORT_TABLE, DataEntry))
1553  return EC;
1554  uint32_t RVA;
1555  if (auto EC = getExportRVA(RVA))
1556  return EC;
1557  uint32_t Begin = DataEntry->RelativeVirtualAddress;
1558  uint32_t End = DataEntry->RelativeVirtualAddress + DataEntry->Size;
1559  Result = (Begin <= RVA && RVA < End);
1560  return std::error_code();
1561 }
1562 
1563 std::error_code ExportDirectoryEntryRef::getForwardTo(StringRef &Result) const {
1564  uint32_t RVA;
1565  if (auto EC = getExportRVA(RVA))
1566  return EC;
1567  uintptr_t IntPtr = 0;
1568  if (auto EC = OwningObject->getRvaPtr(RVA, IntPtr))
1569  return EC;
1570  Result = StringRef(reinterpret_cast<const char *>(IntPtr));
1571  return std::error_code();
1572 }
1573 
1575 operator==(const ImportedSymbolRef &Other) const {
1576  return Entry32 == Other.Entry32 && Entry64 == Other.Entry64
1577  && Index == Other.Index;
1578 }
1579 
1581  ++Index;
1582 }
1583 
1584 std::error_code
1586  uint32_t RVA;
1587  if (Entry32) {
1588  // If a symbol is imported only by ordinal, it has no name.
1589  if (Entry32[Index].isOrdinal())
1590  return std::error_code();
1591  RVA = Entry32[Index].getHintNameRVA();
1592  } else {
1593  if (Entry64[Index].isOrdinal())
1594  return std::error_code();
1595  RVA = Entry64[Index].getHintNameRVA();
1596  }
1597  uintptr_t IntPtr = 0;
1598  if (std::error_code EC = OwningObject->getRvaPtr(RVA, IntPtr))
1599  return EC;
1600  // +2 because the first two bytes is hint.
1601  Result = StringRef(reinterpret_cast<const char *>(IntPtr + 2));
1602  return std::error_code();
1603 }
1604 
1605 std::error_code ImportedSymbolRef::isOrdinal(bool &Result) const {
1606  if (Entry32)
1607  Result = Entry32[Index].isOrdinal();
1608  else
1609  Result = Entry64[Index].isOrdinal();
1610  return std::error_code();
1611 }
1612 
1613 std::error_code ImportedSymbolRef::getHintNameRVA(uint32_t &Result) const {
1614  if (Entry32)
1615  Result = Entry32[Index].getHintNameRVA();
1616  else
1617  Result = Entry64[Index].getHintNameRVA();
1618  return std::error_code();
1619 }
1620 
1621 std::error_code ImportedSymbolRef::getOrdinal(uint16_t &Result) const {
1622  uint32_t RVA;
1623  if (Entry32) {
1624  if (Entry32[Index].isOrdinal()) {
1625  Result = Entry32[Index].getOrdinal();
1626  return std::error_code();
1627  }
1628  RVA = Entry32[Index].getHintNameRVA();
1629  } else {
1630  if (Entry64[Index].isOrdinal()) {
1631  Result = Entry64[Index].getOrdinal();
1632  return std::error_code();
1633  }
1634  RVA = Entry64[Index].getHintNameRVA();
1635  }
1636  uintptr_t IntPtr = 0;
1637  if (std::error_code EC = OwningObject->getRvaPtr(RVA, IntPtr))
1638  return EC;
1639  Result = *reinterpret_cast<const ulittle16_t *>(IntPtr);
1640  return std::error_code();
1641 }
1642 
1645  std::error_code EC;
1646  std::unique_ptr<COFFObjectFile> Ret(new COFFObjectFile(Object, EC));
1647  if (EC)
1648  return errorCodeToError(EC);
1649  return std::move(Ret);
1650 }
1651 
1652 bool BaseRelocRef::operator==(const BaseRelocRef &Other) const {
1653  return Header == Other.Header && Index == Other.Index;
1654 }
1655 
1657  // Header->BlockSize is the size of the current block, including the
1658  // size of the header itself.
1659  uint32_t Size = sizeof(*Header) +
1660  sizeof(coff_base_reloc_block_entry) * (Index + 1);
1661  if (Size == Header->BlockSize) {
1662  // .reloc contains a list of base relocation blocks. Each block
1663  // consists of the header followed by entries. The header contains
1664  // how many entories will follow. When we reach the end of the
1665  // current block, proceed to the next block.
1666  Header = reinterpret_cast<const coff_base_reloc_block_header *>(
1667  reinterpret_cast<const uint8_t *>(Header) + Size);
1668  Index = 0;
1669  } else {
1670  ++Index;
1671  }
1672 }
1673 
1674 std::error_code BaseRelocRef::getType(uint8_t &Type) const {
1675  auto *Entry = reinterpret_cast<const coff_base_reloc_block_entry *>(Header + 1);
1676  Type = Entry[Index].getType();
1677  return std::error_code();
1678 }
1679 
1680 std::error_code BaseRelocRef::getRVA(uint32_t &Result) const {
1681  auto *Entry = reinterpret_cast<const coff_base_reloc_block_entry *>(Header + 1);
1682  Result = Header->PageRVA + Entry[Index].getOffset();
1683  return std::error_code();
1684 }
1685 
1686 #define RETURN_IF_ERROR(E) \
1687  if (E) \
1688  return E;
1689 
1691 ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) {
1692  BinaryStreamReader Reader = BinaryStreamReader(BBS);
1693  Reader.setOffset(Offset);
1694  uint16_t Length;
1695  RETURN_IF_ERROR(Reader.readInteger(Length));
1696  ArrayRef<UTF16> RawDirString;
1697  RETURN_IF_ERROR(Reader.readArray(RawDirString, Length));
1698  return RawDirString;
1699 }
1700 
1703  return getDirStringAtOffset(Entry.Identifier.getNameOffset());
1704 }
1705 
1707 ResourceSectionRef::getTableAtOffset(uint32_t Offset) {
1708  const coff_resource_dir_table *Table = nullptr;
1709 
1710  BinaryStreamReader Reader(BBS);
1711  Reader.setOffset(Offset);
1712  RETURN_IF_ERROR(Reader.readObject(Table));
1713  assert(Table != nullptr);
1714  return *Table;
1715 }
1716 
1719  return getTableAtOffset(Entry.Offset.value());
1720 }
1721 
1723  return getTableAtOffset(0);
1724 }
bool isNull() const
Definition: COFF.h:560
uint32_t getAlignment() const
Definition: COFF.h:457
bool isCommon() const
Definition: COFF.h:379
static uint32_t getNumberOfRelocations(const coff_section *Sec, MemoryBufferRef M, const uint8_t *base)
std::error_code getHintNameRVA(uint32_t &Result) const
The 64-bit PE header that follows the COFF header.
Definition: COFF.h:141
int getType() const
Definition: COFF.h:714
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:250
std::error_code getImportAddress(int AddrIndex, uint64_t &Result) const
section_iterator section_begin() const override
support::ulittle16_t Machine
Definition: COFF.h:77
friend class SymbolRef
Definition: ObjectFile.h:220
std::error_code getType(uint8_t &Type) const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:24
const coff_section * getCOFFSection(const SectionRef &Section) const
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream&#39;s offset.
friend class SectionRef
Definition: ObjectFile.h:234
COFFObjectFile(MemoryBufferRef Object, std::error_code &EC)
uint64_t getRelocationOffset(DataRefImpl Rel) const override
support::ulittle32_t VirtualAddress
Definition: COFF.h:441
bool operator==(const DelayImportDirectoryEntryRef &Other) const
Definition: COFF.h:223
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
void moveSectionNext(DataRefImpl &Sec) const override
static std::error_code getObject(const T *&Obj, MemoryBufferRef M, const void *Ptr, const uint64_t Size=sizeof(T))
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
COFFSymbolRef getCOFFSymbol(const DataRefImpl &Ref) const
static std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr, const uint64_t Size)
Definition: Binary.h:148
export_directory_iterator export_directory_end() const
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
std::error_code getSection(int32_t index, const coff_section *&Res) const
std::error_code getOrdinal(uint32_t &Result) const
base_reloc_iterator base_reloc_end() const
void moveRelocationNext(DataRefImpl &Rel) const override
support::ulittle16_t Version
Definition: COFF.h:91
This class is the base class for all object file types.
Definition: ObjectFile.h:202
support::ulittle16_t NumberOfSections
Definition: COFF.h:78
content_iterator< DelayImportDirectoryEntryRef > delay_import_directory_iterator
Definition: COFF.h:48
uint32_t getPointerToSymbolTable() const
Definition: COFF.h:856
static const coff_relocation * getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base)
iterator_range< imported_symbol_iterator > imported_symbols() const
bool isSectionDefinition() const
Definition: COFF.h:415
bool isSectionCompressed(DataRefImpl Sec) const override
const uint8_t * base() const
Definition: ObjectFile.h:208
uint8_t getNumberOfAuxSymbols() const
Definition: COFF.h:341
export_directory_iterator export_directory_begin() const
Definition: COFF.h:237
std::error_code getName(StringRef &Result) const
detail::packed_endian_specific_integral< uint16_t, little, unaligned > ulittle16_t
Definition: Endian.h:269
std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const override
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
std::error_code getSectionName(DataRefImpl Sec, StringRef &Res) const override
static const char BigObjMagic[]
Definition: COFF.h:39
const coff_relocation * getCOFFRelocation(const RelocationRef &Reloc) const
import_directory_iterator import_directory_begin() const
iterator_range< const debug_directory * > debug_directories() const
Definition: COFF.h:965
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
basic_symbol_iterator symbol_end() const override
detail::packed_endian_specific_integral< uint64_t, little, unaligned > ulittle64_t
Definition: Endian.h:273
std::error_code getCOFFHeader(const coff_file_header *&Res) const
char ShortName[COFF::NameSize]
Definition: COFF.h:272
amdgpu Simplify well known AMD library false Value Value const Twine & Name
support::ulittle64_t ImageBase
Definition: COFF.h:150
friend class ExportDirectoryEntryRef
Definition: COFF.h:766
uint64_t getSectionAlignment(DataRefImpl Sec) const override
char Name[COFF::NameSize]
Definition: COFF.h:439
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
support::ulittle32_t AddressOfEntryPoint
Definition: COFF.h:112
DataRefImpl getRawDataRefImpl() const
Definition: SymbolicFile.h:205
This is a value type class that represents a single relocation in the list of relocations in the obje...
Definition: ObjectFile.h:52
support::ulittle16_t SizeOfOptionalHeader
Definition: COFF.h:82
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
The access may reference the value stored in memory.
iterator_range< base_reloc_iterator > base_relocs() const
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
union llvm::object::coff_symbol_generic::@274 Name
static imported_symbol_iterator importedSymbolBegin(uint32_t RVA, const COFFObjectFile *Object)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
Definition: StringSwitch.h:203
bool isReservedSectionNumber(int32_t SectionNumber)
Definition: COFF.h:720
imported_symbol_iterator lookup_table_begin() const
std::error_code getRvaAndSizeAsBytes(uint32_t RVA, uint32_t Size, ArrayRef< uint8_t > &Contents) const
Given an RVA base and size, returns a valid array of bytes or an error code if the RVA and size is no...
support::ulittle32_t VirtualSize
Definition: COFF.h:440
#define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(reloc_type)
content_iterator< SectionRef > section_iterator
Definition: ObjectFile.h:48
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
iterator_range< imported_symbol_iterator > imported_symbols() const
imported_symbol_iterator imported_symbol_end() const
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
int32_t getSectionNumber() const
Definition: COFF.h:320
uint32_t getSymbolFlags(DataRefImpl Symb) const override
std::error_code getDllName(StringRef &Result) const
union llvm::object::coff_resource_dir_entry::@275 Identifier
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
uint64_t getSectionAddress(DataRefImpl Sec) const override
section_iterator_range sections() const
Definition: ObjectFile.h:292
void moveSymbolNext(DataRefImpl &Symb) const override
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:598
uint8_t getComplexType() const
Definition: COFF.h:348
support::ulittle32_t ExportRVA
Definition: COFF.h:238
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
std::error_code getRVA(uint32_t &Result) const
static bool checkSize(MemoryBufferRef M, std::error_code &EC, uint64_t Size)
relocation_iterator section_rel_end(DataRefImpl Sec) const override
support::ulittle16_t Magic
Definition: COFF.h:106
std::error_code getDelayImportTable(const delay_import_directory_table_entry *&Result) const
#define P(N)
support::ulittle32_t Characteristics
Definition: COFF.h:448
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
base_reloc_iterator base_reloc_begin() const
std::error_code getName(StringRef &Result) const
support::ulittle32_t NumberOfRvaAndSize
Definition: COFF.h:170
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
content_iterator< ExportDirectoryEntryRef > export_directory_iterator
Definition: COFF.h:49
size_t getBufferSize() const
Definition: MemoryBuffer.h:279
delay_import_directory_iterator delay_import_directory_end() const
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
detail::packed_endian_specific_integral< uint32_t, little, unaligned > ulittle32_t
Definition: Endian.h:271
bool operator==(const BaseRelocRef &Other) const
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:88
const dos_header * getDOSHeader() const
Definition: COFF.h:969
content_iterator< ImportedSymbolRef > imported_symbol_iterator
Definition: COFF.h:50
The 32-bit PE header that follows the COFF header.
Definition: COFF.h:105
std::error_code getOrdinal(uint16_t &Result) const
import_lookup_table_entry< support::little64_t > import_lookup_table_entry64
Definition: COFF.h:209
std::error_code getHintName(uint32_t Rva, uint16_t &Hint, StringRef &Name) const
bool operator==(const ImportedSymbolRef &Other) const
delay_import_directory_iterator delay_import_directory_begin() const
support::ulittle32_t RelativeVirtualAddress
Definition: COFF.h:174
content_iterator< ImportDirectoryEntryRef > import_directory_iterator
Definition: COFF.h:46
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
std::error_code isForwarder(bool &Result) const
std::error_code getSymbolName(StringRef &Result) const
imported_symbol_iterator imported_symbol_begin() const
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
const void * getRawPtr() const
Definition: COFF.h:287
support::ulittle16_t Type
Definition: COFF.h:475
std::error_code getDebugPDBInfo(const debug_directory *DebugDir, const codeview::DebugInfo *&Info, StringRef &PDBFileName) const
Get PDB information out of a codeview debug directory entry.
const coff_symbol_generic * getGeneric() const
Definition: COFF.h:291
static imported_symbol_iterator makeImportedSymbolIterator(const COFFObjectFile *Object, uintptr_t Ptr, int Index)
StringTableOffset Offset
Definition: COFF.h:273
support::ulittle32_t SizeOfRawData
Definition: COFF.h:442
bool isImportLibrary() const
Definition: COFF.h:85
uint64_t getRelocationType(DataRefImpl Rel) const override
std::error_code getPE32Header(const pe32_header *&Res) const
std::error_code getOrdinalBase(uint32_t &Result) const
StringRef getFileFormatName() const override
DataRefImpl getRawDataRefImpl() const
Definition: ObjectFile.h:486
unsigned getSectionID(SectionRef Sec) const
support::ulittle32_t VirtualAddress
Definition: COFF.h:473
support::ulittle32_t SymbolTableIndex
Definition: COFF.h:474
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isUndefined() const
Definition: COFF.h:384
const T * data() const
Definition: ArrayRef.h:146
StringRef getRelocationTypeName(uint16_t Type) const
import_directory_iterator import_directory_end() const
uint16_t getMachine() const
Definition: COFF.h:812
Definition: COFF.h:553
friend class ImportDirectoryEntryRef
Definition: COFF.h:765
std::error_code isOrdinal(bool &Result) const
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:497
const coff_aux_weak_external * getWeakExternal() const
Definition: COFF.h:364
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
imported_symbol_iterator imported_symbol_begin() const
void setOffset(uint32_t Off)
support::ulittle32_t PointerToRawData
Definition: COFF.h:443
friend class RelocationRef
Definition: ObjectFile.h:260
iterator_range< import_directory_iterator > import_directories() const
static Expected< std::unique_ptr< COFFObjectFile > > createCOFFObjectFile(MemoryBufferRef Object)
Expected< const coff_resource_dir_table & > getEntrySubDir(const coff_resource_dir_entry &Entry)
uint32_t getNumberOfSections() const
Definition: COFF.h:848
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
Expected< ArrayRef< UTF16 > > getEntryNameString(const coff_resource_dir_entry &Entry)
basic_symbol_iterator symbol_begin() const override
static bool decodeBase64StringEntry(StringRef Str, uint32_t &Result)
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:727
Definition: COFF.h:711
bool isSectionData(DataRefImpl Sec) const override
uint64_t getSymbolValue(DataRefImpl Symb) const
Definition: ObjectFile.cpp:51
std::error_code getForwardTo(StringRef &Result) const
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
std::error_code getVaPtr(uint64_t VA, uintptr_t &Res) const
content_iterator< BasicSymbolRef > basic_symbol_iterator
Definition: SymbolicFile.h:139
The DOS compatible header at the front of all PE/COFF executables.
Definition: COFF.h:54
union llvm::object::coff_resource_dir_entry::@276 Offset
std::error_code getExportRVA(uint32_t &Result) const
A range adaptor for a pair of iterators.
std::error_code getRvaPtr(uint32_t Rva, uintptr_t &Res) const
section_iterator section_end() const override
support::ulittle32_t AddressOfRawData
Definition: COFF.h:185
MemoryBufferRef Data
Definition: Binary.h:37
size_t getSymbolTableEntrySize() const
Definition: COFF.h:1027
Expected< uint64_t > getStartAddress() const override
support::ulittle32_t Size
Definition: COFF.h:175
std::error_code getDataDirectory(uint32_t index, const data_directory *&Res) const
Triple::ArchType getArch() const override
This is a value type class that represents a single symbol in the list of symbols in the object file...
Definition: ObjectFile.h:141
iterator begin() const
Definition: StringRef.h:106
support::ulittle32_t ImageBase
Definition: COFF.h:115
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:394
support::ulittle32_t Zeroes
Definition: COFF.h:246
StringRef mapDebugSectionName(StringRef Name) const override
Maps a debug section name to a standard DWARF section name.
ArrayRef< coff_relocation > getRelocations(const coff_section *Sec) const
bool operator==(const ExportDirectoryEntryRef &Other) const
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
bool isWeakExternal() const
Definition: COFF.h:389
Definition: COFF.h:718
bool isSectionText(DataRefImpl Sec) const override
std::error_code getCOFFBigObjHeader(const coff_bigobj_file_header *&Res) const
Merge contiguous icmps into a memcmp
Definition: MergeICmps.cpp:824
std::error_code getImportTableEntry(const coff_import_directory_table_entry *&Result) const
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:188
Expected< const coff_resource_dir_table & > getBaseTable()
detail::packed_endian_specific_integral< int16_t, little, unaligned > little16_t
Definition: Endian.h:276
support::ulittle32_t AddressTableEntries
Definition: COFF.h:230
#define I(x, y, z)
Definition: MD5.cpp:58
iterator_range< export_directory_iterator > export_directories() const
static const char PEMagic[]
Definition: COFF.h:37
uint32_t Size
Definition: Profile.cpp:47
Definition: COFF.h:211
bool isAnyUndefined() const
Definition: COFF.h:403
bool isSectionVirtual(DataRefImpl Sec) const override
static imported_symbol_iterator importedSymbolEnd(uint32_t RVA, const COFFObjectFile *Object)
ArrayRef< uint8_t > getSymbolAuxData(COFFSymbolRef Symbol) const
uint64_t getSectionSize(DataRefImpl Sec) const override
iterator_range< imported_symbol_iterator > lookup_table_symbols() const
uint8_t NumberOfAuxSymbols
Definition: COFF.h:263
support::ulittle32_t SizeOfData
Definition: COFF.h:184
bool isSectionBSS(DataRefImpl Sec) const override
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
support::ulittle32_t AddressOfNewExeHeader
Definition: COFF.h:73
uintptr_t getSymbolTable() const
Definition: COFF.h:804
bool isFileRecord() const
Definition: COFF.h:407
LLVM Value Representation.
Definition: Value.h:73
content_iterator< BaseRelocRef > base_reloc_iterator
Definition: COFF.h:51
imported_symbol_iterator imported_symbol_end() const
content_iterator< RelocationRef > relocation_iterator
Definition: ObjectFile.h:77
import_lookup_table_entry< support::little32_t > import_lookup_table_entry32
Definition: COFF.h:207
std::error_code getImportAddressTableRVA(uint32_t &Result) const
support::ulittle32_t NumberOfRvaAndSize
Definition: COFF.h:137
uint32_t getValue() const
Definition: COFF.h:318
print Instructions which execute on loop entry
#define RETURN_IF_ERROR(E)
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
bool operator==(const ImportDirectoryEntryRef &Other) const
std::error_code getImportLookupTableRVA(uint32_t &Result) const
std::error_code getPE32PlusHeader(const pe32plus_header *&Res) const
uint32_t getSymbolIndex(COFFSymbolRef Symbol) const
bool isExternal() const
Definition: COFF.h:375
iterator end() const
Definition: StringRef.h:108
imported_symbol_iterator lookup_table_end() const
uint64_t getSectionIndex(DataRefImpl Sec) const override
unsigned getSymbolSectionID(SymbolRef Sym) const
DataRefImpl getRawDataRefImpl() const
Definition: ObjectFile.h:524
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...
std::error_code getSymbolName(StringRef &Result) const
iterator_range< delay_import_directory_iterator > delay_import_directories() const
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:81
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
Definition: MathExtras.h:659
uint32_t getNumberOfSymbols() const
Definition: COFF.h:873
support::ulittle32_t Offset
Definition: COFF.h:247
A function that returns a base type.
Definition: COFF.h:262