Skip to content

Commit 92bd781

Browse files
backesCommit Bot
authored and
Commit Bot
committed
[wasm] Fix placement of the events section
Before, it was specified between the globals and the exports section. This changed with WebAssembly/exception-handling#98. The event section is now placed between the memory and the globals section. [email protected] [email protected] Bug: v8:10176 Change-Id: Icafeaae4ff7796273c73d61ed417c028fcbcb02d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2116032 Reviewed-by: Jakob Kummerow <[email protected]> Commit-Queue: Clemens Backes <[email protected]> Cr-Commit-Position: refs/heads/master@{#66833}
1 parent e897375 commit 92bd781

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

src/wasm/module-decoder.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ class ModuleDecoderImpl : public Decoder {
432432
break;
433433
case kExceptionSectionCode:
434434
if (!CheckUnorderedSection(section_code)) return;
435-
if (!CheckSectionOrder(section_code, kGlobalSectionCode,
436-
kExportSectionCode))
435+
if (!CheckSectionOrder(section_code, kMemorySectionCode,
436+
kGlobalSectionCode))
437437
return;
438438
break;
439439
case kNameSectionCode:

test/mjsunit/wasm/wasm-module-builder.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let kElementSectionCode = 9; // Elements section
6565
let kCodeSectionCode = 10; // Function code
6666
let kDataSectionCode = 11; // Data segments
6767
let kDataCountSectionCode = 12; // Data segment count (between Element & Code)
68-
let kExceptionSectionCode = 13; // Exception section (between Global & Export)
68+
let kExceptionSectionCode = 13; // Exception section (between Memory & Global)
6969

7070
// Name section types
7171
let kModuleNameCode = 0;
@@ -1080,6 +1080,18 @@ class WasmModuleBuilder {
10801080
});
10811081
}
10821082

1083+
// Add event section.
1084+
if (wasm.exceptions.length > 0) {
1085+
if (debug) print("emitting events @ " + binary.length);
1086+
binary.emit_section(kExceptionSectionCode, section => {
1087+
section.emit_u32v(wasm.exceptions.length);
1088+
for (let type of wasm.exceptions) {
1089+
section.emit_u32v(kExceptionAttribute);
1090+
section.emit_u32v(type);
1091+
}
1092+
});
1093+
}
1094+
10831095
// Add global section.
10841096
if (wasm.globals.length > 0) {
10851097
if (debug) print ("emitting globals @ " + binary.length);
@@ -1133,18 +1145,6 @@ class WasmModuleBuilder {
11331145
});
11341146
}
11351147

1136-
// Add exceptions.
1137-
if (wasm.exceptions.length > 0) {
1138-
if (debug) print("emitting exceptions @ " + binary.length);
1139-
binary.emit_section(kExceptionSectionCode, section => {
1140-
section.emit_u32v(wasm.exceptions.length);
1141-
for (let type of wasm.exceptions) {
1142-
section.emit_u32v(kExceptionAttribute);
1143-
section.emit_u32v(type);
1144-
}
1145-
});
1146-
}
1147-
11481148
// Add export table.
11491149
var mem_export = (wasm.memory !== undefined && wasm.memory.exp);
11501150
var exports_count = wasm.exports.length + (mem_export ? 1 : 0);

test/unittests/wasm/module-decoder-unittest.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -724,47 +724,47 @@ TEST_F(WasmModuleVerifyTest, Exception_invalid_attribute) {
724724
}
725725

726726
TEST_F(WasmModuleVerifyTest, ExceptionSectionCorrectPlacement) {
727-
static const byte data[] = {SECTION(Import, ENTRY_COUNT(0)),
727+
static const byte data[] = {SECTION(Memory, ENTRY_COUNT(0)),
728728
SECTION(Exception, ENTRY_COUNT(0)),
729-
SECTION(Export, ENTRY_COUNT(0))};
729+
SECTION(Global, ENTRY_COUNT(0))};
730730
FAIL_IF_NO_EXPERIMENTAL_EH(data);
731731

732732
WASM_FEATURE_SCOPE(eh);
733733
ModuleResult result = DecodeModule(data, data + sizeof(data));
734734
EXPECT_OK(result);
735735
}
736736

737-
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterExport) {
738-
static const byte data[] = {SECTION(Export, ENTRY_COUNT(0)),
737+
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterGlobal) {
738+
static const byte data[] = {SECTION(Global, ENTRY_COUNT(0)),
739739
SECTION(Exception, ENTRY_COUNT(0))};
740740
FAIL_IF_NO_EXPERIMENTAL_EH(data);
741741

742742
WASM_FEATURE_SCOPE(eh);
743743
ModuleResult result = DecodeModule(data, data + sizeof(data));
744744
EXPECT_NOT_OK(result,
745-
"The Exception section must appear before the Export section");
745+
"The Exception section must appear before the Global section");
746746
}
747747

748-
TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeGlobal) {
748+
TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeMemory) {
749749
static const byte data[] = {SECTION(Exception, ENTRY_COUNT(0)),
750-
SECTION(Global, ENTRY_COUNT(0))};
750+
SECTION(Memory, ENTRY_COUNT(0))};
751751
FAIL_IF_NO_EXPERIMENTAL_EH(data);
752752

753753
WASM_FEATURE_SCOPE(eh);
754754
ModuleResult result = DecodeModule(data, data + sizeof(data));
755-
EXPECT_NOT_OK(result, "unexpected section <Global>");
755+
EXPECT_NOT_OK(result, "unexpected section <Memory>");
756756
}
757757

758-
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterMemoryBeforeGlobal) {
758+
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterTableBeforeMemory) {
759759
STATIC_ASSERT(kMemorySectionCode + 1 == kGlobalSectionCode);
760-
static const byte data[] = {SECTION(Memory, ENTRY_COUNT(0)),
760+
static const byte data[] = {SECTION(Table, ENTRY_COUNT(0)),
761761
SECTION(Exception, ENTRY_COUNT(0)),
762-
SECTION(Global, ENTRY_COUNT(0))};
762+
SECTION(Memory, ENTRY_COUNT(0))};
763763
FAIL_IF_NO_EXPERIMENTAL_EH(data);
764764

765765
WASM_FEATURE_SCOPE(eh);
766766
ModuleResult result = DecodeModule(data, data + sizeof(data));
767-
EXPECT_NOT_OK(result, "unexpected section <Global>");
767+
EXPECT_NOT_OK(result, "unexpected section <Memory>");
768768
}
769769

770770
TEST_F(WasmModuleVerifyTest, ExceptionImport) {

0 commit comments

Comments
 (0)