14 #ifndef LLVM_OBJECT_COFF_H 15 #define LLVM_OBJECT_COFF_H 31 #include <system_error> 35 template <
typename T>
class ArrayRef;
40 class DelayImportDirectoryEntryRef;
41 class ExportDirectoryEntryRef;
42 class ImportDirectoryEntryRef;
43 class ImportedSymbolRef;
44 class ResourceSectionRef;
189 template <
typename IntTy>
196 assert(isOrdinal() &&
"ILT entry is not an ordinal!");
197 return Data & 0xFFFF;
201 assert(!isOrdinal() &&
"ILT entry is not a Hint/Name RVA!");
202 return Data & 0xFFFFFFFF;
250 template <
typename SectionNumberType>
288 return CS16 ?
static_cast<const void *
>(CS16) : CS32;
310 return CS16 ? CS16->Name.ShortName : CS32->Name.ShortName;
314 assert(isSet() &&
"COFFSymbolRef points to nothing!");
315 return CS16 ? CS16->Name.Offset : CS32->Name.Offset;
321 assert(isSet() &&
"COFFSymbolRef points to nothing!");
325 return CS16->SectionNumber;
326 return static_cast<int16_t
>(CS16->SectionNumber);
328 return static_cast<int32_t
>(CS32->SectionNumber);
332 assert(isSet() &&
"COFFSymbolRef points to nothing!");
333 return CS16 ? CS16->Type : CS32->Type;
337 assert(isSet() &&
"COFFSymbolRef points to nothing!");
338 return CS16 ? CS16->StorageClass : CS32->StorageClass;
342 assert(isSet() &&
"COFFSymbolRef points to nothing!");
343 return CS16 ? CS16->NumberOfAuxSymbols : CS32->NumberOfAuxSymbols;
352 template <
typename T>
const T *
getAux()
const {
353 return CS16 ?
reinterpret_cast<const T *
>(CS16 + 1)
354 : reinterpret_cast<const T *>(CS32 + 1);
358 if (!getNumberOfAuxSymbols() ||
361 return getAux<coff_aux_section_definition>();
365 if (!getNumberOfAuxSymbols() ||
368 return getAux<coff_aux_weak_external>();
372 return getSectionNumber() == -1;
404 return isUndefined() || isWeakExternal();
418 bool isAppdomainGlobal =
422 if (!getNumberOfAuxSymbols())
424 return isAppdomainGlobal || isOrdinarySection;
432 bool isSet()
const {
return CS16 || CS32; }
454 NumberOfRelocations == UINT16_MAX;
465 uint32_t Shift = (Characteristics >> 20) & 0xF;
467 return 1U << (Shift - 1);
487 "auxiliary entry must be 18 bytes");
498 "auxiliary entry must be 18 bytes");
507 "auxiliary entry must be 18 bytes");
521 Number |=
static_cast<uint32_t>(NumberHighPart) << 16;
522 return static_cast<int32_t
>(Number);
527 "auxiliary entry must be 18 bytes");
537 "auxiliary entry must be 18 bytes");
549 int getType()
const {
return TypeInfo & 0x3; }
561 return ImportLookupTableRVA == 0 && TimeDateStamp == 0 &&
562 ForwarderChain == 0 && NameRVA == 0 && ImportAddressTableRVA == 0;
566 template <
typename IntTy>
577 uint32_t Shift = (Characteristics & 0x00F00000) >> 20;
579 return 1U << (Shift - 1);
715 int getOffset()
const {
return Data & ((1 << 12) - 1); }
723 return maskTrailingOnes<uint32_t>(31) & NameOffset;
727 void setNameOffset(
uint32_t Offset) { NameOffset = Offset | (1 << 31); }
733 bool isSubDir()
const {
return SubdirOffset >> 31; }
735 return maskTrailingOnes<uint32_t>(31) & SubdirOffset;
775 const char *StringTable;
779 uint32_t NumberOfDelayImportDirectory;
786 const void *LoadConfig =
nullptr;
790 template <
typename coff_symbol_type>
791 const coff_symbol_type *toSymb(
DataRefImpl Symb)
const;
795 std::error_code initSymbolTablePtr();
796 std::error_code initImportTablePtr();
797 std::error_code initDelayImportTablePtr();
798 std::error_code initExportTablePtr();
799 std::error_code initBaseRelocPtr();
800 std::error_code initDebugDirectoryPtr();
801 std::error_code initLoadConfigPtr();
806 return reinterpret_cast<uintptr_t
>(SymbolTable16);
808 return reinterpret_cast<uintptr_t
>(SymbolTable32);
815 if (COFFBigObjHeader)
816 return COFFBigObjHeader->
Machine;
825 if (COFFBigObjHeader)
835 if (COFFBigObjHeader)
843 if (COFFBigObjHeader)
851 if (COFFBigObjHeader)
860 if (COFFBigObjHeader)
868 if (COFFBigObjHeader)
874 if (!SymbolTable16 && !SymbolTable32)
876 return getRawNumberOfSymbols();
891 void moveSymbolNext(
DataRefImpl &Symb)
const override;
895 uint64_t getSymbolValueImpl(
DataRefImpl Symb)
const override;
896 uint64_t getCommonSymbolSizeImpl(
DataRefImpl Symb)
const override;
900 void moveSectionNext(
DataRefImpl &Sec)
const override;
903 uint64_t getSectionAddress(
DataRefImpl Sec)
const override;
904 uint64_t getSectionIndex(
DataRefImpl Sec)
const override;
905 uint64_t getSectionSize(
DataRefImpl Sec)
const override;
906 std::error_code getSectionContents(
DataRefImpl Sec,
908 uint64_t getSectionAlignment(
DataRefImpl Sec)
const override;
909 bool isSectionCompressed(
DataRefImpl Sec)
const override;
910 bool isSectionText(
DataRefImpl Sec)
const override;
911 bool isSectionData(
DataRefImpl Sec)
const override;
913 bool isSectionVirtual(
DataRefImpl Sec)
const override;
917 void moveRelocationNext(
DataRefImpl &Rel)
const override;
918 uint64_t getRelocationOffset(
DataRefImpl Rel)
const override;
920 uint64_t getRelocationType(
DataRefImpl Rel)
const override;
939 uint8_t getBytesInAddress()
const override;
940 StringRef getFileFormatName()
const override;
954 return DebugDirectoryBegin;
957 return DebugDirectoryEnd;
962 delay_import_directories()
const;
966 return make_range(debug_directory_begin(), debug_directory_end());
970 if (!PE32Header && !PE32PlusHeader)
972 return reinterpret_cast<const dos_header *
>(base());
977 std::error_code getPE32Header(
const pe32_header *&Res)
const;
979 std::error_code getDataDirectory(
uint32_t index,
985 template <
typename coff_symbol_type>
987 const coff_symbol_type *&Res)
const {
988 if (Index >= getNumberOfSymbols())
991 Res =
reinterpret_cast<coff_symbol_type *
>(getSymbolTable()) + Index;
992 return std::error_code();
997 if (std::error_code EC =
getSymbol(index, Symb))
1001 if (SymbolTable32) {
1003 if (std::error_code EC =
getSymbol(index, Symb))
1010 template <
typename T>
1015 Res =
reinterpret_cast<const T *
>(S->getRawPtr());
1016 return std::error_code();
1030 if (COFFBigObjHeader)
1038 uint64_t getSectionSize(
const coff_section *Sec)
const;
1039 std::error_code getSectionContents(
const coff_section *Sec,
1042 uint64_t getImageBase()
const;
1043 std::error_code getVaPtr(uint64_t VA, uintptr_t &Res)
const;
1044 std::error_code getRvaPtr(
uint32_t Rva, uintptr_t &Res)
const;
1052 std::error_code getHintName(
uint32_t Rva, uint16_t &Hint,
1067 bool isRelocatableObject()
const override;
1068 bool is64()
const {
return PE32PlusHeader; }
1081 : ImportTable(Table),
Index(I), OwningObject(Owner) {}
1095 std::error_code getImportLookupTableRVA(
uint32_t &Result)
const;
1096 std::error_code getImportAddressTableRVA(
uint32_t &Result)
const;
1112 : Table(T),
Index(I), OwningObject(Owner) {}
1122 std::error_code getDelayImportTable(
1124 std::error_code getImportAddress(
int AddrIndex, uint64_t &Result)
const;
1138 : ExportTable(Table),
Index(I), OwningObject(Owner) {}
1143 std::error_code getDllName(
StringRef &Result)
const;
1144 std::error_code getOrdinalBase(
uint32_t &Result)
const;
1145 std::error_code getOrdinal(
uint32_t &Result)
const;
1146 std::error_code getExportRVA(
uint32_t &Result)
const;
1149 std::error_code isForwarder(
bool &Result)
const;
1150 std::error_code getForwardTo(
StringRef &Result)
const;
1163 : Entry32(Entry), Entry64(nullptr),
Index(I), OwningObject(Owner) {}
1166 : Entry32(nullptr), Entry64(Entry),
Index(I), OwningObject(Owner) {}
1172 std::error_code isOrdinal(
bool &Result)
const;
1173 std::error_code getOrdinal(uint16_t &Result)
const;
1174 std::error_code getHintNameRVA(
uint32_t &Result)
const;
1188 : Header(Header),
Index(0) {}
1194 std::error_code getRVA(
uint32_t &Result)
const;
1234 bool hasSEH()
const {
return (Attributes >> 9) & 1; }
1237 bool useBP()
const {
return (Attributes >> 10) & 1; }
1247 #endif // LLVM_OBJECT_COFF_H support::ulittle64_t GuardCFFunctionCount
uint32_t getAlignment() const
support::ulittle32_t GuardCFFunctionTable
coff_symbol< support::ulittle16_t > coff_symbol16
64-bit load config (IMAGE_LOAD_CONFIG_DIRECTORY64)
support::ulittle64_t MaximumAllocationSize
support::ulittle64_t DynamicValueRelocTable
support::ulittle64_t GuardLongJumpTargetCount
support::ulittle16_t MajorVersion
support::ulittle32_t HotPatchTableOffset
support::ulittle64_t GuardCFCheckDispatch
support::ulittle32_t PointerToNextFunction
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer...
support::ulittle32_t CatalogOffset
support::ulittle64_t SecurityCookie
support::ulittle64_t DeCommitTotalFreeThreshold
This class represents lattice values for constants.
support::ulittle32_t TimeDateStamp
support::ulittle16_t MajorVersion
support::ulittle32_t PointerToLinenumbers
support::ulittle32_t Name
support::ulittle32_t OrdinalBase
support::ulittle32_t GlobalFlagsClear
const debug_directory * debug_directory_begin() const
support::ulittle32_t UnloadDelayImportTable
support::ulittle32_t VirtualAddress
support::ulittle32_t Attributes
support::ulittle32_t GuardCFFunctionCount
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
support::ulittle32_t GuardCFCheckDispatch
support::ulittle64_t GuardAddressTakenIatEntryCount
support::ulittle16_t MajorVersion
support::ulittle16_t NumberOfLinenumbers
support::ulittle32_t CHPEMetadataPointer
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null, or not exclusively derived from constant.
support::ulittle64_t GuardRFVerifyStackPointerFunctionPointer
This class is the base class for all object file types.
uint32_t getPointerToSymbolTable() const
support::ulittle32_t PointerToRelocations
32-bit load config (IMAGE_LOAD_CONFIG_DIRECTORY32)
bool isSectionDefinition() const
support::ulittle32_t DynamicValueRelocTableOffset
ImportedSymbolRef(const import_lookup_table_entry64 *Entry, uint32_t I, const COFFObjectFile *Owner)
support::ulittle16_t Flags
uint8_t getNumberOfAuxSymbols() const
support::ulittle16_t NumberLowPart
Error takeError()
Take ownership of the stored error.
detail::packed_endian_specific_integral< uint16_t, little, unaligned > ulittle16_t
uint16_t getSizeOfOptionalHeader() const
support::ulittle32_t TagIndex
uint16_t getOrdinal() const
support::ulittle16_t Data
support::ulittle32_t DelayImportAddressTable
iterator_range< const debug_directory * > debug_directories() const
static unsigned getSymbolSectionID(const ObjectFile &O, SymbolRef Sym)
support::ulittle32_t CheckSum
support::ulittle32_t SecurityCookie
support::ulittle16_t Reserved2
ImportedSymbolRef(const import_lookup_table_entry32 *Entry, uint32_t I, const COFFObjectFile *Owner)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
support::ulittle32_t NameRVA
support::ulittle32_t GuardFlags
support::ulittle64_t GuardLongJumpTargetTable
support::ulittle32_t Reserved
support::ulittle64_t SEHandlerTable
".bf" or ".ef" - beginning or end of function
coff_symbol< support::ulittle32_t > coff_symbol32
support::ulittle16_t MajorVersion
std::error_code getSymbol(uint32_t Index, const coff_symbol_type *&Res) const
static StringRef getSymbolName(SymbolKind SymKind)
support::ulittle32_t Type
support::ulittle16_t NumberOfNameEntries
bool isFunctionLineInfo() const
support::ulittle32_t PointerToRawData
This is a value type class that represents a single relocation in the list of relocations in the obje...
The access may reference the value stored in memory.
const StringTableOffset & getStringTableOffset() const
static StringRef getName(Value *V)
support::ulittle32_t Reserved
support::ulittle32_t NumLocals
Tagged union holding either a T or a Error.
support::ulittle32_t DynamicValueRelocTableOffset
support::ulittle16_t MajorVersion
const int32_t MaxNumberOfSections16
External symbol in dmert public lib.
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
bool isReservedSectionNumber(int32_t SectionNumber)
support::ulittle16_t Reserved2
coff_load_config_code_integrity CodeIntegrity
uint8_t getStorageClass() const
Expected< COFFSymbolRef > getSymbol(uint32_t index) const
support::ulittle32_t VirtualSize
support::ulittle64_t LockPrefixTable
support::ulittle64_t GuardAddressTakenIatEntryTable
support::ulittle16_t DynamicValueRelocTableSection
int32_t getSectionNumber() const
support::ulittle32_t ExportFlags
support::ulittle64_t GuardRFFailureRoutineFunctionPointer
bool isFunctionDefinition() const
Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))
support::ulittle16_t MinorVersion
support::ulittle16_t NumParams
support::ulittle32_t NamePointerRVA
uint8_t getComplexType() const
support::ulittle32_t ExportRVA
support::ulittle32_t NameRVA
support::ulittle32_t Size
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
support::ulittle32_t GlobalFlagsSet
IntTy StartAddressOfRawData
Analysis containing CSE Info
int32_t getNumber(bool IsBigObj) const
support::ulittle16_t MinorVersion
int getPrologSize() const
support::ulittle32_t TagIndex
support::ulittle32_t ProcessHeapFlags
support::ulittle32_t GlobalFlagsSet
support::ulittle32_t ProcessHeapFlags
support::ulittle32_t GuardAddressTakenIatEntryTable
support::ulittle32_t Characteristics
support::ulittle16_t NumberHighPart
support::ulittle32_t Characteristics
std::error_code getAuxSymbol(uint32_t index, const T *&Res) const
support::ulittle32_t DeCommitTotalFreeThreshold
uint16_t getCharacteristics() const
uint32_t getRawNumberOfSymbols() const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
support::ulittle16_t NumberOfIDEntries
The instances of the Type class are immutable: once they are created, they are never changed...
detail::packed_endian_specific_integral< uint32_t, little, unaligned > ulittle32_t
Line number, reformatted as symbol.
support::ulittle32_t SubdirOffset
support::ulittle32_t SizeOfZeroFill
support::ulittle32_t VirtualMemoryThreshold
support::ulittle32_t MaximumAllocationSize
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
const dos_header * getDOSHeader() const
uint32_t getHintNameRVA() const
support::ulittle32_t SymbolTableIndex
support::ulittle16_t MinorVersion
support::ulittle32_t CriticalSectionDefaultTimeout
COFFSymbolRef(const coff_symbol16 *CS)
COFFSymbolRef(const coff_symbol32 *CS)
support::ulittle32_t Size
support::ulittle32_t RelativeVirtualAddress
support::ulittle32_t Value
support::ulittle32_t TimeStamp
support::ulittle32_t DataSize
No type information or unknown base type.
const coff_aux_section_definition * getSectionDefinition() const
support::ulittle32_t ImportAddressTableRVA
support::ulittle32_t NameOffset
support::ulittle32_t Characteristics
const void * getRawPtr() const
support::ulittle16_t Type
int getNumSavedRegs() const
support::ulittle32_t EndAddress
support::ulittle32_t OrdinalTableRVA
support::ulittle32_t GuardRFFailureRoutine
const coff_symbol_generic * getGeneric() const
support::ulittle32_t SizeOfRawData
SubtargetFeatures getFeatures() const override
static unsigned getSectionID(const ObjectFile &O, SectionRef Sec)
support::ulittle16_t Linenumber
DelayImportDirectoryEntryRef(const delay_import_directory_table_entry *T, uint32_t I, const COFFObjectFile *Owner)
support::ulittle32_t ForwarderChain
static wasm::ValType getType(const TargetRegisterClass *RC)
support::ulittle32_t VirtualAddress
support::ulittle32_t SymbolTableIndex
const debug_directory * debug_directory_end() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint16_t getMachine() const
const coff_aux_weak_external * getWeakExternal() const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
support::ulittle32_t TimeDateStamp
support::ulittle32_t TimeDateStamp
support::ulittle64_t ProcessAffinityMask
support::ulittle32_t PointerToRawData
support::ulittle64_t GuardCFCheckFunction
SectionNumberType SectionNumber
support::ulittle16_t MinorVersion
support::ulittle64_t VirtualMemoryThreshold
support::ulittle32_t BeginAddress
support::ulittle32_t DataEntryOffset
coff_load_config_code_integrity CodeIntegrity
BaseRelocRef(const coff_base_reloc_block_header *Header, const COFFObjectFile *Owner)
uint32_t getNumberOfSections() const
support::ulittle32_t GuardLongJumpTargetCount
bool operator==(const DataRefImpl &a, const DataRefImpl &b)
support::ulittle16_t CSDVersion
support::ulittle16_t CSDVersion
ExportDirectoryEntryRef(const export_directory_table_entry *Table, uint32_t I, const COFFObjectFile *Owner)
support::ulittle64_t SEHandlerCount
support::ulittle16_t DependentLoadFlags
support::ulittle32_t GlobalFlagsClear
support::ulittle16_t NumberOfRelocations
friend bool operator<(COFFSymbolRef A, COFFSymbolRef B)
support::ulittle32_t SEHandlerTable
IntTy EndAddressOfRawData
support::ulittle32_t Offset
support::ulittle32_t ModuleHandle
support::ulittle32_t ForwarderRVA
A range adaptor for a pair of iterators.
support::ulittle32_t EditList
support::ulittle32_t AddressOfRawData
Manages the enabling and disabling of subtarget specific features.
size_t getSymbolTableEntrySize() const
support::ulittle32_t Size
uint32_t getAlignment() const
uint32_t getTimeDateStamp() const
This is a value type class that represents a single symbol in the list of symbols in the object file...
const char * getShortName() const
support::ulittle16_t Attributes
static std::unique_ptr< PDBSymbol > getSymbolType(const PDBSymbol &Symbol)
support::ulittle32_t GuardRFVerifyStackPointerFunctionPointer
support::ulittle32_t Zeroes
ImportDirectoryEntryRef(const coff_import_directory_table_entry *Table, uint32_t I, const COFFObjectFile *Owner)
support::ulittle16_t DynamicValueRelocTableSection
support::ulittle32_t DynamicValueRelocTable
support::ulittle32_t NumberOfNamePointers
bool isWeakExternal() const
support::ulittle32_t GuardAddressTakenIatEntryCount
support::ulittle32_t GuardFlags
support::ulittle32_t PointerToNextFunction
ResourceSectionRef(StringRef Ref)
uint8_t getBaseType() const
support::ulittle32_t Characteristics
support::ulittle16_t DependentLoadFlags
support::ulittle32_t ImportLookupTableRVA
support::ulittle32_t AddressTableEntries
support::ulittle32_t TimeDateStamp
const coff_load_configuration32 * getLoadConfig32() const
support::ulittle32_t GuardLongJumpTargetTable
support::ulittle32_t DataRVA
support::ulittle32_t PointerToLinenumber
bool isAnyUndefined() const
support::ulittle64_t EditList
support::ulittle16_t NumberOfLinenumbers
support::ulittle64_t CHPEMetadataPointer
support::ulittle32_t Length
support::ulittle32_t CriticalSectionDefaultTimeout
support::ulittle16_t NumberOfRelocations
uint8_t NumberOfAuxSymbols
support::ulittle32_t SizeOfData
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
support::ulittle32_t Size
support::ulittle16_t Catalog
support::ulittle32_t GuardCFCheckFunction
coff_guard_flags
Bits in control flow guard flags as we understand them.
uintptr_t getSymbolTable() const
bool isFileRecord() const
support::ulittle32_t DeCommitFreeBlockThreshold
support::ulittle32_t GuardRFFailureRoutineFunctionPointer
support::ulittle32_t Value
const coff_load_configuration64 * getLoadConfig64() const
static bool classof(const Binary *v)
support::ulittle32_t ExportAddressTableRVA
Lightweight error class with error context and mandatory checking.
support::ulittle32_t TimeDateStamp
support::ulittle32_t HotPatchTableOffset
support::ulittle64_t GuardCFFunctionTable
uint32_t getValue() const
StringRef - Represent a constant reference to a string, i.e.
bool hasExtendedRelocations() const
support::ulittle32_t DelayImportNameTable
support::ulittle32_t Characteristics
support::ulittle32_t TimeDateStamp
support::ulittle64_t GuardRFFailureRoutine
support::ulittle16_t MinorVersion
support::ulittle32_t Codepage
support::ulittle32_t SEHandlerCount
support::ulittle32_t TotalSize
support::ulittle32_t ProcessAffinityMask
support::ulittle16_t Type
std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
support::ulittle32_t UnwindInformation
support::ulittle32_t LockPrefixTable
support::ulittle32_t BoundDelayImportTable
support::ulittle64_t DeCommitFreeBlockThreshold
This is a value type class that represents a single section in the list of sections in the object fil...
uint32_t getNumberOfSymbols() const
support::ulittle32_t Offset
A function that returns a base type.