summaryrefslogtreecommitdiff
path: root/include/llvm/Object
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Object')
-rw-r--r--include/llvm/Object/COFF.h100
-rw-r--r--include/llvm/Object/IRSymtab.h6
-rw-r--r--include/llvm/Object/MachO.h6
-rw-r--r--include/llvm/Object/Wasm.h31
-rw-r--r--include/llvm/Object/WindowsResource.h57
5 files changed, 170 insertions, 30 deletions
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h
index ae695a529597b..bf0172822d3fc 100644
--- a/include/llvm/Object/COFF.h
+++ b/include/llvm/Object/COFF.h
@@ -562,8 +562,26 @@ struct coff_tls_directory {
using coff_tls_directory32 = coff_tls_directory<support::little32_t>;
using coff_tls_directory64 = coff_tls_directory<support::little64_t>;
+/// Bits in control flow guard flags as we understand them.
+enum class coff_guard_flags : uint32_t {
+ CFInstrumented = 0x00000100,
+ HasFidTable = 0x00000400,
+ ProtectDelayLoadIAT = 0x00001000,
+ DelayLoadIATSection = 0x00002000, // Delay load in separate section
+ HasLongJmpTable = 0x00010000,
+ FidTableHasFlags = 0x10000000, // Indicates that fid tables are 5 bytes
+};
+
+struct coff_load_config_code_integrity {
+ support::ulittle16_t Flags;
+ support::ulittle16_t Catalog;
+ support::ulittle32_t CatalogOffset;
+ support::ulittle32_t Reserved;
+};
+
+/// 32-bit load config (IMAGE_LOAD_CONFIG_DIRECTORY32)
struct coff_load_configuration32 {
- support::ulittle32_t Characteristics;
+ support::ulittle32_t Size;
support::ulittle32_t TimeDateStamp;
support::ulittle16_t MajorVersion;
support::ulittle16_t MinorVersion;
@@ -578,34 +596,81 @@ struct coff_load_configuration32 {
support::ulittle32_t ProcessAffinityMask;
support::ulittle32_t ProcessHeapFlags;
support::ulittle16_t CSDVersion;
- support::ulittle16_t Reserved;
+ support::ulittle16_t DependentLoadFlags;
support::ulittle32_t EditList;
support::ulittle32_t SecurityCookie;
support::ulittle32_t SEHandlerTable;
support::ulittle32_t SEHandlerCount;
+
+ // Added in MSVC 2015 for /guard:cf.
+ support::ulittle32_t GuardCFCheckFunction;
+ support::ulittle32_t GuardCFCheckDispatch;
+ support::ulittle32_t GuardCFFunctionTable;
+ support::ulittle32_t GuardCFFunctionCount;
+ support::ulittle32_t GuardFlags; // coff_guard_flags
+
+ // Added in MSVC 2017
+ coff_load_config_code_integrity CodeIntegrity;
+ support::ulittle32_t GuardAddressTakenIatEntryTable;
+ support::ulittle32_t GuardAddressTakenIatEntryCount;
+ support::ulittle32_t GuardLongJumpTargetTable;
+ support::ulittle32_t GuardLongJumpTargetCount;
+ support::ulittle32_t DynamicValueRelocTable;
+ support::ulittle32_t CHPEMetadataPointer;
+ support::ulittle32_t GuardRFFailureRoutine;
+ support::ulittle32_t GuardRFFailureRoutineFunctionPointer;
+ support::ulittle32_t DynamicValueRelocTableOffset;
+ support::ulittle16_t DynamicValueRelocTableSection;
+ support::ulittle16_t Reserved2;
+ support::ulittle32_t GuardRFVerifyStackPointerFunctionPointer;
+ support::ulittle32_t HotPatchTableOffset;
};
+/// 64-bit load config (IMAGE_LOAD_CONFIG_DIRECTORY64)
struct coff_load_configuration64 {
- support::ulittle32_t Characteristics;
+ support::ulittle32_t Size;
support::ulittle32_t TimeDateStamp;
support::ulittle16_t MajorVersion;
support::ulittle16_t MinorVersion;
support::ulittle32_t GlobalFlagsClear;
support::ulittle32_t GlobalFlagsSet;
support::ulittle32_t CriticalSectionDefaultTimeout;
- support::ulittle32_t DeCommitFreeBlockThreshold;
- support::ulittle32_t DeCommitTotalFreeThreshold;
- support::ulittle32_t LockPrefixTable;
- support::ulittle32_t MaximumAllocationSize;
- support::ulittle32_t VirtualMemoryThreshold;
- support::ulittle32_t ProcessAffinityMask;
+ support::ulittle64_t DeCommitFreeBlockThreshold;
+ support::ulittle64_t DeCommitTotalFreeThreshold;
+ support::ulittle64_t LockPrefixTable;
+ support::ulittle64_t MaximumAllocationSize;
+ support::ulittle64_t VirtualMemoryThreshold;
+ support::ulittle64_t ProcessAffinityMask;
support::ulittle32_t ProcessHeapFlags;
support::ulittle16_t CSDVersion;
- support::ulittle16_t Reserved;
- support::ulittle32_t EditList;
+ support::ulittle16_t DependentLoadFlags;
+ support::ulittle64_t EditList;
support::ulittle64_t SecurityCookie;
support::ulittle64_t SEHandlerTable;
support::ulittle64_t SEHandlerCount;
+
+ // Added in MSVC 2015 for /guard:cf.
+ support::ulittle64_t GuardCFCheckFunction;
+ support::ulittle64_t GuardCFCheckDispatch;
+ support::ulittle64_t GuardCFFunctionTable;
+ support::ulittle64_t GuardCFFunctionCount;
+ support::ulittle32_t GuardFlags;
+
+ // Added in MSVC 2017
+ coff_load_config_code_integrity CodeIntegrity;
+ support::ulittle64_t GuardAddressTakenIatEntryTable;
+ support::ulittle64_t GuardAddressTakenIatEntryCount;
+ support::ulittle64_t GuardLongJumpTargetTable;
+ support::ulittle64_t GuardLongJumpTargetCount;
+ support::ulittle64_t DynamicValueRelocTable;
+ support::ulittle64_t CHPEMetadataPointer;
+ support::ulittle64_t GuardRFFailureRoutine;
+ support::ulittle64_t GuardRFFailureRoutineFunctionPointer;
+ support::ulittle32_t DynamicValueRelocTableOffset;
+ support::ulittle16_t DynamicValueRelocTableSection;
+ support::ulittle16_t Reserved2;
+ support::ulittle64_t GuardRFVerifyStackPointerFunctionPointer;
+ support::ulittle32_t HotPatchTableOffset;
};
struct coff_runtime_function_x64 {
@@ -684,6 +749,8 @@ private:
const coff_base_reloc_block_header *BaseRelocEnd;
const debug_directory *DebugDirectoryBegin;
const debug_directory *DebugDirectoryEnd;
+ // Either coff_load_configuration32 or coff_load_configuration64.
+ const void *LoadConfig;
std::error_code getString(uint32_t offset, StringRef &Res) const;
@@ -698,6 +765,7 @@ private:
std::error_code initExportTablePtr();
std::error_code initBaseRelocPtr();
std::error_code initDebugDirectoryPtr();
+ std::error_code initLoadConfigPtr();
public:
uintptr_t getSymbolTable() const {
@@ -775,6 +843,16 @@ public:
return getRawNumberOfSymbols();
}
+ const coff_load_configuration32 *getLoadConfig32() const {
+ assert(!is64());
+ return reinterpret_cast<const coff_load_configuration32 *>(LoadConfig);
+ }
+
+ const coff_load_configuration64 *getLoadConfig64() const {
+ assert(is64());
+ return reinterpret_cast<const coff_load_configuration64 *>(LoadConfig);
+ }
+
protected:
void moveSymbolNext(DataRefImpl &Symb) const override;
Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
diff --git a/include/llvm/Object/IRSymtab.h b/include/llvm/Object/IRSymtab.h
index 5b832141a8651..502f133d307dd 100644
--- a/include/llvm/Object/IRSymtab.h
+++ b/include/llvm/Object/IRSymtab.h
@@ -38,6 +38,7 @@
namespace llvm {
struct BitcodeFileContents;
+class StringTableBuilder;
namespace irsymtab {
@@ -136,9 +137,10 @@ struct Header {
} // end namespace storage
-/// Fills in Symtab and Strtab with a valid symbol and string table for Mods.
+/// Fills in Symtab and StrtabBuilder with a valid symbol and string table for
+/// Mods.
Error build(ArrayRef<Module *> Mods, SmallVector<char, 0> &Symtab,
- SmallVector<char, 0> &Strtab);
+ StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc);
/// This represents a symbol that has been read from a storage::Symbol and
/// possibly a storage::Uncommon.
diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h
index 3fc726f4ccb8e..2c3c89d10546f 100644
--- a/include/llvm/Object/MachO.h
+++ b/include/llvm/Object/MachO.h
@@ -304,6 +304,12 @@ public:
relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
+ relocation_iterator extrel_begin() const;
+ relocation_iterator extrel_end() const;
+ iterator_range<relocation_iterator> external_relocations() const {
+ return make_range(extrel_begin(), extrel_end());
+ }
+
void moveRelocationNext(DataRefImpl &Rel) const override;
uint64_t getRelocationOffset(DataRefImpl Rel) const override;
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
diff --git a/include/llvm/Object/Wasm.h b/include/llvm/Object/Wasm.h
index 10edc461b9e9c..9d53131234f43 100644
--- a/include/llvm/Object/Wasm.h
+++ b/include/llvm/Object/Wasm.h
@@ -19,6 +19,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringMap.h"
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/ObjectFile.h"
@@ -48,7 +49,24 @@ public:
StringRef Name;
SymbolType Type;
uint32_t Section;
+ uint32_t Flags = 0;
+
+ // Index into the imports, exports or functions array of the object depending
+ // on the type
uint32_t ElementIndex;
+
+ bool isWeak() const {
+ return Flags & wasm::WASM_SYMBOL_FLAG_WEAK;
+ }
+
+ void print(raw_ostream &Out) const {
+ Out << "Name=" << Name << ", Type=" << static_cast<int>(Type)
+ << ", Flags=" << Flags;
+ }
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const { print(dbgs()); }
+#endif
};
class WasmSection {
@@ -63,6 +81,7 @@ public:
};
class WasmObjectFile : public ObjectFile {
+
public:
WasmObjectFile(MemoryBufferRef Object, Error &Err);
@@ -176,6 +195,7 @@ private:
// Custom section types
Error parseNameSection(const uint8_t *Ptr, const uint8_t *End);
+ Error parseLinkingSection(const uint8_t *Ptr, const uint8_t *End);
Error parseRelocSection(StringRef Name, const uint8_t *Ptr,
const uint8_t *End);
@@ -190,13 +210,22 @@ private:
std::vector<wasm::WasmExport> Exports;
std::vector<wasm::WasmElemSegment> ElemSegments;
std::vector<wasm::WasmDataSegment> DataSegments;
- std::vector<WasmSymbol> Symbols;
std::vector<wasm::WasmFunction> Functions;
+ std::vector<WasmSymbol> Symbols;
ArrayRef<uint8_t> CodeSection;
uint32_t StartFunction = -1;
+
+ StringMap<uint32_t> SymbolMap;
};
} // end namespace object
+
+inline raw_ostream &operator<<(raw_ostream &OS,
+ const object::WasmSymbol &Sym) {
+ Sym.print(OS);
+ return OS;
+}
+
} // end namespace llvm
#endif // LLVM_OBJECT_WASM_H
diff --git a/include/llvm/Object/WindowsResource.h b/include/llvm/Object/WindowsResource.h
index 4839013c8228c..3d32409fd4aca 100644
--- a/include/llvm/Object/WindowsResource.h
+++ b/include/llvm/Object/WindowsResource.h
@@ -30,7 +30,6 @@
#define LLVM_INCLUDE_LLVM_OBJECT_RESFILE_H
#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/Error.h"
@@ -44,14 +43,47 @@
#include <map>
namespace llvm {
-
-class FileOutputBuffer;
-
namespace object {
class WindowsResource;
-enum class Machine { UNKNOWN, ARM, X64, X86 };
+const size_t WIN_RES_MAGIC_SIZE = 16;
+const size_t WIN_RES_NULL_ENTRY_SIZE = 16;
+const uint32_t WIN_RES_HEADER_ALIGNMENT = 4;
+const uint32_t WIN_RES_DATA_ALIGNMENT = 4;
+const uint16_t WIN_RES_PURE_MOVEABLE = 0x0030;
+
+struct WinResHeaderPrefix {
+ support::ulittle32_t DataSize;
+ support::ulittle32_t HeaderSize;
+};
+
+// Type and Name may each either be an integer ID or a string. This struct is
+// only used in the case where they are both IDs.
+struct WinResIDs {
+ uint16_t TypeFlag;
+ support::ulittle16_t TypeID;
+ uint16_t NameFlag;
+ support::ulittle16_t NameID;
+
+ void setType(uint16_t ID) {
+ TypeFlag = 0xffff;
+ TypeID = ID;
+ }
+
+ void setName(uint16_t ID) {
+ NameFlag = 0xffff;
+ NameID = ID;
+ }
+};
+
+struct WinResHeaderSuffix {
+ support::ulittle32_t DataVersion;
+ support::ulittle16_t MemoryFlags;
+ support::ulittle16_t Language;
+ support::ulittle32_t Version;
+ support::ulittle32_t Characteristics;
+};
class ResourceEntryRef {
public:
@@ -76,14 +108,6 @@ private:
Error loadNext();
- struct HeaderSuffix {
- support::ulittle32_t DataVersion;
- support::ulittle16_t MemoryFlags;
- support::ulittle16_t Language;
- support::ulittle32_t Version;
- support::ulittle32_t Characteristics;
- };
-
BinaryStreamReader Reader;
bool IsStringType;
ArrayRef<UTF16> Type;
@@ -91,7 +115,7 @@ private:
bool IsStringName;
ArrayRef<UTF16> Name;
uint16_t NameID;
- const HeaderSuffix *Suffix = nullptr;
+ const WinResHeaderSuffix *Suffix = nullptr;
ArrayRef<uint8_t> Data;
const WindowsResource *OwningRes = nullptr;
};
@@ -185,8 +209,9 @@ private:
std::vector<std::vector<UTF16>> StringTable;
};
-Error writeWindowsResourceCOFF(StringRef OutputFile, Machine MachineType,
- const WindowsResourceParser &Parser);
+Expected<std::unique_ptr<MemoryBuffer>>
+writeWindowsResourceCOFF(llvm::COFF::MachineTypes MachineType,
+ const WindowsResourceParser &Parser);
} // namespace object
} // namespace llvm