Commit 92bd7818 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Fix placement of the events section

Before, it was specified between the globals and the exports section.
This changed with
https://github.com/WebAssembly/exception-handling/issues/98. The event
section is now placed between the memory and the globals section.

R=jkummerow@chromium.org
CC=aheejin@chromium.org

Bug: v8:10176
Change-Id: Icafeaae4ff7796273c73d61ed417c028fcbcb02d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2116032Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66833}
parent e8973752
......@@ -432,8 +432,8 @@ class ModuleDecoderImpl : public Decoder {
break;
case kExceptionSectionCode:
if (!CheckUnorderedSection(section_code)) return;
if (!CheckSectionOrder(section_code, kGlobalSectionCode,
kExportSectionCode))
if (!CheckSectionOrder(section_code, kMemorySectionCode,
kGlobalSectionCode))
return;
break;
case kNameSectionCode:
......
......@@ -65,7 +65,7 @@ let kElementSectionCode = 9; // Elements section
let kCodeSectionCode = 10; // Function code
let kDataSectionCode = 11; // Data segments
let kDataCountSectionCode = 12; // Data segment count (between Element & Code)
let kExceptionSectionCode = 13; // Exception section (between Global & Export)
let kExceptionSectionCode = 13; // Exception section (between Memory & Global)
// Name section types
let kModuleNameCode = 0;
......@@ -1080,6 +1080,18 @@ class WasmModuleBuilder {
});
}
// Add event section.
if (wasm.exceptions.length > 0) {
if (debug) print("emitting events @ " + binary.length);
binary.emit_section(kExceptionSectionCode, section => {
section.emit_u32v(wasm.exceptions.length);
for (let type of wasm.exceptions) {
section.emit_u32v(kExceptionAttribute);
section.emit_u32v(type);
}
});
}
// Add global section.
if (wasm.globals.length > 0) {
if (debug) print ("emitting globals @ " + binary.length);
......@@ -1133,18 +1145,6 @@ class WasmModuleBuilder {
});
}
// Add exceptions.
if (wasm.exceptions.length > 0) {
if (debug) print("emitting exceptions @ " + binary.length);
binary.emit_section(kExceptionSectionCode, section => {
section.emit_u32v(wasm.exceptions.length);
for (let type of wasm.exceptions) {
section.emit_u32v(kExceptionAttribute);
section.emit_u32v(type);
}
});
}
// Add export table.
var mem_export = (wasm.memory !== undefined && wasm.memory.exp);
var exports_count = wasm.exports.length + (mem_export ? 1 : 0);
......
......@@ -724,9 +724,9 @@ TEST_F(WasmModuleVerifyTest, Exception_invalid_attribute) {
}
TEST_F(WasmModuleVerifyTest, ExceptionSectionCorrectPlacement) {
static const byte data[] = {SECTION(Import, ENTRY_COUNT(0)),
static const byte data[] = {SECTION(Memory, ENTRY_COUNT(0)),
SECTION(Exception, ENTRY_COUNT(0)),
SECTION(Export, ENTRY_COUNT(0))};
SECTION(Global, ENTRY_COUNT(0))};
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
......@@ -734,37 +734,37 @@ TEST_F(WasmModuleVerifyTest, ExceptionSectionCorrectPlacement) {
EXPECT_OK(result);
}
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterExport) {
static const byte data[] = {SECTION(Export, ENTRY_COUNT(0)),
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterGlobal) {
static const byte data[] = {SECTION(Global, ENTRY_COUNT(0)),
SECTION(Exception, ENTRY_COUNT(0))};
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_NOT_OK(result,
"The Exception section must appear before the Export section");
"The Exception section must appear before the Global section");
}
TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeGlobal) {
TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeMemory) {
static const byte data[] = {SECTION(Exception, ENTRY_COUNT(0)),
SECTION(Global, ENTRY_COUNT(0))};
SECTION(Memory, ENTRY_COUNT(0))};
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_NOT_OK(result, "unexpected section <Global>");
EXPECT_NOT_OK(result, "unexpected section <Memory>");
}
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterMemoryBeforeGlobal) {
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterTableBeforeMemory) {
STATIC_ASSERT(kMemorySectionCode + 1 == kGlobalSectionCode);
static const byte data[] = {SECTION(Memory, ENTRY_COUNT(0)),
static const byte data[] = {SECTION(Table, ENTRY_COUNT(0)),
SECTION(Exception, ENTRY_COUNT(0)),
SECTION(Global, ENTRY_COUNT(0))};
SECTION(Memory, ENTRY_COUNT(0))};
FAIL_IF_NO_EXPERIMENTAL_EH(data);
WASM_FEATURE_SCOPE(eh);
ModuleResult result = DecodeModule(data, data + sizeof(data));
EXPECT_NOT_OK(result, "unexpected section <Global>");
EXPECT_NOT_OK(result, "unexpected section <Memory>");
}
TEST_F(WasmModuleVerifyTest, ExceptionImport) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment