Commit 9604b06e authored by ahaas's avatar ahaas Committed by Commit bot

[wasm] Mutable globals cannot be exported

R=titzer@chromium.org, rossberg@chromium.org
TEST=unittests/WasmModuleVerifyTest.ExportMutableGlobal

Review-Url: https://codereview.chromium.org/2481263003
Cr-Commit-Position: refs/heads/master@{#40838}
parent 7159662b
......@@ -478,7 +478,12 @@ class ModuleDecoder : public Decoder {
case kExternalGlobal: {
WasmGlobal* global = nullptr;
exp->index = consume_global_index(module, &global);
if (global) global->exported = true;
if (global) {
if (global->mutability) {
error("mutable globals cannot be exported");
}
global->exported = true;
}
break;
}
default:
......
......@@ -248,6 +248,47 @@ TEST_F(WasmModuleVerifyTest, ZeroGlobals) {
if (result.val) delete result.val;
}
TEST_F(WasmModuleVerifyTest, ExportMutableGlobal) {
{
static const byte data[] = {
SECTION(Global, 6), // --
1,
kLocalI32, // local type
0, // immutable
WASM_INIT_EXPR_I32V_1(13), // init
SECTION(Export, 8), // --
1, // Export count
4, // name length
'n', // --
'a', // --
'm', // --
'e', // --
kExternalGlobal, // global
0, // global index
};
EXPECT_VERIFIES(data);
}
{
static const byte data[] = {
SECTION(Global, 6), // --
1, // --
kLocalI32, // local type
1, // mutable
WASM_INIT_EXPR_I32V_1(13), // init
SECTION(Export, 8), // --
1, // Export count
4, // name length
'n', // --
'a', // --
'm', // --
'e', // --
kExternalGlobal, // global
0, // global index
};
EXPECT_FAILURE(data);
}
}
static void AppendUint32v(std::vector<byte>& buffer, uint32_t val) {
while (true) {
uint32_t next = val >> 7;
......
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