diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
commit | d8e91e46262bc44006913e6796843909f1ac7bcd (patch) | |
tree | 7d0c143d9b38190e0fa0180805389da22cd834c5 /include/llvm/Object | |
parent | b7eb8e35e481a74962664b63dfb09483b200209a (diff) |
Notes
Diffstat (limited to 'include/llvm/Object')
-rw-r--r-- | include/llvm/Object/COFF.h | 12 | ||||
-rw-r--r-- | include/llvm/Object/ELF.h | 8 | ||||
-rw-r--r-- | include/llvm/Object/ELFObjectFile.h | 29 | ||||
-rw-r--r-- | include/llvm/Object/ELFTypes.h | 25 | ||||
-rw-r--r-- | include/llvm/Object/Error.h | 1 | ||||
-rw-r--r-- | include/llvm/Object/MachO.h | 5 | ||||
-rw-r--r-- | include/llvm/Object/ObjectFile.h | 22 | ||||
-rw-r--r-- | include/llvm/Object/RelocVisitor.h | 3 | ||||
-rw-r--r-- | include/llvm/Object/Wasm.h | 89 | ||||
-rw-r--r-- | include/llvm/Object/WasmTraits.h | 14 |
10 files changed, 174 insertions, 34 deletions
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index 6caadea0175b..b753d261a0fc 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -594,6 +594,8 @@ enum class coff_guard_flags : uint32_t { FidTableHasFlags = 0x10000000, // Indicates that fid tables are 5 bytes }; +enum class frame_type : uint16_t { Fpo = 0, Trap = 1, Tss = 2, NonFpo = 3 }; + struct coff_load_config_code_integrity { support::ulittle16_t Flags; support::ulittle16_t Catalog; @@ -883,6 +885,7 @@ public: assert(is64()); return reinterpret_cast<const coff_load_configuration64 *>(LoadConfig); } + StringRef getRelocationTypeName(uint16_t Type) const; protected: void moveSymbolNext(DataRefImpl &Symb) const override; @@ -968,6 +971,9 @@ public: return nullptr; return reinterpret_cast<const dos_header *>(base()); } + std::error_code getCOFFHeader(const coff_file_header *&Res) const; + std::error_code + getCOFFBigObjHeader(const coff_bigobj_file_header *&Res) const; std::error_code getPE32Header(const pe32_header *&Res) const; std::error_code getPE32PlusHeader(const pe32plus_header *&Res) const; std::error_code getDataDirectory(uint32_t index, @@ -1016,6 +1022,8 @@ public: ArrayRef<uint8_t> getSymbolAuxData(COFFSymbolRef Symbol) const; + uint32_t getSymbolIndex(COFFSymbolRef Symbol) const; + size_t getSymbolTableEntrySize() const { if (COFFHeader) return sizeof(coff_symbol16); @@ -1059,6 +1067,8 @@ public: bool isRelocatableObject() const override; bool is64() const { return PE32PlusHeader; } + StringRef mapDebugSectionName(StringRef Name) const override; + static bool classof(const Binary *v) { return v->isCOFF(); } }; @@ -1227,7 +1237,7 @@ struct FpoData { bool useBP() const { return (Attributes >> 10) & 1; } // cbFrame: frame pointer - int getFP() const { return Attributes >> 14; } + frame_type getFP() const { return static_cast<frame_type>(Attributes >> 14); } }; } // end namespace object diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index 752d468fd25b..bcdc190cc7dc 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -32,7 +32,7 @@ namespace llvm { namespace object { StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type); -uint32_t getELFRelrRelocationType(uint32_t Machine); +uint32_t getELFRelativeRelocationType(uint32_t Machine); StringRef getELFSectionTypeName(uint32_t Machine, uint32_t Type); // Subclasses of ELFFile may need this for template instantiation @@ -113,7 +113,7 @@ public: StringRef getRelocationTypeName(uint32_t Type) const; void getRelocationTypeName(uint32_t Type, SmallVectorImpl<char> &Result) const; - uint32_t getRelrRelocationType() const; + uint32_t getRelativeRelocationType() const; const char *getDynamicTagAsString(unsigned Arch, uint64_t Type) const; const char *getDynamicTagAsString(uint64_t Type) const; @@ -415,8 +415,8 @@ void ELFFile<ELFT>::getRelocationTypeName(uint32_t Type, } template <class ELFT> -uint32_t ELFFile<ELFT>::getRelrRelocationType() const { - return getELFRelrRelocationType(getHeader()->e_machine); +uint32_t ELFFile<ELFT>::getRelativeRelocationType() const { + return getELFRelativeRelocationType(getHeader()->e_machine); } template <class ELFT> diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index 2c0905d545a7..0f620681cd99 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -86,6 +86,8 @@ public: void setARMSubArch(Triple &TheTriple) const override; virtual uint16_t getEType() const = 0; + + std::vector<std::pair<DataRefImpl, uint64_t>> getPltAddresses() const; }; class ELFSectionRef : public SectionRef { @@ -258,6 +260,8 @@ protected: bool isSectionData(DataRefImpl Sec) const override; bool isSectionBSS(DataRefImpl Sec) const override; bool isSectionVirtual(DataRefImpl Sec) const override; + bool isBerkeleyText(DataRefImpl Sec) const override; + bool isBerkeleyData(DataRefImpl Sec) const override; relocation_iterator section_rel_begin(DataRefImpl Sec) const override; relocation_iterator section_rel_end(DataRefImpl Sec) const override; std::vector<SectionRef> dynamic_relocation_sections() const override; @@ -331,9 +335,10 @@ protected: // A symbol is exported if its binding is either GLOBAL or WEAK, and its // visibility is either DEFAULT or PROTECTED. All other symbols are not // exported. - return ((Binding == ELF::STB_GLOBAL || Binding == ELF::STB_WEAK) && - (Visibility == ELF::STV_DEFAULT || - Visibility == ELF::STV_PROTECTED)); + return ( + (Binding == ELF::STB_GLOBAL || Binding == ELF::STB_WEAK || + Binding == ELF::STB_GNU_UNIQUE) && + (Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_PROTECTED)); } // This flag is used for classof, to distinguish ELFObjectFile from @@ -757,6 +762,20 @@ bool ELFObjectFile<ELFT>::isSectionVirtual(DataRefImpl Sec) const { } template <class ELFT> +bool ELFObjectFile<ELFT>::isBerkeleyText(DataRefImpl Sec) const { + return getSection(Sec)->sh_flags & ELF::SHF_ALLOC && + (getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR || + !(getSection(Sec)->sh_flags & ELF::SHF_WRITE)); +} + +template <class ELFT> +bool ELFObjectFile<ELFT>::isBerkeleyData(DataRefImpl Sec) const { + const Elf_Shdr *EShdr = getSection(Sec); + return !isBerkeleyText(Sec) && EShdr->sh_type != ELF::SHT_NOBITS && + EShdr->sh_flags & ELF::SHF_ALLOC; +} + +template <class ELFT> relocation_iterator ELFObjectFile<ELFT>::section_rel_begin(DataRefImpl Sec) const { DataRefImpl RelData; @@ -1019,6 +1038,8 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const { return "ELF32-lanai"; case ELF::EM_MIPS: return "ELF32-mips"; + case ELF::EM_MSP430: + return "ELF32-msp430"; case ELF::EM_PPC: return "ELF32-ppc"; case ELF::EM_RISCV: @@ -1089,6 +1110,8 @@ template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const { default: report_fatal_error("Invalid ELFCLASS!"); } + case ELF::EM_MSP430: + return Triple::msp430; case ELF::EM_PPC: return Triple::ppc; case ELF::EM_PPC64: diff --git a/include/llvm/Object/ELFTypes.h b/include/llvm/Object/ELFTypes.h index fb386120e34d..ec3c8e7bae46 100644 --- a/include/llvm/Object/ELFTypes.h +++ b/include/llvm/Object/ELFTypes.h @@ -605,13 +605,12 @@ public: } /// Get the note's descriptor. - ArrayRef<Elf_Word> getDesc() const { + ArrayRef<uint8_t> getDesc() const { if (!Nhdr.n_descsz) - return ArrayRef<Elf_Word>(); - return ArrayRef<Elf_Word>( - reinterpret_cast<const Elf_Word *>( - reinterpret_cast<const uint8_t *>(&Nhdr) + sizeof(Nhdr) + - alignTo<Elf_Nhdr_Impl<ELFT>::Align>(Nhdr.n_namesz)), + return ArrayRef<uint8_t>(); + return ArrayRef<uint8_t>( + reinterpret_cast<const uint8_t *>(&Nhdr) + sizeof(Nhdr) + + alignTo<Elf_Nhdr_Impl<ELFT>::Align>(Nhdr.n_namesz), Nhdr.n_descsz); } @@ -643,14 +642,19 @@ class Elf_Note_Iterator_Impl // container, either cleanly or with an overflow error. void advanceNhdr(const uint8_t *NhdrPos, size_t NoteSize) { RemainingSize -= NoteSize; - if (RemainingSize == 0u) + if (RemainingSize == 0u) { + // Ensure that if the iterator walks to the end, the error is checked + // afterwards. + *Err = Error::success(); Nhdr = nullptr; - else if (sizeof(*Nhdr) > RemainingSize) + } else if (sizeof(*Nhdr) > RemainingSize) stopWithOverflowError(); else { Nhdr = reinterpret_cast<const Elf_Nhdr_Impl<ELFT> *>(NhdrPos + NoteSize); if (Nhdr->getSize() > RemainingSize) stopWithOverflowError(); + else + *Err = Error::success(); } } @@ -658,6 +662,7 @@ class Elf_Note_Iterator_Impl explicit Elf_Note_Iterator_Impl(Error &Err) : Err(&Err) {} Elf_Note_Iterator_Impl(const uint8_t *Start, size_t Size, Error &Err) : RemainingSize(Size), Err(&Err) { + consumeError(std::move(Err)); assert(Start && "ELF note iterator starting at NULL"); advanceNhdr(Start, 0u); } @@ -671,6 +676,10 @@ public: return *this; } bool operator==(Elf_Note_Iterator_Impl Other) const { + if (!Nhdr && Other.Err) + (void)(bool)(*Other.Err); + if (!Other.Nhdr && Err) + (void)(bool)(*Err); return Nhdr == Other.Nhdr; } bool operator!=(Elf_Note_Iterator_Impl Other) const { diff --git a/include/llvm/Object/Error.h b/include/llvm/Object/Error.h index eb938338715d..a15f8b9236eb 100644 --- a/include/llvm/Object/Error.h +++ b/include/llvm/Object/Error.h @@ -50,6 +50,7 @@ inline std::error_code make_error_code(object_error e) { /// Currently inherits from ECError for easy interoperability with /// std::error_code, but this will be removed in the future. class BinaryError : public ErrorInfo<BinaryError, ECError> { + virtual void anchor(); public: static char ID; BinaryError() { diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 159c1765ab86..c2f4f4062934 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -356,7 +356,7 @@ public: basic_symbol_iterator symbol_end() const override; // MachO specific. - basic_symbol_iterator getSymbolByIndex(unsigned Index) const; + symbol_iterator getSymbolByIndex(unsigned Index) const; uint64_t getSymbolIndex(DataRefImpl Symb) const; section_iterator section_begin() const override; @@ -616,6 +616,9 @@ public: case MachO::PLATFORM_TVOS: return "tvos"; case MachO::PLATFORM_WATCHOS: return "watchos"; case MachO::PLATFORM_BRIDGEOS: return "bridgeos"; + case MachO::PLATFORM_IOSSIMULATOR: return "iossimulator"; + case MachO::PLATFORM_TVOSSIMULATOR: return "tvossimulator"; + case MachO::PLATFORM_WATCHOSSIMULATOR: return "watchossimulator"; default: std::string ret; raw_string_ostream ss(ret); diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 02d62e8e4879..036c99cb6baf 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -104,13 +104,25 @@ public: uint64_t getAlignment() const; bool isCompressed() const; + /// Whether this section contains instructions. bool isText() const; + /// Whether this section contains data, not instructions. bool isData() const; + /// Whether this section contains BSS uninitialized data. bool isBSS() const; bool isVirtual() const; bool isBitcode() const; bool isStripped() const; + /// Whether this section will be placed in the text segment, according to the + /// Berkeley size format. This is true if the section is allocatable, and + /// contains either code or readonly data. + bool isBerkeleyText() const; + /// Whether this section will be placed in the data segment, according to the + /// Berkeley size format. This is true if the section is allocatable and + /// contains data (e.g. PROGBITS), but is not text. + bool isBerkeleyData() const; + bool containsSymbol(SymbolRef S) const; relocation_iterator relocation_begin() const; @@ -238,6 +250,8 @@ protected: virtual bool isSectionVirtual(DataRefImpl Sec) const = 0; virtual bool isSectionBitcode(DataRefImpl Sec) const; virtual bool isSectionStripped(DataRefImpl Sec) const; + virtual bool isBerkeleyText(DataRefImpl Sec) const; + virtual bool isBerkeleyData(DataRefImpl Sec) const; virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0; virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0; virtual section_iterator getRelocatedSection(DataRefImpl Sec) const; @@ -449,6 +463,14 @@ inline bool SectionRef::isStripped() const { return OwningObject->isSectionStripped(SectionPimpl); } +inline bool SectionRef::isBerkeleyText() const { + return OwningObject->isBerkeleyText(SectionPimpl); +} + +inline bool SectionRef::isBerkeleyData() const { + return OwningObject->isBerkeleyData(SectionPimpl); +} + inline relocation_iterator SectionRef::relocation_begin() const { return OwningObject->section_rel_begin(SectionPimpl); } diff --git a/include/llvm/Object/RelocVisitor.h b/include/llvm/Object/RelocVisitor.h index 008e109f6679..9a978de2e599 100644 --- a/include/llvm/Object/RelocVisitor.h +++ b/include/llvm/Object/RelocVisitor.h @@ -129,6 +129,8 @@ private: case ELF::R_X86_64_NONE: return 0; case ELF::R_X86_64_64: + case ELF::R_X86_64_DTPOFF32: + case ELF::R_X86_64_DTPOFF64: return Value + getELFAddend(R); case ELF::R_X86_64_PC32: return Value + getELFAddend(R) - R.getOffset(); @@ -333,6 +335,7 @@ private: case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB: case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32: case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32: + case wasm::R_WEBASSEMBLY_EVENT_INDEX_LEB: // For wasm section, its offset at 0 -- ignoring Value return 0; } diff --git a/include/llvm/Object/Wasm.h b/include/llvm/Object/Wasm.h index fd34e45feb62..ed857652a048 100644 --- a/include/llvm/Object/Wasm.h +++ b/include/llvm/Object/Wasm.h @@ -18,10 +18,11 @@ #define LLVM_OBJECT_WASM_H #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/Wasm.h" #include "llvm/Config/llvm-config.h" +#include "llvm/MC/MCSymbolWasm.h" #include "llvm/Object/Binary.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/Error.h" @@ -36,13 +37,16 @@ namespace object { class WasmSymbol { public: WasmSymbol(const wasm::WasmSymbolInfo &Info, - const wasm::WasmSignature *FunctionType, - const wasm::WasmGlobalType *GlobalType) - : Info(Info), FunctionType(FunctionType), GlobalType(GlobalType) {} + const wasm::WasmGlobalType *GlobalType, + const wasm::WasmEventType *EventType, + const wasm::WasmSignature *Signature) + : Info(Info), GlobalType(GlobalType), EventType(EventType), + Signature(Signature) {} const wasm::WasmSymbolInfo &Info; - const wasm::WasmSignature *FunctionType; const wasm::WasmGlobalType *GlobalType; + const wasm::WasmEventType *EventType; + const wasm::WasmSignature *Signature; bool isTypeFunction() const { return Info.Kind == wasm::WASM_SYMBOL_TYPE_FUNCTION; @@ -58,6 +62,8 @@ public: return Info.Kind == wasm::WASM_SYMBOL_TYPE_SECTION; } + bool isTypeEvent() const { return Info.Kind == wasm::WASM_SYMBOL_TYPE_EVENT; } + bool isDefined() const { return !isUndefined(); } bool isUndefined() const { @@ -98,9 +104,9 @@ public: struct WasmSection { WasmSection() = default; - uint32_t Type = 0; // Section type (See below) - uint32_t Offset = 0; // Offset with in the file - StringRef Name; // Section name (User-defined sections only) + uint32_t Type = 0; // Section type (See below) + uint32_t Offset = 0; // Offset with in the file + StringRef Name; // Section name (User-defined sections only) ArrayRef<uint8_t> Content; // Section content std::vector<wasm::WasmRelocation> Relocations; // Relocations for this section }; @@ -119,19 +125,21 @@ public: const WasmSymbol &getWasmSymbol(const DataRefImpl &Symb) const; const WasmSymbol &getWasmSymbol(const SymbolRef &Symbol) const; const WasmSection &getWasmSection(const SectionRef &Section) const; - const wasm::WasmRelocation &getWasmRelocation(const RelocationRef& Ref) const; + const wasm::WasmRelocation &getWasmRelocation(const RelocationRef &Ref) const; static bool classof(const Binary *v) { return v->isWasm(); } + const wasm::WasmDylinkInfo &dylinkInfo() const { return DylinkInfo; } ArrayRef<wasm::WasmSignature> types() const { return Signatures; } ArrayRef<uint32_t> functionTypes() const { return FunctionTypes; } ArrayRef<wasm::WasmImport> imports() const { return Imports; } ArrayRef<wasm::WasmTable> tables() const { return Tables; } ArrayRef<wasm::WasmLimits> memories() const { return Memories; } ArrayRef<wasm::WasmGlobal> globals() const { return Globals; } + ArrayRef<wasm::WasmEvent> events() const { return Events; } ArrayRef<wasm::WasmExport> exports() const { return Exports; } ArrayRef<WasmSymbol> syms() const { return Symbols; } - const wasm::WasmLinkingData& linkingData() const { return LinkingData; } + const wasm::WasmLinkingData &linkingData() const { return LinkingData; } uint32_t getNumberOfSymbols() const { return Symbols.size(); } ArrayRef<wasm::WasmElemSegment> elements() const { return ElemSegments; } ArrayRef<WasmSegment> dataSegments() const { return DataSegments; } @@ -140,6 +148,7 @@ public: uint32_t startFunction() const { return StartFunction; } uint32_t getNumImportedGlobals() const { return NumImportedGlobals; } uint32_t getNumImportedFunctions() const { return NumImportedFunctions; } + uint32_t getNumImportedEvents() const { return NumImportedEvents; } void moveSymbolNext(DataRefImpl &Symb) const override; @@ -151,7 +160,7 @@ public: Expected<StringRef> getSymbolName(DataRefImpl Symb) const override; Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override; - uint64_t getWasmSymbolValue(const WasmSymbol& Sym) const; + uint64_t getWasmSymbolValue(const WasmSymbol &Sym) const; uint64_t getSymbolValueImpl(DataRefImpl Symb) const override; uint32_t getSymbolAlignment(DataRefImpl Symb) const override; uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override; @@ -192,6 +201,7 @@ public: Triple::ArchType getArch() const override; SubtargetFeatures getFeatures() const override; bool isRelocatableObject() const override; + bool isSharedObject() const; struct ReadContext { const uint8_t *Start; @@ -204,12 +214,16 @@ private: bool isDefinedFunctionIndex(uint32_t Index) const; bool isValidGlobalIndex(uint32_t Index) const; bool isDefinedGlobalIndex(uint32_t Index) const; + bool isValidEventIndex(uint32_t Index) const; + bool isDefinedEventIndex(uint32_t Index) const; bool isValidFunctionSymbol(uint32_t Index) const; bool isValidGlobalSymbol(uint32_t Index) const; + bool isValidEventSymbol(uint32_t Index) const; bool isValidDataSymbol(uint32_t Index) const; bool isValidSectionSymbol(uint32_t Index) const; wasm::WasmFunction &getDefinedFunction(uint32_t Index); wasm::WasmGlobal &getDefinedGlobal(uint32_t Index); + wasm::WasmEvent &getDefinedEvent(uint32_t Index); const WasmSection &getWasmSection(DataRefImpl Ref) const; const wasm::WasmRelocation &getWasmRelocation(DataRefImpl Ref) const; @@ -225,6 +239,7 @@ private: Error parseTableSection(ReadContext &Ctx); Error parseMemorySection(ReadContext &Ctx); Error parseGlobalSection(ReadContext &Ctx); + Error parseEventSection(ReadContext &Ctx); Error parseExportSection(ReadContext &Ctx); Error parseStartSection(ReadContext &Ctx); Error parseElemSection(ReadContext &Ctx); @@ -232,6 +247,7 @@ private: Error parseDataSection(ReadContext &Ctx); // Custom section types + Error parseDylinkSection(ReadContext &Ctx); Error parseNameSection(ReadContext &Ctx); Error parseLinkingSection(ReadContext &Ctx); Error parseLinkingSectionSymtab(ReadContext &Ctx); @@ -240,11 +256,13 @@ private: wasm::WasmObjectHeader Header; std::vector<WasmSection> Sections; + wasm::WasmDylinkInfo DylinkInfo; std::vector<wasm::WasmSignature> Signatures; std::vector<uint32_t> FunctionTypes; std::vector<wasm::WasmTable> Tables; std::vector<wasm::WasmLimits> Memories; std::vector<wasm::WasmGlobal> Globals; + std::vector<wasm::WasmEvent> Events; std::vector<wasm::WasmImport> Imports; std::vector<wasm::WasmExport> Exports; std::vector<wasm::WasmElemSegment> ElemSegments; @@ -254,18 +272,63 @@ private: std::vector<wasm::WasmFunctionName> DebugNames; uint32_t StartFunction = -1; bool HasLinkingSection = false; + bool HasDylinkSection = false; wasm::WasmLinkingData LinkingData; uint32_t NumImportedGlobals = 0; uint32_t NumImportedFunctions = 0; + uint32_t NumImportedEvents = 0; uint32_t CodeSection = 0; uint32_t DataSection = 0; uint32_t GlobalSection = 0; + uint32_t EventSection = 0; +}; + +class WasmSectionOrderChecker { +public: + // We define orders for all core wasm sections and known custom sections. + enum : int { + // Core sections + // The order of standard sections is precisely given by the spec. + WASM_SEC_ORDER_TYPE = 1, + WASM_SEC_ORDER_IMPORT = 2, + WASM_SEC_ORDER_FUNCTION = 3, + WASM_SEC_ORDER_TABLE = 4, + WASM_SEC_ORDER_MEMORY = 5, + WASM_SEC_ORDER_GLOBAL = 6, + WASM_SEC_ORDER_EVENT = 7, + WASM_SEC_ORDER_EXPORT = 8, + WASM_SEC_ORDER_START = 9, + WASM_SEC_ORDER_ELEM = 10, + WASM_SEC_ORDER_DATACOUNT = 11, + WASM_SEC_ORDER_CODE = 12, + WASM_SEC_ORDER_DATA = 13, + + // Custom sections + // "dylink" should be the very first section in the module + WASM_SEC_ORDER_DYLINK = 0, + // "linking" section requires DATA section in order to validate data symbols + WASM_SEC_ORDER_LINKING = 100, + // Must come after "linking" section in order to validate reloc indexes. + WASM_SEC_ORDER_RELOC = 101, + // "name" section must appear after DATA. Comes after "linking" to allow + // symbol table to set default function name. + WASM_SEC_ORDER_NAME = 102, + // "producers" section must appear after "name" section. + WASM_SEC_ORDER_PRODUCERS = 103 + }; + + bool isValidSectionOrder(unsigned ID, StringRef CustomSectionName = ""); + +private: + int LastOrder = -1; // Lastly seen known section's order + + // Returns -1 for unknown sections. + int getSectionOrder(unsigned ID, StringRef CustomSectionName = ""); }; } // end namespace object -inline raw_ostream &operator<<(raw_ostream &OS, - const object::WasmSymbol &Sym) { +inline raw_ostream &operator<<(raw_ostream &OS, const object::WasmSymbol &Sym) { Sym.print(OS); return OS; } diff --git a/include/llvm/Object/WasmTraits.h b/include/llvm/Object/WasmTraits.h index ebcd00b15227..049d72f79e41 100644 --- a/include/llvm/Object/WasmTraits.h +++ b/include/llvm/Object/WasmTraits.h @@ -24,14 +24,20 @@ template <typename T> struct DenseMapInfo; // Traits for using WasmSignature in a DenseMap. template <> struct DenseMapInfo<wasm::WasmSignature> { static wasm::WasmSignature getEmptyKey() { - return wasm::WasmSignature{{}, 1}; + wasm::WasmSignature Sig; + Sig.State = wasm::WasmSignature::Empty; + return Sig; } static wasm::WasmSignature getTombstoneKey() { - return wasm::WasmSignature{{}, 2}; + wasm::WasmSignature Sig; + Sig.State = wasm::WasmSignature::Tombstone; + return Sig; } static unsigned getHashValue(const wasm::WasmSignature &Sig) { - unsigned H = hash_value(Sig.ReturnType); - for (int32_t Param : Sig.ParamTypes) + uintptr_t H = hash_value(Sig.State); + for (auto Ret : Sig.Returns) + H = hash_combine(H, Ret); + for (auto Param : Sig.Params) H = hash_combine(H, Param); return H; } |