Commit 0427d9ff authored by dtc-v8's avatar dtc-v8 Committed by Commit bot

WASM: Reserve an ignored section for source code meta information.

Requesting reservation of a wasm section for experimentation with
storing source code meta information, such as source code comments,
and also extra inform on presentation of the AST such an `if-block`
pattern being presented as a `when` operation.

The wasm design already defines unrecognized sections to be ignored,
and this reserved section is ignored. This section is only intended to
hold source code meta information and to have no effect on code
execution.

With wasm going live (behind a flag) on v8, I would also like to be
able to give people something to play with in terms of the deployed
binary code being a useful source code. It's all experimental, but I
understand the entire binary format that V8 is currently using is
basically a throwaway, and that the working strategy is to get
something running and then revisit format decisions.

I would like a fixed reserved section number to avoid potential
clashes with other projects - although I am not aware of any other
calls for addition sections beyond the need for debug info. If a fixed
number is not acceptable, then could this patch alternatively ignore
all unrecognized sections and perhaps add the section size to them
all - something which is already noted todo in the design document?

BUG=

Review URL: https://codereview.chromium.org/1565693002

Cr-Commit-Position: refs/heads/master@{#33165}
parent 96c6b338
......@@ -181,6 +181,20 @@ class ModuleDecoder : public Decoder {
}
break;
}
case kDeclWLL: {
// Reserved for experimentation by the Web Low-level Language project
// which is augmenting the binary encoding with source code meta
// information. This section does not affect the semantics of the code
// and can be ignored by the runtime. https://github.com/JSStats/wll
int length;
uint32_t section_size = u32v(&length, "section size");
if (pc_ + section_size > limit_ || pc_ + section_size < pc_) {
error(pc_ - length, "invalid section size");
break;
}
pc_ += section_size;
break;
}
default:
error(pc_ - 1, nullptr, "unrecognized section 0x%02x", section);
break;
......
......@@ -30,6 +30,7 @@ enum WasmSectionDeclCode {
kDeclGlobals = 0x03,
kDeclDataSegments = 0x04,
kDeclFunctionTable = 0x05,
kDeclWLL = 0x11,
kDeclEnd = 0x06,
};
......
......@@ -878,6 +878,80 @@ TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) {
if (result.val) delete result.val;
}
TEST_F(WasmModuleVerifyTest, WLLSectionNoLen) {
const byte data[] = {
kDeclWLL, // section without length.
};
EXPECT_FAILURE(data);
}
TEST_F(WasmModuleVerifyTest, WLLSectionEmpty) {
const byte data[] = {
kDeclWLL, 0, // empty section
};
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
if (result.val) delete result.val;
}
TEST_F(WasmModuleVerifyTest, WLLSectionOne) {
const byte data[] = {
kDeclWLL,
1, // LEB128 1
0, // one byte section
};
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
if (result.val) delete result.val;
}
TEST_F(WasmModuleVerifyTest, WLLSectionTen) {
const byte data[] = {
kDeclWLL,
10, // LEB128 10
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section
};
ModuleResult result = DecodeModule(data, data + arraysize(data));
EXPECT_TRUE(result.ok());
if (result.val) delete result.val;
}
TEST_F(WasmModuleVerifyTest, WLLSectionOverflow) {
const byte data[] = {
kDeclWLL,
11, // LEB128 11
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // 10 byte section
};
EXPECT_FAILURE(data);
}
TEST_F(WasmModuleVerifyTest, WLLSectionUnderflow) {
const byte data[] = {
kDeclWLL,
0xff, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xffffffff
1, 2, 3, 4, // 4 byte section
};
EXPECT_FAILURE(data);
}
TEST_F(WasmModuleVerifyTest, WLLSectionLoop) {
// Would infinite loop decoding if wrapping and allowed.
const byte data[] = {
kDeclWLL,
0xfa, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xfffffffa
1, 2, 3, 4, // 4 byte section
};
EXPECT_FAILURE(data);
}
} // namespace wasm
} // namespace internal
} // namespace v8
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