LLVM  13.0.0git
COFFObjectFile.cpp
Go to the documentation of this file.
1 //===- COFFObjectFile.cpp - COFF object file implementation ---------------===//
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 // This file declares the COFFObjectFile class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/StringSwitch.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 <cinttypes>
32 #include <cstddef>
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 Error getObject(const T *&Obj, MemoryBufferRef M, const void *Ptr,
59  const uint64_t Size = sizeof(T)) {
60  uintptr_t Addr = reinterpret_cast<uintptr_t>(Ptr);
62  return E;
63  Obj = reinterpret_cast<const T *>(Addr);
64  return Error::success();
65 }
66 
67 // Decode a string table entry in base 64 (//AAAAAA). Expects \arg Str without
68 // prefixed slashes.
69 static bool decodeBase64StringEntry(StringRef Str, uint32_t &Result) {
70  assert(Str.size() <= 6 && "String too long, possible overflow.");
71  if (Str.size() > 6)
72  return true;
73 
74  uint64_t Value = 0;
75  while (!Str.empty()) {
76  unsigned CharVal;
77  if (Str[0] >= 'A' && Str[0] <= 'Z') // 0..25
78  CharVal = Str[0] - 'A';
79  else if (Str[0] >= 'a' && Str[0] <= 'z') // 26..51
80  CharVal = Str[0] - 'a' + 26;
81  else if (Str[0] >= '0' && Str[0] <= '9') // 52..61
82  CharVal = Str[0] - '0' + 52;
83  else if (Str[0] == '+') // 62
84  CharVal = 62;
85  else if (Str[0] == '/') // 63
86  CharVal = 63;
87  else
88  return true;
89 
90  Value = (Value * 64) + CharVal;
91  Str = Str.substr(1);
92  }
93 
95  return true;
96 
97  Result = static_cast<uint32_t>(Value);
98  return false;
99 }
100 
101 template <typename coff_symbol_type>
102 const coff_symbol_type *COFFObjectFile::toSymb(DataRefImpl Ref) const {
103  const coff_symbol_type *Addr =
104  reinterpret_cast<const coff_symbol_type *>(Ref.p);
105 
106  assert(!checkOffset(Data, reinterpret_cast<uintptr_t>(Addr), sizeof(*Addr)));
107 #ifndef NDEBUG
108  // Verify that the symbol points to a valid entry in the symbol table.
109  uintptr_t Offset =
110  reinterpret_cast<uintptr_t>(Addr) - reinterpret_cast<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 = reinterpret_cast<uintptr_t>(Addr) -
128  reinterpret_cast<uintptr_t>(SectionTable);
129  assert(Offset % sizeof(coff_section) == 0 &&
130  "Section did not point to the beginning of a section");
131 #endif
132 
133  return Addr;
134 }
135 
137  auto End = reinterpret_cast<uintptr_t>(StringTable);
138  if (SymbolTable16) {
139  const coff_symbol16 *Symb = toSymb<coff_symbol16>(Ref);
140  Symb += 1 + Symb->NumberOfAuxSymbols;
141  Ref.p = std::min(reinterpret_cast<uintptr_t>(Symb), End);
142  } else if (SymbolTable32) {
143  const coff_symbol32 *Symb = toSymb<coff_symbol32>(Ref);
144  Symb += 1 + Symb->NumberOfAuxSymbols;
145  Ref.p = std::min(reinterpret_cast<uintptr_t>(Symb), End);
146  } else {
147  llvm_unreachable("no symbol table pointer!");
148  }
149 }
150 
152  return getSymbolName(getCOFFSymbol(Ref));
153 }
154 
156  return getCOFFSymbol(Ref).getValue();
157 }
158 
160  // MSVC/link.exe seems to align symbols to the next-power-of-2
161  // up to 32 bytes.
163  return std::min(uint64_t(32), PowerOf2Ceil(Symb.getValue()));
164 }
165 
167  uint64_t Result = cantFail(getSymbolValue(Ref));
169  int32_t SectionNumber = Symb.getSectionNumber();
170 
171  if (Symb.isAnyUndefined() || Symb.isCommon() ||
172  COFF::isReservedSectionNumber(SectionNumber))
173  return Result;
174 
176  if (!Section)
177  return Section.takeError();
178  Result += (*Section)->VirtualAddress;
179 
180  // The section VirtualAddress does not include ImageBase, and we want to
181  // return virtual addresses.
182  Result += getImageBase();
183 
184  return Result;
185 }
186 
189  int32_t SectionNumber = Symb.getSectionNumber();
190 
192  return SymbolRef::ST_Function;
193  if (Symb.isAnyUndefined())
194  return SymbolRef::ST_Unknown;
195  if (Symb.isCommon())
196  return SymbolRef::ST_Data;
197  if (Symb.isFileRecord())
198  return SymbolRef::ST_File;
199 
200  // TODO: perhaps we need a new symbol type ST_Section.
201  if (SectionNumber == COFF::IMAGE_SYM_DEBUG || Symb.isSectionDefinition())
202  return SymbolRef::ST_Debug;
203 
204  if (!COFF::isReservedSectionNumber(SectionNumber))
205  return SymbolRef::ST_Data;
206 
207  return SymbolRef::ST_Other;
208 }
209 
212  uint32_t Result = SymbolRef::SF_None;
213 
214  if (Symb.isExternal() || Symb.isWeakExternal())
215  Result |= SymbolRef::SF_Global;
216 
217  if (const coff_aux_weak_external *AWE = Symb.getWeakExternal()) {
218  Result |= SymbolRef::SF_Weak;
219  if (AWE->Characteristics != COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS)
220  Result |= SymbolRef::SF_Undefined;
221  }
222 
224  Result |= SymbolRef::SF_Absolute;
225 
226  if (Symb.isFileRecord())
228 
229  if (Symb.isSectionDefinition())
231 
232  if (Symb.isCommon())
233  Result |= SymbolRef::SF_Common;
234 
235  if (Symb.isUndefined())
236  Result |= SymbolRef::SF_Undefined;
237 
238  return Result;
239 }
240 
243  return Symb.getValue();
244 }
245 
250  return section_end();
252  if (!Sec)
253  return Sec.takeError();
255  Ret.p = reinterpret_cast<uintptr_t>(*Sec);
256  return section_iterator(SectionRef(Ret, this));
257 }
258 
261  return Symb.getSectionNumber();
262 }
263 
265  const coff_section *Sec = toSec(Ref);
266  Sec += 1;
267  Ref.p = reinterpret_cast<uintptr_t>(Sec);
268 }
269 
271  const coff_section *Sec = toSec(Ref);
272  return getSectionName(Sec);
273 }
274 
276  const coff_section *Sec = toSec(Ref);
277  uint64_t Result = Sec->VirtualAddress;
278 
279  // The section VirtualAddress does not include ImageBase, and we want to
280  // return virtual addresses.
281  Result += getImageBase();
282  return Result;
283 }
284 
286  return toSec(Sec) - SectionTable;
287 }
288 
289 uint64_t COFFObjectFile::getSectionSize(DataRefImpl Ref) const {
290  return getSectionSize(toSec(Ref));
291 }
292 
294 COFFObjectFile::getSectionContents(DataRefImpl Ref) const {
295  const coff_section *Sec = toSec(Ref);
296  ArrayRef<uint8_t> Res;
297  if (Error E = getSectionContents(Sec, Res))
298  return std::move(E);
299  return Res;
300 }
301 
303  const coff_section *Sec = toSec(Ref);
304  return Sec->getAlignment();
305 }
306 
308  return false;
309 }
310 
312  const coff_section *Sec = toSec(Ref);
314 }
315 
317  const coff_section *Sec = toSec(Ref);
319 }
320 
322  const coff_section *Sec = toSec(Ref);
326  return (Sec->Characteristics & BssFlags) == BssFlags;
327 }
328 
329 // The .debug sections are the only debug sections for COFF
330 // (\see MCObjectFileInfo.cpp).
332  Expected<StringRef> SectionNameOrErr = getSectionName(Ref);
333  if (!SectionNameOrErr) {
334  // TODO: Report the error message properly.
335  consumeError(SectionNameOrErr.takeError());
336  return false;
337  }
338  StringRef SectionName = SectionNameOrErr.get();
339  return SectionName.startswith(".debug");
340 }
341 
343  uintptr_t Offset =
344  Sec.getRawDataRefImpl().p - reinterpret_cast<uintptr_t>(SectionTable);
345  assert((Offset % sizeof(coff_section)) == 0);
346  return (Offset / sizeof(coff_section)) + 1;
347 }
348 
350  const coff_section *Sec = toSec(Ref);
351  // In COFF, a virtual section won't have any in-file
352  // content, so the file pointer to the content will be zero.
353  return Sec->PointerToRawData == 0;
354 }
355 
356 static uint32_t getNumberOfRelocations(const coff_section *Sec,
357  MemoryBufferRef M, const uint8_t *base) {
358  // The field for the number of relocations in COFF section table is only
359  // 16-bit wide. If a section has more than 65535 relocations, 0xFFFF is set to
360  // NumberOfRelocations field, and the actual relocation count is stored in the
361  // VirtualAddress field in the first relocation entry.
362  if (Sec->hasExtendedRelocations()) {
363  const coff_relocation *FirstReloc;
364  if (Error E = getObject(FirstReloc, M,
365  reinterpret_cast<const coff_relocation *>(
366  base + Sec->PointerToRelocations))) {
368  return 0;
369  }
370  // -1 to exclude this first relocation entry.
371  return FirstReloc->VirtualAddress - 1;
372  }
373  return Sec->NumberOfRelocations;
374 }
375 
376 static const coff_relocation *
377 getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base) {
378  uint64_t NumRelocs = getNumberOfRelocations(Sec, M, Base);
379  if (!NumRelocs)
380  return nullptr;
381  auto begin = reinterpret_cast<const coff_relocation *>(
382  Base + Sec->PointerToRelocations);
383  if (Sec->hasExtendedRelocations()) {
384  // Skip the first relocation entry repurposed to store the number of
385  // relocations.
386  begin++;
387  }
388  if (auto E = Binary::checkOffset(M, reinterpret_cast<uintptr_t>(begin),
389  sizeof(coff_relocation) * NumRelocs)) {
391  return nullptr;
392  }
393  return begin;
394 }
395 
397  const coff_section *Sec = toSec(Ref);
398  const coff_relocation *begin = getFirstReloc(Sec, Data, base());
399  if (begin && Sec->VirtualAddress != 0)
400  report_fatal_error("Sections with relocations should have an address of 0");
402  Ret.p = reinterpret_cast<uintptr_t>(begin);
403  return relocation_iterator(RelocationRef(Ret, this));
404 }
405 
407  const coff_section *Sec = toSec(Ref);
408  const coff_relocation *I = getFirstReloc(Sec, Data, base());
409  if (I)
410  I += getNumberOfRelocations(Sec, Data, base());
412  Ret.p = reinterpret_cast<uintptr_t>(I);
413  return relocation_iterator(RelocationRef(Ret, this));
414 }
415 
416 // Initialize the pointer to the symbol table.
417 Error COFFObjectFile::initSymbolTablePtr() {
418  if (COFFHeader)
419  if (Error E = getObject(
420  SymbolTable16, Data, base() + getPointerToSymbolTable(),
422  return E;
423 
424  if (COFFBigObjHeader)
425  if (Error E = getObject(
426  SymbolTable32, Data, base() + getPointerToSymbolTable(),
428  return E;
429 
430  // Find string table. The first four byte of the string table contains the
431  // total size of the string table, including the size field itself. If the
432  // string table is empty, the value of the first four byte would be 4.
435  const uint8_t *StringTableAddr = base() + StringTableOffset;
436  const ulittle32_t *StringTableSizePtr;
437  if (Error E = getObject(StringTableSizePtr, Data, StringTableAddr))
438  return E;
439  StringTableSize = *StringTableSizePtr;
440  if (Error E = getObject(StringTable, Data, StringTableAddr, StringTableSize))
441  return E;
442 
443  // Treat table sizes < 4 as empty because contrary to the PECOFF spec, some
444  // tools like cvtres write a size of 0 for an empty table instead of 4.
445  if (StringTableSize < 4)
446  StringTableSize = 4;
447 
448  // Check that the string table is null terminated if has any in it.
449  if (StringTableSize > 4 && StringTable[StringTableSize - 1] != 0)
451  return Error::success();
452 }
453 
455  if (PE32Header)
456  return PE32Header->ImageBase;
457  else if (PE32PlusHeader)
458  return PE32PlusHeader->ImageBase;
459  // This actually comes up in practice.
460  return 0;
461 }
462 
463 // Returns the file offset for the given VA.
464 Error COFFObjectFile::getVaPtr(uint64_t Addr, uintptr_t &Res) const {
465  uint64_t ImageBase = getImageBase();
466  uint64_t Rva = Addr - ImageBase;
467  assert(Rva <= UINT32_MAX);
468  return getRvaPtr((uint32_t)Rva, Res);
469 }
470 
471 // Returns the file offset for the given RVA.
473  for (const SectionRef &S : sections()) {
475  uint32_t SectionStart = Section->VirtualAddress;
476  uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
477  if (SectionStart <= Addr && Addr < SectionEnd) {
478  uint32_t Offset = Addr - SectionStart;
479  Res = reinterpret_cast<uintptr_t>(base()) + Section->PointerToRawData +
480  Offset;
481  return Error::success();
482  }
483  }
485 }
486 
488  ArrayRef<uint8_t> &Contents) const {
489  for (const SectionRef &S : sections()) {
491  uint32_t SectionStart = Section->VirtualAddress;
492  // Check if this RVA is within the section bounds. Be careful about integer
493  // overflow.
494  uint32_t OffsetIntoSection = RVA - SectionStart;
495  if (SectionStart <= RVA && OffsetIntoSection < Section->VirtualSize &&
496  Size <= Section->VirtualSize - OffsetIntoSection) {
497  uintptr_t Begin = reinterpret_cast<uintptr_t>(base()) +
498  Section->PointerToRawData + OffsetIntoSection;
499  Contents =
500  ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(Begin), Size);
501  return Error::success();
502  }
503  }
505 }
506 
507 // Returns hint and name fields, assuming \p Rva is pointing to a Hint/Name
508 // table entry.
510  StringRef &Name) const {
511  uintptr_t IntPtr = 0;
512  if (Error E = getRvaPtr(Rva, IntPtr))
513  return E;
514  const uint8_t *Ptr = reinterpret_cast<const uint8_t *>(IntPtr);
515  Hint = *reinterpret_cast<const ulittle16_t *>(Ptr);
516  Name = StringRef(reinterpret_cast<const char *>(Ptr + 2));
517  return Error::success();
518 }
519 
521  const codeview::DebugInfo *&PDBInfo,
522  StringRef &PDBFileName) const {
523  ArrayRef<uint8_t> InfoBytes;
525  DebugDir->AddressOfRawData, DebugDir->SizeOfData, InfoBytes))
526  return E;
527  if (InfoBytes.size() < sizeof(*PDBInfo) + 1)
529  PDBInfo = reinterpret_cast<const codeview::DebugInfo *>(InfoBytes.data());
530  InfoBytes = InfoBytes.drop_front(sizeof(*PDBInfo));
531  PDBFileName = StringRef(reinterpret_cast<const char *>(InfoBytes.data()),
532  InfoBytes.size());
533  // Truncate the name at the first null byte. Ignore any padding.
534  PDBFileName = PDBFileName.split('\0').first;
535  return Error::success();
536 }
537 
539  StringRef &PDBFileName) const {
540  for (const debug_directory &D : debug_directories())
542  return getDebugPDBInfo(&D, PDBInfo, PDBFileName);
543  // If we get here, there is no PDB info to return.
544  PDBInfo = nullptr;
545  PDBFileName = StringRef();
546  return Error::success();
547 }
548 
549 // Find the import table.
550 Error COFFObjectFile::initImportTablePtr() {
551  // First, we get the RVA of the import table. If the file lacks a pointer to
552  // the import table, do nothing.
553  const data_directory *DataEntry = getDataDirectory(COFF::IMPORT_TABLE);
554  if (!DataEntry)
555  return Error::success();
556 
557  // Do nothing if the pointer to import table is NULL.
558  if (DataEntry->RelativeVirtualAddress == 0)
559  return Error::success();
560 
561  uint32_t ImportTableRva = DataEntry->RelativeVirtualAddress;
562 
563  // Find the section that contains the RVA. This is needed because the RVA is
564  // the import table's memory address which is different from its file offset.
565  uintptr_t IntPtr = 0;
566  if (Error E = getRvaPtr(ImportTableRva, IntPtr))
567  return E;
568  if (Error E = checkOffset(Data, IntPtr, DataEntry->Size))
569  return E;
570  ImportDirectory = reinterpret_cast<
571  const coff_import_directory_table_entry *>(IntPtr);
572  return Error::success();
573 }
574 
575 // Initializes DelayImportDirectory and NumberOfDelayImportDirectory.
576 Error COFFObjectFile::initDelayImportTablePtr() {
577  const data_directory *DataEntry =
579  if (!DataEntry)
580  return Error::success();
581  if (DataEntry->RelativeVirtualAddress == 0)
582  return Error::success();
583 
584  uint32_t RVA = DataEntry->RelativeVirtualAddress;
585  NumberOfDelayImportDirectory = DataEntry->Size /
586  sizeof(delay_import_directory_table_entry) - 1;
587 
588  uintptr_t IntPtr = 0;
589  if (Error E = getRvaPtr(RVA, IntPtr))
590  return E;
591  DelayImportDirectory = reinterpret_cast<
592  const delay_import_directory_table_entry *>(IntPtr);
593  return Error::success();
594 }
595 
596 // Find the export table.
597 Error COFFObjectFile::initExportTablePtr() {
598  // First, we get the RVA of the export table. If the file lacks a pointer to
599  // the export table, do nothing.
600  const data_directory *DataEntry = getDataDirectory(COFF::EXPORT_TABLE);
601  if (!DataEntry)
602  return Error::success();
603 
604  // Do nothing if the pointer to export table is NULL.
605  if (DataEntry->RelativeVirtualAddress == 0)
606  return Error::success();
607 
608  uint32_t ExportTableRva = DataEntry->RelativeVirtualAddress;
609  uintptr_t IntPtr = 0;
610  if (Error E = getRvaPtr(ExportTableRva, IntPtr))
611  return E;
612  ExportDirectory =
613  reinterpret_cast<const export_directory_table_entry *>(IntPtr);
614  return Error::success();
615 }
616 
617 Error COFFObjectFile::initBaseRelocPtr() {
618  const data_directory *DataEntry =
620  if (!DataEntry)
621  return Error::success();
622  if (DataEntry->RelativeVirtualAddress == 0)
623  return Error::success();
624 
625  uintptr_t IntPtr = 0;
626  if (Error E = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr))
627  return E;
628  BaseRelocHeader = reinterpret_cast<const coff_base_reloc_block_header *>(
629  IntPtr);
630  BaseRelocEnd = reinterpret_cast<coff_base_reloc_block_header *>(
631  IntPtr + DataEntry->Size);
632  // FIXME: Verify the section containing BaseRelocHeader has at least
633  // DataEntry->Size bytes after DataEntry->RelativeVirtualAddress.
634  return Error::success();
635 }
636 
637 Error COFFObjectFile::initDebugDirectoryPtr() {
638  // Get the RVA of the debug directory. Do nothing if it does not exist.
639  const data_directory *DataEntry = getDataDirectory(COFF::DEBUG_DIRECTORY);
640  if (!DataEntry)
641  return Error::success();
642 
643  // Do nothing if the RVA is NULL.
644  if (DataEntry->RelativeVirtualAddress == 0)
645  return Error::success();
646 
647  // Check that the size is a multiple of the entry size.
648  if (DataEntry->Size % sizeof(debug_directory) != 0)
650 
651  uintptr_t IntPtr = 0;
652  if (Error E = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr))
653  return E;
654  DebugDirectoryBegin = reinterpret_cast<const debug_directory *>(IntPtr);
655  DebugDirectoryEnd = reinterpret_cast<const debug_directory *>(
656  IntPtr + DataEntry->Size);
657  // FIXME: Verify the section containing DebugDirectoryBegin has at least
658  // DataEntry->Size bytes after DataEntry->RelativeVirtualAddress.
659  return Error::success();
660 }
661 
662 Error COFFObjectFile::initTLSDirectoryPtr() {
663  // Get the RVA of the TLS directory. Do nothing if it does not exist.
664  const data_directory *DataEntry = getDataDirectory(COFF::TLS_TABLE);
665  if (!DataEntry)
666  return Error::success();
667 
668  // Do nothing if the RVA is NULL.
669  if (DataEntry->RelativeVirtualAddress == 0)
670  return Error::success();
671 
672  uint64_t DirSize =
673  is64() ? sizeof(coff_tls_directory64) : sizeof(coff_tls_directory32);
674 
675  // Check that the size is correct.
676  if (DataEntry->Size != DirSize)
677  return createStringError(
679  "TLS Directory size (%u) is not the expected size (%" PRIu64 ").",
680  static_cast<uint32_t>(DataEntry->Size), DirSize);
681 
682  uintptr_t IntPtr = 0;
683  if (Error E = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr))
684  return E;
685 
686  if (is64())
687  TLSDirectory64 = reinterpret_cast<const coff_tls_directory64 *>(IntPtr);
688  else
689  TLSDirectory32 = reinterpret_cast<const coff_tls_directory32 *>(IntPtr);
690 
691  return Error::success();
692 }
693 
694 Error COFFObjectFile::initLoadConfigPtr() {
695  // Get the RVA of the debug directory. Do nothing if it does not exist.
696  const data_directory *DataEntry = getDataDirectory(COFF::LOAD_CONFIG_TABLE);
697  if (!DataEntry)
698  return Error::success();
699 
700  // Do nothing if the RVA is NULL.
701  if (DataEntry->RelativeVirtualAddress == 0)
702  return Error::success();
703  uintptr_t IntPtr = 0;
704  if (Error E = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr))
705  return E;
706 
707  LoadConfig = (const void *)IntPtr;
708  return Error::success();
709 }
710 
713  std::unique_ptr<COFFObjectFile> Obj(new COFFObjectFile(std::move(Object)));
714  if (Error E = Obj->initialize())
715  return std::move(E);
716  return std::move(Obj);
717 }
718 
719 COFFObjectFile::COFFObjectFile(MemoryBufferRef Object)
720  : ObjectFile(Binary::ID_COFF, Object), COFFHeader(nullptr),
721  COFFBigObjHeader(nullptr), PE32Header(nullptr), PE32PlusHeader(nullptr),
722  DataDirectory(nullptr), SectionTable(nullptr), SymbolTable16(nullptr),
723  SymbolTable32(nullptr), StringTable(nullptr), StringTableSize(0),
724  ImportDirectory(nullptr), DelayImportDirectory(nullptr),
725  NumberOfDelayImportDirectory(0), ExportDirectory(nullptr),
726  BaseRelocHeader(nullptr), BaseRelocEnd(nullptr),
727  DebugDirectoryBegin(nullptr), DebugDirectoryEnd(nullptr),
728  TLSDirectory32(nullptr), TLSDirectory64(nullptr) {}
729 
730 Error COFFObjectFile::initialize() {
731  // Check that we at least have enough room for a header.
732  std::error_code EC;
733  if (!checkSize(Data, EC, sizeof(coff_file_header)))
734  return errorCodeToError(EC);
735 
736  // The current location in the file where we are looking at.
737  uint64_t CurPtr = 0;
738 
739  // PE header is optional and is present only in executables. If it exists,
740  // it is placed right after COFF header.
741  bool HasPEHeader = false;
742 
743  // Check if this is a PE/COFF file.
744  if (checkSize(Data, EC, sizeof(dos_header) + sizeof(COFF::PEMagic))) {
745  // PE/COFF, seek through MS-DOS compatibility stub and 4-byte
746  // PE signature to find 'normal' COFF header.
747  const auto *DH = reinterpret_cast<const dos_header *>(base());
748  if (DH->Magic[0] == 'M' && DH->Magic[1] == 'Z') {
749  CurPtr = DH->AddressOfNewExeHeader;
750  // Check the PE magic bytes. ("PE\0\0")
751  if (memcmp(base() + CurPtr, COFF::PEMagic, sizeof(COFF::PEMagic)) != 0) {
753  }
754  CurPtr += sizeof(COFF::PEMagic); // Skip the PE magic bytes.
755  HasPEHeader = true;
756  }
757  }
758 
759  if (Error E = getObject(COFFHeader, Data, base() + CurPtr))
760  return E;
761 
762  // It might be a bigobj file, let's check. Note that COFF bigobj and COFF
763  // import libraries share a common prefix but bigobj is more restrictive.
764  if (!HasPEHeader && COFFHeader->Machine == COFF::IMAGE_FILE_MACHINE_UNKNOWN &&
765  COFFHeader->NumberOfSections == uint16_t(0xffff) &&
766  checkSize(Data, EC, sizeof(coff_bigobj_file_header))) {
767  if (Error E = getObject(COFFBigObjHeader, Data, base() + CurPtr))
768  return E;
769 
770  // Verify that we are dealing with bigobj.
771  if (COFFBigObjHeader->Version >= COFF::BigObjHeader::MinBigObjectVersion &&
772  std::memcmp(COFFBigObjHeader->UUID, COFF::BigObjMagic,
773  sizeof(COFF::BigObjMagic)) == 0) {
774  COFFHeader = nullptr;
775  CurPtr += sizeof(coff_bigobj_file_header);
776  } else {
777  // It's not a bigobj.
778  COFFBigObjHeader = nullptr;
779  }
780  }
781  if (COFFHeader) {
782  // The prior checkSize call may have failed. This isn't a hard error
783  // because we were just trying to sniff out bigobj.
784  EC = std::error_code();
785  CurPtr += sizeof(coff_file_header);
786 
787  if (COFFHeader->isImportLibrary())
788  return errorCodeToError(EC);
789  }
790 
791  if (HasPEHeader) {
792  const pe32_header *Header;
793  if (Error E = getObject(Header, Data, base() + CurPtr))
794  return E;
795 
796  const uint8_t *DataDirAddr;
797  uint64_t DataDirSize;
798  if (Header->Magic == COFF::PE32Header::PE32) {
799  PE32Header = Header;
800  DataDirAddr = base() + CurPtr + sizeof(pe32_header);
801  DataDirSize = sizeof(data_directory) * PE32Header->NumberOfRvaAndSize;
802  } else if (Header->Magic == COFF::PE32Header::PE32_PLUS) {
803  PE32PlusHeader = reinterpret_cast<const pe32plus_header *>(Header);
804  DataDirAddr = base() + CurPtr + sizeof(pe32plus_header);
805  DataDirSize = sizeof(data_directory) * PE32PlusHeader->NumberOfRvaAndSize;
806  } else {
807  // It's neither PE32 nor PE32+.
809  }
810  if (Error E = getObject(DataDirectory, Data, DataDirAddr, DataDirSize))
811  return E;
812  }
813 
814  if (COFFHeader)
815  CurPtr += COFFHeader->SizeOfOptionalHeader;
816 
817  assert(COFFHeader || COFFBigObjHeader);
818 
819  if (Error E =
820  getObject(SectionTable, Data, base() + CurPtr,
821  (uint64_t)getNumberOfSections() * sizeof(coff_section)))
822  return E;
823 
824  // Initialize the pointer to the symbol table.
825  if (getPointerToSymbolTable() != 0) {
826  if (Error E = initSymbolTablePtr()) {
827  // Recover from errors reading the symbol table.
829  SymbolTable16 = nullptr;
830  SymbolTable32 = nullptr;
831  StringTable = nullptr;
832  StringTableSize = 0;
833  }
834  } else {
835  // We had better not have any symbols if we don't have a symbol table.
836  if (getNumberOfSymbols() != 0) {
838  }
839  }
840 
841  // Initialize the pointer to the beginning of the import table.
842  if (Error E = initImportTablePtr())
843  return E;
844  if (Error E = initDelayImportTablePtr())
845  return E;
846 
847  // Initialize the pointer to the export table.
848  if (Error E = initExportTablePtr())
849  return E;
850 
851  // Initialize the pointer to the base relocation table.
852  if (Error E = initBaseRelocPtr())
853  return E;
854 
855  // Initialize the pointer to the debug directory.
856  if (Error E = initDebugDirectoryPtr())
857  return E;
858 
859  // Initialize the pointer to the TLS directory.
860  if (Error E = initTLSDirectoryPtr())
861  return E;
862 
863  if (Error E = initLoadConfigPtr())
864  return E;
865 
866  return Error::success();
867 }
868 
871  Ret.p = getSymbolTable();
872  return basic_symbol_iterator(SymbolRef(Ret, this));
873 }
874 
876  // The symbol table ends where the string table begins.
878  Ret.p = reinterpret_cast<uintptr_t>(StringTable);
879  return basic_symbol_iterator(SymbolRef(Ret, this));
880 }
881 
883  if (!ImportDirectory)
884  return import_directory_end();
885  if (ImportDirectory->isNull())
886  return import_directory_end();
888  ImportDirectoryEntryRef(ImportDirectory, 0, this));
889 }
890 
893  ImportDirectoryEntryRef(nullptr, -1, this));
894 }
895 
899  DelayImportDirectoryEntryRef(DelayImportDirectory, 0, this));
900 }
901 
906  DelayImportDirectory, NumberOfDelayImportDirectory, this));
907 }
908 
911  ExportDirectoryEntryRef(ExportDirectory, 0, this));
912 }
913 
915  if (!ExportDirectory)
916  return export_directory_iterator(ExportDirectoryEntryRef(nullptr, 0, this));
917  ExportDirectoryEntryRef Ref(ExportDirectory,
918  ExportDirectory->AddressTableEntries, this);
920 }
921 
924  Ret.p = reinterpret_cast<uintptr_t>(SectionTable);
925  return section_iterator(SectionRef(Ret, this));
926 }
927 
930  int NumSections =
931  COFFHeader && COFFHeader->isImportLibrary() ? 0 : getNumberOfSections();
932  Ret.p = reinterpret_cast<uintptr_t>(SectionTable + NumSections);
933  return section_iterator(SectionRef(Ret, this));
934 }
935 
937  return base_reloc_iterator(BaseRelocRef(BaseRelocHeader, this));
938 }
939 
941  return base_reloc_iterator(BaseRelocRef(BaseRelocEnd, this));
942 }
943 
945  return getArch() == Triple::x86_64 || getArch() == Triple::aarch64 ? 8 : 4;
946 }
947 
949  switch(getMachine()) {
951  return "COFF-i386";
953  return "COFF-x86-64";
955  return "COFF-ARM";
957  return "COFF-ARM64";
958  default:
959  return "COFF-<unknown arch>";
960  }
961 }
962 
964  switch (getMachine()) {
966  return Triple::x86;
968  return Triple::x86_64;
970  return Triple::thumb;
972  return Triple::aarch64;
973  default:
974  return Triple::UnknownArch;
975  }
976 }
977 
979  if (PE32Header)
980  return PE32Header->AddressOfEntryPoint;
981  return 0;
982 }
983 
987 }
988 
993 }
994 
998 }
999 
1002 }
1003 
1005  if (!DataDirectory)
1006  return nullptr;
1007  assert(PE32Header || PE32PlusHeader);
1008  uint32_t NumEnt = PE32Header ? PE32Header->NumberOfRvaAndSize
1009  : PE32PlusHeader->NumberOfRvaAndSize;
1010  if (Index >= NumEnt)
1011  return nullptr;
1012  return &DataDirectory[Index];
1013 }
1014 
1016  // Perhaps getting the section of a reserved section index should be an error,
1017  // but callers rely on this to return null.
1019  return (const coff_section *)nullptr;
1020  if (static_cast<uint32_t>(Index) <= getNumberOfSections()) {
1021  // We already verified the section table data, so no need to check again.
1022  return SectionTable + (Index - 1);
1023  }
1025 }
1026 
1027 Expected<StringRef> COFFObjectFile::getString(uint32_t Offset) const {
1028  if (StringTableSize <= 4)
1029  // Tried to get a string from an empty string table.
1031  if (Offset >= StringTableSize)
1033  return StringRef(StringTable + Offset);
1034 }
1035 
1037  return getSymbolName(Symbol.getGeneric());
1038 }
1039 
1042  // Check for string table entry. First 4 bytes are 0.
1043  if (Symbol->Name.Offset.Zeroes == 0)
1044  return getString(Symbol->Name.Offset.Offset);
1045 
1046  // Null terminated, let ::strlen figure out the length.
1047  if (Symbol->Name.ShortName[COFF::NameSize - 1] == 0)
1048  return StringRef(Symbol->Name.ShortName);
1049 
1050  // Not null terminated, use all 8 bytes.
1051  return StringRef(Symbol->Name.ShortName, COFF::NameSize);
1052 }
1053 
1056  const uint8_t *Aux = nullptr;
1057 
1058  size_t SymbolSize = getSymbolTableEntrySize();
1059  if (Symbol.getNumberOfAuxSymbols() > 0) {
1060  // AUX data comes immediately after the symbol in COFF
1061  Aux = reinterpret_cast<const uint8_t *>(Symbol.getRawPtr()) + SymbolSize;
1062 #ifndef NDEBUG
1063  // Verify that the Aux symbol points to a valid entry in the symbol table.
1064  uintptr_t Offset = uintptr_t(Aux) - uintptr_t(base());
1065  if (Offset < getPointerToSymbolTable() ||
1066  Offset >=
1067  getPointerToSymbolTable() + (getNumberOfSymbols() * SymbolSize))
1068  report_fatal_error("Aux Symbol data was outside of symbol table.");
1069 
1070  assert((Offset - getPointerToSymbolTable()) % SymbolSize == 0 &&
1071  "Aux Symbol data did not point to the beginning of a symbol");
1072 #endif
1073  }
1074  return makeArrayRef(Aux, Symbol.getNumberOfAuxSymbols() * SymbolSize);
1075 }
1076 
1078  uintptr_t Offset =
1079  reinterpret_cast<uintptr_t>(Symbol.getRawPtr()) - getSymbolTable();
1081  "Symbol did not point to the beginning of a symbol");
1082  size_t Index = Offset / getSymbolTableEntrySize();
1084  return Index;
1085 }
1086 
1089  StringRef Name;
1090  if (Sec->Name[COFF::NameSize - 1] == 0)
1091  // Null terminated, let ::strlen figure out the length.
1092  Name = Sec->Name;
1093  else
1094  // Not null terminated, use all 8 bytes.
1095  Name = StringRef(Sec->Name, COFF::NameSize);
1096 
1097  // Check for string table entry. First byte is '/'.
1098  if (Name.startswith("/")) {
1099  uint32_t Offset;
1100  if (Name.startswith("//")) {
1101  if (decodeBase64StringEntry(Name.substr(2), Offset))
1103  "invalid section name");
1104  } else {
1105  if (Name.substr(1).getAsInteger(10, Offset))
1107  "invalid section name");
1108  }
1109  return getString(Offset);
1110  }
1111 
1112  return Name;
1113 }
1114 
1115 uint64_t COFFObjectFile::getSectionSize(const coff_section *Sec) const {
1116  // SizeOfRawData and VirtualSize change what they represent depending on
1117  // whether or not we have an executable image.
1118  //
1119  // For object files, SizeOfRawData contains the size of section's data;
1120  // VirtualSize should be zero but isn't due to buggy COFF writers.
1121  //
1122  // For executables, SizeOfRawData *must* be a multiple of FileAlignment; the
1123  // actual section size is in VirtualSize. It is possible for VirtualSize to
1124  // be greater than SizeOfRawData; the contents past that point should be
1125  // considered to be zero.
1126  if (getDOSHeader())
1127  return std::min(Sec->VirtualSize, Sec->SizeOfRawData);
1128  return Sec->SizeOfRawData;
1129 }
1130 
1132  ArrayRef<uint8_t> &Res) const {
1133  // In COFF, a virtual section won't have any in-file
1134  // content, so the file pointer to the content will be zero.
1135  if (Sec->PointerToRawData == 0)
1136  return Error::success();
1137  // The only thing that we need to verify is that the contents is contained
1138  // within the file bounds. We don't need to make sure it doesn't cover other
1139  // data, as there's nothing that says that is not allowed.
1140  uintptr_t ConStart =
1141  reinterpret_cast<uintptr_t>(base()) + Sec->PointerToRawData;
1143  if (Error E = checkOffset(Data, ConStart, SectionSize))
1144  return E;
1145  Res = makeArrayRef(reinterpret_cast<const uint8_t *>(ConStart), SectionSize);
1146  return Error::success();
1147 }
1148 
1149 const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
1150  return reinterpret_cast<const coff_relocation*>(Rel.p);
1151 }
1152 
1154  Rel.p = reinterpret_cast<uintptr_t>(
1155  reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
1156 }
1157 
1159  const coff_relocation *R = toRel(Rel);
1160  return R->VirtualAddress;
1161 }
1162 
1164  const coff_relocation *R = toRel(Rel);
1165  DataRefImpl Ref;
1166  if (R->SymbolTableIndex >= getNumberOfSymbols())
1167  return symbol_end();
1168  if (SymbolTable16)
1169  Ref.p = reinterpret_cast<uintptr_t>(SymbolTable16 + R->SymbolTableIndex);
1170  else if (SymbolTable32)
1171  Ref.p = reinterpret_cast<uintptr_t>(SymbolTable32 + R->SymbolTableIndex);
1172  else
1173  llvm_unreachable("no symbol table pointer!");
1174  return symbol_iterator(SymbolRef(Ref, this));
1175 }
1176 
1178  const coff_relocation* R = toRel(Rel);
1179  return R->Type;
1180 }
1181 
1182 const coff_section *
1184  return toSec(Section.getRawDataRefImpl());
1185 }
1186 
1188  if (SymbolTable16)
1189  return toSymb<coff_symbol16>(Ref);
1190  if (SymbolTable32)
1191  return toSymb<coff_symbol32>(Ref);
1192  llvm_unreachable("no symbol table pointer!");
1193 }
1194 
1196  return getCOFFSymbol(Symbol.getRawDataRefImpl());
1197 }
1198 
1199 const coff_relocation *
1201  return toRel(Reloc.getRawDataRefImpl());
1202 }
1203 
1206  return {getFirstReloc(Sec, Data, base()),
1207  getNumberOfRelocations(Sec, Data, base())};
1208 }
1209 
1210 #define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(reloc_type) \
1211  case COFF::reloc_type: \
1212  return #reloc_type;
1213 
1215  switch (getMachine()) {
1217  switch (Type) {
1235  default:
1236  return "Unknown";
1237  }
1238  break;
1240  switch (Type) {
1258  default:
1259  return "Unknown";
1260  }
1261  break;
1263  switch (Type) {
1282  default:
1283  return "Unknown";
1284  }
1285  break;
1287  switch (Type) {
1299  default:
1300  return "Unknown";
1301  }
1302  break;
1303  default:
1304  return "Unknown";
1305  }
1306 }
1307 
1308 #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
1309 
1311  DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
1312  const coff_relocation *Reloc = toRel(Rel);
1313  StringRef Res = getRelocationTypeName(Reloc->Type);
1314  Result.append(Res.begin(), Res.end());
1315 }
1316 
1318  return !DataDirectory;
1319 }
1320 
1323  .Case("eh_fram", "eh_frame")
1324  .Default(Name);
1325 }
1326 
1329  return ImportTable == Other.ImportTable && Index == Other.Index;
1330 }
1331 
1333  ++Index;
1334  if (ImportTable[Index].isNull()) {
1335  Index = -1;
1336  ImportTable = nullptr;
1337  }
1338 }
1339 
1341  const coff_import_directory_table_entry *&Result) const {
1342  return getObject(Result, OwningObject->Data, ImportTable + Index);
1343 }
1344 
1346 makeImportedSymbolIterator(const COFFObjectFile *Object,
1347  uintptr_t Ptr, int Index) {
1348  if (Object->getBytesInAddress() == 4) {
1349  auto *P = reinterpret_cast<const import_lookup_table_entry32 *>(Ptr);
1350  return imported_symbol_iterator(ImportedSymbolRef(P, Index, Object));
1351  }
1352  auto *P = reinterpret_cast<const import_lookup_table_entry64 *>(Ptr);
1353  return imported_symbol_iterator(ImportedSymbolRef(P, Index, Object));
1354 }
1355 
1357 importedSymbolBegin(uint32_t RVA, const COFFObjectFile *Object) {
1358  uintptr_t IntPtr = 0;
1359  // FIXME: Handle errors.
1360  cantFail(Object->getRvaPtr(RVA, IntPtr));
1361  return makeImportedSymbolIterator(Object, IntPtr, 0);
1362 }
1363 
1365 importedSymbolEnd(uint32_t RVA, const COFFObjectFile *Object) {
1366  uintptr_t IntPtr = 0;
1367  // FIXME: Handle errors.
1368  cantFail(Object->getRvaPtr(RVA, IntPtr));
1369  // Forward the pointer to the last entry which is null.
1370  int Index = 0;
1371  if (Object->getBytesInAddress() == 4) {
1372  auto *Entry = reinterpret_cast<ulittle32_t *>(IntPtr);
1373  while (*Entry++)
1374  ++Index;
1375  } else {
1376  auto *Entry = reinterpret_cast<ulittle64_t *>(IntPtr);
1377  while (*Entry++)
1378  ++Index;
1379  }
1380  return makeImportedSymbolIterator(Object, IntPtr, Index);
1381 }
1382 
1385  return importedSymbolBegin(ImportTable[Index].ImportAddressTableRVA,
1386  OwningObject);
1387 }
1388 
1391  return importedSymbolEnd(ImportTable[Index].ImportAddressTableRVA,
1392  OwningObject);
1393 }
1394 
1398 }
1399 
1401  return importedSymbolBegin(ImportTable[Index].ImportLookupTableRVA,
1402  OwningObject);
1403 }
1404 
1406  return importedSymbolEnd(ImportTable[Index].ImportLookupTableRVA,
1407  OwningObject);
1408 }
1409 
1413 }
1414 
1416  uintptr_t IntPtr = 0;
1417  if (Error E = OwningObject->getRvaPtr(ImportTable[Index].NameRVA, IntPtr))
1418  return E;
1419  Result = StringRef(reinterpret_cast<const char *>(IntPtr));
1420  return Error::success();
1421 }
1422 
1423 Error
1425  Result = ImportTable[Index].ImportLookupTableRVA;
1426  return Error::success();
1427 }
1428 
1430  uint32_t &Result) const {
1431  Result = ImportTable[Index].ImportAddressTableRVA;
1432  return Error::success();
1433 }
1434 
1437  return Table == Other.Table && Index == Other.Index;
1438 }
1439 
1441  ++Index;
1442 }
1443 
1446  return importedSymbolBegin(Table[Index].DelayImportNameTable,
1447  OwningObject);
1448 }
1449 
1452  return importedSymbolEnd(Table[Index].DelayImportNameTable,
1453  OwningObject);
1454 }
1455 
1459 }
1460 
1462  uintptr_t IntPtr = 0;
1463  if (Error E = OwningObject->getRvaPtr(Table[Index].Name, IntPtr))
1464  return E;
1465  Result = StringRef(reinterpret_cast<const char *>(IntPtr));
1466  return Error::success();
1467 }
1468 
1470  const delay_import_directory_table_entry *&Result) const {
1471  Result = &Table[Index];
1472  return Error::success();
1473 }
1474 
1476  uint64_t &Result) const {
1477  uint32_t RVA = Table[Index].DelayImportAddressTable +
1478  AddrIndex * (OwningObject->is64() ? 8 : 4);
1479  uintptr_t IntPtr = 0;
1480  if (Error E = OwningObject->getRvaPtr(RVA, IntPtr))
1481  return E;
1482  if (OwningObject->is64())
1483  Result = *reinterpret_cast<const ulittle64_t *>(IntPtr);
1484  else
1485  Result = *reinterpret_cast<const ulittle32_t *>(IntPtr);
1486  return Error::success();
1487 }
1488 
1491  return ExportTable == Other.ExportTable && Index == Other.Index;
1492 }
1493 
1495  ++Index;
1496 }
1497 
1498 // Returns the name of the current export symbol. If the symbol is exported only
1499 // by ordinal, the empty string is set as a result.
1501  uintptr_t IntPtr = 0;
1502  if (Error E = OwningObject->getRvaPtr(ExportTable->NameRVA, IntPtr))
1503  return E;
1504  Result = StringRef(reinterpret_cast<const char *>(IntPtr));
1505  return Error::success();
1506 }
1507 
1508 // Returns the starting ordinal number.
1510  Result = ExportTable->OrdinalBase;
1511  return Error::success();
1512 }
1513 
1514 // Returns the export ordinal of the current export symbol.
1516  Result = ExportTable->OrdinalBase + Index;
1517  return Error::success();
1518 }
1519 
1520 // Returns the address of the current export symbol.
1522  uintptr_t IntPtr = 0;
1523  if (Error EC =
1524  OwningObject->getRvaPtr(ExportTable->ExportAddressTableRVA, IntPtr))
1525  return EC;
1527  reinterpret_cast<const export_address_table_entry *>(IntPtr);
1528  Result = entry[Index].ExportRVA;
1529  return Error::success();
1530 }
1531 
1532 // Returns the name of the current export symbol. If the symbol is exported only
1533 // by ordinal, the empty string is set as a result.
1534 Error
1536  uintptr_t IntPtr = 0;
1537  if (Error EC =
1538  OwningObject->getRvaPtr(ExportTable->OrdinalTableRVA, IntPtr))
1539  return EC;
1540  const ulittle16_t *Start = reinterpret_cast<const ulittle16_t *>(IntPtr);
1541 
1542  uint32_t NumEntries = ExportTable->NumberOfNamePointers;
1543  int Offset = 0;
1544  for (const ulittle16_t *I = Start, *E = Start + NumEntries;
1545  I < E; ++I, ++Offset) {
1546  if (*I != Index)
1547  continue;
1548  if (Error EC =
1549  OwningObject->getRvaPtr(ExportTable->NamePointerRVA, IntPtr))
1550  return EC;
1551  const ulittle32_t *NamePtr = reinterpret_cast<const ulittle32_t *>(IntPtr);
1552  if (Error EC = OwningObject->getRvaPtr(NamePtr[Offset], IntPtr))
1553  return EC;
1554  Result = StringRef(reinterpret_cast<const char *>(IntPtr));
1555  return Error::success();
1556  }
1557  Result = "";
1558  return Error::success();
1559 }
1560 
1562  const data_directory *DataEntry =
1563  OwningObject->getDataDirectory(COFF::EXPORT_TABLE);
1564  if (!DataEntry)
1566  uint32_t RVA;
1567  if (auto EC = getExportRVA(RVA))
1568  return EC;
1569  uint32_t Begin = DataEntry->RelativeVirtualAddress;
1570  uint32_t End = DataEntry->RelativeVirtualAddress + DataEntry->Size;
1571  Result = (Begin <= RVA && RVA < End);
1572  return Error::success();
1573 }
1574 
1576  uint32_t RVA;
1577  if (auto EC = getExportRVA(RVA))
1578  return EC;
1579  uintptr_t IntPtr = 0;
1580  if (auto EC = OwningObject->getRvaPtr(RVA, IntPtr))
1581  return EC;
1582  Result = StringRef(reinterpret_cast<const char *>(IntPtr));
1583  return Error::success();
1584 }
1585 
1587 operator==(const ImportedSymbolRef &Other) const {
1588  return Entry32 == Other.Entry32 && Entry64 == Other.Entry64
1589  && Index == Other.Index;
1590 }
1591 
1593  ++Index;
1594 }
1595 
1597  uint32_t RVA;
1598  if (Entry32) {
1599  // If a symbol is imported only by ordinal, it has no name.
1600  if (Entry32[Index].isOrdinal())
1601  return Error::success();
1602  RVA = Entry32[Index].getHintNameRVA();
1603  } else {
1604  if (Entry64[Index].isOrdinal())
1605  return Error::success();
1606  RVA = Entry64[Index].getHintNameRVA();
1607  }
1608  uintptr_t IntPtr = 0;
1609  if (Error EC = OwningObject->getRvaPtr(RVA, IntPtr))
1610  return EC;
1611  // +2 because the first two bytes is hint.
1612  Result = StringRef(reinterpret_cast<const char *>(IntPtr + 2));
1613  return Error::success();
1614 }
1615 
1617  if (Entry32)
1618  Result = Entry32[Index].isOrdinal();
1619  else
1620  Result = Entry64[Index].isOrdinal();
1621  return Error::success();
1622 }
1623 
1625  if (Entry32)
1626  Result = Entry32[Index].getHintNameRVA();
1627  else
1628  Result = Entry64[Index].getHintNameRVA();
1629  return Error::success();
1630 }
1631 
1633  uint32_t RVA;
1634  if (Entry32) {
1635  if (Entry32[Index].isOrdinal()) {
1636  Result = Entry32[Index].getOrdinal();
1637  return Error::success();
1638  }
1639  RVA = Entry32[Index].getHintNameRVA();
1640  } else {
1641  if (Entry64[Index].isOrdinal()) {
1642  Result = Entry64[Index].getOrdinal();
1643  return Error::success();
1644  }
1645  RVA = Entry64[Index].getHintNameRVA();
1646  }
1647  uintptr_t IntPtr = 0;
1648  if (Error EC = OwningObject->getRvaPtr(RVA, IntPtr))
1649  return EC;
1650  Result = *reinterpret_cast<const ulittle16_t *>(IntPtr);
1651  return Error::success();
1652 }
1653 
1657 }
1658 
1659 bool BaseRelocRef::operator==(const BaseRelocRef &Other) const {
1660  return Header == Other.Header && Index == Other.Index;
1661 }
1662 
1664  // Header->BlockSize is the size of the current block, including the
1665  // size of the header itself.
1666  uint32_t Size = sizeof(*Header) +
1667  sizeof(coff_base_reloc_block_entry) * (Index + 1);
1668  if (Size == Header->BlockSize) {
1669  // .reloc contains a list of base relocation blocks. Each block
1670  // consists of the header followed by entries. The header contains
1671  // how many entories will follow. When we reach the end of the
1672  // current block, proceed to the next block.
1673  Header = reinterpret_cast<const coff_base_reloc_block_header *>(
1674  reinterpret_cast<const uint8_t *>(Header) + Size);
1675  Index = 0;
1676  } else {
1677  ++Index;
1678  }
1679 }
1680 
1682  auto *Entry = reinterpret_cast<const coff_base_reloc_block_entry *>(Header + 1);
1683  Type = Entry[Index].getType();
1684  return Error::success();
1685 }
1686 
1688  auto *Entry = reinterpret_cast<const coff_base_reloc_block_entry *>(Header + 1);
1689  Result = Header->PageRVA + Entry[Index].getOffset();
1690  return Error::success();
1691 }
1692 
1693 #define RETURN_IF_ERROR(Expr) \
1694  do { \
1695  Error E = (Expr); \
1696  if (E) \
1697  return std::move(E); \
1698  } while (0)
1699 
1701 ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) {
1702  BinaryStreamReader Reader = BinaryStreamReader(BBS);
1703  Reader.setOffset(Offset);
1704  uint16_t Length;
1705  RETURN_IF_ERROR(Reader.readInteger(Length));
1706  ArrayRef<UTF16> RawDirString;
1707  RETURN_IF_ERROR(Reader.readArray(RawDirString, Length));
1708  return RawDirString;
1709 }
1710 
1713  return getDirStringAtOffset(Entry.Identifier.getNameOffset());
1714 }
1715 
1717 ResourceSectionRef::getTableAtOffset(uint32_t Offset) {
1718  const coff_resource_dir_table *Table = nullptr;
1719 
1720  BinaryStreamReader Reader(BBS);
1721  Reader.setOffset(Offset);
1722  RETURN_IF_ERROR(Reader.readObject(Table));
1723  assert(Table != nullptr);
1724  return *Table;
1725 }
1726 
1728 ResourceSectionRef::getTableEntryAtOffset(uint32_t Offset) {
1729  const coff_resource_dir_entry *Entry = nullptr;
1730 
1731  BinaryStreamReader Reader(BBS);
1732  Reader.setOffset(Offset);
1733  RETURN_IF_ERROR(Reader.readObject(Entry));
1734  assert(Entry != nullptr);
1735  return *Entry;
1736 }
1737 
1739 ResourceSectionRef::getDataEntryAtOffset(uint32_t Offset) {
1740  const coff_resource_data_entry *Entry = nullptr;
1741 
1742  BinaryStreamReader Reader(BBS);
1743  Reader.setOffset(Offset);
1744  RETURN_IF_ERROR(Reader.readObject(Entry));
1745  assert(Entry != nullptr);
1746  return *Entry;
1747 }
1748 
1751  assert(Entry.Offset.isSubDir());
1752  return getTableAtOffset(Entry.Offset.value());
1753 }
1754 
1757  assert(!Entry.Offset.isSubDir());
1758  return getDataEntryAtOffset(Entry.Offset.value());
1759 }
1760 
1762  return getTableAtOffset(0);
1763 }
1764 
1767  uint32_t Index) {
1768  if (Index >= (uint32_t)(Table.NumberOfNameEntries + Table.NumberOfIDEntries))
1769  return createStringError(object_error::parse_failed, "index out of range");
1770  const uint8_t *TablePtr = reinterpret_cast<const uint8_t *>(&Table);
1771  ptrdiff_t TableOffset = TablePtr - BBS.data().data();
1772  return getTableEntryAtOffset(TableOffset + sizeof(Table) +
1773  Index * sizeof(coff_resource_dir_entry));
1774 }
1775 
1777  for (const SectionRef &S : O->sections()) {
1778  Expected<StringRef> Name = S.getName();
1779  if (!Name)
1780  return Name.takeError();
1781 
1782  if (*Name == ".rsrc" || *Name == ".rsrc$01")
1783  return load(O, S);
1784  }
1786  "no resource section found");
1787 }
1788 
1790  Obj = O;
1791  Section = S;
1792  Expected<StringRef> Contents = Section.getContents();
1793  if (!Contents)
1794  return Contents.takeError();
1795  BBS = BinaryByteStream(*Contents, support::little);
1796  const coff_section *COFFSect = Obj->getCOFFSection(Section);
1797  ArrayRef<coff_relocation> OrigRelocs = Obj->getRelocations(COFFSect);
1798  Relocs.reserve(OrigRelocs.size());
1799  for (const coff_relocation &R : OrigRelocs)
1800  Relocs.push_back(&R);
1801  llvm::sort(Relocs, [](const coff_relocation *A, const coff_relocation *B) {
1802  return A->VirtualAddress < B->VirtualAddress;
1803  });
1804  return Error::success();
1805 }
1806 
1809  if (!Obj)
1810  return createStringError(object_error::parse_failed, "no object provided");
1811 
1812  // Find a potential relocation at the DataRVA field (first member of
1813  // the coff_resource_data_entry struct).
1814  const uint8_t *EntryPtr = reinterpret_cast<const uint8_t *>(&Entry);
1815  ptrdiff_t EntryOffset = EntryPtr - BBS.data().data();
1816  coff_relocation RelocTarget{ulittle32_t(EntryOffset), ulittle32_t(0),
1817  ulittle16_t(0)};
1818  auto RelocsForOffset =
1819  std::equal_range(Relocs.begin(), Relocs.end(), &RelocTarget,
1820  [](const coff_relocation *A, const coff_relocation *B) {
1821  return A->VirtualAddress < B->VirtualAddress;
1822  });
1823 
1824  if (RelocsForOffset.first != RelocsForOffset.second) {
1825  // We found a relocation with the right offset. Check that it does have
1826  // the expected type.
1827  const coff_relocation &R = **RelocsForOffset.first;
1828  uint16_t RVAReloc;
1829  switch (Obj->getMachine()) {
1831  RVAReloc = COFF::IMAGE_REL_I386_DIR32NB;
1832  break;
1834  RVAReloc = COFF::IMAGE_REL_AMD64_ADDR32NB;
1835  break;
1837  RVAReloc = COFF::IMAGE_REL_ARM_ADDR32NB;
1838  break;
1840  RVAReloc = COFF::IMAGE_REL_ARM64_ADDR32NB;
1841  break;
1842  default:
1844  "unsupported architecture");
1845  }
1846  if (R.Type != RVAReloc)
1848  "unexpected relocation type");
1849  // Get the relocation's symbol
1850  Expected<COFFSymbolRef> Sym = Obj->getSymbol(R.SymbolTableIndex);
1851  if (!Sym)
1852  return Sym.takeError();
1853  // And the symbol's section
1855  Obj->getSection(Sym->getSectionNumber());
1856  if (!Section)
1857  return Section.takeError();
1858  // Add the initial value of DataRVA to the symbol's offset to find the
1859  // data it points at.
1860  uint64_t Offset = Entry.DataRVA + Sym->getValue();
1861  ArrayRef<uint8_t> Contents;
1862  if (Error E = Obj->getSectionContents(*Section, Contents))
1863  return std::move(E);
1864  if (Offset + Entry.DataSize > Contents.size())
1866  "data outside of section");
1867  // Return a reference to the data inside the section.
1868  return StringRef(reinterpret_cast<const char *>(Contents.data()) + Offset,
1869  Entry.DataSize);
1870  } else {
1871  // Relocatable objects need a relocation for the DataRVA field.
1872  if (Obj->isRelocatableObject())
1874  "no relocation found for DataRVA");
1875 
1876  // Locate the section that contains the address that DataRVA points at.
1877  uint64_t VA = Entry.DataRVA + Obj->getImageBase();
1878  for (const SectionRef &S : Obj->sections()) {
1879  if (VA >= S.getAddress() &&
1880  VA + Entry.DataSize <= S.getAddress() + S.getSize()) {
1881  uint64_t Offset = VA - S.getAddress();
1882  Expected<StringRef> Contents = S.getContents();
1883  if (!Contents)
1884  return Contents.takeError();
1885  return Contents->slice(Offset, Offset + Entry.DataSize);
1886  }
1887  }
1889  "address not found in image");
1890  }
1891 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
llvm::object::COFFObjectFile::base_relocs
iterator_range< base_reloc_iterator > base_relocs() const
Definition: COFFObjectFile.cpp:1000
llvm::object::object_error::unexpected_eof
@ unexpected_eof
MemoryBuffer.h
BinaryStreamReader.h
llvm::object::COFFObjectFile::getBytesInAddress
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
Definition: COFFObjectFile.cpp:944
llvm::object::DelayImportDirectoryEntryRef::imported_symbol_begin
imported_symbol_iterator imported_symbol_begin() const
Definition: COFFObjectFile.cpp:1445
llvm::object::DelayImportDirectoryEntryRef::getName
Error getName(StringRef &Result) const
Definition: COFFObjectFile.cpp:1461
llvm::object::COFFObjectFile::getSectionAlignment
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Definition: COFFObjectFile.cpp:302
llvm::object::BaseRelocRef::getRVA
Error getRVA(uint32_t &Result) const
Definition: COFFObjectFile.cpp:1687
llvm::COFF::IMAGE_REL_I386_SECTION
@ IMAGE_REL_I386_SECTION
Definition: COFF.h:338
llvm::COFF::IMAGE_REL_AMD64_PAIR
@ IMAGE_REL_AMD64_PAIR
Definition: COFF.h:361
llvm::object::coff_base_reloc_block_entry
Definition: COFF.h:747
llvm::COFF::IMAGE_REL_AMD64_ADDR32
@ IMAGE_REL_AMD64_ADDR32
Definition: COFF.h:348
llvm::object::debug_directory::SizeOfData
support::ulittle32_t SizeOfData
Definition: COFF.h:183
llvm::COFF::IMAGE_REL_ARM64_SECREL
@ IMAGE_REL_ARM64_SECREL
Definition: COFF.h:394
MathExtras.h
llvm::object::import_lookup_table_entry64
import_lookup_table_entry< support::little64_t > import_lookup_table_entry64
Definition: COFF.h:208
llvm
Definition: AllocatorList.h:23
llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition: COFF.h:290
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::object::COFFObjectFile::getSymbolAddress
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
Definition: COFFObjectFile.cpp:166
llvm::object::COFFObjectFile::ExportDirectoryEntryRef
friend class ExportDirectoryEntryRef
Definition: COFF.h:804
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
llvm::COFF::IMAGE_REL_ARM64_ADDR32NB
@ IMAGE_REL_ARM64_ADDR32NB
Definition: COFF.h:388
llvm::object::delay_import_directory_table_entry::DelayImportAddressTable
support::ulittle32_t DelayImportAddressTable
Definition: COFF.h:215
llvm::object::COFFObjectFile::section_begin
section_iterator section_begin() const override
Definition: COFFObjectFile.cpp:922
llvm::object::COFFSymbolRef::getWeakExternal
const coff_aux_weak_external * getWeakExternal() const
Definition: COFF.h:366
llvm::object::COFFSymbolRef::getSectionNumber
int32_t getSectionNumber() const
Definition: COFF.h:322
llvm::object::COFFObjectFile::getRelocationType
uint64_t getRelocationType(DataRefImpl Rel) const override
Definition: COFFObjectFile.cpp:1177
llvm::Triple::UnknownArch
@ UnknownArch
Definition: Triple.h:48
llvm::object::COFFObjectFile::getCOFFRelocation
const coff_relocation * getCOFFRelocation(const RelocationRef &Reloc) const
Definition: COFFObjectFile.cpp:1200
getFirstReloc
static const coff_relocation * getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base)
Definition: COFFObjectFile.cpp:377
importedSymbolEnd
static imported_symbol_iterator importedSymbolEnd(uint32_t RVA, const COFFObjectFile *Object)
Definition: COFFObjectFile.cpp:1365
llvm::object::COFFObjectFile::getSectionAddress
uint64_t getSectionAddress(DataRefImpl Sec) const override
Definition: COFFObjectFile.cpp:275
llvm::object::COFFObjectFile::getDataDirectory
const data_directory * getDataDirectory(uint32_t index) const
Definition: COFFObjectFile.cpp:1004
llvm::object::COFFObjectFile::getHintName
Error getHintName(uint32_t Rva, uint16_t &Hint, StringRef &Name) const
Definition: COFFObjectFile.cpp:509
llvm::COFF::IMAGE_REL_ARM64_PAGEBASE_REL21
@ IMAGE_REL_ARM64_PAGEBASE_REL21
Definition: COFF.h:390
llvm::object::coff_section::VirtualAddress
support::ulittle32_t VirtualAddress
Definition: COFF.h:443
llvm::object::COFFObjectFile::isSectionVirtual
bool isSectionVirtual(DataRefImpl Sec) const override
Definition: COFFObjectFile.cpp:349
llvm::COFF::PE32Header::PE32
@ PE32
Definition: COFF.h:540
llvm::object::COFFObjectFile::getCommonSymbolSizeImpl
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
Definition: COFFObjectFile.cpp:241
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::object::coff_file_header::Machine
support::ulittle16_t Machine
Definition: COFF.h:76
llvm::object::BasicSymbolRef::SF_Common
@ SF_Common
Definition: SymbolicFile.h:112
llvm::StringSwitch::Default
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
llvm::Triple::x86
@ x86
Definition: Triple.h:83
llvm::object::coff_tls_directory32
coff_tls_directory< support::little32_t > coff_tls_directory32
Definition: COFF.h:597
llvm::object::ObjectFile::RelocationRef
friend class RelocationRef
Definition: ObjectFile.h:286
llvm::object::ImportedSymbolRef::moveNext
void moveNext()
Definition: COFFObjectFile.cpp:1592
RETURN_IF_ERROR
#define RETURN_IF_ERROR(Expr)
Definition: COFFObjectFile.cpp:1693
llvm::object::export_directory_table_entry::OrdinalTableRVA
support::ulittle32_t OrdinalTableRVA
Definition: COFF.h:233
llvm::object::COFFObjectFile::debug_directories
iterator_range< const debug_directory * > debug_directories() const
Definition: COFF.h:1012
LLVM_COFF_SWITCH_RELOC_TYPE_NAME
#define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(reloc_type)
Definition: COFFObjectFile.cpp:1210
llvm::COFF::IMAGE_REL_ARM64_PAGEOFFSET_12L
@ IMAGE_REL_ARM64_PAGEOFFSET_12L
Definition: COFF.h:393
llvm::object::COFFObjectFile::getStartAddress
Expected< uint64_t > getStartAddress() const override
Definition: COFFObjectFile.cpp:978
llvm::object::COFFObjectFile::getSymbolSection
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
Definition: COFFObjectFile.cpp:247
llvm::object::ImportDirectoryEntryRef::getImportAddressTableRVA
Error getImportAddressTableRVA(uint32_t &Result) const
Definition: COFFObjectFile.cpp:1429
llvm::object::coff_section::getAlignment
uint32_t getAlignment() const
Definition: COFF.h:459
llvm::object::SectionRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition: ObjectFile.h:526
llvm::object::COFFObjectFile::import_directories
iterator_range< import_directory_iterator > import_directories() const
Definition: COFFObjectFile.cpp:985
ErrorHandling.h
llvm::object::COFFObjectFile::section_rel_end
relocation_iterator section_rel_end(DataRefImpl Sec) const override
Definition: COFFObjectFile.cpp:406
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:332
llvm::COFF::IMAGE_REL_I386_ABSOLUTE
@ IMAGE_REL_I386_ABSOLUTE
Definition: COFF.h:332
llvm::COFF::IMAGE_REL_ARM_MOV32A
@ IMAGE_REL_ARM_MOV32A
Definition: COFF.h:377
llvm::object::BaseRelocRef::operator==
bool operator==(const BaseRelocRef &Other) const
Definition: COFFObjectFile.cpp:1659
llvm::COFF::IMAGE_FILE_MACHINE_AMD64
@ IMAGE_FILE_MACHINE_AMD64
Definition: COFF.h:98
llvm::BinaryStreamReader::setOffset
void setOffset(uint32_t Off)
Definition: BinaryStreamReader.h:254
llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN
@ IMAGE_FILE_MACHINE_UNKNOWN
Definition: COFF.h:96
memcmp
Merge contiguous icmps into a memcmp
Definition: MergeICmps.cpp:927
Error.h
llvm::COFF::IMAGE_REL_ARM64_REL21
@ IMAGE_REL_ARM64_REL21
Definition: COFF.h:391
llvm::object::COFFObjectFile::getSectionID
unsigned getSectionID(SectionRef Sec) const
Definition: COFFObjectFile.cpp:342
COFF.h
llvm::object::COFFObjectFile::getVaPtr
Error getVaPtr(uint64_t VA, uintptr_t &Res) const
Definition: COFFObjectFile.cpp:464
llvm::object::ObjectFile::getSymbolValue
Expected< uint64_t > getSymbolValue(DataRefImpl Symb) const
Definition: ObjectFile.cpp:57
llvm::object::ResourceSectionRef::getTableEntry
Expected< const coff_resource_dir_entry & > getTableEntry(const coff_resource_dir_table &Table, uint32_t Index)
Definition: COFFObjectFile.cpp:1766
llvm::object::relocation_iterator
content_iterator< RelocationRef > relocation_iterator
Definition: ObjectFile.h:76
llvm::object::import_lookup_table_entry::getOrdinal
uint16_t getOrdinal() const
Definition: COFF.h:194
llvm::object::ExportDirectoryEntryRef::getSymbolName
Error getSymbolName(StringRef &Result) const
Definition: COFFObjectFile.cpp:1535
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:84
llvm::COFF::IMAGE_REL_I386_DIR32NB
@ IMAGE_REL_I386_DIR32NB
Definition: COFF.h:336
llvm::object::SymbolRef::ST_Unknown
@ ST_Unknown
Definition: ObjectFile.h:172
llvm::object::Binary::Data
MemoryBufferRef Data
Definition: Binary.h:37
llvm::COFF::IMAGE_REL_AMD64_REL32
@ IMAGE_REL_AMD64_REL32
Definition: COFF.h:350
llvm::object::ImportDirectoryEntryRef::lookup_table_begin
imported_symbol_iterator lookup_table_begin() const
Definition: COFFObjectFile.cpp:1400
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
llvm::object::getObject
static Expected< const T * > getObject(MemoryBufferRef M, const void *Ptr, const uint64_t Size=sizeof(T))
Definition: XCOFFObjectFile.cpp:33
llvm::object::ObjectFile::createCOFFObjectFile
static Expected< std::unique_ptr< COFFObjectFile > > createCOFFObjectFile(MemoryBufferRef Object)
Definition: COFFObjectFile.cpp:1655
llvm::COFF::IMAGE_FILE_MACHINE_ARMNT
@ IMAGE_FILE_MACHINE_ARMNT
Definition: COFF.h:100
getNumberOfRelocations
static uint32_t getNumberOfRelocations(const coff_section *Sec, MemoryBufferRef M, const uint8_t *base)
Definition: COFFObjectFile.cpp:356
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::object::COFFSymbolRef::isExternal
bool isExternal() const
Definition: COFF.h:377
llvm::object::delay_import_directory_iterator
content_iterator< DelayImportDirectoryEntryRef > delay_import_directory_iterator
Definition: COFF.h:47
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::object::ExportDirectoryEntryRef::getExportRVA
Error getExportRVA(uint32_t &Result) const
Definition: COFFObjectFile.cpp:1521
llvm::object::coff_section::VirtualSize
support::ulittle32_t VirtualSize
Definition: COFF.h:442
llvm::object::COFFObjectFile::getArch
Triple::ArchType getArch() const override
Definition: COFFObjectFile.cpp:963
llvm::object::ImportDirectoryEntryRef::imported_symbol_begin
imported_symbol_iterator imported_symbol_begin() const
Definition: COFFObjectFile.cpp:1384
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::object::SymbolRef::ST_Data
@ ST_Data
Definition: ObjectFile.h:173
llvm::COFF::IMAGE_REL_ARM64_SECREL_HIGH12A
@ IMAGE_REL_ARM64_SECREL_HIGH12A
Definition: COFF.h:396
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::object::COFFObjectFile::export_directory_end
export_directory_iterator export_directory_end() const
Definition: COFFObjectFile.cpp:914
llvm::object::ImportDirectoryEntryRef::getName
Error getName(StringRef &Result) const
Definition: COFFObjectFile.cpp:1415
llvm::PowerOf2Ceil
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
Definition: MathExtras.h:702
llvm::object::SymbolRef::ST_File
@ ST_File
Definition: ObjectFile.h:175
llvm::COFF::IMAGE_REL_ARM_BRANCH20T
@ IMAGE_REL_ARM_BRANCH20T
Definition: COFF.h:379
llvm::object::BasicSymbolRef::SF_Weak
@ SF_Weak
Definition: SymbolicFile.h:110
llvm::COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS
@ IMAGE_WEAK_EXTERN_SEARCH_ALIAS
Definition: COFF.h:442
llvm::object::coff_base_reloc_block_header
Definition: COFF.h:742
llvm::object::import_lookup_table_entry32
import_lookup_table_entry< support::little32_t > import_lookup_table_entry32
Definition: COFF.h:206
llvm::COFF::IMAGE_SYM_ABSOLUTE
@ IMAGE_SYM_ABSOLUTE
Definition: COFF.h:198
llvm::object::ExportDirectoryEntryRef::getForwardTo
Error getForwardTo(StringRef &Result) const
Definition: COFFObjectFile.cpp:1575
llvm::object::COFFObjectFile::getRvaPtr
Error getRvaPtr(uint32_t Rva, uintptr_t &Res) const
Definition: COFFObjectFile.cpp:472
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1006
llvm::COFF::IMAGE_REL_ARM64_BRANCH26
@ IMAGE_REL_ARM64_BRANCH26
Definition: COFF.h:389
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::object::export_directory_table_entry::ExportAddressTableRVA
support::ulittle32_t ExportAddressTableRVA
Definition: COFF.h:231
llvm::COFF::IMAGE_REL_ARM64_ABSOLUTE
@ IMAGE_REL_ARM64_ABSOLUTE
Definition: COFF.h:386
llvm::ArrayRef::data
const T * data() const
Definition: ArrayRef.h:162
llvm::COFF::IMAGE_REL_ARM64_SECREL_LOW12A
@ IMAGE_REL_ARM64_SECREL_LOW12A
Definition: COFF.h:395
llvm::object::COFFSymbolRef::isFileRecord
bool isFileRecord() const
Definition: COFF.h:409
llvm::object::coff_import_directory_table_entry::ImportAddressTableRVA
support::ulittle32_t ImportAddressTableRVA
Definition: COFF.h:560
llvm::object::COFFObjectFile::getRelocations
ArrayRef< coff_relocation > getRelocations(const coff_section *Sec) const
Definition: COFFObjectFile.cpp:1205
llvm::object::coff_file_header::NumberOfSections
support::ulittle16_t NumberOfSections
Definition: COFF.h:77
llvm::object::ImportDirectoryEntryRef::lookup_table_symbols
iterator_range< imported_symbol_iterator > lookup_table_symbols() const
Definition: COFFObjectFile.cpp:1411
llvm::COFF::PEMagic
static const char PEMagic[]
Definition: COFF.h:36
llvm::object::ResourceSectionRef::getEntryData
Expected< const coff_resource_data_entry & > getEntryData(const coff_resource_dir_entry &Entry)
Definition: COFFObjectFile.cpp:1756
llvm::object::COFFSymbolRef::isWeakExternal
bool isWeakExternal() const
Definition: COFF.h:391
llvm::COFF::IMAGE_REL_I386_DIR16
@ IMAGE_REL_I386_DIR16
Definition: COFF.h:333
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
llvm::object::ImportedSymbolRef::getOrdinal
Error getOrdinal(uint16_t &Result) const
Definition: COFFObjectFile.cpp:1632
llvm::object::COFFObjectFile::getFileFormatName
StringRef getFileFormatName() const override
Definition: COFFObjectFile.cpp:948
llvm::object::COFFObjectFile::section_end
section_iterator section_end() const override
Definition: COFFObjectFile.cpp:928
llvm::COFF::DELAY_IMPORT_DESCRIPTOR
@ DELAY_IMPORT_DESCRIPTOR
Definition: COFF.h:595
llvm::COFF::IMAGE_REL_ARM_SECREL
@ IMAGE_REL_ARM_SECREL
Definition: COFF.h:376
llvm::object::COFFObjectFile::getSectionSize
uint64_t getSectionSize(DataRefImpl Sec) const override
llvm::COFF::IMAGE_FILE_MACHINE_I386
@ IMAGE_FILE_MACHINE_I386
Definition: COFF.h:103
llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
@ IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: COFF.h:289
llvm::object::ImportedSymbolRef::getSymbolName
Error getSymbolName(StringRef &Result) const
Definition: COFFObjectFile.cpp:1596
Error.h
llvm::object::data_directory::RelativeVirtualAddress
support::ulittle32_t RelativeVirtualAddress
Definition: COFF.h:173
llvm::object::COFFSymbolRef
Definition: COFF.h:280
llvm::object::ImportedSymbolRef::getHintNameRVA
Error getHintNameRVA(uint32_t &Result) const
Definition: COFFObjectFile.cpp:1624
llvm::Triple::ArchType
ArchType
Definition: Triple.h:47
llvm::COFF::IMAGE_REL_ARM_MOV32T
@ IMAGE_REL_ARM_MOV32T
Definition: COFF.h:378
llvm::ModRefInfo::Ref
@ Ref
The access may reference the value stored in memory.
ptrdiff_t
llvm::object::coff_import_directory_table_entry::NameRVA
support::ulittle32_t NameRVA
Definition: COFF.h:559
llvm::object::import_lookup_table_entry::isOrdinal
bool isOrdinal() const
Definition: COFF.h:192
llvm::COFF::LOAD_CONFIG_TABLE
@ LOAD_CONFIG_TABLE
Definition: COFF.h:592
llvm::object::COFFObjectFile::getMachine
uint16_t getMachine() const
Definition: COFF.h:859
llvm::object::BasicSymbolRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition: SymbolicFile.h:206
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::support::little
@ little
Definition: Endian.h:27
llvm::object::COFFObjectFile::getSymbolAlignment
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
Definition: COFFObjectFile.cpp:159
llvm::StringRef::split
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
llvm::object::export_directory_table_entry::OrdinalBase
support::ulittle32_t OrdinalBase
Definition: COFF.h:228
llvm::COFF::IMAGE_DEBUG_TYPE_CODEVIEW
@ IMAGE_DEBUG_TYPE_CODEVIEW
Definition: COFF.h:654
llvm::object::coff_symbol::NumberOfAuxSymbols
uint8_t NumberOfAuxSymbols
Definition: COFF.h:262
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:87
llvm::object::COFFObjectFile::getPointerToSymbolTable
uint32_t getPointerToSymbolTable() const
Definition: COFF.h:903
llvm::BinaryByteStream
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
Definition: BinaryByteStream.h:31
llvm::object::coff_resource_data_entry
Definition: COFF.h:777
llvm::COFF::IMAGE_SCN_MEM_READ
@ IMAGE_SCN_MEM_READ
Definition: COFF.h:321
llvm::object::export_directory_table_entry::AddressTableEntries
support::ulittle32_t AddressTableEntries
Definition: COFF.h:229
llvm::object::ExportDirectoryEntryRef::isForwarder
Error isForwarder(bool &Result) const
Definition: COFFObjectFile.cpp:1561
llvm::object::export_directory_table_entry::NamePointerRVA
support::ulittle32_t NamePointerRVA
Definition: COFF.h:232
llvm::object::coff_section::Name
char Name[COFF::NameSize]
Definition: COFF.h:441
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::object::coff_section::PointerToRawData
support::ulittle32_t PointerToRawData
Definition: COFF.h:445
llvm::COFF::IMAGE_REL_ARM_ADDR32NB
@ IMAGE_REL_ARM_ADDR32NB
Definition: COFF.h:368
llvm::COFF::IMAGE_REL_ARM_TOKEN
@ IMAGE_REL_ARM_TOKEN
Definition: COFF.h:371
llvm::COFF::IMAGE_REL_ARM64_ADDR32
@ IMAGE_REL_ARM64_ADDR32
Definition: COFF.h:387
llvm::object::pe32plus_header::ImageBase
support::ulittle64_t ImageBase
Definition: COFF.h:149
llvm::object::export_directory_table_entry::NumberOfNamePointers
support::ulittle32_t NumberOfNamePointers
Definition: COFF.h:230
llvm::object::COFFObjectFile::getRelocationOffset
uint64_t getRelocationOffset(DataRefImpl Rel) const override
Definition: COFFObjectFile.cpp:1158
llvm::BinaryStreamReader::readInteger
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
Definition: BinaryStreamReader.h:75
llvm::object::ResourceSectionRef::getEntrySubDir
Expected< const coff_resource_dir_table & > getEntrySubDir(const coff_resource_dir_entry &Entry)
Definition: COFFObjectFile.cpp:1750
llvm::BinaryByteStream::data
ArrayRef< uint8_t > data() const
Definition: BinaryByteStream.h:59
llvm::report_fatal_error
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
llvm::COFF::IMAGE_REL_I386_DIR32
@ IMAGE_REL_I386_DIR32
Definition: COFF.h:335
llvm::object::object_error::parse_failed
@ parse_failed
llvm::object::DataRefImpl::p
uintptr_t p
Definition: SymbolicFile.h:39
llvm::object::coff_file_header::isImportLibrary
bool isImportLibrary() const
Definition: COFF.h:84
llvm::object::export_address_table_entry
Definition: COFF.h:236
llvm::object::coff_symbol
Definition: COFF.h:250
llvm::object::coff_section::Characteristics
support::ulittle32_t Characteristics
Definition: COFF.h:450
llvm::object::export_directory_table_entry::NameRVA
support::ulittle32_t NameRVA
Definition: COFF.h:227
llvm::object::pe32_header::ImageBase
support::ulittle32_t ImageBase
Definition: COFF.h:114
llvm::object::coff_relocation
Definition: COFF.h:474
llvm::COFF::IMAGE_REL_AMD64_SREL32
@ IMAGE_REL_AMD64_SREL32
Definition: COFF.h:360
llvm::object::COFFObjectFile::getSymbolTableEntrySize
size_t getSymbolTableEntrySize() const
Definition: COFF.h:1065
llvm::object::COFFObjectFile::getSymbolFlags
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
Definition: COFFObjectFile.cpp:210
llvm::object::COFFObjectFile::getSymbolIndex
uint32_t getSymbolIndex(COFFSymbolRef Symbol) const
Definition: COFFObjectFile.cpp:1077
llvm::object::COFFObjectFile::getSymbolSectionID
unsigned getSymbolSectionID(SymbolRef Sym) const
Definition: COFFObjectFile.cpp:259
llvm::object::COFFObjectFile::section_rel_begin
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Definition: COFFObjectFile.cpp:396
llvm::object::import_lookup_table_entry::getHintNameRVA
uint32_t getHintNameRVA() const
Definition: COFF.h:199
llvm::object::COFFObjectFile::moveSectionNext
void moveSectionNext(DataRefImpl &Sec) const override
Definition: COFFObjectFile.cpp:264
llvm::object::RelocationRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition: ObjectFile.h:564
llvm::COFF::IMAGE_REL_AMD64_SSPAN32
@ IMAGE_REL_AMD64_SSPAN32
Definition: COFF.h:362
llvm::object::coff_resource_dir_entry
Definition: COFF.h:754
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:31
llvm::object::ImportedSymbolRef
Definition: COFF.h:1196
llvm::object::COFFSymbolRef::isSectionDefinition
bool isSectionDefinition() const
Definition: COFF.h:417
llvm::COFF::TLS_TABLE
@ TLS_TABLE
Definition: COFF.h:591
llvm::object::COFFSymbolRef::isUndefined
bool isUndefined() const
Definition: COFF.h:386
llvm::OutputFileType::Object
@ Object
llvm::object::SectionRef
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:80
llvm::object::COFFObjectFile::export_directory_begin
export_directory_iterator export_directory_begin() const
Definition: COFFObjectFile.cpp:909
llvm::support::ulittle32_t
detail::packed_endian_specific_integral< uint32_t, little, unaligned > ulittle32_t
Definition: Endian.h:272
llvm::object::COFFSymbolRef::isAnyUndefined
bool isAnyUndefined() const
Definition: COFF.h:405
llvm::object::COFFObjectFile::isSectionData
bool isSectionData(DataRefImpl Sec) const override
Definition: COFFObjectFile.cpp:316
llvm::object::COFFObjectFile::base_reloc_end
base_reloc_iterator base_reloc_end() const
Definition: COFFObjectFile.cpp:940
llvm::COFF::IMAGE_REL_ARM64_SECREL_LOW12L
@ IMAGE_REL_ARM64_SECREL_LOW12L
Definition: COFF.h:397
llvm::COFF::IMAGE_REL_ARM_PAIR
@ IMAGE_REL_ARM_PAIR
Definition: COFF.h:382
llvm::object::ObjectFile::SymbolRef
friend class SymbolRef
Definition: ObjectFile.h:246
llvm::object::coff_bigobj_file_header::UUID
uint8_t UUID[16]
Definition: COFF.h:93
llvm::COFF::NameSize
@ NameSize
Definition: COFF.h:58
llvm::object::COFFObjectFile::getSymbolTable
uintptr_t getSymbolTable() const
Definition: COFF.h:851
llvm::object::data_directory
Definition: COFF.h:172
llvm::object::COFFObjectFile::getImageBase
uint64_t getImageBase() const
Definition: COFFObjectFile.cpp:454
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:179
llvm::support::ulittle16_t
detail::packed_endian_specific_integral< uint16_t, little, unaligned > ulittle16_t
Definition: Endian.h:270
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::object::BasicSymbolRef::SF_FormatSpecific
@ SF_FormatSpecific
Definition: SymbolicFile.h:115
llvm::COFF::IMAGE_REL_AMD64_ABSOLUTE
@ IMAGE_REL_AMD64_ABSOLUTE
Definition: COFF.h:346
llvm::ArrayRef::drop_front
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:204
makeImportedSymbolIterator
static imported_symbol_iterator makeImportedSymbolIterator(const COFFObjectFile *Object, uintptr_t Ptr, int Index)
Definition: COFFObjectFile.cpp:1346
llvm::COFF::IMAGE_REL_I386_REL32
@ IMAGE_REL_I386_REL32
Definition: COFF.h:342
llvm::object::coff_import_directory_table_entry::isNull
bool isNull() const
Definition: COFF.h:562
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::object::symbol_iterator
Definition: ObjectFile.h:207
llvm::object::pe32plus_header::NumberOfRvaAndSize
support::ulittle32_t NumberOfRvaAndSize
Definition: COFF.h:169
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::StringRef::end
iterator end() const
Definition: StringRef.h:130
importedSymbolBegin
static imported_symbol_iterator importedSymbolBegin(uint32_t RVA, const COFFObjectFile *Object)
Definition: COFFObjectFile.cpp:1357
llvm::object::SymbolRef::ST_Function
@ ST_Function
Definition: ObjectFile.h:176
llvm::COFF::IMAGE_REL_ARM_BRANCH24T
@ IMAGE_REL_ARM_BRANCH24T
Definition: COFF.h:380
llvm::object::coff_aux_weak_external
Definition: COFF.h:502
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
llvm::COFF::IMAGE_REL_AMD64_REL32_4
@ IMAGE_REL_AMD64_REL32_4
Definition: COFF.h:354
llvm::COFF::IMAGE_REL_ARM_BRANCH24
@ IMAGE_REL_ARM_BRANCH24
Definition: COFF.h:369
llvm::COFF::IMAGE_REL_ARM_BRANCH11
@ IMAGE_REL_ARM_BRANCH11
Definition: COFF.h:370
llvm::object::ImportedSymbolRef::isOrdinal
Error isOrdinal(bool &Result) const
Definition: COFFObjectFile.cpp:1616
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::COFF::SectionSize
@ SectionSize
Definition: COFF.h:61
llvm::object::BasicSymbolRef::SF_None
@ SF_None
Definition: SymbolicFile.h:107
llvm::object::ExportDirectoryEntryRef::operator==
bool operator==(const ExportDirectoryEntryRef &Other) const
Definition: COFFObjectFile.cpp:1490
llvm::COFF::IMAGE_REL_AMD64_REL32_5
@ IMAGE_REL_AMD64_REL32_5
Definition: COFF.h:355
llvm::object::ObjectFile::SectionRef
friend class SectionRef
Definition: ObjectFile.h:260
llvm::object::ResourceSectionRef::getBaseTable
Expected< const coff_resource_dir_table & > getBaseTable()
Definition: COFFObjectFile.cpp:1761
llvm::object::imported_symbol_iterator
content_iterator< ImportedSymbolRef > imported_symbol_iterator
Definition: COFF.h:49
llvm::object::ExportDirectoryEntryRef
Definition: COFF.h:1171
llvm::object::COFFObjectFile::mapDebugSectionName
StringRef mapDebugSectionName(StringRef Name) const override
Maps a debug section name to a standard DWARF section name.
Definition: COFFObjectFile.cpp:1321
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::object::BasicSymbolRef::SF_Undefined
@ SF_Undefined
Definition: SymbolicFile.h:108
llvm::object::StringTableOffset
Definition: COFF.h:244
llvm::COFF::IMAGE_REL_AMD64_ADDR64
@ IMAGE_REL_AMD64_ADDR64
Definition: COFF.h:347
llvm::object::COFFObjectFile::create
static Expected< std::unique_ptr< COFFObjectFile > > create(MemoryBufferRef Object)
Definition: COFFObjectFile.cpp:712
llvm::object::COFFObjectFile::getNumberOfSections
uint32_t getNumberOfSections() const
Definition: COFF.h:895
llvm::object::BaseRelocRef::getType
Error getType(uint8_t &Type) const
Definition: COFFObjectFile.cpp:1681
ArrayRef.h
llvm::object::ResourceSectionRef::getContents
Expected< StringRef > getContents(const coff_resource_data_entry &Entry)
Definition: COFFObjectFile.cpp:1808
llvm::object::pe32_header::AddressOfEntryPoint
support::ulittle32_t AddressOfEntryPoint
Definition: COFF.h:111
llvm::COFF::IMAGE_REL_AMD64_SECREL7
@ IMAGE_REL_AMD64_SECREL7
Definition: COFF.h:358
llvm::object::SymbolRef::ST_Debug
@ ST_Debug
Definition: ObjectFile.h:174
llvm::object::COFFObjectFile::moveSymbolNext
void moveSymbolNext(DataRefImpl &Symb) const override
Definition: COFFObjectFile.cpp:136
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::object::ResourceSectionRef::getEntryNameString
Expected< ArrayRef< UTF16 > > getEntryNameString(const coff_resource_dir_entry &Entry)
Definition: COFFObjectFile.cpp:1712
ObjectFile.h
llvm::object::BaseRelocRef
Definition: COFF.h:1221
base
therefore end up llgh r3 lr r0 br r14 but truncating the load would lh r3 br r14 Functions ret i64 and ought to be implemented ngr r0 br r14 but two address optimizations reverse the order of the AND and ngr r2 lgr r0 br r14 CodeGen SystemZ and ll has several examples of this Out of range displacements are usually handled by loading the full address into a register In many cases it would be better to create an anchor point instead E g i64 base
Definition: README.txt:125
llvm::object::content_iterator
Definition: SymbolicFile.h:67
llvm::object::pe32_header::NumberOfRvaAndSize
support::ulittle32_t NumberOfRvaAndSize
Definition: COFF.h:136
llvm::object::ImportDirectoryEntryRef::imported_symbol_end
imported_symbol_iterator imported_symbol_end() const
Definition: COFFObjectFile.cpp:1390
llvm::object::coff_symbol_generic
Definition: COFF.h:269
llvm::codeview::CompileSym2Flags::EC
@ EC
checkSize
static bool checkSize(MemoryBufferRef M, std::error_code &EC, uint64_t Size)
Definition: COFFObjectFile.cpp:47
llvm::object::ObjectFile::base
const uint8_t * base() const
Definition: ObjectFile.h:234
iterator_range.h
llvm::object::DelayImportDirectoryEntryRef::getDelayImportTable
Error getDelayImportTable(const delay_import_directory_table_entry *&Result) const
Definition: COFFObjectFile.cpp:1469
decodeBase64StringEntry
static bool decodeBase64StringEntry(StringRef Str, uint32_t &Result)
Definition: COFFObjectFile.cpp:69
llvm::object::COFFObjectFile::getNumberOfSymbols
uint32_t getNumberOfSymbols() const
Definition: COFF.h:920
llvm::COFF::IMAGE_REL_ARM_ABSOLUTE
@ IMAGE_REL_ARM_ABSOLUTE
Definition: COFF.h:366
llvm::object::SectionRef::getContents
Expected< StringRef > getContents() const
Definition: ObjectFile.h:462
llvm::COFF::DEBUG_DIRECTORY
@ DEBUG_DIRECTORY
Definition: COFF.h:588
llvm::object::COFFObjectFile::getCOFFSymbol
COFFSymbolRef getCOFFSymbol(const DataRefImpl &Ref) const
Definition: COFFObjectFile.cpp:1187
llvm::object::ExportDirectoryEntryRef::getOrdinalBase
Error getOrdinalBase(uint32_t &Result) const
Definition: COFFObjectFile.cpp:1509
llvm::object::ResourceSectionRef::load
Error load(const COFFObjectFile *O)
Definition: COFFObjectFile.cpp:1776
llvm::object::COFFObjectFile::moveRelocationNext
void moveRelocationNext(DataRefImpl &Rel) const override
Definition: COFFObjectFile.cpp:1153
llvm::object::COFFObjectFile::getSectionContents
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
llvm::object::ImportDirectoryEntryRef::getImportLookupTableRVA
Error getImportLookupTableRVA(uint32_t &Result) const
Definition: COFFObjectFile.cpp:1424
Triple.h
llvm::object::coff_bigobj_file_header::Version
support::ulittle16_t Version
Definition: COFF.h:90
llvm::object::COFFObjectFile::base_reloc_begin
base_reloc_iterator base_reloc_begin() const
Definition: COFFObjectFile.cpp:936
llvm::object::ImportDirectoryEntryRef::imported_symbols
iterator_range< imported_symbol_iterator > imported_symbols() const
Definition: COFFObjectFile.cpp:1396
llvm::ArrayRef< uint8_t >
llvm::COFF::BigObjMagic
static const char BigObjMagic[]
Definition: COFF.h:38
llvm::object::COFFSymbolRef::getValue
uint32_t getValue() const
Definition: COFF.h:317
llvm::object::section_iterator
content_iterator< SectionRef > section_iterator
Definition: ObjectFile.h:47
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
llvm::object::COFFSymbolRef::isCommon
bool isCommon() const
Definition: COFF.h:381
llvm::object::COFFObjectFile::getSymbolAuxData
ArrayRef< uint8_t > getSymbolAuxData(COFFSymbolRef Symbol) const
Definition: COFFObjectFile.cpp:1055
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::object::export_directory_iterator
content_iterator< ExportDirectoryEntryRef > export_directory_iterator
Definition: COFF.h:48
llvm::object::COFFObjectFile::isDebugSection
bool isDebugSection(DataRefImpl Sec) const override
Definition: COFFObjectFile.cpp:331
llvm::object::ObjectFile
This class is the base class for all object file types.
Definition: ObjectFile.h:228
llvm::object::coff_resource_dir_table::NumberOfIDEntries
support::ulittle16_t NumberOfIDEntries
Definition: COFF.h:790
llvm::object::Binary
Definition: Binary.h:32
llvm::object::COFFObjectFile::getDebugPDBInfo
Error getDebugPDBInfo(const debug_directory *DebugDir, const codeview::DebugInfo *&Info, StringRef &PDBFileName) const
Get PDB information out of a codeview debug directory entry.
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::object::COFFObjectFile::getSectionIndex
uint64_t getSectionIndex(DataRefImpl Sec) const override
Definition: COFFObjectFile.cpp:285
llvm::object::COFFObjectFile::getCOFFSection
const coff_section * getCOFFSection(const SectionRef &Section) const
Definition: COFFObjectFile.cpp:1183
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition: Error.h:537
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:708
llvm::object::COFFObjectFile::isSectionText
bool isSectionText(DataRefImpl Sec) const override
Definition: COFFObjectFile.cpp:311
uint32_t
llvm::Triple::thumb
@ thumb
Definition: Triple.h:81
llvm::object::coff_section::SizeOfRawData
support::ulittle32_t SizeOfRawData
Definition: COFF.h:444
llvm::object::debug_directory
Definition: COFF.h:177
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::COFF::IMAGE_REL_AMD64_REL32_2
@ IMAGE_REL_AMD64_REL32_2
Definition: COFF.h:352
llvm::object::COFFObjectFile::getDOSHeader
const dos_header * getDOSHeader() const
Definition: COFF.h:1023
llvm::object::DataRefImpl
Definition: SymbolicFile.h:33
llvm::object::import_directory_iterator
content_iterator< ImportDirectoryEntryRef > import_directory_iterator
Definition: COFF.h:45
llvm::object::ImportedSymbolRef::operator==
bool operator==(const ImportedSymbolRef &Other) const
Definition: COFFObjectFile.cpp:1587
llvm::COFF::IMAGE_REL_ARM64_PAGEOFFSET_12A
@ IMAGE_REL_ARM64_PAGEOFFSET_12A
Definition: COFF.h:392
llvm::object::COFFObjectFile::getSection
Expected< const coff_section * > getSection(int32_t index) const
Definition: COFFObjectFile.cpp:1015
llvm::COFF::IMAGE_REL_AMD64_SECREL
@ IMAGE_REL_AMD64_SECREL
Definition: COFF.h:357
llvm::COFF::IMAGE_REL_ARM_REL32
@ IMAGE_REL_ARM_REL32
Definition: COFF.h:374
llvm::codeview::DebugInfo
Definition: CVDebugRecord.h:45
llvm::COFF::IMAGE_FILE_MACHINE_ARM64
@ IMAGE_FILE_MACHINE_ARM64
Definition: COFF.h:101
llvm::object::COFFObjectFile::ImportDirectoryEntryRef
friend class ImportDirectoryEntryRef
Definition: COFF.h:803
llvm::COFF::IMAGE_REL_ARM_BLX24
@ IMAGE_REL_ARM_BLX24
Definition: COFF.h:372
llvm::COFF::IMAGE_REL_I386_TOKEN
@ IMAGE_REL_I386_TOKEN
Definition: COFF.h:340
llvm::COFF::IMAGE_REL_ARM64_REL32
@ IMAGE_REL_ARM64_REL32
Definition: COFF.h:403
llvm::object::DelayImportDirectoryEntryRef::operator==
bool operator==(const DelayImportDirectoryEntryRef &Other) const
Definition: COFFObjectFile.cpp:1436
llvm::object::base_reloc_iterator
content_iterator< BaseRelocRef > base_reloc_iterator
Definition: COFF.h:50
llvm::object::coff_tls_directory64
coff_tls_directory< support::little64_t > coff_tls_directory64
Definition: COFF.h:598
llvm::object::coff_relocation::Type
support::ulittle16_t Type
Definition: COFF.h:477
llvm::COFF::IMPORT_TABLE
@ IMPORT_TABLE
Definition: COFF.h:583
llvm::object::coff_import_directory_table_entry
Definition: COFF.h:555
llvm::COFF::BASE_RELOCATION_TABLE
@ BASE_RELOCATION_TABLE
Definition: COFF.h:587
llvm::COFF::IMAGE_REL_ARM_SECTION
@ IMAGE_REL_ARM_SECTION
Definition: COFF.h:375
llvm::object::COFFObjectFile::isRelocatableObject
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
Definition: COFFObjectFile.cpp:1317
llvm::object::ExportDirectoryEntryRef::getOrdinal
Error getOrdinal(uint32_t &Result) const
Definition: COFFObjectFile.cpp:1515
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1202
llvm::object::ImportDirectoryEntryRef::getImportTableEntry
Error getImportTableEntry(const coff_import_directory_table_entry *&Result) const
Definition: COFFObjectFile.cpp:1340
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::object::COFFObjectFile::getRelocationSymbol
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
Definition: COFFObjectFile.cpp:1163
uint16_t
llvm::object::COFFObjectFile::delay_import_directory_end
delay_import_directory_iterator delay_import_directory_end() const
Definition: COFFObjectFile.cpp:903
llvm::COFF::EXPORT_TABLE
@ EXPORT_TABLE
Definition: COFF.h:582
llvm::object::COFFObjectFile::symbol_begin
basic_symbol_iterator symbol_begin() const override
Definition: COFFObjectFile.cpp:869
llvm::COFF::IMAGE_REL_ARM64_TOKEN
@ IMAGE_REL_ARM64_TOKEN
Definition: COFF.h:398
llvm::SectionName
Definition: DWARFSection.h:21
llvm::object::COFFObjectFile::isSectionBSS
bool isSectionBSS(DataRefImpl Sec) const override
Definition: COFFObjectFile.cpp:321
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::COFF::IMAGE_REL_ARM64_BRANCH14
@ IMAGE_REL_ARM64_BRANCH14
Definition: COFF.h:402
llvm::object::coff_section
Definition: COFF.h:440
llvm::COFF::IMAGE_SCN_CNT_CODE
@ IMAGE_SCN_CNT_CODE
Definition: COFF.h:288
llvm::COFF::IMAGE_REL_AMD64_ADDR32NB
@ IMAGE_REL_AMD64_ADDR32NB
Definition: COFF.h:349
llvm::object::ImportDirectoryEntryRef
Definition: COFF.h:1114
llvm::COFF::BigObjHeader::MinBigObjectVersion
@ MinBigObjectVersion
Definition: COFF.h:76
llvm::object::DelayImportDirectoryEntryRef::getImportAddress
Error getImportAddress(int AddrIndex, uint64_t &Result) const
Definition: COFFObjectFile.cpp:1475
llvm::COFF::IMAGE_REL_I386_REL16
@ IMAGE_REL_I386_REL16
Definition: COFF.h:334
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1423
llvm::object::COFFObjectFile::isSectionCompressed
bool isSectionCompressed(DataRefImpl Sec) const override
Definition: COFFObjectFile.cpp:307
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::object::BasicSymbolRef::SF_Absolute
@ SF_Absolute
Definition: SymbolicFile.h:111
llvm::COFF::IMAGE_REL_I386_SEG12
@ IMAGE_REL_I386_SEG12
Definition: COFF.h:337
llvm::object::delay_import_directory_table_entry
Definition: COFF.h:210
llvm::COFF::IMAGE_REL_ARM_BLX23T
@ IMAGE_REL_ARM_BLX23T
Definition: COFF.h:381
llvm::object::COFFObjectFile::getSymbolValueImpl
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
Definition: COFFObjectFile.cpp:155
llvm::COFF::IMAGE_REL_AMD64_REL32_1
@ IMAGE_REL_AMD64_REL32_1
Definition: COFF.h:351
llvm::object::DelayImportDirectoryEntryRef::imported_symbols
iterator_range< imported_symbol_iterator > imported_symbols() const
Definition: COFFObjectFile.cpp:1457
llvm::object::COFFObjectFile::getRvaAndSizeAsBytes
Error 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...
Definition: COFFObjectFile.cpp:487
llvm::object::COFFObjectFile
Definition: COFF.h:799
llvm::object::BaseRelocRef::moveNext
void moveNext()
Definition: COFFObjectFile.cpp:1663
StringSwitch.h
llvm::object::coff_resource_dir_table::NumberOfNameEntries
support::ulittle16_t NumberOfNameEntries
Definition: COFF.h:789
llvm::object::SymbolRef::ST_Other
@ ST_Other
Definition: ObjectFile.h:177
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::support::ulittle64_t
detail::packed_endian_specific_integral< uint64_t, little, unaligned > ulittle64_t
Definition: Endian.h:274
llvm::object::ExportDirectoryEntryRef::moveNext
void moveNext()
Definition: COFFObjectFile.cpp:1494
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:557
llvm::object::COFFObjectFile::getSymbolType
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
Definition: COFFObjectFile.cpp:187
llvm::object::COFFObjectFile::delay_import_directories
iterator_range< delay_import_directory_iterator > delay_import_directories() const
Definition: COFFObjectFile.cpp:990
llvm::COFF::IMAGE_REL_AMD64_REL32_3
@ IMAGE_REL_AMD64_REL32_3
Definition: COFF.h:353
Binary.h
llvm::COFF::IMAGE_REL_I386_SECREL
@ IMAGE_REL_I386_SECREL
Definition: COFF.h:339
llvm::support::little16_t
detail::packed_endian_specific_integral< int16_t, little, unaligned > little16_t
Definition: Endian.h:277
llvm::object::COFFObjectFile::delay_import_directory_begin
delay_import_directory_iterator delay_import_directory_begin() const
Definition: COFFObjectFile.cpp:897
COFF.h
llvm::object::DelayImportDirectoryEntryRef::moveNext
void moveNext()
Definition: COFFObjectFile.cpp:1440
llvm::COFF::isReservedSectionNumber
bool isReservedSectionNumber(int32_t SectionNumber)
Definition: COFF.h:729
llvm::COFF::IMAGE_REL_ARM64_BRANCH19
@ IMAGE_REL_ARM64_BRANCH19
Definition: COFF.h:401
llvm::object::DelayImportDirectoryEntryRef::imported_symbol_end
imported_symbol_iterator imported_symbol_end() const
Definition: COFFObjectFile.cpp:1451
llvm::object::BasicSymbolRef::SF_Global
@ SF_Global
Definition: SymbolicFile.h:109
llvm::object::ExportDirectoryEntryRef::getDllName
Error getDllName(StringRef &Result) const
Definition: COFFObjectFile.cpp:1500
llvm::object::COFFObjectFile::import_directory_begin
import_directory_iterator import_directory_begin() const
Definition: COFFObjectFile.cpp:882
llvm::object::ImportDirectoryEntryRef::operator==
bool operator==(const ImportDirectoryEntryRef &Other) const
Definition: COFFObjectFile.cpp:1328
llvm::object::coff_resource_dir_table
Definition: COFF.h:784
llvm::object::COFFObjectFile::symbol_end
basic_symbol_iterator symbol_end() const override
Definition: COFFObjectFile.cpp:875
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::COFF::IMAGE_REL_AMD64_SECTION
@ IMAGE_REL_AMD64_SECTION
Definition: COFF.h:356
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::object::coff_file_header::SizeOfOptionalHeader
support::ulittle16_t SizeOfOptionalHeader
Definition: COFF.h:81
llvm::object::ObjectFile::sections
section_iterator_range sections() const
Definition: ObjectFile.h:322
llvm::object::Binary::checkOffset
static Error checkOffset(MemoryBufferRef M, uintptr_t Addr, const uint64_t Size)
Definition: Binary.h:166
llvm::object::debug_directory::AddressOfRawData
support::ulittle32_t AddressOfRawData
Definition: COFF.h:184
llvm::SmallVectorImpl< char >
llvm::object::COFFObjectFile::is64
bool is64() const
Definition: COFF.h:1106
llvm::object::SymbolRef
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition: ObjectFile.h:167
llvm::object::data_directory::Size
support::ulittle32_t Size
Definition: COFF.h:174
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
llvm::object::DelayImportDirectoryEntryRef
Definition: COFF.h:1145
llvm::object::ImportDirectoryEntryRef::moveNext
void moveNext()
Definition: COFFObjectFile.cpp:1332
llvm::object::delay_import_directory_table_entry::Name
support::ulittle32_t Name
Definition: COFF.h:213
llvm::object::RelocationRef
This is a value type class that represents a single relocation in the list of relocations in the obje...
Definition: ObjectFile.h:51
llvm::COFF::IMAGE_REL_AMD64_TOKEN
@ IMAGE_REL_AMD64_TOKEN
Definition: COFF.h:359
llvm::object::COFFObjectFile::getRelocationTypeName
StringRef getRelocationTypeName(uint16_t Type) const
Definition: COFFObjectFile.cpp:1214
llvm::COFF::IMAGE_REL_ARM64_ADDR64
@ IMAGE_REL_ARM64_ADDR64
Definition: COFF.h:400
llvm::object::COFFObjectFile::import_directory_end
import_directory_iterator import_directory_end() const
Definition: COFFObjectFile.cpp:891
llvm::COFF::IMAGE_REL_ARM_BLX11
@ IMAGE_REL_ARM_BLX11
Definition: COFF.h:373
llvm::object::COFFSymbolRef::getComplexType
uint8_t getComplexType() const
Definition: COFF.h:350
llvm::COFF::IMAGE_REL_ARM_ADDR32
@ IMAGE_REL_ARM_ADDR32
Definition: COFF.h:367
llvm::COFF::IMAGE_SYM_DTYPE_FUNCTION
@ IMAGE_SYM_DTYPE_FUNCTION
A function that returns a base type.
Definition: COFF.h:261
Endian.h
llvm::StringRef::begin
iterator begin() const
Definition: StringRef.h:128
llvm::COFF::IMAGE_REL_I386_SECREL7
@ IMAGE_REL_I386_SECREL7
Definition: COFF.h:341
llvm::COFF::IMAGE_SYM_DEBUG
@ IMAGE_SYM_DEBUG
Definition: COFF.h:197
llvm::object::COFFObjectFile::getSymbolName
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
llvm::object::COFFObjectFile::export_directories
iterator_range< export_directory_iterator > export_directories() const
Definition: COFFObjectFile.cpp:996
llvm::object::basic_symbol_iterator
content_iterator< BasicSymbolRef > basic_symbol_iterator
Definition: SymbolicFile.h:141
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::object::COFFObjectFile::getSectionName
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
llvm::object::ImportDirectoryEntryRef::lookup_table_end
imported_symbol_iterator lookup_table_end() const
Definition: COFFObjectFile.cpp:1405
llvm::Triple::aarch64
@ aarch64
Definition: Triple.h:52
entry
print Instructions which execute on loop entry
Definition: MustExecute.cpp:339
llvm::BinaryStreamReader::readArray
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 ...
Definition: BinaryStreamReader.h:187
llvm::COFF::IMAGE_SCN_MEM_WRITE
@ IMAGE_SCN_MEM_WRITE
Definition: COFF.h:322
llvm::object::coff_import_directory_table_entry::ImportLookupTableRVA
support::ulittle32_t ImportLookupTableRVA
Definition: COFF.h:556
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1169
llvm::COFF::IMAGE_REL_ARM64_SECTION
@ IMAGE_REL_ARM64_SECTION
Definition: COFF.h:399
llvm::COFF::PE32Header::PE32_PLUS
@ PE32_PLUS
Definition: COFF.h:540