Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.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/iterator_range.h"
17#include "llvm/Object/Binary.h"
18#include "llvm/Object/COFF.h"
19#include "llvm/Object/Error.h"
20#include "llvm/Object/ObjectFile.h"
21#include "llvm/Object/WindowsMachineFlag.h"
22#include "llvm/Support/BinaryStreamReader.h"
23#include "llvm/Support/Endian.h"
24#include "llvm/Support/Error.h"
25#include "llvm/Support/ErrorHandling.h"
26#include "llvm/Support/MathExtras.h"
27#include "llvm/Support/MemoryBufferRef.h"
28#include <algorithm>
29#include <cassert>
30#include <cinttypes>
31#include <cstddef>
32#include <cstring>
33#include <limits>
34#include <memory>
35#include <system_error>
36
37using namespacellvm;
38using namespaceobject;
39
40usingsupport::ulittle16_t;
41usingsupport::ulittle32_t;
42usingsupport::ulittle64_t;
43usingsupport::little16_t;
44
45// Returns false if size is greater than the buffer size. And sets ec.
46staticboolcheckSize(MemoryBufferRef M, std::error_code &EC,uint64_tSize) {
47if (M.getBufferSize() <Size) {
48 EC = object_error::unexpected_eof;
49returnfalse;
50 }
51returntrue;
52}
53
54// Sets Obj unless any bytes in [addr, addr + size) fall outsize of m.
55// Returns unexpected_eof if error.
56template <typename T>
57staticErrorgetObject(constT *&Obj,MemoryBufferRef M,constvoid *Ptr,
58constuint64_tSize =sizeof(T)) {
59 uintptr_tAddr =reinterpret_cast<uintptr_t>(Ptr);
60if (Error E =Binary::checkOffset(M,Addr,Size))
61return E;
62 Obj =reinterpret_cast<constT *>(Addr);
63returnError::success();
64}
65
66// Decode a string table entry in base 64 (//AAAAAA). Expects \arg Str without
67// prefixed slashes.
68staticbooldecodeBase64StringEntry(StringRef Str,uint32_t &Result) {
69assert(Str.size() <= 6 &&"String too long, possible overflow.");
70if (Str.size() > 6)
71returntrue;
72
73uint64_tValue = 0;
74while (!Str.empty()) {
75unsigned CharVal;
76if (Str[0] >='A' && Str[0] <='Z')// 0..25
77 CharVal = Str[0] -'A';
78elseif (Str[0] >='a' && Str[0] <='z')// 26..51
79 CharVal = Str[0] -'a' + 26;
80elseif (Str[0] >='0' && Str[0] <='9')// 52..61
81 CharVal = Str[0] -'0' + 52;
82elseif (Str[0] =='+')// 62
83 CharVal = 62;
84elseif (Str[0] =='/')// 63
85 CharVal = 63;
86else
87returntrue;
88
89Value = (Value * 64) + CharVal;
90 Str = Str.substr(1);
91 }
92
93if (Value > std::numeric_limits<uint32_t>::max())
94returntrue;
95
96 Result =static_cast<uint32_t>(Value);
97returnfalse;
98}
99
100template <typename coff_symbol_type>
101const coff_symbol_type *COFFObjectFile::toSymb(DataRefImplRef) const{
102const coff_symbol_type *Addr =
103reinterpret_cast<constcoff_symbol_type *>(Ref.p);
104
105assert(!checkOffset(Data,reinterpret_cast<uintptr_t>(Addr),sizeof(*Addr)));
106#ifndef NDEBUG
107// Verify that the symbol points to a valid entry in the symbol table.
108 uintptr_tOffset =
109reinterpret_cast<uintptr_t>(Addr) -reinterpret_cast<uintptr_t>(base());
110
111assert((Offset -getPointerToSymbolTable()) %sizeof(coff_symbol_type) == 0 &&
112"Symbol did not point to the beginning of a symbol");
113#endif
114
115returnAddr;
116}
117
118constcoff_section *COFFObjectFile::toSec(DataRefImplRef) const{
119constcoff_section *Addr =reinterpret_cast<constcoff_section*>(Ref.p);
120
121#ifndef NDEBUG
122// Verify that the section points to a valid entry in the section table.
123if (Addr < SectionTable || Addr >= (SectionTable +getNumberOfSections()))
124report_fatal_error("Section was outside of section table.");
125
126 uintptr_tOffset =reinterpret_cast<uintptr_t>(Addr) -
127reinterpret_cast<uintptr_t>(SectionTable);
128assert(Offset %sizeof(coff_section) == 0 &&
129"Section did not point to the beginning of a section");
130#endif
131
132returnAddr;
133}
134
135voidCOFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const{
136autoEnd =reinterpret_cast<uintptr_t>(StringTable);
137if (SymbolTable16) {
138constcoff_symbol16 *Symb = toSymb<coff_symbol16>(Ref);
139 Symb += 1 + Symb->NumberOfAuxSymbols;
140Ref.p = std::min(reinterpret_cast<uintptr_t>(Symb),End);
141 }elseif (SymbolTable32) {
142constcoff_symbol32 *Symb = toSymb<coff_symbol32>(Ref);
143 Symb += 1 + Symb->NumberOfAuxSymbols;
144Ref.p = std::min(reinterpret_cast<uintptr_t>(Symb),End);
145 }else {
146llvm_unreachable("no symbol table pointer!");
147 }
148}
149
150Expected<StringRef>COFFObjectFile::getSymbolName(DataRefImplRef) const{
151returngetSymbolName(getCOFFSymbol(Ref));
152}
153
154uint64_tCOFFObjectFile::getSymbolValueImpl(DataRefImplRef) const{
155returngetCOFFSymbol(Ref).getValue();
156}
157
158uint32_tCOFFObjectFile::getSymbolAlignment(DataRefImplRef) const{
159// MSVC/link.exe seems to align symbols to the next-power-of-2
160// up to 32 bytes.
161COFFSymbolRef Symb =getCOFFSymbol(Ref);
162return std::min(uint64_t(32),PowerOf2Ceil(Symb.getValue()));
163}
164
165Expected<uint64_t>COFFObjectFile::getSymbolAddress(DataRefImplRef) const{
166uint64_t Result =cantFail(getSymbolValue(Ref));
167COFFSymbolRef Symb =getCOFFSymbol(Ref);
168 int32_t SectionNumber = Symb.getSectionNumber();
169
170if (Symb.isAnyUndefined() || Symb.isCommon() ||
171COFF::isReservedSectionNumber(SectionNumber))
172return Result;
173
174Expected<const coff_section *> Section =getSection(SectionNumber);
175if (!Section)
176return Section.takeError();
177 Result += (*Section)->VirtualAddress;
178
179// The section VirtualAddress does not include ImageBase, and we want to
180// return virtual addresses.
181 Result +=getImageBase();
182
183return Result;
184}
185
186Expected<SymbolRef::Type>COFFObjectFile::getSymbolType(DataRefImplRef) const{
187COFFSymbolRef Symb =getCOFFSymbol(Ref);
188 int32_t SectionNumber = Symb.getSectionNumber();
189
190if (Symb.getComplexType() ==COFF::IMAGE_SYM_DTYPE_FUNCTION)
191returnSymbolRef::ST_Function;
192if (Symb.isAnyUndefined())
193returnSymbolRef::ST_Unknown;
194if (Symb.isCommon())
195returnSymbolRef::ST_Data;
196if (Symb.isFileRecord())
197returnSymbolRef::ST_File;
198
199// TODO: perhaps we need a new symbol type ST_Section.
200if (SectionNumber ==COFF::IMAGE_SYM_DEBUG || Symb.isSectionDefinition())
201returnSymbolRef::ST_Debug;
202
203if (!COFF::isReservedSectionNumber(SectionNumber))
204returnSymbolRef::ST_Data;
205
206returnSymbolRef::ST_Other;
207}
208
209Expected<uint32_t>COFFObjectFile::getSymbolFlags(DataRefImplRef) const{
210COFFSymbolRef Symb =getCOFFSymbol(Ref);
211uint32_t Result =SymbolRef::SF_None;
212
213if (Symb.isExternal() || Symb.isWeakExternal())
214 Result |=SymbolRef::SF_Global;
215
216if (constcoff_aux_weak_external *AWE = Symb.getWeakExternal()) {
217 Result |=SymbolRef::SF_Weak;
218if (AWE->Characteristics !=COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS)
219 Result |=SymbolRef::SF_Undefined;
220 }
221
222if (Symb.getSectionNumber() ==COFF::IMAGE_SYM_ABSOLUTE)
223 Result |=SymbolRef::SF_Absolute;
224
225if (Symb.isFileRecord())
226 Result |=SymbolRef::SF_FormatSpecific;
227
228if (Symb.isSectionDefinition())
229 Result |=SymbolRef::SF_FormatSpecific;
230
231if (Symb.isCommon())
232 Result |=SymbolRef::SF_Common;
233
234if (Symb.isUndefined())
235 Result |=SymbolRef::SF_Undefined;
236
237return Result;
238}
239
240uint64_tCOFFObjectFile::getCommonSymbolSizeImpl(DataRefImplRef) const{
241COFFSymbolRef Symb =getCOFFSymbol(Ref);
242return Symb.getValue();
243}
244
245Expected<section_iterator>
246COFFObjectFile::getSymbolSection(DataRefImplRef) const{
247COFFSymbolRef Symb =getCOFFSymbol(Ref);
248if (COFF::isReservedSectionNumber(Symb.getSectionNumber()))
249returnsection_end();
250Expected<const coff_section *> Sec =getSection(Symb.getSectionNumber());
251if (!Sec)
252return Sec.takeError();
253DataRefImpl Ret;
254 Ret.p =reinterpret_cast<uintptr_t>(*Sec);
255returnsection_iterator(SectionRef(Ret,this));
256}
257
258unsignedCOFFObjectFile::getSymbolSectionID(SymbolRefSym) const{
259COFFSymbolRef Symb =getCOFFSymbol(Sym.getRawDataRefImpl());
260return Symb.getSectionNumber();
261}
262
263voidCOFFObjectFile::moveSectionNext(DataRefImpl &Ref) const{
264constcoff_section *Sec = toSec(Ref);
265 Sec += 1;
266Ref.p =reinterpret_cast<uintptr_t>(Sec);
267}
268
269Expected<StringRef>COFFObjectFile::getSectionName(DataRefImplRef) const{
270constcoff_section *Sec = toSec(Ref);
271returngetSectionName(Sec);
272}
273
274uint64_tCOFFObjectFile::getSectionAddress(DataRefImplRef) const{
275constcoff_section *Sec = toSec(Ref);
276uint64_t Result = Sec->VirtualAddress;
277
278// The section VirtualAddress does not include ImageBase, and we want to
279// return virtual addresses.
280 Result +=getImageBase();
281return Result;
282}
283
284uint64_tCOFFObjectFile::getSectionIndex(DataRefImpl Sec) const{
285return toSec(Sec) - SectionTable;
286}
287
288uint64_tCOFFObjectFile::getSectionSize(DataRefImplRef) const{
289returngetSectionSize(toSec(Ref));
290}
291
292Expected<ArrayRef<uint8_t>>
293COFFObjectFile::getSectionContents(DataRefImplRef) const{
294constcoff_section *Sec = toSec(Ref);
295ArrayRef<uint8_t> Res;
296if (Error E =getSectionContents(Sec, Res))
297return E;
298return Res;
299}
300
301uint64_tCOFFObjectFile::getSectionAlignment(DataRefImplRef) const{
302constcoff_section *Sec = toSec(Ref);
303return Sec->getAlignment();
304}
305
306boolCOFFObjectFile::isSectionCompressed(DataRefImpl Sec) const{
307returnfalse;
308}
309
310boolCOFFObjectFile::isSectionText(DataRefImplRef) const{
311constcoff_section *Sec = toSec(Ref);
312return Sec->Characteristics &COFF::IMAGE_SCN_CNT_CODE;
313}
314
315boolCOFFObjectFile::isSectionData(DataRefImplRef) const{
316constcoff_section *Sec = toSec(Ref);
317return Sec->Characteristics &COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
318}
319
320boolCOFFObjectFile::isSectionBSS(DataRefImplRef) const{
321constcoff_section *Sec = toSec(Ref);
322constuint32_t BssFlags =COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
323COFF::IMAGE_SCN_MEM_READ |
324COFF::IMAGE_SCN_MEM_WRITE;
325return (Sec->Characteristics & BssFlags) == BssFlags;
326}
327
328// The .debug sections are the only debug sections for COFF
329// (\see MCObjectFileInfo.cpp).
330boolCOFFObjectFile::isDebugSection(DataRefImplRef) const{
331Expected<StringRef> SectionNameOrErr =getSectionName(Ref);
332if (!SectionNameOrErr) {
333// TODO: Report the error message properly.
334consumeError(SectionNameOrErr.takeError());
335returnfalse;
336 }
337StringRefSectionName = SectionNameOrErr.get();
338returnSectionName.starts_with(".debug");
339}
340
341unsignedCOFFObjectFile::getSectionID(SectionRef Sec) const{
342 uintptr_tOffset =
343 Sec.getRawDataRefImpl().p -reinterpret_cast<uintptr_t>(SectionTable);
344assert((Offset %sizeof(coff_section)) == 0);
345return (Offset /sizeof(coff_section)) + 1;
346}
347
348boolCOFFObjectFile::isSectionVirtual(DataRefImplRef) const{
349constcoff_section *Sec = toSec(Ref);
350// In COFF, a virtual section won't have any in-file
351// content, so the file pointer to the content will be zero.
352return Sec->PointerToRawData == 0;
353}
354
355staticuint32_tgetNumberOfRelocations(constcoff_section *Sec,
356MemoryBufferRef M,constuint8_t *base) {
357// The field for the number of relocations in COFF section table is only
358// 16-bit wide. If a section has more than 65535 relocations, 0xFFFF is set to
359// NumberOfRelocations field, and the actual relocation count is stored in the
360// VirtualAddress field in the first relocation entry.
361if (Sec->hasExtendedRelocations()) {
362constcoff_relocation *FirstReloc;
363if (Error E =getObject(FirstReloc, M,
364reinterpret_cast<constcoff_relocation *>(
365 base + Sec->PointerToRelocations))) {
366consumeError(std::move(E));
367return 0;
368 }
369// -1 to exclude this first relocation entry.
370return FirstReloc->VirtualAddress - 1;
371 }
372return Sec->NumberOfRelocations;
373}
374
375staticconstcoff_relocation *
376getFirstReloc(constcoff_section *Sec,MemoryBufferRef M,constuint8_t *Base) {
377uint64_t NumRelocs =getNumberOfRelocations(Sec, M,Base);
378if (!NumRelocs)
379returnnullptr;
380auto begin =reinterpret_cast<constcoff_relocation *>(
381Base + Sec->PointerToRelocations);
382if (Sec->hasExtendedRelocations()) {
383// Skip the first relocation entry repurposed to store the number of
384// relocations.
385 begin++;
386 }
387if (auto E =Binary::checkOffset(M,reinterpret_cast<uintptr_t>(begin),
388sizeof(coff_relocation) * NumRelocs)) {
389consumeError(std::move(E));
390returnnullptr;
391 }
392return begin;
393}
394
395relocation_iteratorCOFFObjectFile::section_rel_begin(DataRefImplRef) const{
396constcoff_section *Sec = toSec(Ref);
397constcoff_relocation *begin =getFirstReloc(Sec,Data,base());
398if (begin && Sec->VirtualAddress != 0)
399report_fatal_error("Sections with relocations should have an address of 0");
400DataRefImpl Ret;
401 Ret.p =reinterpret_cast<uintptr_t>(begin);
402returnrelocation_iterator(RelocationRef(Ret,this));
403}
404
405relocation_iteratorCOFFObjectFile::section_rel_end(DataRefImplRef) const{
406constcoff_section *Sec = toSec(Ref);
407constcoff_relocation *I =getFirstReloc(Sec,Data,base());
408if (I)
409I +=getNumberOfRelocations(Sec,Data,base());
410DataRefImpl Ret;
411 Ret.p =reinterpret_cast<uintptr_t>(I);
412returnrelocation_iterator(RelocationRef(Ret,this));
413}
414
415// Initialize the pointer to the symbol table.
416Error COFFObjectFile::initSymbolTablePtr() {
417if (COFFHeader)
418if (Error E =getObject(
419 SymbolTable16,Data,base() +getPointerToSymbolTable(),
420 (uint64_t)getNumberOfSymbols() *getSymbolTableEntrySize()))
421return E;
422
423if (COFFBigObjHeader)
424if (Error E =getObject(
425 SymbolTable32,Data,base() +getPointerToSymbolTable(),
426 (uint64_t)getNumberOfSymbols() *getSymbolTableEntrySize()))
427return E;
428
429// Find string table. The first four byte of the string table contains the
430// total size of the string table, including the size field itself. If the
431// string table is empty, the value of the first four byte would be 4.
432uint32_tStringTableOffset =getPointerToSymbolTable() +
433getNumberOfSymbols() *getSymbolTableEntrySize();
434constuint8_t *StringTableAddr =base() +StringTableOffset;
435const ulittle32_t *StringTableSizePtr;
436if (Error E =getObject(StringTableSizePtr,Data, StringTableAddr))
437return E;
438 StringTableSize = *StringTableSizePtr;
439if (Error E =getObject(StringTable,Data, StringTableAddr, StringTableSize))
440return E;
441
442// Treat table sizes < 4 as empty because contrary to the PECOFF spec, some
443// tools like cvtres write a size of 0 for an empty table instead of 4.
444if (StringTableSize < 4)
445 StringTableSize = 4;
446
447// Check that the string table is null terminated if has any in it.
448if (StringTableSize > 4 &&StringTable[StringTableSize - 1] != 0)
449returncreateStringError(object_error::parse_failed,
450"string table missing null terminator");
451returnError::success();
452}
453
454uint64_tCOFFObjectFile::getImageBase() const{
455if (PE32Header)
456return PE32Header->ImageBase;
457elseif (PE32PlusHeader)
458return PE32PlusHeader->ImageBase;
459// This actually comes up in practice.
460return 0;
461}
462
463// Returns the file offset for the given VA.
464ErrorCOFFObjectFile::getVaPtr(uint64_tAddr, uintptr_t &Res) const{
465uint64_t ImageBase =getImageBase();
466uint64_t Rva =Addr - ImageBase;
467assert(Rva <= UINT32_MAX);
468returngetRvaPtr((uint32_t)Rva, Res);
469}
470
471// Returns the file offset for the given RVA.
472ErrorCOFFObjectFile::getRvaPtr(uint32_tAddr, uintptr_t &Res,
473constchar *ErrorContext) const{
474for (constSectionRef &S :sections()) {
475constcoff_section *Section =getCOFFSection(S);
476uint32_t SectionStart = Section->VirtualAddress;
477uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
478if (SectionStart <=Addr &&Addr < SectionEnd) {
479// A table/directory entry can be pointing to somewhere in a stripped
480// section, in an object that went through `objcopy --only-keep-debug`.
481// In this case we don't want to cause the parsing of the object file to
482// fail, otherwise it will be impossible to use this object as debug info
483// in LLDB. Return SectionStrippedError here so that
484// COFFObjectFile::initialize can ignore the error.
485// Somewhat common binaries may have RVAs pointing outside of the
486// provided raw data. Instead of rejecting the binaries, just
487// treat the section as stripped for these purposes.
488if (Section->SizeOfRawData < Section->VirtualSize &&
489Addr >= SectionStart + Section->SizeOfRawData) {
490return make_error<SectionStrippedError>();
491 }
492uint32_tOffset =Addr - SectionStart;
493 Res =reinterpret_cast<uintptr_t>(base()) + Section->PointerToRawData +
494Offset;
495returnError::success();
496 }
497 }
498if (ErrorContext)
499returncreateStringError(object_error::parse_failed,
500"RVA 0x%" PRIx32" for %s not found",Addr,
501 ErrorContext);
502returncreateStringError(object_error::parse_failed,
503"RVA 0x%" PRIx32" not found",Addr);
504}
505
506ErrorCOFFObjectFile::getRvaAndSizeAsBytes(uint32_t RVA,uint32_tSize,
507ArrayRef<uint8_t> &Contents,
508constchar *ErrorContext) const{
509for (constSectionRef &S :sections()) {
510constcoff_section *Section =getCOFFSection(S);
511uint32_t SectionStart = Section->VirtualAddress;
512// Check if this RVA is within the section bounds. Be careful about integer
513// overflow.
514uint32_t OffsetIntoSection = RVA - SectionStart;
515if (SectionStart <= RVA && OffsetIntoSection < Section->VirtualSize &&
516 Size <= Section->VirtualSize - OffsetIntoSection) {
517 uintptr_t Begin =reinterpret_cast<uintptr_t>(base()) +
518 Section->PointerToRawData + OffsetIntoSection;
519 Contents =
520ArrayRef<uint8_t>(reinterpret_cast<constuint8_t *>(Begin),Size);
521returnError::success();
522 }
523 }
524if (ErrorContext)
525returncreateStringError(object_error::parse_failed,
526"RVA 0x%" PRIx32" for %s not found", RVA,
527 ErrorContext);
528returncreateStringError(object_error::parse_failed,
529"RVA 0x%" PRIx32" not found", RVA);
530}
531
532// Returns hint and name fields, assuming \p Rva is pointing to a Hint/Name
533// table entry.
534ErrorCOFFObjectFile::getHintName(uint32_t Rva,uint16_t &Hint,
535StringRef &Name) const{
536 uintptr_t IntPtr = 0;
537if (Error E =getRvaPtr(Rva, IntPtr))
538return E;
539constuint8_t *Ptr =reinterpret_cast<constuint8_t *>(IntPtr);
540 Hint = *reinterpret_cast<constulittle16_t *>(Ptr);
541Name =StringRef(reinterpret_cast<constchar *>(Ptr + 2));
542returnError::success();
543}
544
545ErrorCOFFObjectFile::getDebugPDBInfo(constdebug_directory *DebugDir,
546constcodeview::DebugInfo *&PDBInfo,
547StringRef &PDBFileName) const{
548ArrayRef<uint8_t> InfoBytes;
549if (Error E =
550getRvaAndSizeAsBytes(DebugDir->AddressOfRawData, DebugDir->SizeOfData,
551 InfoBytes,"PDB info"))
552return E;
553if (InfoBytes.size() <sizeof(*PDBInfo) + 1)
554returncreateStringError(object_error::parse_failed,"PDB info too small");
555 PDBInfo =reinterpret_cast<constcodeview::DebugInfo *>(InfoBytes.data());
556 InfoBytes = InfoBytes.drop_front(sizeof(*PDBInfo));
557 PDBFileName =StringRef(reinterpret_cast<constchar *>(InfoBytes.data()),
558 InfoBytes.size());
559// Truncate the name at the first null byte. Ignore any padding.
560 PDBFileName = PDBFileName.split('\0').first;
561returnError::success();
562}
563
564ErrorCOFFObjectFile::getDebugPDBInfo(constcodeview::DebugInfo *&PDBInfo,
565StringRef &PDBFileName) const{
566for (constdebug_directory &D :debug_directories())
567if (D.Type ==COFF::IMAGE_DEBUG_TYPE_CODEVIEW)
568returngetDebugPDBInfo(&D, PDBInfo, PDBFileName);
569// If we get here, there is no PDB info to return.
570 PDBInfo =nullptr;
571 PDBFileName =StringRef();
572returnError::success();
573}
574
575// Find the import table.
576Error COFFObjectFile::initImportTablePtr() {
577// First, we get the RVA of the import table. If the file lacks a pointer to
578// the import table, do nothing.
579constdata_directory *DataEntry =getDataDirectory(COFF::IMPORT_TABLE);
580if (!DataEntry)
581returnError::success();
582
583// Do nothing if the pointer to import table is NULL.
584if (DataEntry->RelativeVirtualAddress == 0)
585returnError::success();
586
587uint32_t ImportTableRva = DataEntry->RelativeVirtualAddress;
588
589// Find the section that contains the RVA. This is needed because the RVA is
590// the import table's memory address which is different from its file offset.
591 uintptr_t IntPtr = 0;
592if (Error E =getRvaPtr(ImportTableRva, IntPtr,"import table"))
593return E;
594if (Error E =checkOffset(Data, IntPtr, DataEntry->Size))
595return E;
596 ImportDirectory =reinterpret_cast<
597constcoff_import_directory_table_entry *>(IntPtr);
598returnError::success();
599}
600
601// Initializes DelayImportDirectory and NumberOfDelayImportDirectory.
602Error COFFObjectFile::initDelayImportTablePtr() {
603constdata_directory *DataEntry =
604getDataDirectory(COFF::DELAY_IMPORT_DESCRIPTOR);
605if (!DataEntry)
606returnError::success();
607if (DataEntry->RelativeVirtualAddress == 0)
608returnError::success();
609
610uint32_t RVA = DataEntry->RelativeVirtualAddress;
611 NumberOfDelayImportDirectory = DataEntry->Size /
612sizeof(delay_import_directory_table_entry) - 1;
613
614 uintptr_t IntPtr = 0;
615if (Error E =getRvaPtr(RVA, IntPtr,"delay import table"))
616return E;
617if (Error E =checkOffset(Data, IntPtr, DataEntry->Size))
618return E;
619
620 DelayImportDirectory =reinterpret_cast<
621constdelay_import_directory_table_entry *>(IntPtr);
622returnError::success();
623}
624
625// Find the export table.
626Error COFFObjectFile::initExportTablePtr() {
627// First, we get the RVA of the export table. If the file lacks a pointer to
628// the export table, do nothing.
629constdata_directory *DataEntry =getDataDirectory(COFF::EXPORT_TABLE);
630if (!DataEntry)
631returnError::success();
632
633// Do nothing if the pointer to export table is NULL.
634if (DataEntry->RelativeVirtualAddress == 0)
635returnError::success();
636
637uint32_t ExportTableRva = DataEntry->RelativeVirtualAddress;
638 uintptr_t IntPtr = 0;
639if (Error E =getRvaPtr(ExportTableRva, IntPtr,"export table"))
640return E;
641if (Error E =checkOffset(Data, IntPtr, DataEntry->Size))
642return E;
643
644 ExportDirectory =
645reinterpret_cast<constexport_directory_table_entry *>(IntPtr);
646returnError::success();
647}
648
649Error COFFObjectFile::initBaseRelocPtr() {
650constdata_directory *DataEntry =
651getDataDirectory(COFF::BASE_RELOCATION_TABLE);
652if (!DataEntry)
653returnError::success();
654if (DataEntry->RelativeVirtualAddress == 0)
655returnError::success();
656
657 uintptr_t IntPtr = 0;
658if (Error E =getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr,
659"base reloc table"))
660return E;
661if (Error E =checkOffset(Data, IntPtr, DataEntry->Size))
662return E;
663
664 BaseRelocHeader =reinterpret_cast<constcoff_base_reloc_block_header *>(
665 IntPtr);
666 BaseRelocEnd =reinterpret_cast<coff_base_reloc_block_header *>(
667 IntPtr + DataEntry->Size);
668// FIXME: Verify the section containing BaseRelocHeader has at least
669// DataEntry->Size bytes after DataEntry->RelativeVirtualAddress.
670returnError::success();
671}
672
673Error COFFObjectFile::initDebugDirectoryPtr() {
674// Get the RVA of the debug directory. Do nothing if it does not exist.
675constdata_directory *DataEntry =getDataDirectory(COFF::DEBUG_DIRECTORY);
676if (!DataEntry)
677returnError::success();
678
679// Do nothing if the RVA is NULL.
680if (DataEntry->RelativeVirtualAddress == 0)
681returnError::success();
682
683// Check that the size is a multiple of the entry size.
684if (DataEntry->Size %sizeof(debug_directory) != 0)
685returncreateStringError(object_error::parse_failed,
686"debug directory has uneven size");
687
688 uintptr_t IntPtr = 0;
689if (Error E =getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr,
690"debug directory"))
691return E;
692if (Error E =checkOffset(Data, IntPtr, DataEntry->Size))
693return E;
694
695 DebugDirectoryBegin =reinterpret_cast<constdebug_directory *>(IntPtr);
696 DebugDirectoryEnd =reinterpret_cast<constdebug_directory *>(
697 IntPtr + DataEntry->Size);
698// FIXME: Verify the section containing DebugDirectoryBegin has at least
699// DataEntry->Size bytes after DataEntry->RelativeVirtualAddress.
700returnError::success();
701}
702
703Error COFFObjectFile::initTLSDirectoryPtr() {
704// Get the RVA of the TLS directory. Do nothing if it does not exist.
705constdata_directory *DataEntry =getDataDirectory(COFF::TLS_TABLE);
706if (!DataEntry)
707returnError::success();
708
709// Do nothing if the RVA is NULL.
710if (DataEntry->RelativeVirtualAddress == 0)
711returnError::success();
712
713uint64_t DirSize =
714is64() ?sizeof(coff_tls_directory64) :sizeof(coff_tls_directory32);
715
716// Check that the size is correct.
717if (DataEntry->Size != DirSize)
718returncreateStringError(
719object_error::parse_failed,
720"TLS Directory size (%u) is not the expected size (%" PRIu64").",
721static_cast<uint32_t>(DataEntry->Size), DirSize);
722
723 uintptr_t IntPtr = 0;
724if (Error E =
725getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr,"TLS directory"))
726return E;
727if (Error E =checkOffset(Data, IntPtr, DataEntry->Size))
728return E;
729
730if (is64())
731 TLSDirectory64 =reinterpret_cast<constcoff_tls_directory64 *>(IntPtr);
732else
733 TLSDirectory32 =reinterpret_cast<constcoff_tls_directory32 *>(IntPtr);
734
735returnError::success();
736}
737
738Error COFFObjectFile::initLoadConfigPtr() {
739// Get the RVA of the debug directory. Do nothing if it does not exist.
740constdata_directory *DataEntry =getDataDirectory(COFF::LOAD_CONFIG_TABLE);
741if (!DataEntry)
742returnError::success();
743
744// Do nothing if the RVA is NULL.
745if (DataEntry->RelativeVirtualAddress == 0)
746returnError::success();
747 uintptr_t IntPtr = 0;
748if (Error E =getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr,
749"load config table"))
750return E;
751if (Error E =checkOffset(Data, IntPtr, DataEntry->Size))
752return E;
753
754 LoadConfig = (constvoid *)IntPtr;
755
756if (is64()) {
757autoConfig =getLoadConfig64();
758if (Config->Size >=
759offsetof(coff_load_configuration64, CHPEMetadataPointer) +
760sizeof(Config->CHPEMetadataPointer) &&
761Config->CHPEMetadataPointer) {
762uint64_t ChpeOff =Config->CHPEMetadataPointer;
763if (Error E =
764getRvaPtr(ChpeOff -getImageBase(), IntPtr,"CHPE metadata"))
765return E;
766if (Error E =checkOffset(Data, IntPtr,sizeof(*CHPEMetadata)))
767return E;
768
769 CHPEMetadata =reinterpret_cast<constchpe_metadata *>(IntPtr);
770
771// Validate CHPE metadata
772if (CHPEMetadata->CodeMapCount) {
773if (Error E =getRvaPtr(CHPEMetadata->CodeMap, IntPtr,"CHPE code map"))
774return E;
775if (Error E =checkOffset(Data, IntPtr,
776 CHPEMetadata->CodeMapCount *
777sizeof(chpe_range_entry)))
778return E;
779 }
780
781if (CHPEMetadata->CodeRangesToEntryPointsCount) {
782if (Error E =getRvaPtr(CHPEMetadata->CodeRangesToEntryPoints, IntPtr,
783"CHPE entry point ranges"))
784return E;
785if (Error E =checkOffset(Data, IntPtr,
786 CHPEMetadata->CodeRangesToEntryPointsCount *
787sizeof(chpe_code_range_entry)))
788return E;
789 }
790
791if (CHPEMetadata->RedirectionMetadataCount) {
792if (Error E =getRvaPtr(CHPEMetadata->RedirectionMetadata, IntPtr,
793"CHPE redirection metadata"))
794return E;
795if (Error E =checkOffset(Data, IntPtr,
796 CHPEMetadata->RedirectionMetadataCount *
797sizeof(chpe_redirection_entry)))
798return E;
799 }
800 }
801
802if (Config->Size >=
803offsetof(coff_load_configuration64, DynamicValueRelocTableSection) +
804sizeof(Config->DynamicValueRelocTableSection))
805if (Error E = initDynamicRelocPtr(Config->DynamicValueRelocTableSection,
806Config->DynamicValueRelocTableOffset))
807return E;
808 }else {
809autoConfig =getLoadConfig32();
810if (Config->Size >=
811offsetof(coff_load_configuration32, DynamicValueRelocTableSection) +
812sizeof(Config->DynamicValueRelocTableSection)) {
813if (Error E = initDynamicRelocPtr(Config->DynamicValueRelocTableSection,
814Config->DynamicValueRelocTableOffset))
815return E;
816 }
817 }
818returnError::success();
819}
820
821Error COFFObjectFile::initDynamicRelocPtr(uint32_t SectionIndex,
822uint32_t SectionOffset) {
823Expected<const coff_section *>Section =getSection(SectionIndex);
824if (!Section)
825returnSection.takeError();
826if (!*Section)
827returnError::success();
828
829// Interpret and validate dynamic relocations.
830ArrayRef<uint8_t> Contents;
831if (Error E =getSectionContents(*Section, Contents))
832return E;
833
834 Contents = Contents.drop_front(SectionOffset);
835if (Contents.size() <sizeof(coff_dynamic_reloc_table))
836returncreateStringError(object_error::parse_failed,
837"Too large DynamicValueRelocTableOffset (" +
838Twine(SectionOffset) +")");
839
840 DynamicRelocTable =
841reinterpret_cast<constcoff_dynamic_reloc_table *>(Contents.data());
842
843if (DynamicRelocTable->Version != 1 && DynamicRelocTable->Version != 2)
844returncreateStringError(object_error::parse_failed,
845"Unsupported dynamic relocations table version (" +
846Twine(DynamicRelocTable->Version) +")");
847if (DynamicRelocTable->Size > Contents.size() -sizeof(*DynamicRelocTable))
848returncreateStringError(object_error::parse_failed,
849"Indvalid dynamic relocations directory size (" +
850Twine(DynamicRelocTable->Size) +")");
851
852for (auto DynReloc :dynamic_relocs()) {
853if (Error e = DynReloc.validate())
854returne;
855 }
856
857returnError::success();
858}
859
860Expected<std::unique_ptr<COFFObjectFile>>
861COFFObjectFile::create(MemoryBufferRef Object) {
862 std::unique_ptr<COFFObjectFile> Obj(newCOFFObjectFile(std::move(Object)));
863if (Error E = Obj->initialize())
864return E;
865return std::move(Obj);
866}
867
868COFFObjectFile::COFFObjectFile(MemoryBufferRef Object)
869 :ObjectFile(Binary::ID_COFF, Object), COFFHeader(nullptr),
870 COFFBigObjHeader(nullptr), PE32Header(nullptr), PE32PlusHeader(nullptr),
871 DataDirectory(nullptr), SectionTable(nullptr), SymbolTable16(nullptr),
872 SymbolTable32(nullptr),StringTable(nullptr), StringTableSize(0),
873 ImportDirectory(nullptr), DelayImportDirectory(nullptr),
874 NumberOfDelayImportDirectory(0), ExportDirectory(nullptr),
875 BaseRelocHeader(nullptr), BaseRelocEnd(nullptr),
876 DebugDirectoryBegin(nullptr), DebugDirectoryEnd(nullptr),
877 TLSDirectory32(nullptr), TLSDirectory64(nullptr) {}
878
879staticErrorignoreStrippedErrors(Error E) {
880if (E.isA<SectionStrippedError>()) {
881consumeError(std::move(E));
882returnError::success();
883 }
884return E;
885}
886
887Error COFFObjectFile::initialize() {
888// Check that we at least have enough room for a header.
889 std::error_codeEC;
890if (!checkSize(Data, EC,sizeof(coff_file_header)))
891returnerrorCodeToError(EC);
892
893// The current location in the file where we are looking at.
894uint64_t CurPtr = 0;
895
896// PE header is optional and is present only in executables. If it exists,
897// it is placed right after COFF header.
898bool HasPEHeader =false;
899
900// Check if this is a PE/COFF file.
901if (checkSize(Data, EC,sizeof(dos_header) +sizeof(COFF::PEMagic))) {
902// PE/COFF, seek through MS-DOS compatibility stub and 4-byte
903// PE signature to find 'normal' COFF header.
904constauto *DH =reinterpret_cast<constdos_header *>(base());
905if (DH->Magic[0] =='M' && DH->Magic[1] =='Z') {
906 CurPtr = DH->AddressOfNewExeHeader;
907// Check the PE magic bytes. ("PE\0\0")
908if (memcmp(base() + CurPtr,COFF::PEMagic,sizeof(COFF::PEMagic)) != 0) {
909returncreateStringError(object_error::parse_failed,
910"incorrect PE magic");
911 }
912 CurPtr +=sizeof(COFF::PEMagic);// Skip the PE magic bytes.
913 HasPEHeader =true;
914 }
915 }
916
917if (Error E =getObject(COFFHeader,Data,base() + CurPtr))
918return E;
919
920// It might be a bigobj file, let's check. Note that COFF bigobj and COFF
921// import libraries share a common prefix but bigobj is more restrictive.
922if (!HasPEHeader && COFFHeader->Machine ==COFF::IMAGE_FILE_MACHINE_UNKNOWN &&
923 COFFHeader->NumberOfSections ==uint16_t(0xffff) &&
924checkSize(Data, EC,sizeof(coff_bigobj_file_header))) {
925if (Error E =getObject(COFFBigObjHeader,Data,base() + CurPtr))
926return E;
927
928// Verify that we are dealing with bigobj.
929if (COFFBigObjHeader->Version >=COFF::BigObjHeader::MinBigObjectVersion &&
930 std::memcmp(COFFBigObjHeader->UUID,COFF::BigObjMagic,
931sizeof(COFF::BigObjMagic)) == 0) {
932 COFFHeader =nullptr;
933 CurPtr +=sizeof(coff_bigobj_file_header);
934 }else {
935// It's not a bigobj.
936 COFFBigObjHeader =nullptr;
937 }
938 }
939if (COFFHeader) {
940// The prior checkSize call may have failed. This isn't a hard error
941// because we were just trying to sniff out bigobj.
942EC = std::error_code();
943 CurPtr +=sizeof(coff_file_header);
944
945if (COFFHeader->isImportLibrary())
946returnerrorCodeToError(EC);
947 }
948
949if (HasPEHeader) {
950constpe32_header *Header;
951if (Error E =getObject(Header,Data,base() + CurPtr))
952return E;
953
954constuint8_t *DataDirAddr;
955uint64_t DataDirSize;
956if (Header->Magic ==COFF::PE32Header::PE32) {
957 PE32Header = Header;
958 DataDirAddr =base() + CurPtr +sizeof(pe32_header);
959 DataDirSize =sizeof(data_directory) * PE32Header->NumberOfRvaAndSize;
960 }elseif (Header->Magic ==COFF::PE32Header::PE32_PLUS) {
961 PE32PlusHeader =reinterpret_cast<constpe32plus_header *>(Header);
962 DataDirAddr =base() + CurPtr +sizeof(pe32plus_header);
963 DataDirSize =sizeof(data_directory) * PE32PlusHeader->NumberOfRvaAndSize;
964 }else {
965// It's neither PE32 nor PE32+.
966returncreateStringError(object_error::parse_failed,
967"incorrect PE magic");
968 }
969if (Error E =getObject(DataDirectory,Data, DataDirAddr, DataDirSize))
970return E;
971 }
972
973if (COFFHeader)
974 CurPtr += COFFHeader->SizeOfOptionalHeader;
975
976assert(COFFHeader || COFFBigObjHeader);
977
978if (Error E =
979getObject(SectionTable,Data,base() + CurPtr,
980 (uint64_t)getNumberOfSections() *sizeof(coff_section)))
981return E;
982
983// Initialize the pointer to the symbol table.
984if (getPointerToSymbolTable() != 0) {
985if (Error E = initSymbolTablePtr()) {
986// Recover from errors reading the symbol table.
987consumeError(std::move(E));
988 SymbolTable16 =nullptr;
989 SymbolTable32 =nullptr;
990StringTable =nullptr;
991 StringTableSize = 0;
992 }
993 }else {
994// We had better not have any symbols if we don't have a symbol table.
995if (getNumberOfSymbols() != 0) {
996returncreateStringError(object_error::parse_failed,
997"symbol table missing");
998 }
999 }
1000
1001// Initialize the pointer to the beginning of the import table.
1002if (Error E =ignoreStrippedErrors(initImportTablePtr()))
1003return E;
1004if (Error E =ignoreStrippedErrors(initDelayImportTablePtr()))
1005return E;
1006
1007// Initialize the pointer to the export table.
1008if (Error E =ignoreStrippedErrors(initExportTablePtr()))
1009return E;
1010
1011// Initialize the pointer to the base relocation table.
1012if (Error E =ignoreStrippedErrors(initBaseRelocPtr()))
1013return E;
1014
1015// Initialize the pointer to the debug directory.
1016if (Error E =ignoreStrippedErrors(initDebugDirectoryPtr()))
1017return E;
1018
1019// Initialize the pointer to the TLS directory.
1020if (Error E =ignoreStrippedErrors(initTLSDirectoryPtr()))
1021return E;
1022
1023if (Error E =ignoreStrippedErrors(initLoadConfigPtr()))
1024return E;
1025
1026returnError::success();
1027}
1028
1029basic_symbol_iteratorCOFFObjectFile::symbol_begin() const{
1030DataRefImpl Ret;
1031 Ret.p =getSymbolTable();
1032returnbasic_symbol_iterator(SymbolRef(Ret,this));
1033}
1034
1035basic_symbol_iteratorCOFFObjectFile::symbol_end() const{
1036// The symbol table ends where the string table begins.
1037DataRefImpl Ret;
1038 Ret.p =reinterpret_cast<uintptr_t>(StringTable);
1039returnbasic_symbol_iterator(SymbolRef(Ret,this));
1040}
1041
1042import_directory_iteratorCOFFObjectFile::import_directory_begin() const{
1043if (!ImportDirectory)
1044returnimport_directory_end();
1045if (ImportDirectory->isNull())
1046returnimport_directory_end();
1047returnimport_directory_iterator(
1048ImportDirectoryEntryRef(ImportDirectory, 0,this));
1049}
1050
1051import_directory_iteratorCOFFObjectFile::import_directory_end() const{
1052returnimport_directory_iterator(
1053ImportDirectoryEntryRef(nullptr, -1,this));
1054}
1055
1056delay_import_directory_iterator
1057COFFObjectFile::delay_import_directory_begin() const{
1058returndelay_import_directory_iterator(
1059DelayImportDirectoryEntryRef(DelayImportDirectory, 0,this));
1060}
1061
1062delay_import_directory_iterator
1063COFFObjectFile::delay_import_directory_end() const{
1064returndelay_import_directory_iterator(
1065DelayImportDirectoryEntryRef(
1066 DelayImportDirectory, NumberOfDelayImportDirectory,this));
1067}
1068
1069export_directory_iteratorCOFFObjectFile::export_directory_begin() const{
1070returnexport_directory_iterator(
1071ExportDirectoryEntryRef(ExportDirectory, 0,this));
1072}
1073
1074export_directory_iteratorCOFFObjectFile::export_directory_end() const{
1075if (!ExportDirectory)
1076returnexport_directory_iterator(ExportDirectoryEntryRef(nullptr, 0,this));
1077ExportDirectoryEntryRefRef(ExportDirectory,
1078 ExportDirectory->AddressTableEntries,this);
1079returnexport_directory_iterator(Ref);
1080}
1081
1082section_iteratorCOFFObjectFile::section_begin() const{
1083DataRefImpl Ret;
1084 Ret.p =reinterpret_cast<uintptr_t>(SectionTable);
1085returnsection_iterator(SectionRef(Ret,this));
1086}
1087
1088section_iteratorCOFFObjectFile::section_end() const{
1089DataRefImpl Ret;
1090int NumSections =
1091 COFFHeader && COFFHeader->isImportLibrary() ? 0 :getNumberOfSections();
1092 Ret.p =reinterpret_cast<uintptr_t>(SectionTable + NumSections);
1093returnsection_iterator(SectionRef(Ret,this));
1094}
1095
1096base_reloc_iteratorCOFFObjectFile::base_reloc_begin() const{
1097returnbase_reloc_iterator(BaseRelocRef(BaseRelocHeader,this));
1098}
1099
1100base_reloc_iteratorCOFFObjectFile::base_reloc_end() const{
1101returnbase_reloc_iterator(BaseRelocRef(BaseRelocEnd,this));
1102}
1103
1104dynamic_reloc_iteratorCOFFObjectFile::dynamic_reloc_begin() const{
1105constvoid *Header = DynamicRelocTable ? DynamicRelocTable + 1 :nullptr;
1106returndynamic_reloc_iterator(DynamicRelocRef(Header,this));
1107}
1108
1109dynamic_reloc_iteratorCOFFObjectFile::dynamic_reloc_end() const{
1110constvoid *Header =nullptr;
1111if (DynamicRelocTable)
1112 Header =reinterpret_cast<constuint8_t *>(DynamicRelocTable + 1) +
1113 DynamicRelocTable->Size;
1114returndynamic_reloc_iterator(DynamicRelocRef(Header,this));
1115}
1116
1117uint8_tCOFFObjectFile::getBytesInAddress() const{
1118returngetArch() ==Triple::x86_64 ||getArch() ==Triple::aarch64 ? 8 : 4;
1119}
1120
1121StringRefCOFFObjectFile::getFileFormatName() const{
1122switch(getMachine()) {
1123caseCOFF::IMAGE_FILE_MACHINE_I386:
1124return"COFF-i386";
1125caseCOFF::IMAGE_FILE_MACHINE_AMD64:
1126return"COFF-x86-64";
1127caseCOFF::IMAGE_FILE_MACHINE_ARMNT:
1128return"COFF-ARM";
1129caseCOFF::IMAGE_FILE_MACHINE_ARM64:
1130return"COFF-ARM64";
1131caseCOFF::IMAGE_FILE_MACHINE_ARM64EC:
1132return"COFF-ARM64EC";
1133caseCOFF::IMAGE_FILE_MACHINE_ARM64X:
1134return"COFF-ARM64X";
1135caseCOFF::IMAGE_FILE_MACHINE_R4000:
1136return"COFF-MIPS";
1137default:
1138return"COFF-<unknown arch>";
1139 }
1140}
1141
1142Triple::ArchTypeCOFFObjectFile::getArch() const{
1143returngetMachineArchType(getMachine());
1144}
1145
1146Expected<uint64_t>COFFObjectFile::getStartAddress() const{
1147if (PE32Header)
1148return PE32Header->AddressOfEntryPoint;
1149return 0;
1150}
1151
1152iterator_range<import_directory_iterator>
1153COFFObjectFile::import_directories() const{
1154returnmake_range(import_directory_begin(),import_directory_end());
1155}
1156
1157iterator_range<delay_import_directory_iterator>
1158COFFObjectFile::delay_import_directories() const{
1159returnmake_range(delay_import_directory_begin(),
1160delay_import_directory_end());
1161}
1162
1163iterator_range<export_directory_iterator>
1164COFFObjectFile::export_directories() const{
1165returnmake_range(export_directory_begin(),export_directory_end());
1166}
1167
1168iterator_range<base_reloc_iterator>COFFObjectFile::base_relocs() const{
1169returnmake_range(base_reloc_begin(),base_reloc_end());
1170}
1171
1172iterator_range<dynamic_reloc_iterator>COFFObjectFile::dynamic_relocs() const{
1173returnmake_range(dynamic_reloc_begin(),dynamic_reloc_end());
1174}
1175
1176constdata_directory *COFFObjectFile::getDataDirectory(uint32_t Index) const{
1177if (!DataDirectory)
1178returnnullptr;
1179assert(PE32Header || PE32PlusHeader);
1180uint32_t NumEnt = PE32Header ? PE32Header->NumberOfRvaAndSize
1181 : PE32PlusHeader->NumberOfRvaAndSize;
1182if (Index >= NumEnt)
1183returnnullptr;
1184return &DataDirectory[Index];
1185}
1186
1187Expected<const coff_section *>COFFObjectFile::getSection(int32_t Index) const{
1188// Perhaps getting the section of a reserved section index should be an error,
1189// but callers rely on this to return null.
1190if (COFF::isReservedSectionNumber(Index))
1191return (constcoff_section *)nullptr;
1192if (static_cast<uint32_t>(Index) <=getNumberOfSections()) {
1193// We already verified the section table data, so no need to check again.
1194return SectionTable + (Index - 1);
1195 }
1196returncreateStringError(object_error::parse_failed,
1197"section index out of bounds");
1198}
1199
1200Expected<StringRef> COFFObjectFile::getString(uint32_tOffset) const{
1201if (StringTableSize <= 4)
1202// Tried to get a string from an empty string table.
1203returncreateStringError(object_error::parse_failed,"string table empty");
1204if (Offset >= StringTableSize)
1205returnerrorCodeToError(object_error::unexpected_eof);
1206returnStringRef(StringTable +Offset);
1207}
1208
1209Expected<StringRef>COFFObjectFile::getSymbolName(COFFSymbolRef Symbol) const{
1210returngetSymbolName(Symbol.getGeneric());
1211}
1212
1213Expected<StringRef>
1214COFFObjectFile::getSymbolName(constcoff_symbol_generic *Symbol) const{
1215// Check for string table entry. First 4 bytes are 0.
1216if (Symbol->Name.Offset.Zeroes == 0)
1217return getString(Symbol->Name.Offset.Offset);
1218
1219// Null terminated, let ::strlen figure out the length.
1220if (Symbol->Name.ShortName[COFF::NameSize - 1] == 0)
1221returnStringRef(Symbol->Name.ShortName);
1222
1223// Not null terminated, use all 8 bytes.
1224returnStringRef(Symbol->Name.ShortName,COFF::NameSize);
1225}
1226
1227ArrayRef<uint8_t>
1228COFFObjectFile::getSymbolAuxData(COFFSymbolRef Symbol) const{
1229constuint8_t *Aux =nullptr;
1230
1231size_t SymbolSize =getSymbolTableEntrySize();
1232if (Symbol.getNumberOfAuxSymbols() > 0) {
1233// AUX data comes immediately after the symbol in COFF
1234 Aux =reinterpret_cast<constuint8_t *>(Symbol.getRawPtr()) + SymbolSize;
1235#ifndef NDEBUG
1236// Verify that the Aux symbol points to a valid entry in the symbol table.
1237 uintptr_tOffset = uintptr_t(Aux) - uintptr_t(base());
1238if (Offset <getPointerToSymbolTable() ||
1239Offset >=
1240getPointerToSymbolTable() + (getNumberOfSymbols() * SymbolSize))
1241report_fatal_error("Aux Symbol data was outside of symbol table.");
1242
1243assert((Offset -getPointerToSymbolTable()) % SymbolSize == 0 &&
1244"Aux Symbol data did not point to the beginning of a symbol");
1245#endif
1246 }
1247returnArrayRef(Aux, Symbol.getNumberOfAuxSymbols() * SymbolSize);
1248}
1249
1250uint32_tCOFFObjectFile::getSymbolIndex(COFFSymbolRef Symbol) const{
1251 uintptr_tOffset =
1252reinterpret_cast<uintptr_t>(Symbol.getRawPtr()) -getSymbolTable();
1253assert(Offset %getSymbolTableEntrySize() == 0 &&
1254"Symbol did not point to the beginning of a symbol");
1255size_t Index =Offset /getSymbolTableEntrySize();
1256assert(Index <getNumberOfSymbols());
1257return Index;
1258}
1259
1260Expected<StringRef>
1261COFFObjectFile::getSectionName(constcoff_section *Sec) const{
1262StringRefName =StringRef(Sec->Name,COFF::NameSize).split('\0').first;
1263
1264// Check for string table entry. First byte is '/'.
1265if (Name.starts_with("/")) {
1266uint32_tOffset;
1267if (Name.starts_with("//")) {
1268if (decodeBase64StringEntry(Name.substr(2),Offset))
1269returncreateStringError(object_error::parse_failed,
1270"invalid section name");
1271 }else {
1272if (Name.substr(1).getAsInteger(10,Offset))
1273returncreateStringError(object_error::parse_failed,
1274"invalid section name");
1275 }
1276return getString(Offset);
1277 }
1278
1279returnName;
1280}
1281
1282uint64_tCOFFObjectFile::getSectionSize(constcoff_section *Sec) const{
1283// SizeOfRawData and VirtualSize change what they represent depending on
1284// whether or not we have an executable image.
1285//
1286// For object files, SizeOfRawData contains the size of section's data;
1287// VirtualSize should be zero but isn't due to buggy COFF writers.
1288//
1289// For executables, SizeOfRawData *must* be a multiple of FileAlignment; the
1290// actual section size is in VirtualSize. It is possible for VirtualSize to
1291// be greater than SizeOfRawData; the contents past that point should be
1292// considered to be zero.
1293if (getDOSHeader())
1294return std::min(Sec->VirtualSize, Sec->SizeOfRawData);
1295return Sec->SizeOfRawData;
1296}
1297
1298ErrorCOFFObjectFile::getSectionContents(constcoff_section *Sec,
1299ArrayRef<uint8_t> &Res) const{
1300// In COFF, a virtual section won't have any in-file
1301// content, so the file pointer to the content will be zero.
1302if (Sec->PointerToRawData == 0)
1303returnError::success();
1304// The only thing that we need to verify is that the contents is contained
1305// within the file bounds. We don't need to make sure it doesn't cover other
1306// data, as there's nothing that says that is not allowed.
1307 uintptr_t ConStart =
1308reinterpret_cast<uintptr_t>(base()) + Sec->PointerToRawData;
1309uint32_t SectionSize =getSectionSize(Sec);
1310if (Error E =checkOffset(Data, ConStart, SectionSize))
1311return E;
1312 Res =ArrayRef(reinterpret_cast<constuint8_t *>(ConStart), SectionSize);
1313returnError::success();
1314}
1315
1316constcoff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const{
1317returnreinterpret_cast<constcoff_relocation*>(Rel.p);
1318}
1319
1320voidCOFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const{
1321 Rel.p =reinterpret_cast<uintptr_t>(
1322reinterpret_cast<constcoff_relocation*>(Rel.p) + 1);
1323}
1324
1325uint64_tCOFFObjectFile::getRelocationOffset(DataRefImpl Rel) const{
1326constcoff_relocation *R = toRel(Rel);
1327return R->VirtualAddress;
1328}
1329
1330symbol_iteratorCOFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const{
1331constcoff_relocation *R = toRel(Rel);
1332DataRefImplRef;
1333if (R->SymbolTableIndex >=getNumberOfSymbols())
1334returnsymbol_end();
1335if (SymbolTable16)
1336Ref.p =reinterpret_cast<uintptr_t>(SymbolTable16 + R->SymbolTableIndex);
1337elseif (SymbolTable32)
1338Ref.p =reinterpret_cast<uintptr_t>(SymbolTable32 + R->SymbolTableIndex);
1339else
1340llvm_unreachable("no symbol table pointer!");
1341returnsymbol_iterator(SymbolRef(Ref,this));
1342}
1343
1344uint64_tCOFFObjectFile::getRelocationType(DataRefImpl Rel) const{
1345constcoff_relocation* R = toRel(Rel);
1346return R->Type;
1347}
1348
1349constcoff_section *
1350COFFObjectFile::getCOFFSection(constSectionRef &Section) const{
1351return toSec(Section.getRawDataRefImpl());
1352}
1353
1354COFFSymbolRefCOFFObjectFile::getCOFFSymbol(constDataRefImpl &Ref) const{
1355if (SymbolTable16)
1356return toSymb<coff_symbol16>(Ref);
1357if (SymbolTable32)
1358return toSymb<coff_symbol32>(Ref);
1359llvm_unreachable("no symbol table pointer!");
1360}
1361
1362COFFSymbolRefCOFFObjectFile::getCOFFSymbol(constSymbolRef &Symbol) const{
1363returngetCOFFSymbol(Symbol.getRawDataRefImpl());
1364}
1365
1366constcoff_relocation *
1367COFFObjectFile::getCOFFRelocation(constRelocationRef &Reloc) const{
1368return toRel(Reloc.getRawDataRefImpl());
1369}
1370
1371ArrayRef<coff_relocation>
1372COFFObjectFile::getRelocations(constcoff_section *Sec) const{
1373return {getFirstReloc(Sec,Data,base()),
1374getNumberOfRelocations(Sec,Data,base())};
1375}
1376
1377#define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(reloc_type) \
1378 case COFF::reloc_type: \
1379 return #reloc_type;
1380
1381StringRefCOFFObjectFile::getRelocationTypeName(uint16_tType) const{
1382switch (getArch()) {
1383caseTriple::x86_64:
1384switch (Type) {
1385LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ABSOLUTE);
1386LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR64);
1387LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR32);
1388LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR32NB);
1389LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32);
1390LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_1);
1391LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_2);
1392LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_3);
1393LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_4);
1394LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_5);
1395LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECTION);
1396LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECREL);
1397LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECREL7);
1398LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_TOKEN);
1399LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SREL32);
1400LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_PAIR);
1401LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SSPAN32);
1402default:
1403return"Unknown";
1404 }
1405break;
1406caseTriple::thumb:
1407switch (Type) {
1408LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_ABSOLUTE);
1409LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_ADDR32);
1410LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_ADDR32NB);
1411LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_BRANCH24);
1412LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_BRANCH11);
1413LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_TOKEN);
1414LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_BLX24);
1415LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_BLX11);
1416LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_REL32);
1417LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_SECTION);
1418LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_SECREL);
1419LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_MOV32A);
1420LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_MOV32T);
1421LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_BRANCH20T);
1422LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_BRANCH24T);
1423LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_BLX23T);
1424LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM_PAIR);
1425default:
1426return"Unknown";
1427 }
1428break;
1429caseTriple::aarch64:
1430switch (Type) {
1431LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_ABSOLUTE);
1432LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_ADDR32);
1433LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_ADDR32NB);
1434LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_BRANCH26);
1435LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_PAGEBASE_REL21);
1436LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_REL21);
1437LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_PAGEOFFSET_12A);
1438LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_PAGEOFFSET_12L);
1439LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_SECREL);
1440LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_SECREL_LOW12A);
1441LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_SECREL_HIGH12A);
1442LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_SECREL_LOW12L);
1443LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_TOKEN);
1444LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_SECTION);
1445LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_ADDR64);
1446LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_BRANCH19);
1447LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_BRANCH14);
1448LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_ARM64_REL32);
1449default:
1450return"Unknown";
1451 }
1452break;
1453caseTriple::x86:
1454switch (Type) {
1455LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_ABSOLUTE);
1456LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR16);
1457LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_REL16);
1458LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR32);
1459LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR32NB);
1460LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SEG12);
1461LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECTION);
1462LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECREL);
1463LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_TOKEN);
1464LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECREL7);
1465LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_REL32);
1466default:
1467return"Unknown";
1468 }
1469break;
1470caseTriple::mipsel:
1471switch (Type) {
1472LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_ABSOLUTE);
1473LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFHALF);
1474LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFWORD);
1475LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_JMPADDR);
1476LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFHI);
1477LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFLO);
1478LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_GPREL);
1479LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_LITERAL);
1480LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECTION);
1481LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECREL);
1482LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECRELLO);
1483LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_SECRELHI);
1484LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_JMPADDR16);
1485LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_REFWORDNB);
1486LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_MIPS_PAIR);
1487default:
1488return"Unknown";
1489 }
1490break;
1491default:
1492return"Unknown";
1493 }
1494}
1495
1496#undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
1497
1498voidCOFFObjectFile::getRelocationTypeName(
1499DataRefImpl Rel,SmallVectorImpl<char> &Result) const{
1500constcoff_relocation *Reloc = toRel(Rel);
1501StringRef Res =getRelocationTypeName(Reloc->Type);
1502 Result.append(Res.begin(), Res.end());
1503}
1504
1505boolCOFFObjectFile::isRelocatableObject() const{
1506return !DataDirectory;
1507}
1508
1509StringRefCOFFObjectFile::mapDebugSectionName(StringRefName) const{
1510returnStringSwitch<StringRef>(Name)
1511 .Case("eh_fram","eh_frame")
1512 .Default(Name);
1513}
1514
1515std::unique_ptr<MemoryBuffer>COFFObjectFile::getHybridObjectView() const{
1516if (getMachine() !=COFF::IMAGE_FILE_MACHINE_ARM64X)
1517returnnullptr;
1518
1519 std::unique_ptr<WritableMemoryBuffer> HybridView;
1520
1521for (auto DynReloc :dynamic_relocs()) {
1522if (DynReloc.getType() !=COFF::IMAGE_DYNAMIC_RELOCATION_ARM64X)
1523continue;
1524
1525for (auto reloc : DynReloc.arm64x_relocs()) {
1526if (!HybridView) {
1527 HybridView =
1528WritableMemoryBuffer::getNewUninitMemBuffer(Data.getBufferSize());
1529 memcpy(HybridView->getBufferStart(),Data.getBufferStart(),
1530Data.getBufferSize());
1531 }
1532
1533uint32_t RVA = reloc.getRVA();
1534void *Ptr;
1535 uintptr_t IntPtr;
1536if (RVA & ~0xfff) {
1537cantFail(getRvaPtr(RVA, IntPtr));
1538Ptr = HybridView->getBufferStart() + IntPtr -
1539reinterpret_cast<uintptr_t>(base());
1540 }else {
1541// PE header relocation.
1542Ptr = HybridView->getBufferStart() + RVA;
1543 }
1544
1545switch (reloc.getType()) {
1546caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_ZEROFILL:
1547 memset(Ptr, 0, reloc.getSize());
1548break;
1549caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE: {
1550autoValue =static_cast<ulittle64_t>(reloc.getValue());
1551 memcpy(Ptr, &Value, reloc.getSize());
1552break;
1553 }
1554caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_DELTA:
1555 *reinterpret_cast<ulittle32_t *>(Ptr) += reloc.getValue();
1556break;
1557 }
1558 }
1559 }
1560return HybridView;
1561}
1562
1563boolImportDirectoryEntryRef::
1564operator==(constImportDirectoryEntryRef &Other) const{
1565return ImportTable ==Other.ImportTable && Index ==Other.Index;
1566}
1567
1568voidImportDirectoryEntryRef::moveNext() {
1569 ++Index;
1570if (ImportTable[Index].isNull()) {
1571 Index = -1;
1572 ImportTable =nullptr;
1573 }
1574}
1575
1576ErrorImportDirectoryEntryRef::getImportTableEntry(
1577constcoff_import_directory_table_entry *&Result) const{
1578returngetObject(Result, OwningObject->Data, ImportTable + Index);
1579}
1580
1581staticimported_symbol_iterator
1582makeImportedSymbolIterator(constCOFFObjectFile *Object,
1583 uintptr_tPtr,int Index) {
1584if (Object->getBytesInAddress() == 4) {
1585auto *P =reinterpret_cast<constimport_lookup_table_entry32 *>(Ptr);
1586returnimported_symbol_iterator(ImportedSymbolRef(P, Index, Object));
1587 }
1588auto *P =reinterpret_cast<constimport_lookup_table_entry64 *>(Ptr);
1589returnimported_symbol_iterator(ImportedSymbolRef(P, Index, Object));
1590}
1591
1592staticimported_symbol_iterator
1593importedSymbolBegin(uint32_t RVA,constCOFFObjectFile *Object) {
1594 uintptr_t IntPtr = 0;
1595// FIXME: Handle errors.
1596cantFail(Object->getRvaPtr(RVA, IntPtr));
1597returnmakeImportedSymbolIterator(Object, IntPtr, 0);
1598}
1599
1600staticimported_symbol_iterator
1601importedSymbolEnd(uint32_t RVA,constCOFFObjectFile *Object) {
1602 uintptr_t IntPtr = 0;
1603// FIXME: Handle errors.
1604cantFail(Object->getRvaPtr(RVA, IntPtr));
1605// Forward the pointer to the last entry which is null.
1606int Index = 0;
1607if (Object->getBytesInAddress() == 4) {
1608auto *Entry =reinterpret_cast<ulittle32_t *>(IntPtr);
1609while (*Entry++)
1610 ++Index;
1611 }else {
1612auto *Entry =reinterpret_cast<ulittle64_t *>(IntPtr);
1613while (*Entry++)
1614 ++Index;
1615 }
1616returnmakeImportedSymbolIterator(Object, IntPtr, Index);
1617}
1618
1619imported_symbol_iterator
1620ImportDirectoryEntryRef::imported_symbol_begin() const{
1621returnimportedSymbolBegin(ImportTable[Index].ImportAddressTableRVA,
1622 OwningObject);
1623}
1624
1625imported_symbol_iterator
1626ImportDirectoryEntryRef::imported_symbol_end() const{
1627returnimportedSymbolEnd(ImportTable[Index].ImportAddressTableRVA,
1628 OwningObject);
1629}
1630
1631iterator_range<imported_symbol_iterator>
1632ImportDirectoryEntryRef::imported_symbols() const{
1633returnmake_range(imported_symbol_begin(),imported_symbol_end());
1634}
1635
1636imported_symbol_iteratorImportDirectoryEntryRef::lookup_table_begin() const{
1637returnimportedSymbolBegin(ImportTable[Index].ImportLookupTableRVA,
1638 OwningObject);
1639}
1640
1641imported_symbol_iteratorImportDirectoryEntryRef::lookup_table_end() const{
1642returnimportedSymbolEnd(ImportTable[Index].ImportLookupTableRVA,
1643 OwningObject);
1644}
1645
1646iterator_range<imported_symbol_iterator>
1647ImportDirectoryEntryRef::lookup_table_symbols() const{
1648returnmake_range(lookup_table_begin(),lookup_table_end());
1649}
1650
1651ErrorImportDirectoryEntryRef::getName(StringRef &Result) const{
1652 uintptr_t IntPtr = 0;
1653if (Error E = OwningObject->getRvaPtr(ImportTable[Index].NameRVA, IntPtr,
1654"import directory name"))
1655return E;
1656 Result =StringRef(reinterpret_cast<constchar *>(IntPtr));
1657returnError::success();
1658}
1659
1660Error
1661ImportDirectoryEntryRef::getImportLookupTableRVA(uint32_t &Result) const{
1662 Result = ImportTable[Index].ImportLookupTableRVA;
1663returnError::success();
1664}
1665
1666ErrorImportDirectoryEntryRef::getImportAddressTableRVA(
1667uint32_t &Result) const{
1668 Result = ImportTable[Index].ImportAddressTableRVA;
1669returnError::success();
1670}
1671
1672boolDelayImportDirectoryEntryRef::
1673operator==(constDelayImportDirectoryEntryRef &Other) const{
1674return Table ==Other.Table && Index ==Other.Index;
1675}
1676
1677voidDelayImportDirectoryEntryRef::moveNext() {
1678 ++Index;
1679}
1680
1681imported_symbol_iterator
1682DelayImportDirectoryEntryRef::imported_symbol_begin() const{
1683returnimportedSymbolBegin(Table[Index].DelayImportNameTable,
1684 OwningObject);
1685}
1686
1687imported_symbol_iterator
1688DelayImportDirectoryEntryRef::imported_symbol_end() const{
1689returnimportedSymbolEnd(Table[Index].DelayImportNameTable,
1690 OwningObject);
1691}
1692
1693iterator_range<imported_symbol_iterator>
1694DelayImportDirectoryEntryRef::imported_symbols() const{
1695returnmake_range(imported_symbol_begin(),imported_symbol_end());
1696}
1697
1698ErrorDelayImportDirectoryEntryRef::getName(StringRef &Result) const{
1699 uintptr_t IntPtr = 0;
1700if (Error E = OwningObject->getRvaPtr(Table[Index].Name, IntPtr,
1701"delay import directory name"))
1702return E;
1703 Result =StringRef(reinterpret_cast<constchar *>(IntPtr));
1704returnError::success();
1705}
1706
1707ErrorDelayImportDirectoryEntryRef::getDelayImportTable(
1708constdelay_import_directory_table_entry *&Result) const{
1709 Result = &Table[Index];
1710returnError::success();
1711}
1712
1713ErrorDelayImportDirectoryEntryRef::getImportAddress(int AddrIndex,
1714uint64_t &Result) const{
1715uint32_t RVA = Table[Index].DelayImportAddressTable +
1716 AddrIndex * (OwningObject->is64() ? 8 : 4);
1717 uintptr_t IntPtr = 0;
1718if (Error E = OwningObject->getRvaPtr(RVA, IntPtr,"import address"))
1719return E;
1720if (OwningObject->is64())
1721 Result = *reinterpret_cast<constulittle64_t *>(IntPtr);
1722else
1723 Result = *reinterpret_cast<constulittle32_t *>(IntPtr);
1724returnError::success();
1725}
1726
1727boolExportDirectoryEntryRef::
1728operator==(constExportDirectoryEntryRef &Other) const{
1729return ExportTable ==Other.ExportTable && Index ==Other.Index;
1730}
1731
1732voidExportDirectoryEntryRef::moveNext() {
1733 ++Index;
1734}
1735
1736// Returns the name of the current export symbol. If the symbol is exported only
1737// by ordinal, the empty string is set as a result.
1738ErrorExportDirectoryEntryRef::getDllName(StringRef &Result) const{
1739 uintptr_t IntPtr = 0;
1740if (Error E =
1741 OwningObject->getRvaPtr(ExportTable->NameRVA, IntPtr,"dll name"))
1742return E;
1743 Result =StringRef(reinterpret_cast<constchar *>(IntPtr));
1744returnError::success();
1745}
1746
1747// Returns the starting ordinal number.
1748ErrorExportDirectoryEntryRef::getOrdinalBase(uint32_t &Result) const{
1749 Result = ExportTable->OrdinalBase;
1750returnError::success();
1751}
1752
1753// Returns the export ordinal of the current export symbol.
1754ErrorExportDirectoryEntryRef::getOrdinal(uint32_t &Result) const{
1755 Result = ExportTable->OrdinalBase + Index;
1756returnError::success();
1757}
1758
1759// Returns the address of the current export symbol.
1760ErrorExportDirectoryEntryRef::getExportRVA(uint32_t &Result) const{
1761 uintptr_t IntPtr = 0;
1762if (Error EC = OwningObject->getRvaPtr(ExportTable->ExportAddressTableRVA,
1763 IntPtr,"export address"))
1764return EC;
1765constexport_address_table_entry *entry =
1766reinterpret_cast<constexport_address_table_entry *>(IntPtr);
1767 Result = entry[Index].ExportRVA;
1768returnError::success();
1769}
1770
1771// Returns the name of the current export symbol. If the symbol is exported only
1772// by ordinal, the empty string is set as a result.
1773Error
1774ExportDirectoryEntryRef::getSymbolName(StringRef &Result) const{
1775 uintptr_t IntPtr = 0;
1776if (Error EC = OwningObject->getRvaPtr(ExportTable->OrdinalTableRVA, IntPtr,
1777"export ordinal table"))
1778return EC;
1779const ulittle16_t *Start =reinterpret_cast<constulittle16_t *>(IntPtr);
1780
1781uint32_t NumEntries = ExportTable->NumberOfNamePointers;
1782intOffset = 0;
1783for (const ulittle16_t *I = Start, *E = Start + NumEntries;
1784I < E; ++I, ++Offset) {
1785if (*I != Index)
1786continue;
1787if (Error EC = OwningObject->getRvaPtr(ExportTable->NamePointerRVA, IntPtr,
1788"export table entry"))
1789return EC;
1790const ulittle32_t *NamePtr =reinterpret_cast<constulittle32_t *>(IntPtr);
1791if (Error EC = OwningObject->getRvaPtr(NamePtr[Offset], IntPtr,
1792"export symbol name"))
1793return EC;
1794 Result =StringRef(reinterpret_cast<constchar *>(IntPtr));
1795returnError::success();
1796 }
1797 Result ="";
1798returnError::success();
1799}
1800
1801ErrorExportDirectoryEntryRef::isForwarder(bool &Result) const{
1802constdata_directory *DataEntry =
1803 OwningObject->getDataDirectory(COFF::EXPORT_TABLE);
1804if (!DataEntry)
1805returncreateStringError(object_error::parse_failed,
1806"export table missing");
1807uint32_t RVA;
1808if (auto EC =getExportRVA(RVA))
1809return EC;
1810uint32_t Begin = DataEntry->RelativeVirtualAddress;
1811uint32_tEnd = DataEntry->RelativeVirtualAddress + DataEntry->Size;
1812 Result = (Begin <= RVA && RVA <End);
1813returnError::success();
1814}
1815
1816ErrorExportDirectoryEntryRef::getForwardTo(StringRef &Result) const{
1817uint32_t RVA;
1818if (auto EC =getExportRVA(RVA))
1819return EC;
1820 uintptr_t IntPtr = 0;
1821if (auto EC = OwningObject->getRvaPtr(RVA, IntPtr,"export forward target"))
1822return EC;
1823 Result =StringRef(reinterpret_cast<constchar *>(IntPtr));
1824returnError::success();
1825}
1826
1827boolImportedSymbolRef::
1828operator==(constImportedSymbolRef &Other) const{
1829return Entry32 ==Other.Entry32 && Entry64 ==Other.Entry64
1830 && Index ==Other.Index;
1831}
1832
1833voidImportedSymbolRef::moveNext() {
1834 ++Index;
1835}
1836
1837ErrorImportedSymbolRef::getSymbolName(StringRef &Result) const{
1838uint32_t RVA;
1839if (Entry32) {
1840// If a symbol is imported only by ordinal, it has no name.
1841if (Entry32[Index].isOrdinal())
1842returnError::success();
1843 RVA = Entry32[Index].getHintNameRVA();
1844 }else {
1845if (Entry64[Index].isOrdinal())
1846returnError::success();
1847 RVA = Entry64[Index].getHintNameRVA();
1848 }
1849 uintptr_t IntPtr = 0;
1850if (Error EC = OwningObject->getRvaPtr(RVA, IntPtr,"import symbol name"))
1851return EC;
1852// +2 because the first two bytes is hint.
1853 Result =StringRef(reinterpret_cast<constchar *>(IntPtr + 2));
1854returnError::success();
1855}
1856
1857ErrorImportedSymbolRef::isOrdinal(bool &Result) const{
1858if (Entry32)
1859 Result = Entry32[Index].isOrdinal();
1860else
1861 Result = Entry64[Index].isOrdinal();
1862returnError::success();
1863}
1864
1865ErrorImportedSymbolRef::getHintNameRVA(uint32_t &Result) const{
1866if (Entry32)
1867 Result = Entry32[Index].getHintNameRVA();
1868else
1869 Result = Entry64[Index].getHintNameRVA();
1870returnError::success();
1871}
1872
1873ErrorImportedSymbolRef::getOrdinal(uint16_t &Result) const{
1874uint32_t RVA;
1875if (Entry32) {
1876if (Entry32[Index].isOrdinal()) {
1877 Result = Entry32[Index].getOrdinal();
1878returnError::success();
1879 }
1880 RVA = Entry32[Index].getHintNameRVA();
1881 }else {
1882if (Entry64[Index].isOrdinal()) {
1883 Result = Entry64[Index].getOrdinal();
1884returnError::success();
1885 }
1886 RVA = Entry64[Index].getHintNameRVA();
1887 }
1888 uintptr_t IntPtr = 0;
1889if (Error EC = OwningObject->getRvaPtr(RVA, IntPtr,"import symbol ordinal"))
1890return EC;
1891 Result = *reinterpret_cast<constulittle16_t *>(IntPtr);
1892returnError::success();
1893}
1894
1895Expected<std::unique_ptr<COFFObjectFile>>
1896ObjectFile::createCOFFObjectFile(MemoryBufferRef Object) {
1897returnCOFFObjectFile::create(Object);
1898}
1899
1900boolBaseRelocRef::operator==(constBaseRelocRef &Other) const{
1901return Header ==Other.Header && Index ==Other.Index;
1902}
1903
1904voidBaseRelocRef::moveNext() {
1905// Header->BlockSize is the size of the current block, including the
1906// size of the header itself.
1907uint32_tSize =sizeof(*Header) +
1908sizeof(coff_base_reloc_block_entry) * (Index + 1);
1909if (Size == Header->BlockSize) {
1910// .reloc contains a list of base relocation blocks. Each block
1911// consists of the header followed by entries. The header contains
1912// how many entories will follow. When we reach the end of the
1913// current block, proceed to the next block.
1914 Header =reinterpret_cast<constcoff_base_reloc_block_header *>(
1915reinterpret_cast<constuint8_t *>(Header) +Size);
1916 Index = 0;
1917 }else {
1918 ++Index;
1919 }
1920}
1921
1922ErrorBaseRelocRef::getType(uint8_t &Type) const{
1923auto *Entry =reinterpret_cast<constcoff_base_reloc_block_entry *>(Header + 1);
1924Type = Entry[Index].getType();
1925returnError::success();
1926}
1927
1928ErrorBaseRelocRef::getRVA(uint32_t &Result) const{
1929auto *Entry =reinterpret_cast<constcoff_base_reloc_block_entry *>(Header + 1);
1930 Result = Header->PageRVA + Entry[Index].getOffset();
1931returnError::success();
1932}
1933
1934boolDynamicRelocRef::operator==(constDynamicRelocRef &Other) const{
1935return Header ==Other.Header;
1936}
1937
1938voidDynamicRelocRef::moveNext() {
1939switch (Obj->getDynamicRelocTable()->Version) {
1940case 1:
1941if (Obj->is64()) {
1942autoH =reinterpret_cast<constcoff_dynamic_relocation64 *>(Header);
1943 Header +=sizeof(*H) +H->BaseRelocSize;
1944 }else {
1945autoH =reinterpret_cast<constcoff_dynamic_relocation32 *>(Header);
1946 Header +=sizeof(*H) +H->BaseRelocSize;
1947 }
1948break;
1949case 2:
1950if (Obj->is64()) {
1951autoH =reinterpret_cast<constcoff_dynamic_relocation64_v2 *>(Header);
1952 Header +=H->HeaderSize +H->FixupInfoSize;
1953 }else {
1954autoH =reinterpret_cast<constcoff_dynamic_relocation32_v2 *>(Header);
1955 Header +=H->HeaderSize +H->FixupInfoSize;
1956 }
1957break;
1958 }
1959}
1960
1961uint32_tDynamicRelocRef::getType() const{
1962switch (Obj->getDynamicRelocTable()->Version) {
1963case 1:
1964if (Obj->is64()) {
1965autoH =reinterpret_cast<constcoff_dynamic_relocation64 *>(Header);
1966returnH->Symbol;
1967 }else {
1968autoH =reinterpret_cast<constcoff_dynamic_relocation32 *>(Header);
1969returnH->Symbol;
1970 }
1971break;
1972case 2:
1973if (Obj->is64()) {
1974autoH =reinterpret_cast<constcoff_dynamic_relocation64_v2 *>(Header);
1975returnH->Symbol;
1976 }else {
1977autoH =reinterpret_cast<constcoff_dynamic_relocation32_v2 *>(Header);
1978returnH->Symbol;
1979 }
1980break;
1981default:
1982llvm_unreachable("invalid version");
1983 }
1984}
1985
1986voidDynamicRelocRef::getContents(ArrayRef<uint8_t> &Ref) const{
1987switch (Obj->getDynamicRelocTable()->Version) {
1988case 1:
1989if (Obj->is64()) {
1990autoH =reinterpret_cast<constcoff_dynamic_relocation64 *>(Header);
1991Ref =ArrayRef(Header +sizeof(*H),H->BaseRelocSize);
1992 }else {
1993autoH =reinterpret_cast<constcoff_dynamic_relocation32 *>(Header);
1994Ref =ArrayRef(Header +sizeof(*H),H->BaseRelocSize);
1995 }
1996break;
1997case 2:
1998if (Obj->is64()) {
1999autoH =reinterpret_cast<constcoff_dynamic_relocation64_v2 *>(Header);
2000Ref =ArrayRef(Header +H->HeaderSize,H->FixupInfoSize);
2001 }else {
2002autoH =reinterpret_cast<constcoff_dynamic_relocation32_v2 *>(Header);
2003Ref =ArrayRef(Header +H->HeaderSize,H->FixupInfoSize);
2004 }
2005break;
2006 }
2007}
2008
2009Error DynamicRelocRef::validate() const{
2010constcoff_dynamic_reloc_table *Table = Obj->getDynamicRelocTable();
2011size_t ContentsSize =
2012reinterpret_cast<constuint8_t *>(Table + 1) + Table->Size - Header;
2013size_t HeaderSize;
2014if (Table->Version == 1)
2015 HeaderSize = Obj->is64() ?sizeof(coff_dynamic_relocation64)
2016 :sizeof(coff_dynamic_relocation32);
2017else
2018 HeaderSize = Obj->is64() ?sizeof(coff_dynamic_relocation64_v2)
2019 :sizeof(coff_dynamic_relocation32_v2);
2020if (HeaderSize > ContentsSize)
2021returncreateStringError(object_error::parse_failed,
2022"Unexpected end of dynamic relocations data");
2023
2024if (Table->Version == 2) {
2025size_tSize =
2026 Obj->is64()
2027 ?reinterpret_cast<constcoff_dynamic_relocation64_v2 *>(Header)
2028 ->HeaderSize
2029 :reinterpret_cast<constcoff_dynamic_relocation32_v2 *>(Header)
2030 ->HeaderSize;
2031if (Size < HeaderSize || Size > ContentsSize)
2032returncreateStringError(object_error::parse_failed,
2033"Invalid dynamic relocation header size (" +
2034Twine(Size) +")");
2035 HeaderSize =Size;
2036 }
2037
2038ArrayRef<uint8_t> Contents;
2039getContents(Contents);
2040if (Contents.size() > ContentsSize - HeaderSize)
2041returncreateStringError(object_error::parse_failed,
2042"Too large dynamic relocation size (" +
2043Twine(Contents.size()) +")");
2044
2045switch (getType()) {
2046caseCOFF::IMAGE_DYNAMIC_RELOCATION_ARM64X:
2047for (auto Reloc :arm64x_relocs()) {
2048if (Error E = Reloc.validate(Obj))
2049return E;
2050 }
2051break;
2052 }
2053
2054returnError::success();
2055}
2056
2057arm64x_reloc_iteratorDynamicRelocRef::arm64x_reloc_begin() const{
2058assert(getType() ==COFF::IMAGE_DYNAMIC_RELOCATION_ARM64X);
2059ArrayRef<uint8_t>Content;
2060getContents(Content);
2061auto Header =
2062reinterpret_cast<constcoff_base_reloc_block_header *>(Content.begin());
2063returnarm64x_reloc_iterator(Arm64XRelocRef(Header));
2064}
2065
2066arm64x_reloc_iteratorDynamicRelocRef::arm64x_reloc_end() const{
2067assert(getType() ==COFF::IMAGE_DYNAMIC_RELOCATION_ARM64X);
2068ArrayRef<uint8_t>Content;
2069getContents(Content);
2070auto Header =
2071reinterpret_cast<constcoff_base_reloc_block_header *>(Content.end());
2072returnarm64x_reloc_iterator(Arm64XRelocRef(Header, 0));
2073}
2074
2075iterator_range<arm64x_reloc_iterator>DynamicRelocRef::arm64x_relocs() const{
2076returnmake_range(arm64x_reloc_begin(),arm64x_reloc_end());
2077}
2078
2079boolArm64XRelocRef::operator==(constArm64XRelocRef &Other) const{
2080return Header ==Other.Header && Index ==Other.Index;
2081}
2082
2083uint8_t Arm64XRelocRef::getEntrySize() const{
2084switch (getType()) {
2085caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE:
2086return (1ull << getArg()) /sizeof(uint16_t) + 1;
2087caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_DELTA:
2088return 2;
2089default:
2090return 1;
2091 }
2092}
2093
2094voidArm64XRelocRef::moveNext() {
2095 Index += getEntrySize();
2096if (sizeof(*Header) + Index *sizeof(uint16_t) < Header->BlockSize &&
2097 !getReloc())
2098 ++Index;// Skip padding
2099if (sizeof(*Header) + Index *sizeof(uint16_t) == Header->BlockSize) {
2100// The end of the block, move to the next one.
2101 Header =
2102reinterpret_cast<constcoff_base_reloc_block_header *>(&getReloc());
2103 Index = 0;
2104 }
2105}
2106
2107uint8_tArm64XRelocRef::getSize() const{
2108switch (getType()) {
2109caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_ZEROFILL:
2110caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE:
2111return 1 << getArg();
2112caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_DELTA:
2113returnsizeof(uint32_t);
2114 }
2115llvm_unreachable("Unknown Arm64XFixupType enum");
2116}
2117
2118uint64_tArm64XRelocRef::getValue() const{
2119autoPtr =reinterpret_cast<constulittle16_t *>(Header + 1) + Index + 1;
2120
2121switch (getType()) {
2122caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE: {
2123 ulittle64_tValue(0);
2124 memcpy(&Value,Ptr,getSize());
2125returnValue;
2126 }
2127caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_DELTA: {
2128uint16_t arg = getArg();
2129int delta = *Ptr;
2130
2131if (arg & 1)
2132 delta = -delta;
2133 delta *= (arg & 2) ? 8 : 4;
2134return delta;
2135 }
2136default:
2137return 0;
2138 }
2139}
2140
2141Error Arm64XRelocRef::validate(constCOFFObjectFile *Obj) const{
2142if (!Index) {
2143constcoff_dynamic_reloc_table *Table = Obj->getDynamicRelocTable();
2144size_t ContentsSize =reinterpret_cast<constuint8_t *>(Table + 1) +
2145 Table->Size -
2146reinterpret_cast<constuint8_t *>(Header);
2147if (ContentsSize <sizeof(coff_base_reloc_block_header))
2148returncreateStringError(object_error::parse_failed,
2149"Unexpected end of ARM64X relocations data");
2150if (Header->BlockSize <=sizeof(*Header))
2151returncreateStringError(object_error::parse_failed,
2152"ARM64X relocations block size (" +
2153Twine(Header->BlockSize) +") is too small");
2154if (Header->BlockSize %sizeof(uint32_t))
2155returncreateStringError(object_error::parse_failed,
2156"Unaligned ARM64X relocations block size (" +
2157Twine(Header->BlockSize) +")");
2158if (Header->BlockSize > ContentsSize)
2159returncreateStringError(object_error::parse_failed,
2160"ARM64X relocations block size (" +
2161Twine(Header->BlockSize) +") is too large");
2162if (Header->PageRVA & 0xfff)
2163returncreateStringError(object_error::parse_failed,
2164"Unaligned ARM64X relocations page RVA (" +
2165Twine(Header->PageRVA) +")");
2166 }
2167
2168switch ((getReloc() >> 12) & 3) {
2169caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_ZEROFILL:
2170caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_DELTA:
2171break;
2172caseCOFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE:
2173if (!getArg())
2174returncreateStringError(object_error::parse_failed,
2175"Invalid ARM64X relocation value size (0)");
2176break;
2177default:
2178returncreateStringError(object_error::parse_failed,
2179"Invalid relocation type");
2180 }
2181
2182uint32_t RelocsSize =
2183 (Header->BlockSize -sizeof(*Header)) /sizeof(uint16_t);
2184uint16_t EntrySize = getEntrySize();
2185if (!getReloc() ||
2186 (Index + EntrySize + 1 < RelocsSize && !getReloc(EntrySize)))
2187returncreateStringError(object_error::parse_failed,
2188"Unexpected ARM64X relocations terminator");
2189if (Index + EntrySize > RelocsSize)
2190returncreateStringError(object_error::parse_failed,
2191"Unexpected end of ARM64X relocations");
2192if (getRVA() %getSize())
2193returncreateStringError(object_error::parse_failed,
2194"Unaligned ARM64X relocation RVA (" +
2195Twine(getRVA()) +")");
2196if (Header->PageRVA) {
2197 uintptr_t IntPtr;
2198return Obj->getRvaPtr(getRVA() +getSize(), IntPtr,"ARM64X reloc");
2199 }
2200returnError::success();
2201}
2202
2203#define RETURN_IF_ERROR(Expr) \
2204 do { \
2205 Error E = (Expr); \
2206 if (E) \
2207 return std::move(E); \
2208 } while (0)
2209
2210Expected<ArrayRef<UTF16>>
2211ResourceSectionRef::getDirStringAtOffset(uint32_tOffset) {
2212BinaryStreamReader Reader =BinaryStreamReader(BBS);
2213 Reader.setOffset(Offset);
2214uint16_tLength;
2215RETURN_IF_ERROR(Reader.readInteger(Length));
2216ArrayRef<UTF16> RawDirString;
2217RETURN_IF_ERROR(Reader.readArray(RawDirString,Length));
2218return RawDirString;
2219}
2220
2221Expected<ArrayRef<UTF16>>
2222ResourceSectionRef::getEntryNameString(constcoff_resource_dir_entry &Entry) {
2223return getDirStringAtOffset(Entry.Identifier.getNameOffset());
2224}
2225
2226Expected<const coff_resource_dir_table &>
2227ResourceSectionRef::getTableAtOffset(uint32_tOffset) {
2228constcoff_resource_dir_table *Table =nullptr;
2229
2230BinaryStreamReader Reader(BBS);
2231 Reader.setOffset(Offset);
2232RETURN_IF_ERROR(Reader.readObject(Table));
2233assert(Table !=nullptr);
2234return *Table;
2235}
2236
2237Expected<const coff_resource_dir_entry &>
2238ResourceSectionRef::getTableEntryAtOffset(uint32_tOffset) {
2239constcoff_resource_dir_entry *Entry =nullptr;
2240
2241BinaryStreamReader Reader(BBS);
2242 Reader.setOffset(Offset);
2243RETURN_IF_ERROR(Reader.readObject(Entry));
2244assert(Entry !=nullptr);
2245return *Entry;
2246}
2247
2248Expected<const coff_resource_data_entry &>
2249ResourceSectionRef::getDataEntryAtOffset(uint32_tOffset) {
2250constcoff_resource_data_entry *Entry =nullptr;
2251
2252BinaryStreamReader Reader(BBS);
2253 Reader.setOffset(Offset);
2254RETURN_IF_ERROR(Reader.readObject(Entry));
2255assert(Entry !=nullptr);
2256return *Entry;
2257}
2258
2259Expected<const coff_resource_dir_table &>
2260ResourceSectionRef::getEntrySubDir(constcoff_resource_dir_entry &Entry) {
2261assert(Entry.Offset.isSubDir());
2262return getTableAtOffset(Entry.Offset.value());
2263}
2264
2265Expected<const coff_resource_data_entry &>
2266ResourceSectionRef::getEntryData(constcoff_resource_dir_entry &Entry) {
2267assert(!Entry.Offset.isSubDir());
2268return getDataEntryAtOffset(Entry.Offset.value());
2269}
2270
2271Expected<const coff_resource_dir_table &>ResourceSectionRef::getBaseTable() {
2272return getTableAtOffset(0);
2273}
2274
2275Expected<const coff_resource_dir_entry &>
2276ResourceSectionRef::getTableEntry(constcoff_resource_dir_table &Table,
2277uint32_t Index) {
2278if (Index >= (uint32_t)(Table.NumberOfNameEntries + Table.NumberOfIDEntries))
2279returncreateStringError(object_error::parse_failed,"index out of range");
2280constuint8_t *TablePtr =reinterpret_cast<constuint8_t *>(&Table);
2281ptrdiff_t TableOffset = TablePtr - BBS.data().data();
2282return getTableEntryAtOffset(TableOffset +sizeof(Table) +
2283 Index *sizeof(coff_resource_dir_entry));
2284}
2285
2286ErrorResourceSectionRef::load(constCOFFObjectFile *O) {
2287for (constSectionRef &S : O->sections()) {
2288Expected<StringRef>Name = S.getName();
2289if (!Name)
2290returnName.takeError();
2291
2292if (*Name ==".rsrc" || *Name ==".rsrc$01")
2293returnload(O, S);
2294 }
2295returncreateStringError(object_error::parse_failed,
2296"no resource section found");
2297}
2298
2299ErrorResourceSectionRef::load(constCOFFObjectFile *O,constSectionRef &S) {
2300 Obj = O;
2301 Section = S;
2302Expected<StringRef> Contents = Section.getContents();
2303if (!Contents)
2304return Contents.takeError();
2305 BBS =BinaryByteStream(*Contents,llvm::endianness::little);
2306constcoff_section *COFFSect = Obj->getCOFFSection(Section);
2307ArrayRef<coff_relocation> OrigRelocs = Obj->getRelocations(COFFSect);
2308 Relocs.reserve(OrigRelocs.size());
2309for (constcoff_relocation &R : OrigRelocs)
2310 Relocs.push_back(&R);
2311llvm::sort(Relocs, [](constcoff_relocation *A,constcoff_relocation *B) {
2312returnA->VirtualAddress <B->VirtualAddress;
2313 });
2314returnError::success();
2315}
2316
2317Expected<StringRef>
2318ResourceSectionRef::getContents(constcoff_resource_data_entry &Entry) {
2319if (!Obj)
2320returncreateStringError(object_error::parse_failed,"no object provided");
2321
2322// Find a potential relocation at the DataRVA field (first member of
2323// the coff_resource_data_entry struct).
2324constuint8_t *EntryPtr =reinterpret_cast<constuint8_t *>(&Entry);
2325ptrdiff_t EntryOffset = EntryPtr - BBS.data().data();
2326coff_relocation RelocTarget{ulittle32_t(EntryOffset), ulittle32_t(0),
2327 ulittle16_t(0)};
2328auto RelocsForOffset =
2329 std::equal_range(Relocs.begin(), Relocs.end(), &RelocTarget,
2330 [](constcoff_relocation *A,constcoff_relocation *B) {
2331 return A->VirtualAddress < B->VirtualAddress;
2332 });
2333
2334if (RelocsForOffset.first != RelocsForOffset.second) {
2335// We found a relocation with the right offset. Check that it does have
2336// the expected type.
2337constcoff_relocation &R = **RelocsForOffset.first;
2338uint16_t RVAReloc;
2339switch (Obj->getArch()) {
2340caseTriple::x86:
2341 RVAReloc =COFF::IMAGE_REL_I386_DIR32NB;
2342break;
2343caseTriple::x86_64:
2344 RVAReloc =COFF::IMAGE_REL_AMD64_ADDR32NB;
2345break;
2346caseTriple::thumb:
2347 RVAReloc =COFF::IMAGE_REL_ARM_ADDR32NB;
2348break;
2349caseTriple::aarch64:
2350 RVAReloc =COFF::IMAGE_REL_ARM64_ADDR32NB;
2351break;
2352default:
2353returncreateStringError(object_error::parse_failed,
2354"unsupported architecture");
2355 }
2356if (R.Type != RVAReloc)
2357returncreateStringError(object_error::parse_failed,
2358"unexpected relocation type");
2359// Get the relocation's symbol
2360Expected<COFFSymbolRef>Sym = Obj->getSymbol(R.SymbolTableIndex);
2361if (!Sym)
2362returnSym.takeError();
2363// And the symbol's section
2364Expected<const coff_section *> Section =
2365 Obj->getSection(Sym->getSectionNumber());
2366if (!Section)
2367return Section.takeError();
2368// Add the initial value of DataRVA to the symbol's offset to find the
2369// data it points at.
2370uint64_tOffset = Entry.DataRVA +Sym->getValue();
2371ArrayRef<uint8_t> Contents;
2372if (Error E = Obj->getSectionContents(*Section, Contents))
2373return E;
2374if (Offset + Entry.DataSize > Contents.size())
2375returncreateStringError(object_error::parse_failed,
2376"data outside of section");
2377// Return a reference to the data inside the section.
2378returnStringRef(reinterpret_cast<constchar *>(Contents.data()) +Offset,
2379 Entry.DataSize);
2380 }else {
2381// Relocatable objects need a relocation for the DataRVA field.
2382if (Obj->isRelocatableObject())
2383returncreateStringError(object_error::parse_failed,
2384"no relocation found for DataRVA");
2385
2386// Locate the section that contains the address that DataRVA points at.
2387uint64_t VA = Entry.DataRVA + Obj->getImageBase();
2388for (constSectionRef &S : Obj->sections()) {
2389if (VA >= S.getAddress() &&
2390 VA + Entry.DataSize <= S.getAddress() + S.getSize()) {
2391uint64_tOffset = VA - S.getAddress();
2392Expected<StringRef> Contents = S.getContents();
2393if (!Contents)
2394return Contents.takeError();
2395return Contents->substr(Offset, Entry.DataSize);
2396 }
2397 }
2398returncreateStringError(object_error::parse_failed,
2399"address not found in image");
2400 }
2401}
load
AMDGPU Mark last scratch load
Definition:AMDGPUMarkLastScratchLoad.cpp:142
offsetof
#define offsetof(TYPE, MEMBER)
Definition:AMDHSAKernelDescriptor.h:30
ArrayRef.h
BinaryStreamReader.h
Binary.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
importedSymbolEnd
static imported_symbol_iterator importedSymbolEnd(uint32_t RVA, const COFFObjectFile *Object)
Definition:COFFObjectFile.cpp:1601
getNumberOfRelocations
static uint32_t getNumberOfRelocations(const coff_section *Sec, MemoryBufferRef M, const uint8_t *base)
Definition:COFFObjectFile.cpp:355
getObject
static Error getObject(const T *&Obj, MemoryBufferRef M, const void *Ptr, const uint64_t Size=sizeof(T))
Definition:COFFObjectFile.cpp:57
makeImportedSymbolIterator
static imported_symbol_iterator makeImportedSymbolIterator(const COFFObjectFile *Object, uintptr_t Ptr, int Index)
Definition:COFFObjectFile.cpp:1582
LLVM_COFF_SWITCH_RELOC_TYPE_NAME
#define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(reloc_type)
Definition:COFFObjectFile.cpp:1377
getFirstReloc
static const coff_relocation * getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base)
Definition:COFFObjectFile.cpp:376
importedSymbolBegin
static imported_symbol_iterator importedSymbolBegin(uint32_t RVA, const COFFObjectFile *Object)
Definition:COFFObjectFile.cpp:1593
checkSize
static bool checkSize(MemoryBufferRef M, std::error_code &EC, uint64_t Size)
Definition:COFFObjectFile.cpp:46
RETURN_IF_ERROR
#define RETURN_IF_ERROR(Expr)
Definition:COFFObjectFile.cpp:2203
decodeBase64StringEntry
static bool decodeBase64StringEntry(StringRef Str, uint32_t &Result)
Definition:COFFObjectFile.cpp:68
ignoreStrippedErrors
static Error ignoreStrippedErrors(Error E)
Definition:COFFObjectFile.cpp:879
Content
T Content
Definition:ELFObjHandler.cpp:89
Addr
uint64_t Addr
Definition:ELFObjHandler.cpp:79
Name
std::string Name
Definition:ELFObjHandler.cpp:77
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
End
bool End
Definition:ELF_riscv.cpp:480
Config
RelaxConfig Config
Definition:ELF_riscv.cpp:506
Sym
Symbol * Sym
Definition:ELF_riscv.cpp:479
Endian.h
I
#define I(x, y, z)
Definition:MD5.cpp:58
H
#define H(x, y, z)
Definition:MD5.cpp:57
MathExtras.h
MemoryBufferRef.h
memcmp
Merge contiguous icmps into a memcmp
Definition:MergeICmps.cpp:911
ObjectFile.h
COFF.h
P
#define P(N)
if
if(PassOpts->AAPipeline)
Definition:PassBuilderBindings.cpp:64
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef.h
StringSwitch.h
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Ptr
@ Ptr
Definition:TargetLibraryInfo.cpp:77
WindowsMachineFlag.h
T
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::ArrayRef::drop_front
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition:ArrayRef.h:207
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition:ArrayRef.h:168
llvm::ArrayRef::data
const T * data() const
Definition:ArrayRef.h:165
llvm::BinaryByteStream
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
Definition:BinaryByteStream.h:30
llvm::BinaryByteStream::data
ArrayRef< uint8_t > data() const
Definition:BinaryByteStream.h:58
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition:BinaryStreamReader.h:29
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:67
llvm::BinaryStreamReader::setOffset
void setOffset(uint64_t Off)
Definition:BinaryStreamReader.h:245
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:178
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition:Error.h:337
llvm::Error::isA
bool isA() const
Check whether one error is a subclass of another.
Definition:Error.h:247
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition:Error.h:608
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition:Error.h:578
llvm::MemoryBufferRef
Definition:MemoryBufferRef.h:22
llvm::MemoryBufferRef::getBufferSize
size_t getBufferSize() const
Definition:MemoryBufferRef.h:37
llvm::MemoryBufferRef::getBufferStart
const char * getBufferStart() const
Definition:MemoryBufferRef.h:35
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::split
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition:StringRef.h:700
llvm::StringRef::begin
iterator begin() const
Definition:StringRef.h:116
llvm::StringRef::end
iterator end() const
Definition:StringRef.h:118
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition:StringSwitch.h:44
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition:StringSwitch.h:69
llvm::StringSwitch::Default
R Default(T Value)
Definition:StringSwitch.h:182
llvm::StringTable
A table of densely packed, null-terminated strings indexed by offset.
Definition:StringTable.h:33
llvm::Triple::ArchType
ArchType
Definition:Triple.h:46
llvm::Triple::x86
@ x86
Definition:Triple.h:85
llvm::Triple::x86_64
@ x86_64
Definition:Triple.h:86
llvm::Triple::mipsel
@ mipsel
Definition:Triple.h:65
llvm::Triple::thumb
@ thumb
Definition:Triple.h:83
llvm::Triple::aarch64
@ aarch64
Definition:Triple.h:51
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::WritableMemoryBuffer::getNewUninitMemBuffer
static std::unique_ptr< WritableMemoryBuffer > getNewUninitMemBuffer(size_t Size, const Twine &BufferName="", std::optional< Align > Alignment=std::nullopt)
Allocate a new MemoryBuffer of the specified size that is not initialized.
Definition:MemoryBuffer.cpp:308
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition:iterator_range.h:42
llvm::object::Arm64XRelocRef
Definition:COFF.h:1375
llvm::object::Arm64XRelocRef::getRVA
uint32_t getRVA() const
Definition:COFF.h:1387
llvm::object::Arm64XRelocRef::operator==
bool operator==(const Arm64XRelocRef &Other) const
Definition:COFFObjectFile.cpp:2079
llvm::object::Arm64XRelocRef::getType
COFF::Arm64XFixupType getType() const
Definition:COFF.h:1384
llvm::object::Arm64XRelocRef::getSize
uint8_t getSize() const
Definition:COFFObjectFile.cpp:2107
llvm::object::Arm64XRelocRef::getValue
uint64_t getValue() const
Definition:COFFObjectFile.cpp:2118
llvm::object::Arm64XRelocRef::moveNext
void moveNext()
Definition:COFFObjectFile.cpp:2094
llvm::object::BaseRelocRef
Definition:COFF.h:1333
llvm::object::BaseRelocRef::moveNext
void moveNext()
Definition:COFFObjectFile.cpp:1904
llvm::object::BaseRelocRef::getType
Error getType(uint8_t &Type) const
Definition:COFFObjectFile.cpp:1922
llvm::object::BaseRelocRef::operator==
bool operator==(const BaseRelocRef &Other) const
Definition:COFFObjectFile.cpp:1900
llvm::object::BaseRelocRef::getRVA
Error getRVA(uint32_t &Result) const
Definition:COFFObjectFile.cpp:1928
llvm::object::BasicSymbolRef::SF_Global
@ SF_Global
Definition:SymbolicFile.h:111
llvm::object::BasicSymbolRef::SF_Common
@ SF_Common
Definition:SymbolicFile.h:114
llvm::object::BasicSymbolRef::SF_FormatSpecific
@ SF_FormatSpecific
Definition:SymbolicFile.h:117
llvm::object::BasicSymbolRef::SF_Weak
@ SF_Weak
Definition:SymbolicFile.h:112
llvm::object::BasicSymbolRef::SF_Absolute
@ SF_Absolute
Definition:SymbolicFile.h:113
llvm::object::BasicSymbolRef::SF_Undefined
@ SF_Undefined
Definition:SymbolicFile.h:110
llvm::object::BasicSymbolRef::SF_None
@ SF_None
Definition:SymbolicFile.h:109
llvm::object::Binary
Definition:Binary.h:32
llvm::object::Binary::Data
MemoryBufferRef Data
Definition:Binary.h:37
llvm::object::Binary::checkOffset
static Error checkOffset(MemoryBufferRef M, uintptr_t Addr, const uint64_t Size)
Definition:Binary.h:175
llvm::object::COFFObjectFile
Definition:COFF.h:879
llvm::object::COFFObjectFile::getDOSHeader
const dos_header * getDOSHeader() const
Definition:COFF.h:1133
llvm::object::COFFObjectFile::getSectionSize
uint64_t getSectionSize(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:288
llvm::object::COFFObjectFile::getSectionName
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:269
llvm::object::COFFObjectFile::getSectionIndex
uint64_t getSectionIndex(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:284
llvm::object::COFFObjectFile::dynamic_reloc_begin
dynamic_reloc_iterator dynamic_reloc_begin() const
Definition:COFFObjectFile.cpp:1104
llvm::object::COFFObjectFile::getHybridObjectView
std::unique_ptr< MemoryBuffer > getHybridObjectView() const
Definition:COFFObjectFile.cpp:1515
llvm::object::COFFObjectFile::getSymbolAlignment
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
Definition:COFFObjectFile.cpp:158
llvm::object::COFFObjectFile::isSectionCompressed
bool isSectionCompressed(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:306
llvm::object::COFFObjectFile::moveRelocationNext
void moveRelocationNext(DataRefImpl &Rel) const override
Definition:COFFObjectFile.cpp:1320
llvm::object::COFFObjectFile::getSymbolSection
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
Definition:COFFObjectFile.cpp:246
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:1117
llvm::object::COFFObjectFile::export_directory_begin
export_directory_iterator export_directory_begin() const
Definition:COFFObjectFile.cpp:1069
llvm::object::COFFObjectFile::delay_import_directory_end
delay_import_directory_iterator delay_import_directory_end() const
Definition:COFFObjectFile.cpp:1063
llvm::object::COFFObjectFile::base_reloc_begin
base_reloc_iterator base_reloc_begin() const
Definition:COFFObjectFile.cpp:1096
llvm::object::COFFObjectFile::section_end
section_iterator section_end() const override
Definition:COFFObjectFile.cpp:1088
llvm::object::COFFObjectFile::getSymbol
Expected< COFFSymbolRef > getSymbol(uint32_t index) const
Definition:COFF.h:1149
llvm::object::COFFObjectFile::getVaPtr
Error getVaPtr(uint64_t VA, uintptr_t &Res) const
Definition:COFFObjectFile.cpp:464
llvm::object::COFFObjectFile::getRelocationType
uint64_t getRelocationType(DataRefImpl Rel) const override
Definition:COFFObjectFile.cpp:1344
llvm::object::COFFObjectFile::moveSymbolNext
void moveSymbolNext(DataRefImpl &Symb) const override
Definition:COFFObjectFile.cpp:135
llvm::object::COFFObjectFile::getCommonSymbolSizeImpl
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
Definition:COFFObjectFile.cpp:240
llvm::object::COFFObjectFile::delay_import_directories
iterator_range< delay_import_directory_iterator > delay_import_directories() const
Definition:COFFObjectFile.cpp:1158
llvm::object::COFFObjectFile::import_directory_end
import_directory_iterator import_directory_end() const
Definition:COFFObjectFile.cpp:1051
llvm::object::COFFObjectFile::getPointerToSymbolTable
uint32_t getPointerToSymbolTable() const
Definition:COFF.h:995
llvm::object::COFFObjectFile::getCOFFRelocation
const coff_relocation * getCOFFRelocation(const RelocationRef &Reloc) const
Definition:COFFObjectFile.cpp:1367
llvm::object::COFFObjectFile::getSymbolName
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
Definition:COFFObjectFile.cpp:150
llvm::object::COFFObjectFile::isDebugSection
bool isDebugSection(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:330
llvm::object::COFFObjectFile::debug_directories
iterator_range< const debug_directory * > debug_directories() const
Definition:COFF.h:1122
llvm::object::COFFObjectFile::getDynamicRelocTable
const coff_dynamic_reloc_table * getDynamicRelocTable() const
Definition:COFF.h:1035
llvm::object::COFFObjectFile::getRelocationTypeName
StringRef getRelocationTypeName(uint16_t Type) const
Definition:COFFObjectFile.cpp:1381
llvm::object::COFFObjectFile::isSectionBSS
bool isSectionBSS(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:320
llvm::object::COFFObjectFile::base_reloc_end
base_reloc_iterator base_reloc_end() const
Definition:COFFObjectFile.cpp:1100
llvm::object::COFFObjectFile::is64
bool is64() const
Definition:COFF.h:1218
llvm::object::COFFObjectFile::getSectionAddress
uint64_t getSectionAddress(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:274
llvm::object::COFFObjectFile::getSymbolAddress
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
Definition:COFFObjectFile.cpp:165
llvm::object::COFFObjectFile::getNumberOfSymbols
uint32_t getNumberOfSymbols() const
Definition:COFF.h:1012
llvm::object::COFFObjectFile::section_begin
section_iterator section_begin() const override
Definition:COFFObjectFile.cpp:1082
llvm::object::COFFObjectFile::getSymbolType
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
Definition:COFFObjectFile.cpp:186
llvm::object::COFFObjectFile::getSymbolTableEntrySize
size_t getSymbolTableEntrySize() const
Definition:COFF.h:1175
llvm::object::COFFObjectFile::ImportDirectoryEntryRef
friend class ImportDirectoryEntryRef
Definition:COFF.h:883
llvm::object::COFFObjectFile::export_directory_end
export_directory_iterator export_directory_end() const
Definition:COFFObjectFile.cpp:1074
llvm::object::COFFObjectFile::getHintName
Error getHintName(uint32_t Rva, uint16_t &Hint, StringRef &Name) const
Definition:COFFObjectFile.cpp:534
llvm::object::COFFObjectFile::getSymbolTable
uintptr_t getSymbolTable() const
Definition:COFF.h:934
llvm::object::COFFObjectFile::create
static Expected< std::unique_ptr< COFFObjectFile > > create(MemoryBufferRef Object)
Definition:COFFObjectFile.cpp:861
llvm::object::COFFObjectFile::isSectionVirtual
bool isSectionVirtual(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:348
llvm::object::COFFObjectFile::getSectionID
unsigned getSectionID(SectionRef Sec) const
Definition:COFFObjectFile.cpp:341
llvm::object::COFFObjectFile::section_rel_begin
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:395
llvm::object::COFFObjectFile::import_directories
iterator_range< import_directory_iterator > import_directories() const
Definition:COFFObjectFile.cpp:1153
llvm::object::COFFObjectFile::delay_import_directory_begin
delay_import_directory_iterator delay_import_directory_begin() const
Definition:COFFObjectFile.cpp:1057
llvm::object::COFFObjectFile::symbol_end
basic_symbol_iterator symbol_end() const override
Definition:COFFObjectFile.cpp:1035
llvm::object::COFFObjectFile::getRvaAndSizeAsBytes
Error getRvaAndSizeAsBytes(uint32_t RVA, uint32_t Size, ArrayRef< uint8_t > &Contents, const char *ErrorContext=nullptr) 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:506
llvm::object::COFFObjectFile::getLoadConfig64
const coff_load_configuration64 * getLoadConfig64() const
Definition:COFF.h:1029
llvm::object::COFFObjectFile::export_directories
iterator_range< export_directory_iterator > export_directories() const
Definition:COFFObjectFile.cpp:1164
llvm::object::COFFObjectFile::getNumberOfSections
uint32_t getNumberOfSections() const
Definition:COFF.h:987
llvm::object::COFFObjectFile::getRelocationOffset
uint64_t getRelocationOffset(DataRefImpl Rel) const override
Definition:COFFObjectFile.cpp:1325
llvm::object::COFFObjectFile::symbol_begin
basic_symbol_iterator symbol_begin() const override
Definition:COFFObjectFile.cpp:1029
llvm::object::COFFObjectFile::getArch
Triple::ArchType getArch() const override
Definition:COFFObjectFile.cpp:1142
llvm::object::COFFObjectFile::isRelocatableObject
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
Definition:COFFObjectFile.cpp:1505
llvm::object::COFFObjectFile::getSymbolFlags
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
Definition:COFFObjectFile.cpp:209
llvm::object::COFFObjectFile::getSection
Expected< const coff_section * > getSection(int32_t index) const
Definition:COFFObjectFile.cpp:1187
llvm::object::COFFObjectFile::isSectionText
bool isSectionText(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:310
llvm::object::COFFObjectFile::getSectionContents
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:293
llvm::object::COFFObjectFile::getDataDirectory
const data_directory * getDataDirectory(uint32_t index) const
Definition:COFFObjectFile.cpp:1176
llvm::object::COFFObjectFile::mapDebugSectionName
StringRef mapDebugSectionName(StringRef Name) const override
Maps a debug section name to a standard DWARF section name.
Definition:COFFObjectFile.cpp:1509
llvm::object::COFFObjectFile::getSymbolAuxData
ArrayRef< uint8_t > getSymbolAuxData(COFFSymbolRef Symbol) const
Definition:COFFObjectFile.cpp:1228
llvm::object::COFFObjectFile::getImageBase
uint64_t getImageBase() const
Definition:COFFObjectFile.cpp:454
llvm::object::COFFObjectFile::getLoadConfig32
const coff_load_configuration32 * getLoadConfig32() const
Definition:COFF.h:1024
llvm::object::COFFObjectFile::getCOFFSection
const coff_section * getCOFFSection(const SectionRef &Section) const
Definition:COFFObjectFile.cpp:1350
llvm::object::COFFObjectFile::import_directory_begin
import_directory_iterator import_directory_begin() const
Definition:COFFObjectFile.cpp:1042
llvm::object::COFFObjectFile::moveSectionNext
void moveSectionNext(DataRefImpl &Sec) const override
Definition:COFFObjectFile.cpp:263
llvm::object::COFFObjectFile::section_rel_end
relocation_iterator section_rel_end(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:405
llvm::object::COFFObjectFile::dynamic_reloc_end
dynamic_reloc_iterator dynamic_reloc_end() const
Definition:COFFObjectFile.cpp:1109
llvm::object::COFFObjectFile::getRelocations
ArrayRef< coff_relocation > getRelocations(const coff_section *Sec) const
Definition:COFFObjectFile.cpp:1372
llvm::object::COFFObjectFile::getSymbolValueImpl
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
Definition:COFFObjectFile.cpp:154
llvm::object::COFFObjectFile::getRvaPtr
Error getRvaPtr(uint32_t Rva, uintptr_t &Res, const char *ErrorContext=nullptr) const
Definition:COFFObjectFile.cpp:472
llvm::object::COFFObjectFile::dynamic_relocs
iterator_range< dynamic_reloc_iterator > dynamic_relocs() const
Definition:COFFObjectFile.cpp:1172
llvm::object::COFFObjectFile::getSymbolSectionID
unsigned getSymbolSectionID(SymbolRef Sym) const
Definition:COFFObjectFile.cpp:258
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.
Definition:COFFObjectFile.cpp:545
llvm::object::COFFObjectFile::ExportDirectoryEntryRef
friend class ExportDirectoryEntryRef
Definition:COFF.h:884
llvm::object::COFFObjectFile::getRelocationSymbol
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
Definition:COFFObjectFile.cpp:1330
llvm::object::COFFObjectFile::getSectionAlignment
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:301
llvm::object::COFFObjectFile::getSymbolIndex
uint32_t getSymbolIndex(COFFSymbolRef Symbol) const
Definition:COFFObjectFile.cpp:1250
llvm::object::COFFObjectFile::getMachine
uint16_t getMachine() const
Definition:COFF.h:942
llvm::object::COFFObjectFile::getCOFFSymbol
COFFSymbolRef getCOFFSymbol(const DataRefImpl &Ref) const
Definition:COFFObjectFile.cpp:1354
llvm::object::COFFObjectFile::getStartAddress
Expected< uint64_t > getStartAddress() const override
Definition:COFFObjectFile.cpp:1146
llvm::object::COFFObjectFile::base_relocs
iterator_range< base_reloc_iterator > base_relocs() const
Definition:COFFObjectFile.cpp:1168
llvm::object::COFFObjectFile::isSectionData
bool isSectionData(DataRefImpl Sec) const override
Definition:COFFObjectFile.cpp:315
llvm::object::COFFObjectFile::getFileFormatName
StringRef getFileFormatName() const override
Definition:COFFObjectFile.cpp:1121
llvm::object::COFFSymbolRef
Definition:COFF.h:284
llvm::object::COFFSymbolRef::isCommon
bool isCommon() const
Definition:COFF.h:385
llvm::object::COFFSymbolRef::isAnyUndefined
bool isAnyUndefined() const
Definition:COFF.h:413
llvm::object::COFFSymbolRef::isFileRecord
bool isFileRecord() const
Definition:COFF.h:417
llvm::object::COFFSymbolRef::getWeakExternal
const coff_aux_weak_external * getWeakExternal() const
Definition:COFF.h:370
llvm::object::COFFSymbolRef::isSectionDefinition
bool isSectionDefinition() const
Definition:COFF.h:425
llvm::object::COFFSymbolRef::getComplexType
uint8_t getComplexType() const
Definition:COFF.h:354
llvm::object::COFFSymbolRef::isExternal
bool isExternal() const
Definition:COFF.h:381
llvm::object::COFFSymbolRef::getValue
uint32_t getValue() const
Definition:COFF.h:321
llvm::object::COFFSymbolRef::isWeakExternal
bool isWeakExternal() const
Definition:COFF.h:399
llvm::object::COFFSymbolRef::getSectionNumber
int32_t getSectionNumber() const
Definition:COFF.h:326
llvm::object::COFFSymbolRef::isUndefined
bool isUndefined() const
Definition:COFF.h:390
llvm::object::DelayImportDirectoryEntryRef
Definition:COFF.h:1257
llvm::object::DelayImportDirectoryEntryRef::moveNext
void moveNext()
Definition:COFFObjectFile.cpp:1677
llvm::object::DelayImportDirectoryEntryRef::operator==
bool operator==(const DelayImportDirectoryEntryRef &Other) const
Definition:COFFObjectFile.cpp:1673
llvm::object::DelayImportDirectoryEntryRef::imported_symbol_begin
imported_symbol_iterator imported_symbol_begin() const
Definition:COFFObjectFile.cpp:1682
llvm::object::DelayImportDirectoryEntryRef::getImportAddress
Error getImportAddress(int AddrIndex, uint64_t &Result) const
Definition:COFFObjectFile.cpp:1713
llvm::object::DelayImportDirectoryEntryRef::imported_symbols
iterator_range< imported_symbol_iterator > imported_symbols() const
Definition:COFFObjectFile.cpp:1694
llvm::object::DelayImportDirectoryEntryRef::imported_symbol_end
imported_symbol_iterator imported_symbol_end() const
Definition:COFFObjectFile.cpp:1688
llvm::object::DelayImportDirectoryEntryRef::getDelayImportTable
Error getDelayImportTable(const delay_import_directory_table_entry *&Result) const
Definition:COFFObjectFile.cpp:1707
llvm::object::DelayImportDirectoryEntryRef::getName
Error getName(StringRef &Result) const
Definition:COFFObjectFile.cpp:1698
llvm::object::DynamicRelocRef
Definition:COFF.h:1351
llvm::object::DynamicRelocRef::operator==
bool operator==(const DynamicRelocRef &Other) const
Definition:COFFObjectFile.cpp:1934
llvm::object::DynamicRelocRef::arm64x_reloc_begin
arm64x_reloc_iterator arm64x_reloc_begin() const
Definition:COFFObjectFile.cpp:2057
llvm::object::DynamicRelocRef::getContents
void getContents(ArrayRef< uint8_t > &Ref) const
Definition:COFFObjectFile.cpp:1986
llvm::object::DynamicRelocRef::getType
uint32_t getType() const
Definition:COFFObjectFile.cpp:1961
llvm::object::DynamicRelocRef::arm64x_reloc_end
arm64x_reloc_iterator arm64x_reloc_end() const
Definition:COFFObjectFile.cpp:2066
llvm::object::DynamicRelocRef::arm64x_relocs
iterator_range< arm64x_reloc_iterator > arm64x_relocs() const
Definition:COFFObjectFile.cpp:2075
llvm::object::DynamicRelocRef::moveNext
void moveNext()
Definition:COFFObjectFile.cpp:1938
llvm::object::ExportDirectoryEntryRef
Definition:COFF.h:1283
llvm::object::ExportDirectoryEntryRef::operator==
bool operator==(const ExportDirectoryEntryRef &Other) const
Definition:COFFObjectFile.cpp:1728
llvm::object::ExportDirectoryEntryRef::getDllName
Error getDllName(StringRef &Result) const
Definition:COFFObjectFile.cpp:1738
llvm::object::ExportDirectoryEntryRef::moveNext
void moveNext()
Definition:COFFObjectFile.cpp:1732
llvm::object::ExportDirectoryEntryRef::getExportRVA
Error getExportRVA(uint32_t &Result) const
Definition:COFFObjectFile.cpp:1760
llvm::object::ExportDirectoryEntryRef::getOrdinalBase
Error getOrdinalBase(uint32_t &Result) const
Definition:COFFObjectFile.cpp:1748
llvm::object::ExportDirectoryEntryRef::getOrdinal
Error getOrdinal(uint32_t &Result) const
Definition:COFFObjectFile.cpp:1754
llvm::object::ExportDirectoryEntryRef::isForwarder
Error isForwarder(bool &Result) const
Definition:COFFObjectFile.cpp:1801
llvm::object::ExportDirectoryEntryRef::getForwardTo
Error getForwardTo(StringRef &Result) const
Definition:COFFObjectFile.cpp:1816
llvm::object::ExportDirectoryEntryRef::getSymbolName
Error getSymbolName(StringRef &Result) const
Definition:COFFObjectFile.cpp:1774
llvm::object::ImportDirectoryEntryRef
Definition:COFF.h:1226
llvm::object::ImportDirectoryEntryRef::operator==
bool operator==(const ImportDirectoryEntryRef &Other) const
Definition:COFFObjectFile.cpp:1564
llvm::object::ImportDirectoryEntryRef::imported_symbol_end
imported_symbol_iterator imported_symbol_end() const
Definition:COFFObjectFile.cpp:1626
llvm::object::ImportDirectoryEntryRef::imported_symbol_begin
imported_symbol_iterator imported_symbol_begin() const
Definition:COFFObjectFile.cpp:1620
llvm::object::ImportDirectoryEntryRef::getImportLookupTableRVA
Error getImportLookupTableRVA(uint32_t &Result) const
Definition:COFFObjectFile.cpp:1661
llvm::object::ImportDirectoryEntryRef::getImportTableEntry
Error getImportTableEntry(const coff_import_directory_table_entry *&Result) const
Definition:COFFObjectFile.cpp:1576
llvm::object::ImportDirectoryEntryRef::lookup_table_end
imported_symbol_iterator lookup_table_end() const
Definition:COFFObjectFile.cpp:1641
llvm::object::ImportDirectoryEntryRef::lookup_table_symbols
iterator_range< imported_symbol_iterator > lookup_table_symbols() const
Definition:COFFObjectFile.cpp:1647
llvm::object::ImportDirectoryEntryRef::imported_symbols
iterator_range< imported_symbol_iterator > imported_symbols() const
Definition:COFFObjectFile.cpp:1632
llvm::object::ImportDirectoryEntryRef::lookup_table_begin
imported_symbol_iterator lookup_table_begin() const
Definition:COFFObjectFile.cpp:1636
llvm::object::ImportDirectoryEntryRef::moveNext
void moveNext()
Definition:COFFObjectFile.cpp:1568
llvm::object::ImportDirectoryEntryRef::getImportAddressTableRVA
Error getImportAddressTableRVA(uint32_t &Result) const
Definition:COFFObjectFile.cpp:1666
llvm::object::ImportDirectoryEntryRef::getName
Error getName(StringRef &Result) const
Definition:COFFObjectFile.cpp:1651
llvm::object::ImportedSymbolRef
Definition:COFF.h:1308
llvm::object::ImportedSymbolRef::operator==
bool operator==(const ImportedSymbolRef &Other) const
Definition:COFFObjectFile.cpp:1828
llvm::object::ImportedSymbolRef::getHintNameRVA
Error getHintNameRVA(uint32_t &Result) const
Definition:COFFObjectFile.cpp:1865
llvm::object::ImportedSymbolRef::getOrdinal
Error getOrdinal(uint16_t &Result) const
Definition:COFFObjectFile.cpp:1873
llvm::object::ImportedSymbolRef::moveNext
void moveNext()
Definition:COFFObjectFile.cpp:1833
llvm::object::ImportedSymbolRef::getSymbolName
Error getSymbolName(StringRef &Result) const
Definition:COFFObjectFile.cpp:1837
llvm::object::ImportedSymbolRef::isOrdinal
Error isOrdinal(bool &Result) const
Definition:COFFObjectFile.cpp:1857
llvm::object::ObjectFile
This class is the base class for all object file types.
Definition:ObjectFile.h:229
llvm::object::ObjectFile::RelocationRef
friend class RelocationRef
Definition:ObjectFile.h:287
llvm::object::ObjectFile::SymbolRef
friend class SymbolRef
Definition:ObjectFile.h:247
llvm::object::ObjectFile::createCOFFObjectFile
static Expected< std::unique_ptr< COFFObjectFile > > createCOFFObjectFile(MemoryBufferRef Object)
Definition:COFFObjectFile.cpp:1896
llvm::object::ObjectFile::sections
section_iterator_range sections() const
Definition:ObjectFile.h:329
llvm::object::ObjectFile::SectionRef
friend class SectionRef
Definition:ObjectFile.h:261
llvm::object::ObjectFile::getSymbolValue
Expected< uint64_t > getSymbolValue(DataRefImpl Symb) const
Definition:ObjectFile.cpp:56
llvm::object::ObjectFile::base
const uint8_t * base() const
Definition:ObjectFile.h:235
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:52
llvm::object::RelocationRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition:ObjectFile.h:636
llvm::object::ResourceSectionRef::getBaseTable
Expected< const coff_resource_dir_table & > getBaseTable()
Definition:COFFObjectFile.cpp:2271
llvm::object::ResourceSectionRef::getEntrySubDir
Expected< const coff_resource_dir_table & > getEntrySubDir(const coff_resource_dir_entry &Entry)
Definition:COFFObjectFile.cpp:2260
llvm::object::ResourceSectionRef::getEntryData
Expected< const coff_resource_data_entry & > getEntryData(const coff_resource_dir_entry &Entry)
Definition:COFFObjectFile.cpp:2266
llvm::object::ResourceSectionRef::load
Error load(const COFFObjectFile *O)
Definition:COFFObjectFile.cpp:2286
llvm::object::ResourceSectionRef::getEntryNameString
Expected< ArrayRef< UTF16 > > getEntryNameString(const coff_resource_dir_entry &Entry)
Definition:COFFObjectFile.cpp:2222
llvm::object::ResourceSectionRef::getContents
Expected< StringRef > getContents(const coff_resource_data_entry &Entry)
Definition:COFFObjectFile.cpp:2318
llvm::object::ResourceSectionRef::getTableEntry
Expected< const coff_resource_dir_entry & > getTableEntry(const coff_resource_dir_table &Table, uint32_t Index)
Definition:COFFObjectFile.cpp:2276
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:81
llvm::object::SectionRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition:ObjectFile.h:598
llvm::object::SectionStrippedError
Definition:COFF.h:1469
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:168
llvm::object::SymbolRef::ST_Other
@ ST_Other
Definition:ObjectFile.h:174
llvm::object::SymbolRef::ST_Unknown
@ ST_Unknown
Definition:ObjectFile.h:173
llvm::object::SymbolRef::ST_Function
@ ST_Function
Definition:ObjectFile.h:178
llvm::object::SymbolRef::ST_File
@ ST_File
Definition:ObjectFile.h:177
llvm::object::SymbolRef::ST_Data
@ ST_Data
Definition:ObjectFile.h:175
llvm::object::SymbolRef::ST_Debug
@ ST_Debug
Definition:ObjectFile.h:176
llvm::object::content_iterator
Definition:SymbolicFile.h:69
llvm::object::symbol_iterator
Definition:ObjectFile.h:208
ptrdiff_t
uint16_t
uint32_t
uint64_t
uint8_t
iterator_range.h
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
Error.h
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
Error.h
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition:ARMBuildAttributes.h:82
llvm::COFF::IMAGE_DYNAMIC_RELOCATION_ARM64X
@ IMAGE_DYNAMIC_RELOCATION_ARM64X
Definition:COFF.h:444
llvm::COFF::IMAGE_FILE_MACHINE_ARM64
@ IMAGE_FILE_MACHINE_ARM64
Definition:COFF.h:100
llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN
@ IMAGE_FILE_MACHINE_UNKNOWN
Definition:COFF.h:95
llvm::COFF::IMAGE_FILE_MACHINE_AMD64
@ IMAGE_FILE_MACHINE_AMD64
Definition:COFF.h:97
llvm::COFF::IMAGE_FILE_MACHINE_ARM64EC
@ IMAGE_FILE_MACHINE_ARM64EC
Definition:COFF.h:101
llvm::COFF::IMAGE_FILE_MACHINE_R4000
@ IMAGE_FILE_MACHINE_R4000
Definition:COFF.h:112
llvm::COFF::IMAGE_FILE_MACHINE_I386
@ IMAGE_FILE_MACHINE_I386
Definition:COFF.h:104
llvm::COFF::IMAGE_FILE_MACHINE_ARM64X
@ IMAGE_FILE_MACHINE_ARM64X
Definition:COFF.h:102
llvm::COFF::IMAGE_FILE_MACHINE_ARMNT
@ IMAGE_FILE_MACHINE_ARMNT
Definition:COFF.h:99
llvm::COFF::IMAGE_SCN_CNT_CODE
@ IMAGE_SCN_CNT_CODE
Definition:COFF.h:302
llvm::COFF::IMAGE_SCN_MEM_READ
@ IMAGE_SCN_MEM_READ
Definition:COFF.h:335
llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition:COFF.h:304
llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
@ IMAGE_SCN_CNT_INITIALIZED_DATA
Definition:COFF.h:303
llvm::COFF::IMAGE_SCN_MEM_WRITE
@ IMAGE_SCN_MEM_WRITE
Definition:COFF.h:336
llvm::COFF::IMAGE_DEBUG_TYPE_CODEVIEW
@ IMAGE_DEBUG_TYPE_CODEVIEW
Definition:COFF.h:702
llvm::COFF::IMAGE_REL_ARM64_ADDR32NB
@ IMAGE_REL_ARM64_ADDR32NB
Definition:COFF.h:402
llvm::COFF::NameSize
@ NameSize
Definition:COFF.h:57
llvm::COFF::IMAGE_REL_AMD64_ADDR32NB
@ IMAGE_REL_AMD64_ADDR32NB
Definition:COFF.h:363
llvm::COFF::TLS_TABLE
@ TLS_TABLE
Definition:COFF.h:639
llvm::COFF::EXPORT_TABLE
@ EXPORT_TABLE
Definition:COFF.h:630
llvm::COFF::LOAD_CONFIG_TABLE
@ LOAD_CONFIG_TABLE
Definition:COFF.h:640
llvm::COFF::IMPORT_TABLE
@ IMPORT_TABLE
Definition:COFF.h:631
llvm::COFF::DELAY_IMPORT_DESCRIPTOR
@ DELAY_IMPORT_DESCRIPTOR
Definition:COFF.h:643
llvm::COFF::DEBUG_DIRECTORY
@ DEBUG_DIRECTORY
Definition:COFF.h:636
llvm::COFF::BASE_RELOCATION_TABLE
@ BASE_RELOCATION_TABLE
Definition:COFF.h:635
llvm::COFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE
@ IMAGE_DVRT_ARM64X_FIXUP_TYPE_VALUE
Definition:COFF.h:449
llvm::COFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_DELTA
@ IMAGE_DVRT_ARM64X_FIXUP_TYPE_DELTA
Definition:COFF.h:450
llvm::COFF::IMAGE_DVRT_ARM64X_FIXUP_TYPE_ZEROFILL
@ IMAGE_DVRT_ARM64X_FIXUP_TYPE_ZEROFILL
Definition:COFF.h:448
llvm::COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS
@ IMAGE_WEAK_EXTERN_SEARCH_ALIAS
Definition:COFF.h:489
llvm::COFF::IMAGE_REL_ARM_ADDR32NB
@ IMAGE_REL_ARM_ADDR32NB
Definition:COFF.h:382
llvm::COFF::isReservedSectionNumber
bool isReservedSectionNumber(int32_t SectionNumber)
Definition:COFF.h:848
llvm::COFF::IMAGE_REL_I386_DIR32NB
@ IMAGE_REL_I386_DIR32NB
Definition:COFF.h:350
llvm::COFF::BigObjMagic
static const char BigObjMagic[]
Definition:COFF.h:37
llvm::COFF::PEMagic
static const char PEMagic[]
Definition:COFF.h:35
llvm::COFF::IMAGE_SYM_DEBUG
@ IMAGE_SYM_DEBUG
Definition:COFF.h:211
llvm::COFF::IMAGE_SYM_ABSOLUTE
@ IMAGE_SYM_ABSOLUTE
Definition:COFF.h:212
llvm::COFF::IMAGE_SYM_DTYPE_FUNCTION
@ IMAGE_SYM_DTYPE_FUNCTION
A function that returns a base type.
Definition:COFF.h:275
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::numbers::e
constexpr double e
Definition:MathExtras.h:47
llvm::object::getObject
static Expected< const T * > getObject(MemoryBufferRef M, const void *Ptr, const uint64_t Size=sizeof(T))
Definition:XCOFFObjectFile.cpp:34
llvm::object::import_directory_iterator
content_iterator< ImportDirectoryEntryRef > import_directory_iterator
Definition:COFF.h:47
llvm::object::imported_symbol_iterator
content_iterator< ImportedSymbolRef > imported_symbol_iterator
Definition:COFF.h:51
llvm::object::export_directory_iterator
content_iterator< ExportDirectoryEntryRef > export_directory_iterator
Definition:COFF.h:50
llvm::object::arm64x_reloc_iterator
content_iterator< Arm64XRelocRef > arm64x_reloc_iterator
Definition:COFF.h:54
llvm::object::base_reloc_iterator
content_iterator< BaseRelocRef > base_reloc_iterator
Definition:COFF.h:52
llvm::object::object_error::unexpected_eof
@ unexpected_eof
llvm::object::object_error::parse_failed
@ parse_failed
llvm::object::coff_tls_directory64
coff_tls_directory< support::little64_t > coff_tls_directory64
Definition:COFF.h:606
llvm::object::section_iterator
content_iterator< SectionRef > section_iterator
Definition:ObjectFile.h:47
llvm::object::relocation_iterator
content_iterator< RelocationRef > relocation_iterator
Definition:ObjectFile.h:77
llvm::object::basic_symbol_iterator
content_iterator< BasicSymbolRef > basic_symbol_iterator
Definition:SymbolicFile.h:143
llvm::object::delay_import_directory_iterator
content_iterator< DelayImportDirectoryEntryRef > delay_import_directory_iterator
Definition:COFF.h:49
llvm::object::dynamic_reloc_iterator
content_iterator< DynamicRelocRef > dynamic_reloc_iterator
Definition:COFF.h:53
llvm::sampleprof::Base
@ Base
Definition:Discriminator.h:58
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::Length
@ Length
Definition:DWP.cpp:480
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition:iterator_range.h:77
llvm::getMachineArchType
Triple::ArchType getMachineArchType(T machine)
Definition:WindowsMachineFlag.h:34
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition:Error.h:1291
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:395
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition:STLExtras.h:1664
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::ModRefInfo::Ref
@ Ref
The access may reference the value stored in memory.
llvm::IRMemLocation::Other
@ Other
Any other memory.
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition:Error.h:756
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition:Error.cpp:111
llvm::endianness::little
@ little
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition:Error.h:1069
llvm::COFF::BigObjHeader::MinBigObjectVersion
@ MinBigObjectVersion
Definition:COFF.h:75
llvm::COFF::PE32Header::PE32_PLUS
@ PE32_PLUS
Definition:COFF.h:588
llvm::COFF::PE32Header::PE32
@ PE32
Definition:COFF.h:588
llvm::SectionName
Definition:DWARFSection.h:21
llvm::object::StringTableOffset
Definition:COFF.h:248
llvm::object::chpe_code_range_entry
Definition:COFF.h:774
llvm::object::chpe_metadata
Definition:COFF.h:733
llvm::object::chpe_metadata::RedirectionMetadataCount
support::ulittle32_t RedirectionMetadataCount
Definition:COFF.h:747
llvm::object::chpe_metadata::CodeMap
support::ulittle32_t CodeMap
Definition:COFF.h:735
llvm::object::chpe_metadata::CodeRangesToEntryPointsCount
support::ulittle32_t CodeRangesToEntryPointsCount
Definition:COFF.h:746
llvm::object::chpe_metadata::CodeMapCount
support::ulittle32_t CodeMapCount
Definition:COFF.h:736
llvm::object::chpe_metadata::RedirectionMetadata
support::ulittle32_t RedirectionMetadata
Definition:COFF.h:738
llvm::object::chpe_metadata::CodeRangesToEntryPoints
support::ulittle32_t CodeRangesToEntryPoints
Definition:COFF.h:737
llvm::object::chpe_range_entry
Definition:COFF.h:763
llvm::object::chpe_redirection_entry
Definition:COFF.h:780
llvm::object::coff_aux_weak_external
Definition:COFF.h:510
llvm::object::coff_base_reloc_block_entry
Definition:COFF.h:796
llvm::object::coff_base_reloc_block_header
Definition:COFF.h:791
llvm::object::coff_bigobj_file_header
Definition:COFF.h:91
llvm::object::coff_bigobj_file_header::Version
support::ulittle16_t Version
Definition:COFF.h:94
llvm::object::coff_bigobj_file_header::UUID
uint8_t UUID[16]
Definition:COFF.h:97
llvm::object::coff_dynamic_reloc_table
Definition:COFF.h:848
llvm::object::coff_dynamic_reloc_table::Version
support::ulittle32_t Version
Definition:COFF.h:849
llvm::object::coff_dynamic_reloc_table::Size
support::ulittle32_t Size
Definition:COFF.h:850
llvm::object::coff_dynamic_relocation32_v2
Definition:COFF.h:863
llvm::object::coff_dynamic_relocation32_v2::HeaderSize
support::ulittle32_t HeaderSize
Definition:COFF.h:864
llvm::object::coff_dynamic_relocation32
Definition:COFF.h:853
llvm::object::coff_dynamic_relocation64_v2
Definition:COFF.h:871
llvm::object::coff_dynamic_relocation64
Definition:COFF.h:858
llvm::object::coff_file_header
Definition:COFF.h:79
llvm::object::coff_file_header::Machine
support::ulittle16_t Machine
Definition:COFF.h:80
llvm::object::coff_file_header::NumberOfSections
support::ulittle16_t NumberOfSections
Definition:COFF.h:81
llvm::object::coff_file_header::isImportLibrary
bool isImportLibrary() const
Definition:COFF.h:88
llvm::object::coff_file_header::SizeOfOptionalHeader
support::ulittle16_t SizeOfOptionalHeader
Definition:COFF.h:85
llvm::object::coff_import_directory_table_entry
Definition:COFF.h:563
llvm::object::coff_import_directory_table_entry::ImportAddressTableRVA
support::ulittle32_t ImportAddressTableRVA
Definition:COFF.h:568
llvm::object::coff_import_directory_table_entry::isNull
bool isNull() const
Definition:COFF.h:570
llvm::object::coff_import_directory_table_entry::NameRVA
support::ulittle32_t NameRVA
Definition:COFF.h:567
llvm::object::coff_import_directory_table_entry::ImportLookupTableRVA
support::ulittle32_t ImportLookupTableRVA
Definition:COFF.h:564
llvm::object::coff_load_configuration32
32-bit load config (IMAGE_LOAD_CONFIG_DIRECTORY32)
Definition:COFF.h:618
llvm::object::coff_load_configuration64
64-bit load config (IMAGE_LOAD_CONFIG_DIRECTORY64)
Definition:COFF.h:676
llvm::object::coff_relocation
Definition:COFF.h:482
llvm::object::coff_relocation::Type
support::ulittle16_t Type
Definition:COFF.h:485
llvm::object::coff_relocation::VirtualAddress
support::ulittle32_t VirtualAddress
Definition:COFF.h:483
llvm::object::coff_resource_data_entry
Definition:COFF.h:826
llvm::object::coff_resource_dir_entry
Definition:COFF.h:803
llvm::object::coff_resource_dir_table
Definition:COFF.h:833
llvm::object::coff_resource_dir_table::NumberOfNameEntries
support::ulittle16_t NumberOfNameEntries
Definition:COFF.h:838
llvm::object::coff_resource_dir_table::NumberOfIDEntries
support::ulittle16_t NumberOfIDEntries
Definition:COFF.h:839
llvm::object::coff_section
Definition:COFF.h:448
llvm::object::coff_section::PointerToRawData
support::ulittle32_t PointerToRawData
Definition:COFF.h:453
llvm::object::coff_section::Name
char Name[COFF::NameSize]
Definition:COFF.h:449
llvm::object::coff_section::VirtualSize
support::ulittle32_t VirtualSize
Definition:COFF.h:450
llvm::object::coff_section::hasExtendedRelocations
bool hasExtendedRelocations() const
Definition:COFF.h:462
llvm::object::coff_section::getAlignment
uint32_t getAlignment() const
Definition:COFF.h:467
llvm::object::coff_section::Characteristics
support::ulittle32_t Characteristics
Definition:COFF.h:458
llvm::object::coff_section::SizeOfRawData
support::ulittle32_t SizeOfRawData
Definition:COFF.h:452
llvm::object::coff_section::VirtualAddress
support::ulittle32_t VirtualAddress
Definition:COFF.h:451
llvm::object::coff_section::PointerToRelocations
support::ulittle32_t PointerToRelocations
Definition:COFF.h:454
llvm::object::coff_section::NumberOfRelocations
support::ulittle16_t NumberOfRelocations
Definition:COFF.h:456
llvm::object::coff_symbol_generic
Definition:COFF.h:273
llvm::object::coff_symbol
Definition:COFF.h:254
llvm::object::coff_symbol::NumberOfAuxSymbols
uint8_t NumberOfAuxSymbols
Definition:COFF.h:266
llvm::object::coff_tls_directory
Definition:COFF.h:577
llvm::object::data_directory
Definition:COFF.h:176
llvm::object::data_directory::RelativeVirtualAddress
support::ulittle32_t RelativeVirtualAddress
Definition:COFF.h:177
llvm::object::data_directory::Size
support::ulittle32_t Size
Definition:COFF.h:178
llvm::object::debug_directory
Definition:COFF.h:181
llvm::object::debug_directory::SizeOfData
support::ulittle32_t SizeOfData
Definition:COFF.h:187
llvm::object::debug_directory::AddressOfRawData
support::ulittle32_t AddressOfRawData
Definition:COFF.h:188
llvm::object::delay_import_directory_table_entry
Definition:COFF.h:214
llvm::object::delay_import_directory_table_entry::DelayImportAddressTable
support::ulittle32_t DelayImportAddressTable
Definition:COFF.h:219
llvm::object::delay_import_directory_table_entry::Name
support::ulittle32_t Name
Definition:COFF.h:217
llvm::object::dos_header
The DOS compatible header at the front of all PE/COFF executables.
Definition:COFF.h:57
llvm::object::export_directory_table_entry
Definition:COFF.h:226
llvm::object::export_directory_table_entry::OrdinalBase
support::ulittle32_t OrdinalBase
Definition:COFF.h:232
llvm::object::export_directory_table_entry::ExportAddressTableRVA
support::ulittle32_t ExportAddressTableRVA
Definition:COFF.h:235
llvm::object::export_directory_table_entry::NameRVA
support::ulittle32_t NameRVA
Definition:COFF.h:231
llvm::object::export_directory_table_entry::NumberOfNamePointers
support::ulittle32_t NumberOfNamePointers
Definition:COFF.h:234
llvm::object::export_directory_table_entry::NamePointerRVA
support::ulittle32_t NamePointerRVA
Definition:COFF.h:236
llvm::object::export_directory_table_entry::AddressTableEntries
support::ulittle32_t AddressTableEntries
Definition:COFF.h:233
llvm::object::export_directory_table_entry::OrdinalTableRVA
support::ulittle32_t OrdinalTableRVA
Definition:COFF.h:237
llvm::object::import_lookup_table_entry
Definition:COFF.h:193
llvm::object::import_lookup_table_entry::isOrdinal
bool isOrdinal() const
Definition:COFF.h:196
llvm::object::import_lookup_table_entry::getHintNameRVA
uint32_t getHintNameRVA() const
Definition:COFF.h:203
llvm::object::import_lookup_table_entry::getOrdinal
uint16_t getOrdinal() const
Definition:COFF.h:198
llvm::object::pe32_header
The 32-bit PE header that follows the COFF header.
Definition:COFF.h:108
llvm::object::pe32_header::NumberOfRvaAndSize
support::ulittle32_t NumberOfRvaAndSize
Definition:COFF.h:140
llvm::object::pe32_header::AddressOfEntryPoint
support::ulittle32_t AddressOfEntryPoint
Definition:COFF.h:115
llvm::object::pe32_header::ImageBase
support::ulittle32_t ImageBase
Definition:COFF.h:118
llvm::object::pe32plus_header
The 64-bit PE header that follows the COFF header.
Definition:COFF.h:144
llvm::object::pe32plus_header::ImageBase
support::ulittle64_t ImageBase
Definition:COFF.h:153
llvm::object::pe32plus_header::NumberOfRvaAndSize
support::ulittle32_t NumberOfRvaAndSize
Definition:COFF.h:173
llvm::support::detail::packed_endian_specific_integral
Definition:Endian.h:217
llvm::codeview::DebugInfo
Definition:CVDebugRecord.h:45
llvm::object::DataRefImpl
Definition:SymbolicFile.h:35
llvm::object::DataRefImpl::p
uintptr_t p
Definition:SymbolicFile.h:41
llvm::object::export_address_table_entry
Definition:COFF.h:240
llvm::object::export_address_table_entry::ExportRVA
support::ulittle32_t ExportRVA
Definition:COFF.h:241

Generated on Fri Jul 18 2025 11:45:35 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp