From 6f08c84ae5597002ea6f07d64480600142b32296 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 24 Apr 2018 18:11:36 +0000 Subject: [WebAssembly] Use section index in relocation section header Rather than referring to sections my their code, use the absolute index of the target section within the module. See https://github.com/WebAssembly/tool-conventions/issues/52 Differential Revision: https://reviews.llvm.org/D45980 llvm-svn: 330749 --- llvm/lib/Object/WasmObjectFile.cpp | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) (limited to 'llvm/lib/Object') diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index a9a64928d30..6eb0d05dfad 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -524,38 +524,15 @@ Error WasmObjectFile::parseLinkingSectionComdat(const uint8_t *&Ptr, return Error::success(); } -WasmSection* WasmObjectFile::findCustomSectionByName(StringRef Name) { - for (WasmSection& Section : Sections) { - if (Section.Type == wasm::WASM_SEC_CUSTOM && Section.Name == Name) - return &Section; - } - return nullptr; -} - -WasmSection* WasmObjectFile::findSectionByType(uint32_t Type) { - assert(Type != wasm::WASM_SEC_CUSTOM); - for (WasmSection& Section : Sections) { - if (Section.Type == Type) - return &Section; - } - return nullptr; -} - Error WasmObjectFile::parseRelocSection(StringRef Name, const uint8_t *Ptr, const uint8_t *End) { - uint8_t SectionCode = readUint8(Ptr); - WasmSection* Section = nullptr; - if (SectionCode == wasm::WASM_SEC_CUSTOM) { - StringRef Name = readString(Ptr); - Section = findCustomSectionByName(Name); - } else { - Section = findSectionByType(SectionCode); - } - if (!Section) - return make_error("Invalid section code", + uint32_t SectionIndex = readVaruint32(Ptr); + if (SectionIndex >= Sections.size()) + return make_error("Invalid section index", object_error::parse_failed); + WasmSection& Section = Sections[SectionIndex]; uint32_t RelocCount = readVaruint32(Ptr); - uint32_t EndOffset = Section->Content.size(); + uint32_t EndOffset = Section.Content.size(); while (RelocCount--) { wasm::WasmRelocation Reloc = {}; Reloc.Type = readVaruint32(Ptr); @@ -604,7 +581,7 @@ Error WasmObjectFile::parseRelocSection(StringRef Name, const uint8_t *Ptr, return make_error("Bad relocation offset", object_error::parse_failed); - Section->Relocations.push_back(Reloc); + Section.Relocations.push_back(Reloc); } if (Ptr != End) return make_error("Reloc section ended prematurely", -- cgit v1.2.3