aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2018-04-24 18:11:36 +0000
committerSam Clegg <sbc@chromium.org>2018-04-24 18:11:36 +0000
commit6f08c84ae5597002ea6f07d64480600142b32296 (patch)
treed30e5fb768bc82ff5e952b439ccdec3734ee9ffe /llvm/lib/Object/WasmObjectFile.cpp
parent97ae30b8d6d90baed17ebc57a0d12da7c14d4223 (diff)
downloadllvm-6f08c84ae5597002ea6f07d64480600142b32296.zip
llvm-6f08c84ae5597002ea6f07d64480600142b32296.tar.gz
llvm-6f08c84ae5597002ea6f07d64480600142b32296.tar.bz2
[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
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp35
1 files changed, 6 insertions, 29 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index a9a6492..6eb0d05d 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<GenericBinaryError>("Invalid section code",
+ uint32_t SectionIndex = readVaruint32(Ptr);
+ if (SectionIndex >= Sections.size())
+ return make_error<GenericBinaryError>("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<GenericBinaryError>("Bad relocation offset",
object_error::parse_failed);
- Section->Relocations.push_back(Reloc);
+ Section.Relocations.push_back(Reloc);
}
if (Ptr != End)
return make_error<GenericBinaryError>("Reloc section ended prematurely",