From fef8de66a6ad56d71eb8bf8a401f8cdc82dea225 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Fri, 12 Apr 2019 22:27:48 +0000 Subject: [WebAssembly] Add DataCount section to object files Summary: This ensures that object files will continue to validate as WebAssembly modules in the presence of bulk memory operations. Engines that don't support bulk memory operations will not recognize the DataCount section and will report validation errors, but that's ok because object files aren't supposed to be run directly anyway. Reviewers: aheejin, dschuff, sbc100 Subscribers: jgravelle-google, hiraditya, sunfish, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60623 llvm-svn: 358315 --- llvm/lib/Object/WasmObjectFile.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'llvm/lib/Object') diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 16645002a6d..167b8c25c2b 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -316,6 +316,8 @@ Error WasmObjectFile::parseSection(WasmSection &Sec) { return parseCodeSection(Ctx); case wasm::WASM_SEC_DATA: return parseDataSection(Ctx); + case wasm::WASM_SEC_DATACOUNT: + return parseDataCountSection(Ctx); default: return make_error("Bad section type", object_error::parse_failed); @@ -1201,6 +1203,9 @@ Error WasmObjectFile::parseElemSection(ReadContext &Ctx) { Error WasmObjectFile::parseDataSection(ReadContext &Ctx) { DataSection = Sections.size(); uint32_t Count = readVaruint32(Ctx); + if (DataCount && Count != DataCount.getValue()) + return make_error( + "Number of data segments does not match DataCount section"); DataSegments.reserve(Count); while (Count--) { WasmSegment Segment; @@ -1234,6 +1239,11 @@ Error WasmObjectFile::parseDataSection(ReadContext &Ctx) { return Error::success(); } +Error WasmObjectFile::parseDataCountSection(ReadContext &Ctx) { + DataCount = readVaruint32(Ctx); + return Error::success(); +} + const wasm::WasmObjectHeader &WasmObjectFile::getHeader() const { return Header; } @@ -1399,6 +1409,7 @@ std::error_code WasmObjectFile::getSectionName(DataRefImpl Sec, ECase(ELEM); ECase(CODE); ECase(DATA); + ECase(DATACOUNT); case wasm::WASM_SEC_CUSTOM: Res = S.Name; break; -- cgit v1.2.3