2015-12-11 12:26:16 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
|
2019-05-22 12:44:24 +00:00
|
|
|
#include "src/handles/handles.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2015-12-11 12:26:16 +00:00
|
|
|
#include "src/wasm/module-decoder.h"
|
2018-08-08 14:54:44 +00:00
|
|
|
#include "src/wasm/wasm-features.h"
|
2016-12-14 17:45:59 +00:00
|
|
|
#include "src/wasm/wasm-limits.h"
|
2015-12-11 12:26:16 +00:00
|
|
|
#include "src/wasm/wasm-opcodes.h"
|
2017-05-31 13:31:52 +00:00
|
|
|
#include "test/common/wasm/flag-utils.h"
|
2017-04-25 11:29:17 +00:00
|
|
|
#include "test/common/wasm/wasm-macro-gen.h"
|
2018-10-19 08:24:38 +00:00
|
|
|
#include "testing/gmock-support.h"
|
|
|
|
|
|
|
|
using testing::HasSubstr;
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
2017-09-28 17:55:52 +00:00
|
|
|
namespace module_decoder_unittest {
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define WASM_INIT_EXPR_I32V_1(val) WASM_I32V_1(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_I32V_2(val) WASM_I32V_2(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_I32V_3(val) WASM_I32V_3(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_I32V_4(val) WASM_I32V_4(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_I32V_5(val) WASM_I32V_5(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_F32(val) WASM_F32(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_I64(val) WASM_I64(val), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_F64(val) WASM_F64(val), kExprEnd
|
2020-09-29 07:46:36 +00:00
|
|
|
#define WASM_INIT_EXPR_EXTERN_REF_NULL WASM_REF_NULL(kExternRefCode), kExprEnd
|
|
|
|
#define WASM_INIT_EXPR_FUNC_REF_NULL WASM_REF_NULL(kFuncRefCode), kExprEnd
|
2019-05-13 11:35:43 +00:00
|
|
|
#define WASM_INIT_EXPR_REF_FUNC(val) WASM_REF_FUNC(val), kExprEnd
|
2020-12-17 16:56:08 +00:00
|
|
|
#define WASM_INIT_EXPR_GLOBAL(index) WASM_GLOBAL_GET(index), kExprEnd
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2020-09-29 07:46:36 +00:00
|
|
|
#define REF_NULL_ELEMENT kExprRefNull, kFuncRefCode, kExprEnd
|
2019-03-04 18:52:03 +00:00
|
|
|
#define REF_FUNC_ELEMENT(v) kExprRefFunc, U32V_1(v), kExprEnd
|
|
|
|
|
2016-03-09 22:50:36 +00:00
|
|
|
#define EMPTY_BODY 0
|
|
|
|
#define NOP_BODY 2, 0, kExprNop
|
2016-03-10 12:36:42 +00:00
|
|
|
|
2020-09-29 07:46:36 +00:00
|
|
|
#define SIG_ENTRY_i_i SIG_ENTRY_x_x(kI32Code, kI32Code)
|
2016-04-29 09:39:26 +00:00
|
|
|
|
2018-10-17 09:31:01 +00:00
|
|
|
#define UNKNOWN_SECTION(size) 0, U32V_1(size + 5), ADD_COUNT('l', 'u', 'l', 'z')
|
2020-09-24 11:52:48 +00:00
|
|
|
#define TYPE_SECTION(count, ...) SECTION(Type, U32V_1(count), __VA_ARGS__)
|
|
|
|
#define FUNCTION_SECTION(count, ...) \
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Function, U32V_1(count), __VA_ARGS__)
|
2016-04-29 09:39:26 +00:00
|
|
|
|
2018-10-17 09:31:01 +00:00
|
|
|
#define FOO_STRING ADD_COUNT('f', 'o', 'o')
|
2016-04-29 09:39:26 +00:00
|
|
|
#define NO_LOCAL_NAMES 0
|
|
|
|
|
2020-09-24 11:52:48 +00:00
|
|
|
#define EMPTY_TYPE_SECTION SECTION(Type, ENTRY_COUNT(0))
|
|
|
|
#define EMPTY_FUNCTION_SECTION SECTION(Function, ENTRY_COUNT(0))
|
2018-10-17 08:43:53 +00:00
|
|
|
#define EMPTY_FUNCTION_BODIES_SECTION SECTION(Code, ENTRY_COUNT(0))
|
|
|
|
#define SECTION_NAMES(...) \
|
2018-10-17 09:31:01 +00:00
|
|
|
SECTION(Unknown, ADD_COUNT('n', 'a', 'm', 'e'), ##__VA_ARGS__)
|
2018-10-17 08:43:53 +00:00
|
|
|
#define EMPTY_NAMES_SECTION SECTION_NAMES()
|
2018-10-17 11:52:34 +00:00
|
|
|
#define SECTION_SRC_MAP(...) \
|
|
|
|
SECTION(Unknown, \
|
|
|
|
ADD_COUNT('s', 'o', 'u', 'r', 'c', 'e', 'M', 'a', 'p', 'p', 'i', \
|
|
|
|
'n', 'g', 'U', 'R', 'L'), \
|
|
|
|
ADD_COUNT(__VA_ARGS__))
|
2019-03-19 18:45:36 +00:00
|
|
|
#define SECTION_COMPILATION_HINTS(...) \
|
|
|
|
SECTION(Unknown, \
|
|
|
|
ADD_COUNT('c', 'o', 'm', 'p', 'i', 'l', 'a', 't', 'i', 'o', 'n', \
|
|
|
|
'H', 'i', 'n', 't', 's'), \
|
|
|
|
ADD_COUNT(__VA_ARGS__))
|
2016-04-29 09:39:26 +00:00
|
|
|
|
2017-08-01 20:56:39 +00:00
|
|
|
#define FAIL_IF_NO_EXPERIMENTAL_EH(data) \
|
|
|
|
do { \
|
|
|
|
ModuleResult result = DecodeModule((data), (data) + sizeof((data))); \
|
|
|
|
EXPECT_FALSE(result.ok()); \
|
2018-09-19 17:41:30 +00:00
|
|
|
} while (false)
|
2017-08-01 20:56:39 +00:00
|
|
|
|
2016-05-25 16:12:09 +00:00
|
|
|
#define X1(...) __VA_ARGS__
|
|
|
|
#define X2(...) __VA_ARGS__, __VA_ARGS__
|
|
|
|
#define X3(...) __VA_ARGS__, __VA_ARGS__, __VA_ARGS__
|
|
|
|
#define X4(...) __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__
|
|
|
|
|
2018-10-16 15:34:13 +00:00
|
|
|
#define ONE_EMPTY_FUNCTION(sig_index) \
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Function, ENTRY_COUNT(1), X1(sig_index))
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2018-10-16 15:34:13 +00:00
|
|
|
#define TWO_EMPTY_FUNCTIONS(sig_index) \
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Function, ENTRY_COUNT(2), X2(sig_index))
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2018-10-16 15:34:13 +00:00
|
|
|
#define THREE_EMPTY_FUNCTIONS(sig_index) \
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Function, ENTRY_COUNT(3), X3(sig_index))
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2018-10-16 15:34:13 +00:00
|
|
|
#define FOUR_EMPTY_FUNCTIONS(sig_index) \
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Function, ENTRY_COUNT(4), X4(sig_index))
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2018-10-17 12:46:06 +00:00
|
|
|
#define ONE_EMPTY_BODY SECTION(Code, ENTRY_COUNT(1), X1(EMPTY_BODY))
|
|
|
|
#define TWO_EMPTY_BODIES SECTION(Code, ENTRY_COUNT(2), X2(EMPTY_BODY))
|
|
|
|
#define THREE_EMPTY_BODIES SECTION(Code, ENTRY_COUNT(3), X3(EMPTY_BODY))
|
|
|
|
#define FOUR_EMPTY_BODIES SECTION(Code, ENTRY_COUNT(4), X4(EMPTY_BODY))
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2020-09-24 11:52:48 +00:00
|
|
|
#define TYPE_SECTION_ONE_SIG_VOID_VOID \
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Type, ENTRY_COUNT(1), SIG_ENTRY_v_v)
|
2016-09-27 20:46:10 +00:00
|
|
|
|
|
|
|
#define LINEAR_MEMORY_INDEX_0 0
|
2016-02-27 01:52:30 +00:00
|
|
|
|
2018-10-22 08:39:58 +00:00
|
|
|
#define EXCEPTION_ENTRY(sig_index) U32V_1(kExceptionAttribute), sig_index
|
|
|
|
|
2020-07-07 12:12:23 +00:00
|
|
|
#define FIELD_COUNT(count) U32V_1(count)
|
|
|
|
#define STRUCT_FIELD(type, mutability) type, (mutability ? 1 : 0)
|
2020-09-29 07:46:36 +00:00
|
|
|
#define WASM_REF(index) kRefCode, index
|
|
|
|
#define WASM_OPT_REF(index) kOptRefCode, index
|
2020-07-07 12:12:23 +00:00
|
|
|
#define WASM_STRUCT_DEF(...) kWasmStructTypeCode, __VA_ARGS__
|
|
|
|
#define WASM_ARRAY_DEF(type, mutability) \
|
|
|
|
kWasmArrayTypeCode, type, (mutability ? 1 : 0)
|
|
|
|
#define WASM_FUNCTION_DEF(...) kWasmFunctionTypeCode, __VA_ARGS__
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
#define EXPECT_VERIFIES(data) \
|
|
|
|
do { \
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data)); \
|
2020-06-12 08:54:52 +00:00
|
|
|
EXPECT_OK(result); \
|
2015-12-11 12:26:16 +00:00
|
|
|
} while (false)
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
#define EXPECT_FAILURE_LEN(data, length) \
|
|
|
|
do { \
|
|
|
|
ModuleResult result = DecodeModule(data, data + length); \
|
|
|
|
EXPECT_FALSE(result.ok()); \
|
2015-12-11 12:26:16 +00:00
|
|
|
} while (false)
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
#define EXPECT_FAILURE(data) EXPECT_FAILURE_LEN(data, sizeof(data))
|
|
|
|
|
2020-02-17 16:21:02 +00:00
|
|
|
#define EXPECT_FAILURE_WITH_MSG(data, msg) \
|
|
|
|
do { \
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data)); \
|
|
|
|
EXPECT_FALSE(result.ok()); \
|
2020-09-18 15:22:35 +00:00
|
|
|
if (!result.ok()) { \
|
|
|
|
EXPECT_THAT(result.error().message(), HasSubstr(msg)); \
|
|
|
|
} \
|
2020-02-17 16:21:02 +00:00
|
|
|
} while (false)
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
#define EXPECT_OFF_END_FAILURE(data, min) \
|
|
|
|
do { \
|
|
|
|
STATIC_ASSERT(min < arraysize(data)); \
|
|
|
|
for (size_t length = min; length < arraysize(data); length++) { \
|
|
|
|
EXPECT_FAILURE_LEN(data, length); \
|
|
|
|
} \
|
2016-02-28 00:37:11 +00:00
|
|
|
} while (false)
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2020-06-12 08:54:52 +00:00
|
|
|
#define EXPECT_OK(result) \
|
|
|
|
do { \
|
|
|
|
if (!result.ok()) { \
|
|
|
|
GTEST_NONFATAL_FAILURE_(result.error().message().c_str()); \
|
|
|
|
return; \
|
|
|
|
} \
|
2016-04-21 11:18:41 +00:00
|
|
|
} while (false)
|
|
|
|
|
2019-01-14 17:51:56 +00:00
|
|
|
#define EXPECT_NOT_OK(result, msg) \
|
|
|
|
do { \
|
|
|
|
EXPECT_FALSE(result.ok()); \
|
|
|
|
EXPECT_THAT(result.error().message(), HasSubstr(msg)); \
|
2018-10-19 08:24:38 +00:00
|
|
|
} while (false)
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
static size_t SizeOfVarInt(size_t value) {
|
|
|
|
size_t size = 0;
|
|
|
|
do {
|
|
|
|
size++;
|
|
|
|
value = value >> 7;
|
|
|
|
} while (value > 0);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
struct ValueTypePair {
|
2015-12-11 12:26:16 +00:00
|
|
|
uint8_t code;
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType type;
|
2018-07-09 09:15:45 +00:00
|
|
|
} kValueTypes[] = {
|
2020-09-29 07:46:36 +00:00
|
|
|
{kI32Code, kWasmI32}, // --
|
|
|
|
{kI64Code, kWasmI64}, // --
|
|
|
|
{kF32Code, kWasmF32}, // --
|
|
|
|
{kF64Code, kWasmF64}, // --
|
|
|
|
{kFuncRefCode, kWasmFuncRef}, // --
|
|
|
|
{kExternRefCode, kWasmExternRef}, // --
|
2018-07-09 09:15:45 +00:00
|
|
|
};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
[wasm] Adding metrics for Asm/Wasm.
Collecting:
Time histograms for: instantiate, decode module, decode function, compile, compile function.
Memory histograms for: decode peak, instantiate peak, compile function peak, min mem pages, max mem pages, function bytes, module bytes.
Range histograms of: functions per module.
BUG= https://code.google.com/p/v8/issues/detail?id=4203
BUG= https://bugs.chromium.org/p/chromium/issues/detail?id=575167
TEST=None
R=ahaas@chromium.org,bmeurer@chromium.org
LOG=N
Review URL: https://codereview.chromium.org/1866873002
Cr-Commit-Position: refs/heads/master@{#35467}
2016-04-14 07:28:22 +00:00
|
|
|
class WasmModuleVerifyTest : public TestWithIsolateAndZone {
|
2016-02-28 00:37:11 +00:00
|
|
|
public:
|
2019-11-26 16:25:14 +00:00
|
|
|
WasmFeatures enabled_features_ = WasmFeatures::None();
|
2018-08-08 14:54:44 +00:00
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
ModuleResult DecodeModule(const byte* module_start, const byte* module_end) {
|
2017-06-09 12:21:52 +00:00
|
|
|
// Add the wasm magic and version number automatically.
|
2016-02-28 00:37:11 +00:00
|
|
|
size_t size = static_cast<size_t>(module_end - module_start);
|
|
|
|
byte header[] = {WASM_MODULE_HEADER};
|
|
|
|
size_t total = sizeof(header) + size;
|
|
|
|
auto temp = new byte[total];
|
|
|
|
memcpy(temp, header, sizeof(header));
|
2019-01-25 00:34:59 +00:00
|
|
|
if (size > 0) {
|
|
|
|
memcpy(temp + sizeof(header), module_start, size);
|
|
|
|
}
|
2018-08-08 14:54:44 +00:00
|
|
|
ModuleResult result = DecodeWasmModule(
|
|
|
|
enabled_features_, temp, temp + total, false, kWasmOrigin,
|
2020-08-13 15:04:08 +00:00
|
|
|
isolate()->counters(), isolate()->metrics_recorder(),
|
|
|
|
v8::metrics::Recorder::ContextId::Empty(), DecodingMethod::kSync,
|
|
|
|
isolate()->wasm_engine()->allocator());
|
2016-02-28 00:37:11 +00:00
|
|
|
delete[] temp;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
ModuleResult DecodeModuleNoHeader(const byte* module_start,
|
|
|
|
const byte* module_end) {
|
2020-08-13 15:04:08 +00:00
|
|
|
return DecodeWasmModule(
|
|
|
|
enabled_features_, module_start, module_end, false, kWasmOrigin,
|
|
|
|
isolate()->counters(), isolate()->metrics_recorder(),
|
|
|
|
v8::metrics::Recorder::ContextId::Empty(), DecodingMethod::kSync,
|
|
|
|
isolate()->wasm_engine()->allocator());
|
2018-08-08 14:54:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, WrongMagic) {
|
|
|
|
for (uint32_t x = 1; x; x <<= 1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)};
|
2016-02-28 00:37:11 +00:00
|
|
|
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
|
|
|
|
EXPECT_FALSE(result.ok());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
2016-02-28 00:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, WrongVersion) {
|
|
|
|
for (uint32_t x = 1; x; x <<= 1) {
|
2016-09-27 20:46:10 +00:00
|
|
|
const byte data[] = {U32_LE(kWasmMagic), U32_LE(kWasmVersion ^ x)};
|
2016-02-28 00:37:11 +00:00
|
|
|
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
|
|
|
|
EXPECT_FALSE(result.ok());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:20:24 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, WrongSection) {
|
|
|
|
constexpr byte kInvalidSection = 0x1c;
|
|
|
|
const byte data[] = {kInvalidSection, 0};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_FALSE(result.ok());
|
|
|
|
}
|
|
|
|
|
2016-02-28 00:37:11 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DecodeEmpty) {
|
2018-09-13 14:55:18 +00:00
|
|
|
ModuleResult result = DecodeModule(nullptr, nullptr);
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_TRUE(result.ok());
|
2016-02-28 00:37:11 +00:00
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, OneGlobal) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // local type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_I32V_1(13)) // init
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// Should decode to exactly one global.
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->data_segments.size());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
const WasmGlobal* global = &result.value()->globals.back();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
EXPECT_EQ(kWasmI32, global->type);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, global->offset);
|
2016-09-27 22:09:36 +00:00
|
|
|
EXPECT_FALSE(global->mutability);
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kI32Const, global->init.kind());
|
|
|
|
EXPECT_EQ(13, global->init.immediate().i32_const);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 17:21:30 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, S128Global) {
|
|
|
|
WASM_FEATURE_SCOPE(simd);
|
2020-07-24 04:12:09 +00:00
|
|
|
std::array<uint8_t, kSimd128Size> v = {1, 2, 3, 4, 5, 6, 7, 8,
|
|
|
|
9, 10, 11, 12, 13, 14, 15};
|
2020-07-21 17:21:30 +00:00
|
|
|
static const byte data[] = {SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kS128Code, // memory type
|
2020-07-21 17:21:30 +00:00
|
|
|
0, // immutable
|
2020-07-24 04:12:09 +00:00
|
|
|
WASM_SIMD_CONSTANT(v.data()), kExprEnd)};
|
2020-07-21 17:21:30 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
const WasmGlobal* global = &result.value()->globals.back();
|
|
|
|
EXPECT_EQ(kWasmS128, global->type);
|
|
|
|
EXPECT_EQ(0u, global->offset);
|
|
|
|
EXPECT_FALSE(global->mutability);
|
|
|
|
EXPECT_EQ(WasmInitExpr::kS128Const, global->init.kind());
|
2020-07-24 04:12:09 +00:00
|
|
|
EXPECT_EQ(global->init.immediate().s128_const, v);
|
2020-07-21 17:21:30 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExternRefGlobal) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2018-04-05 10:49:26 +00:00
|
|
|
static const byte data[] = {
|
2019-05-13 11:35:43 +00:00
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2019-05-13 11:35:43 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
|
|
|
TWO_EMPTY_FUNCTIONS(SIG_INDEX(0)),
|
2020-06-09 15:54:14 +00:00
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(2), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kExternRefCode, // local type
|
2020-06-09 15:54:14 +00:00
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_EXTERN_REF_NULL, // init
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // local type
|
2020-06-09 15:54:14 +00:00
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_REF_FUNC(1)), // init
|
|
|
|
SECTION(Element, // section name
|
|
|
|
ENTRY_COUNT(2), // entry count
|
|
|
|
DECLARATIVE, // flags 0
|
|
|
|
kExternalFunction, // type
|
|
|
|
ENTRY_COUNT(1), // func entry count
|
|
|
|
FUNC_INDEX(0), // func index
|
|
|
|
DECLARATIVE_WITH_ELEMENTS, // flags 1
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // local type
|
2020-06-09 15:54:14 +00:00
|
|
|
ENTRY_COUNT(1), // func ref count
|
|
|
|
REF_FUNC_ELEMENT(1)), // func ref
|
2019-05-13 11:35:43 +00:00
|
|
|
TWO_EMPTY_BODIES};
|
2018-04-05 10:49:26 +00:00
|
|
|
|
|
|
|
{
|
2019-05-13 11:35:43 +00:00
|
|
|
// Should decode to two globals.
|
2018-04-05 10:49:26 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
2019-05-13 11:35:43 +00:00
|
|
|
EXPECT_EQ(2u, result.value()->globals.size());
|
|
|
|
EXPECT_EQ(2u, result.value()->functions.size());
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(0u, result.value()->data_segments.size());
|
2018-04-05 10:49:26 +00:00
|
|
|
|
2019-05-13 11:35:43 +00:00
|
|
|
const WasmGlobal* global = &result.value()->globals[0];
|
2020-06-09 15:54:14 +00:00
|
|
|
EXPECT_EQ(kWasmExternRef, global->type);
|
2019-05-13 11:35:43 +00:00
|
|
|
EXPECT_FALSE(global->mutability);
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kRefNullConst, global->init.kind());
|
2018-04-05 10:49:26 +00:00
|
|
|
|
2019-05-13 11:35:43 +00:00
|
|
|
global = &result.value()->globals[1];
|
2020-06-03 12:48:16 +00:00
|
|
|
EXPECT_EQ(kWasmFuncRef, global->type);
|
2018-04-05 10:49:26 +00:00
|
|
|
EXPECT_FALSE(global->mutability);
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kRefFuncConst, global->init.kind());
|
|
|
|
EXPECT_EQ(uint32_t{1}, global->init.immediate().index);
|
2019-05-13 11:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-08 20:23:30 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, FuncRefGlobal) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2019-05-13 11:35:43 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2019-05-13 11:35:43 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
|
|
|
TWO_EMPTY_FUNCTIONS(SIG_INDEX(0)),
|
2020-06-03 12:48:16 +00:00
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(2), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // local type
|
2020-06-03 12:48:16 +00:00
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_FUNC_REF_NULL, // init
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // local type
|
2020-06-03 12:48:16 +00:00
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_REF_FUNC(1)), // init
|
|
|
|
SECTION(Element, // section name
|
|
|
|
ENTRY_COUNT(2), // entry count
|
|
|
|
DECLARATIVE, // flags 0
|
|
|
|
kExternalFunction, // type
|
|
|
|
ENTRY_COUNT(1), // func entry count
|
|
|
|
FUNC_INDEX(0), // func index
|
|
|
|
DECLARATIVE_WITH_ELEMENTS, // flags 1
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // local type
|
2020-06-03 12:48:16 +00:00
|
|
|
ENTRY_COUNT(1), // func ref count
|
|
|
|
REF_FUNC_ELEMENT(1)), // func ref
|
2019-05-13 11:35:43 +00:00
|
|
|
TWO_EMPTY_BODIES};
|
|
|
|
{
|
|
|
|
// Should decode to two globals.
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(2u, result.value()->globals.size());
|
|
|
|
EXPECT_EQ(2u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->data_segments.size());
|
|
|
|
|
|
|
|
const WasmGlobal* global = &result.value()->globals[0];
|
2019-07-08 20:23:30 +00:00
|
|
|
EXPECT_EQ(kWasmFuncRef, global->type);
|
2019-05-13 11:35:43 +00:00
|
|
|
EXPECT_FALSE(global->mutability);
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kRefNullConst, global->init.kind());
|
2019-05-13 11:35:43 +00:00
|
|
|
|
|
|
|
global = &result.value()->globals[1];
|
2019-07-08 20:23:30 +00:00
|
|
|
EXPECT_EQ(kWasmFuncRef, global->type);
|
2019-05-13 11:35:43 +00:00
|
|
|
EXPECT_FALSE(global->mutability);
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kRefFuncConst, global->init.kind());
|
|
|
|
EXPECT_EQ(uint32_t{1}, global->init.immediate().index);
|
2018-04-05 10:49:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-17 09:18:41 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, InvalidFuncRefGlobal) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2019-09-17 09:18:41 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2019-09-17 09:18:41 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
|
|
|
TWO_EMPTY_FUNCTIONS(SIG_INDEX(0)),
|
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // local type
|
2019-09-17 09:18:41 +00:00
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_REF_FUNC(7)), // invalid function index
|
|
|
|
TWO_EMPTY_BODIES};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExternRefGlobalWithGlobalInit) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2018-04-05 10:49:26 +00:00
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import, // --
|
|
|
|
ENTRY_COUNT(1), // number of imports
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('f'), // global name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalGlobal, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kExternRefCode, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
0), // mutability
|
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1),
|
2020-09-29 07:46:36 +00:00
|
|
|
kExternRefCode, // local type
|
|
|
|
0, // immutable
|
2018-10-17 08:43:53 +00:00
|
|
|
WASM_INIT_EXPR_GLOBAL(0)),
|
2018-04-05 10:49:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// Should decode to exactly one global.
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(2u, result.value()->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->data_segments.size());
|
2018-04-05 10:49:26 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
const WasmGlobal* global = &result.value()->globals.back();
|
2018-04-05 10:49:26 +00:00
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
EXPECT_EQ(kWasmExternRef, global->type);
|
2018-04-05 10:49:26 +00:00
|
|
|
EXPECT_FALSE(global->mutability);
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kGlobalGet, global->init.kind());
|
2018-04-05 10:49:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 07:22:22 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, NullGlobalWithGlobalInit) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-01-15 11:55:19 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Import, // --
|
|
|
|
ENTRY_COUNT(1), // number of imports
|
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('n'), // global name
|
|
|
|
kExternalGlobal, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kExternRefCode, // type
|
2020-01-15 11:55:19 +00:00
|
|
|
0), // mutability
|
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1),
|
2020-09-29 07:46:36 +00:00
|
|
|
kExternRefCode, // local type
|
|
|
|
0, // immutable
|
2020-01-15 11:55:19 +00:00
|
|
|
WASM_INIT_EXPR_GLOBAL(0)),
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// Should decode to exactly one global.
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
std::cout << result.error().message() << std::endl;
|
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(2u, result.value()->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->data_segments.size());
|
|
|
|
|
|
|
|
const WasmGlobal* global = &result.value()->globals.back();
|
|
|
|
|
2020-06-10 07:22:22 +00:00
|
|
|
EXPECT_EQ(kWasmExternRef, global->type);
|
2020-01-15 11:55:19 +00:00
|
|
|
EXPECT_FALSE(global->mutability);
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kGlobalGet, global->init.kind());
|
2020-01-15 11:55:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 18:30:35 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalInvalidType) {
|
2016-06-07 09:35:52 +00:00
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
2020-09-28 18:30:35 +00:00
|
|
|
64, // invalid value type
|
2018-10-17 08:43:53 +00:00
|
|
|
1, // mutable
|
|
|
|
WASM_INIT_EXPR_I32V_1(33)), // init
|
2016-06-07 09:35:52 +00:00
|
|
|
};
|
|
|
|
|
2018-10-16 13:19:03 +00:00
|
|
|
EXPECT_FAILURE(data);
|
2016-09-14 15:44:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 18:30:35 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalInvalidType2) {
|
2016-09-14 15:44:15 +00:00
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kVoidCode, // invalid value type
|
2018-10-17 08:43:53 +00:00
|
|
|
1, // mutable
|
|
|
|
WASM_INIT_EXPR_I32V_1(33)), // init
|
2016-09-14 15:44:15 +00:00
|
|
|
};
|
|
|
|
|
2018-10-16 13:19:03 +00:00
|
|
|
EXPECT_FAILURE(data);
|
2016-06-07 09:35:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 18:30:35 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalInitializer) {
|
2020-08-13 19:55:19 +00:00
|
|
|
static const byte no_initializer_no_end[] = {
|
|
|
|
SECTION(Global, //--
|
|
|
|
ENTRY_COUNT(1), //--
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-08-13 19:55:19 +00:00
|
|
|
1) // mutable
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(no_initializer_no_end,
|
|
|
|
"Global initializer is missing 'end'");
|
|
|
|
|
|
|
|
static const byte no_initializer[] = {
|
|
|
|
SECTION(Global, //--
|
|
|
|
ENTRY_COUNT(1), //--
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-08-13 19:55:19 +00:00
|
|
|
1, // mutable
|
|
|
|
kExprEnd) // --
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(no_initializer,
|
|
|
|
"Found 'end' in global initalizer, but no "
|
|
|
|
"expressions were found on the stack");
|
|
|
|
|
|
|
|
static const byte too_many_initializers_no_end[] = {
|
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-08-13 19:55:19 +00:00
|
|
|
1, // mutable
|
|
|
|
WASM_I32V_1(42), // one value is good
|
|
|
|
WASM_I32V_1(43)) // another value is too much
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(too_many_initializers_no_end,
|
|
|
|
"Global initializer is missing 'end'");
|
|
|
|
|
|
|
|
static const byte too_many_initializers[] = {
|
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-08-13 19:55:19 +00:00
|
|
|
1, // mutable
|
|
|
|
WASM_I32V_1(42), // one value is good
|
|
|
|
WASM_I32V_1(43), // another value is too much
|
|
|
|
kExprEnd)};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(too_many_initializers,
|
|
|
|
"Found 'end' in global initalizer, but more than one "
|
|
|
|
"expressions were found on the stack");
|
|
|
|
|
|
|
|
static const byte missing_end_opcode[] = {
|
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-08-13 19:55:19 +00:00
|
|
|
1, // mutable
|
|
|
|
WASM_I32V_1(42)) // init value
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(missing_end_opcode,
|
|
|
|
"Global initializer is missing 'end'");
|
2020-09-28 18:30:35 +00:00
|
|
|
|
|
|
|
static const byte referencing_out_of_bounds_global[] = {
|
|
|
|
SECTION(Global, ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-09-28 18:30:35 +00:00
|
|
|
1, // mutable
|
2020-12-17 16:56:08 +00:00
|
|
|
WASM_GLOBAL_GET(42), kExprEnd) // init value
|
2020-09-28 18:30:35 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(referencing_out_of_bounds_global,
|
|
|
|
"global index is out of bounds");
|
|
|
|
|
|
|
|
static const byte referencing_undefined_global[] = {
|
|
|
|
SECTION(Global, ENTRY_COUNT(2), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-09-28 18:30:35 +00:00
|
|
|
0, // mutable
|
2020-12-17 16:56:08 +00:00
|
|
|
WASM_GLOBAL_GET(1), kExprEnd, // init value
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-09-28 18:30:35 +00:00
|
|
|
0, // mutable
|
|
|
|
WASM_I32V(0), kExprEnd) // init value
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(referencing_undefined_global,
|
|
|
|
"global #1 is not defined yet");
|
|
|
|
|
|
|
|
{
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
static const byte referencing_undefined_global_nested[] = {
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
SECTION(Global, ENTRY_COUNT(2), // --
|
|
|
|
WASM_RTT(2, kFuncRefCode), // type
|
|
|
|
0, // mutable
|
|
|
|
WASM_RTT_SUB(kFuncRefCode, // init value
|
|
|
|
WASM_GLOBAL_GET(1)), // --
|
|
|
|
kExprEnd, // --
|
|
|
|
WASM_RTT(1, kFuncRefCode), // type
|
|
|
|
0, // mutable
|
|
|
|
WASM_RTT_CANON(kFuncRefCode), kExprEnd) // init value
|
2020-09-28 18:30:35 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(referencing_undefined_global_nested,
|
|
|
|
"global #1 is not defined yet");
|
|
|
|
}
|
|
|
|
|
|
|
|
static const byte referencing_mutable_global[] = {
|
|
|
|
SECTION(Global, ENTRY_COUNT(2), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-09-28 18:30:35 +00:00
|
|
|
1, // mutable
|
|
|
|
WASM_I32V(1), kExprEnd, // init value
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-09-28 18:30:35 +00:00
|
|
|
0, // mutable
|
2020-12-17 16:56:08 +00:00
|
|
|
WASM_GLOBAL_GET(0), kExprEnd) // init value
|
2020-09-28 18:30:35 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(
|
|
|
|
referencing_mutable_global,
|
|
|
|
"mutable globals cannot be used in initializer expressions");
|
|
|
|
|
|
|
|
static const byte referencing_mutable_imported_global[] = {
|
|
|
|
SECTION(Import, ENTRY_COUNT(1), // --
|
|
|
|
ADD_COUNT('m'), ADD_COUNT('n'), // module, name
|
|
|
|
kExternalGlobal, // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-09-28 18:30:35 +00:00
|
|
|
1), // mutable
|
|
|
|
SECTION(Global, ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-09-28 18:30:35 +00:00
|
|
|
0, // mutable
|
2020-12-17 16:56:08 +00:00
|
|
|
WASM_GLOBAL_GET(0), kExprEnd) // init value
|
2020-09-28 18:30:35 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(
|
|
|
|
referencing_mutable_imported_global,
|
|
|
|
"mutable globals cannot be used in initializer expressions");
|
|
|
|
|
|
|
|
static const byte referencing_immutable_imported_global[] = {
|
|
|
|
SECTION(Import, ENTRY_COUNT(1), // --
|
|
|
|
ADD_COUNT('m'), ADD_COUNT('n'), // module, name
|
|
|
|
kExternalGlobal, // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-09-28 18:30:35 +00:00
|
|
|
0), // mutable
|
|
|
|
SECTION(Global, ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-09-28 18:30:35 +00:00
|
|
|
0, // mutable
|
2020-12-17 16:56:08 +00:00
|
|
|
WASM_GLOBAL_GET(0), kExprEnd) // init value
|
2020-09-28 18:30:35 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(referencing_immutable_imported_global);
|
|
|
|
|
|
|
|
static const byte referencing_local_global[] = {
|
|
|
|
SECTION(Global, ENTRY_COUNT(2), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-09-28 18:30:35 +00:00
|
|
|
0, // mutable
|
|
|
|
WASM_I32V(1), kExprEnd, // init value
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-09-28 18:30:35 +00:00
|
|
|
0, // mutable
|
2020-12-17 16:56:08 +00:00
|
|
|
WASM_GLOBAL_GET(0), kExprEnd) // init value
|
2020-09-28 18:30:35 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(
|
|
|
|
referencing_local_global,
|
|
|
|
"non-imported globals cannot be used in initializer expressions");
|
|
|
|
|
|
|
|
{
|
|
|
|
// But: experimental-wasm-gc should enable referencing immutable local
|
|
|
|
// globals.
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
EXPECT_VERIFIES(referencing_local_global);
|
|
|
|
// Referencing mutable glocals still invalid.
|
|
|
|
EXPECT_FAILURE_WITH_MSG(
|
|
|
|
referencing_mutable_global,
|
|
|
|
"mutable globals cannot be used in initializer expressions");
|
|
|
|
}
|
2020-08-13 19:55:19 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ZeroGlobals) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {SECTION(Global, ENTRY_COUNT(0))};
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:18:07 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportMutableGlobal) {
|
|
|
|
{
|
|
|
|
static const byte data[] = {
|
2018-10-17 09:31:01 +00:00
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // local type
|
2018-10-17 09:31:01 +00:00
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_I32V_1(13)), // init
|
|
|
|
SECTION(Export, // --
|
|
|
|
ENTRY_COUNT(1), // export count
|
|
|
|
ADD_COUNT('n', 'a', 'm', 'e'), // name
|
|
|
|
kExternalGlobal, // global
|
|
|
|
0), // global index
|
2016-11-08 14:18:07 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
static const byte data[] = {
|
2018-10-17 09:31:01 +00:00
|
|
|
SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // local type
|
2018-10-17 09:31:01 +00:00
|
|
|
1, // mutable
|
|
|
|
WASM_INIT_EXPR_I32V_1(13)), // init
|
|
|
|
SECTION(Export, // --
|
|
|
|
ENTRY_COUNT(1), // export count
|
|
|
|
ADD_COUNT('n', 'a', 'm', 'e'), // name
|
|
|
|
kExternalGlobal, // global
|
|
|
|
0), // global index
|
2016-11-08 14:18:07 +00:00
|
|
|
};
|
2018-06-12 22:23:35 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-11-08 14:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 08:37:53 +00:00
|
|
|
static void AppendUint32v(std::vector<byte>* buffer, uint32_t val) {
|
2015-12-11 12:26:16 +00:00
|
|
|
while (true) {
|
|
|
|
uint32_t next = val >> 7;
|
2017-12-02 00:30:37 +00:00
|
|
|
uint32_t out = val & 0x7F;
|
2015-12-11 12:26:16 +00:00
|
|
|
if (next) {
|
2019-09-10 08:37:53 +00:00
|
|
|
buffer->push_back(static_cast<byte>(0x80 | out));
|
2015-12-11 12:26:16 +00:00
|
|
|
val = next;
|
|
|
|
} else {
|
2019-09-10 08:37:53 +00:00
|
|
|
buffer->push_back(static_cast<byte>(out));
|
2015-12-11 12:26:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, NGlobals) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2020-09-29 07:46:36 +00:00
|
|
|
kF32Code, // memory type
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_F32(7.7), // init
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
2016-02-28 00:37:11 +00:00
|
|
|
|
2016-12-14 17:45:59 +00:00
|
|
|
for (uint32_t i = 0; i < kV8MaxWasmGlobals; i = i * 13 + 1) {
|
2015-12-11 12:26:16 +00:00
|
|
|
std::vector<byte> buffer;
|
2016-04-29 09:39:26 +00:00
|
|
|
size_t size = SizeOfVarInt(i) + i * sizeof(data);
|
2016-09-27 20:46:10 +00:00
|
|
|
const byte globals[] = {kGlobalSectionCode, U32V_5(size)};
|
2016-03-10 12:36:42 +00:00
|
|
|
for (size_t g = 0; g != sizeof(globals); ++g) {
|
|
|
|
buffer.push_back(globals[g]);
|
|
|
|
}
|
2019-09-10 08:37:53 +00:00
|
|
|
AppendUint32v(&buffer, i); // Number of globals.
|
2015-12-17 11:38:28 +00:00
|
|
|
for (uint32_t j = 0; j < i; j++) {
|
2016-02-28 00:37:11 +00:00
|
|
|
buffer.insert(buffer.end(), data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(&buffer[0], &buffer[0] + buffer.size());
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, TwoGlobals) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {SECTION(Global, // --
|
|
|
|
ENTRY_COUNT(2), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kF32Code, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_F32(22.0), // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kF64Code, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
1, // mutable
|
|
|
|
WASM_INIT_EXPR_F64(23.0))}; // --
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Should decode to exactly two globals.
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(2u, result.value()->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->data_segments.size());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
const WasmGlobal* g0 = &result.value()->globals[0];
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
EXPECT_EQ(kWasmF32, g0->type);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, g0->offset);
|
2016-09-27 22:09:36 +00:00
|
|
|
EXPECT_FALSE(g0->mutability);
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kF32Const, g0->init.kind());
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
const WasmGlobal* g1 = &result.value()->globals[1];
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
EXPECT_EQ(kWasmF64, g1->type);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(8u, g1->offset);
|
2016-09-27 22:09:36 +00:00
|
|
|
EXPECT_TRUE(g1->mutability);
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kF64Const, g1->init.kind());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 17:52:56 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, RefNullGlobal) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-09-29 07:46:36 +00:00
|
|
|
static const byte data[] = {SECTION(Global, ENTRY_COUNT(1), kFuncRefCode, 1,
|
|
|
|
WASM_REF_NULL(kFuncRefCode), kExprEnd)};
|
2020-07-09 17:52:56 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, RefNullGlobalInvalid1) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
2020-09-29 07:46:36 +00:00
|
|
|
static const byte data[] = {SECTION(Global, ENTRY_COUNT(1), kOptRefCode, 0, 1,
|
|
|
|
WASM_REF_NULL(0), kExprEnd)};
|
2020-07-09 17:52:56 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2020-08-05 11:12:29 +00:00
|
|
|
EXPECT_NOT_OK(result, "Type index 0 is out of bounds");
|
2020-07-09 17:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, RefNullGlobalInvalid2) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
2020-09-29 07:46:36 +00:00
|
|
|
static const byte data[] = {SECTION(Global, ENTRY_COUNT(1), kFuncRefCode, 1,
|
2020-07-09 17:52:56 +00:00
|
|
|
kExprRefNull, U32V_5(1000001), kExprEnd)};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result,
|
|
|
|
"Type index 1000001 is greater than the maximum number 1000000 "
|
|
|
|
"of type definitions supported by V8");
|
|
|
|
}
|
|
|
|
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, RttCanonGlobalGeneric) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
static const byte data[] = {SECTION(Global, ENTRY_COUNT(1),
|
|
|
|
WASM_RTT(1, kFuncRefCode), 1,
|
|
|
|
WASM_RTT_CANON(kFuncRefCode), kExprEnd)};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
}
|
|
|
|
|
2020-07-10 15:47:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, RttCanonGlobalStruct) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1),
|
2020-09-29 07:46:36 +00:00
|
|
|
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI32Code, true))),
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
SECTION(Global, ENTRY_COUNT(1), WASM_RTT(1, 0), 0, WASM_RTT_CANON(0),
|
2020-07-10 15:47:42 +00:00
|
|
|
kExprEnd)};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, RttCanonGlobalTypeError) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
static const byte data[] = {SECTION(Global, ENTRY_COUNT(1),
|
|
|
|
WASM_RTT(1, kExternRefCode), 1,
|
|
|
|
WASM_RTT_CANON(kFuncRefCode), kExprEnd)};
|
2020-07-10 15:47:42 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result,
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
"type error in init expression, expected (rtt 1 extern), got "
|
|
|
|
"(rtt 1 func)");
|
2020-07-10 15:47:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalRttSubOfCanon) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
2020-09-29 07:46:36 +00:00
|
|
|
static const byte data[] = {
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
SECTION(Global, ENTRY_COUNT(1), WASM_RTT(2, kI31RefCode), 1,
|
|
|
|
WASM_RTT_SUB(kI31RefCode, WASM_RTT_CANON(kEqRefCode)), kExprEnd)};
|
2020-07-10 15:47:42 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
WasmInitExpr expected = WasmInitExpr::RttSub(
|
|
|
|
HeapType::kI31, WasmInitExpr::RttCanon(HeapType::kEq));
|
2020-07-10 15:47:42 +00:00
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(result.value()->globals.front().init, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalRttSubOfSubOfCanon) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
static const byte data[] = {SECTION(
|
|
|
|
Global, ENTRY_COUNT(1), WASM_RTT(3, kEqRefCode), 1,
|
|
|
|
WASM_RTT_SUB(kEqRefCode,
|
|
|
|
WASM_RTT_SUB(kEqRefCode, WASM_RTT_CANON(kEqRefCode))),
|
|
|
|
kExprEnd)};
|
2020-07-10 15:47:42 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
WasmInitExpr expected = WasmInitExpr::RttSub(
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
HeapType::kEq, WasmInitExpr::RttSub(
|
|
|
|
HeapType::kEq, WasmInitExpr::RttCanon(HeapType::kEq)));
|
2020-07-10 15:47:42 +00:00
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(result.value()->globals.front().init, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalRttSubOfGlobal) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
static const byte data[] = {
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
SECTION(Import, // section header
|
|
|
|
ENTRY_COUNT(1), // number of imports
|
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('f'), // global name
|
|
|
|
kExternalGlobal, // import kind
|
|
|
|
WASM_RTT(1, kEqRefCode), // type
|
|
|
|
0), // mutability
|
|
|
|
SECTION(Global, ENTRY_COUNT(1), WASM_RTT(2, kI31RefCode), 1,
|
|
|
|
WASM_RTT_SUB(kI31RefCode, WASM_GLOBAL_GET(0)), kExprEnd)};
|
2020-07-10 15:47:42 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
WasmInitExpr expected =
|
|
|
|
WasmInitExpr::RttSub(HeapType::kI31, WasmInitExpr::GlobalGet(0));
|
2020-07-10 15:47:42 +00:00
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(result.value()->globals[1].init, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalRttSubOfGlobalTypeError) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Import, // section header
|
|
|
|
ENTRY_COUNT(1), // number of imports
|
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('f'), // global name
|
|
|
|
kExternalGlobal, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2020-07-10 15:47:42 +00:00
|
|
|
0), // mutability
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
SECTION(Global, ENTRY_COUNT(1), WASM_RTT(2, kExternRefCode), 1,
|
|
|
|
WASM_RTT_SUB(kExternRefCode, WASM_GLOBAL_GET(0)), kExprEnd)};
|
2020-07-10 15:47:42 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result, "rtt.sub requires a supertype rtt on stack");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, GlobalRttSubIllegalParent) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
static const byte data[] = {SECTION(
|
|
|
|
Global, ENTRY_COUNT(1), WASM_RTT(2, kEqRefCode), 1,
|
|
|
|
WASM_RTT_SUB(kEqRefCode, WASM_RTT_CANON(kExternRefCode)), kExprEnd)};
|
2020-07-10 15:47:42 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result, "rtt.sub requires a supertype rtt on stack");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, RttSubGlobalTypeError) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
static const byte data[] = {SECTION(
|
|
|
|
Global, ENTRY_COUNT(1), WASM_RTT(1 /* Should be 2 */, kI31RefCode), 1,
|
|
|
|
WASM_RTT_SUB(kI31RefCode, WASM_RTT_CANON(kEqRefCode)), kExprEnd)};
|
2020-07-10 15:47:42 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result,
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
"type error in init expression, expected (rtt 1 i31), got "
|
|
|
|
"(rtt 2 i31)");
|
2020-07-10 15:47:42 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 13:51:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, EmptyStruct) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
static const byte empty_struct[] = {SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmStructTypeCode, // --
|
|
|
|
U32V_1(0))}; // field count
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(empty_struct);
|
|
|
|
}
|
|
|
|
|
2020-09-11 16:55:24 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, InvalidStructTypeDef) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
static const byte all_good[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmStructTypeCode, // --
|
|
|
|
U32V_1(1), // field count
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // perfectly valid field type
|
2020-09-11 16:55:24 +00:00
|
|
|
1)}; // mutability
|
|
|
|
EXPECT_VERIFIES(all_good);
|
|
|
|
|
|
|
|
static const byte invalid_field_type[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmStructTypeCode, // --
|
|
|
|
U32V_1(1), // field count
|
|
|
|
kWasmArrayTypeCode, // bogus field type
|
|
|
|
1)}; // mutability
|
|
|
|
EXPECT_FAILURE_WITH_MSG(invalid_field_type, "invalid value type");
|
|
|
|
|
|
|
|
static const byte field_type_oob_ref[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmStructTypeCode, // --
|
|
|
|
U32V_1(1), // field count
|
2020-09-29 07:46:36 +00:00
|
|
|
kOptRefCode, // field type: reference...
|
2020-09-11 16:55:24 +00:00
|
|
|
3, // ...to nonexistent type
|
|
|
|
1)}; // mutability
|
|
|
|
EXPECT_FAILURE_WITH_MSG(field_type_oob_ref, "Type index 3 is out of bounds");
|
|
|
|
|
|
|
|
static const byte field_type_invalid_ref[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmStructTypeCode, // --
|
|
|
|
U32V_1(1), // field count
|
2020-09-29 07:46:36 +00:00
|
|
|
kOptRefCode, // field type: reference...
|
2020-09-11 16:55:24 +00:00
|
|
|
U32V_4(1234567), // ...to a type > kV8MaxWasmTypes
|
|
|
|
1)}; // mutability
|
|
|
|
EXPECT_FAILURE_WITH_MSG(field_type_invalid_ref, "greater than the maximum");
|
|
|
|
|
|
|
|
static const byte field_type_invalid_ref2[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmStructTypeCode, // --
|
|
|
|
U32V_1(1), // field count
|
2020-09-29 07:46:36 +00:00
|
|
|
kOptRefCode, // field type: reference...
|
|
|
|
kI32Code, // ...to a non-referenceable type
|
2020-09-11 16:55:24 +00:00
|
|
|
1)}; // mutability
|
|
|
|
EXPECT_FAILURE_WITH_MSG(field_type_invalid_ref2, "Unknown heap type");
|
|
|
|
|
|
|
|
static const byte not_enough_field_types[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmStructTypeCode, // --
|
|
|
|
U32V_1(2), // field count
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // field type 1
|
2020-09-11 16:55:24 +00:00
|
|
|
1)}; // mutability 1
|
|
|
|
EXPECT_FAILURE_WITH_MSG(not_enough_field_types, "expected 1 byte");
|
|
|
|
|
|
|
|
static const byte not_enough_field_types2[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmStructTypeCode, // --
|
|
|
|
U32V_1(2), // field count
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // field type 1
|
2020-09-11 16:55:24 +00:00
|
|
|
1, // mutability 1
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code)}; // field type 2
|
2020-09-11 16:55:24 +00:00
|
|
|
EXPECT_FAILURE_WITH_MSG(not_enough_field_types2, "expected 1 byte");
|
|
|
|
|
|
|
|
static const byte invalid_mutability[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmStructTypeCode, // --
|
|
|
|
U32V_1(1), // field count
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // field type
|
2020-09-11 16:55:24 +00:00
|
|
|
2)}; // invalid mutability value
|
|
|
|
EXPECT_FAILURE_WITH_MSG(invalid_mutability, "invalid mutability");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, InvalidArrayTypeDef) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
static const byte all_good[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmArrayTypeCode, // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // perfectly valid field type
|
2020-09-11 16:55:24 +00:00
|
|
|
1)}; // mutability
|
|
|
|
EXPECT_VERIFIES(all_good);
|
|
|
|
|
|
|
|
static const byte invalid_field_type[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmArrayTypeCode, // --
|
|
|
|
kWasmArrayTypeCode, // bogus field type
|
|
|
|
1)}; // mutability
|
|
|
|
EXPECT_FAILURE_WITH_MSG(invalid_field_type, "invalid value type");
|
|
|
|
|
|
|
|
static const byte field_type_oob_ref[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmArrayTypeCode, // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kOptRefCode, // field type: reference...
|
2020-09-11 16:55:24 +00:00
|
|
|
3, // ...to nonexistent type
|
|
|
|
1)}; // mutability
|
|
|
|
EXPECT_FAILURE_WITH_MSG(field_type_oob_ref, "Type index 3 is out of bounds");
|
|
|
|
|
|
|
|
static const byte field_type_invalid_ref[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmArrayTypeCode, // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kOptRefCode, // field type: reference...
|
2020-09-11 16:55:24 +00:00
|
|
|
U32V_3(1234567), // ...to a type > kV8MaxWasmTypes
|
|
|
|
1)}; // mutability
|
|
|
|
EXPECT_FAILURE_WITH_MSG(field_type_invalid_ref, "Unknown heap type");
|
|
|
|
|
|
|
|
static const byte field_type_invalid_ref2[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmArrayTypeCode, // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kOptRefCode, // field type: reference...
|
|
|
|
kI32Code, // ...to a non-referenceable type
|
2020-09-11 16:55:24 +00:00
|
|
|
1)}; // mutability
|
|
|
|
EXPECT_FAILURE_WITH_MSG(field_type_invalid_ref2, "Unknown heap type");
|
|
|
|
|
|
|
|
static const byte invalid_mutability[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), // --
|
|
|
|
kWasmArrayTypeCode, // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // field type
|
2020-09-11 16:55:24 +00:00
|
|
|
2)}; // invalid mutability value
|
|
|
|
EXPECT_FAILURE_WITH_MSG(invalid_mutability, "invalid mutability");
|
|
|
|
|
|
|
|
static const byte invalid_mutability2[] = {
|
|
|
|
SECTION(Type,
|
|
|
|
ENTRY_COUNT(1), // --
|
|
|
|
kWasmArrayTypeCode, // --
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // field type
|
2020-09-11 16:55:24 +00:00
|
|
|
0)}; // immmutability (disallowed in MVP)
|
|
|
|
EXPECT_FAILURE_WITH_MSG(invalid_mutability2,
|
|
|
|
"immutable arrays are not supported");
|
|
|
|
}
|
|
|
|
|
2017-07-10 19:15:28 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ZeroExceptions) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {SECTION(Exception, ENTRY_COUNT(0))};
|
2017-08-01 20:56:39 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
2017-07-10 19:15:28 +00:00
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2017-08-01 20:56:39 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(0u, result.value()->exceptions.size());
|
2017-07-10 19:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, OneI32Exception) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Type, ENTRY_COUNT(1), SIG_ENTRY_v_x(kI32Code)), // sig#0 (i32)
|
2018-10-22 08:39:58 +00:00
|
|
|
SECTION(Exception, ENTRY_COUNT(1),
|
|
|
|
EXCEPTION_ENTRY(SIG_INDEX(0)))}; // except[0] (sig#0)
|
2017-08-01 20:56:39 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
2017-07-10 19:15:28 +00:00
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2017-08-01 20:56:39 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->exceptions.size());
|
2017-07-10 19:15:28 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
const WasmException& e0 = result.value()->exceptions.front();
|
2017-08-01 20:56:39 +00:00
|
|
|
EXPECT_EQ(1u, e0.sig->parameter_count());
|
2018-05-07 11:02:21 +00:00
|
|
|
EXPECT_EQ(kWasmI32, e0.sig->GetParam(0));
|
2017-07-10 19:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, TwoExceptions) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(2),
|
2020-09-29 07:46:36 +00:00
|
|
|
SIG_ENTRY_v_x(kI32Code), // sig#0 (i32)
|
|
|
|
SIG_ENTRY_v_xx(kF32Code, kI64Code)), // sig#1 (f32, i64)
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Exception, ENTRY_COUNT(2),
|
2018-10-22 08:39:58 +00:00
|
|
|
EXCEPTION_ENTRY(SIG_INDEX(1)), // except[0] (sig#1)
|
|
|
|
EXCEPTION_ENTRY(SIG_INDEX(0)))}; // except[1] (sig#0)
|
2017-08-01 20:56:39 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2017-08-01 20:56:39 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(2u, result.value()->exceptions.size());
|
|
|
|
const WasmException& e0 = result.value()->exceptions.front();
|
2017-08-01 20:56:39 +00:00
|
|
|
EXPECT_EQ(2u, e0.sig->parameter_count());
|
2018-05-07 11:02:21 +00:00
|
|
|
EXPECT_EQ(kWasmF32, e0.sig->GetParam(0));
|
|
|
|
EXPECT_EQ(kWasmI64, e0.sig->GetParam(1));
|
2018-10-19 12:35:56 +00:00
|
|
|
const WasmException& e1 = result.value()->exceptions.back();
|
2018-05-07 11:02:21 +00:00
|
|
|
EXPECT_EQ(kWasmI32, e1.sig->GetParam(0));
|
2017-07-10 19:15:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-15 14:31:16 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Exception_invalid_sig_index) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Exception, ENTRY_COUNT(1),
|
2018-10-22 08:39:58 +00:00
|
|
|
EXCEPTION_ENTRY(
|
|
|
|
SIG_INDEX(23)))}; // except[0] (sig#23 [out-of-bounds])
|
2018-10-15 14:31:16 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
// Should fail decoding exception section.
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2018-10-19 08:24:38 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result, "signature index 23 out of bounds");
|
2018-10-15 14:31:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, Exception_invalid_sig_return) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), SIG_ENTRY_i_i),
|
|
|
|
SECTION(Exception, ENTRY_COUNT(1),
|
2018-10-22 08:39:58 +00:00
|
|
|
EXCEPTION_ENTRY(
|
|
|
|
SIG_INDEX(0)))}; // except[0] (sig#0 [invalid-return-type])
|
2017-08-01 20:56:39 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
2017-07-10 19:15:28 +00:00
|
|
|
|
2017-08-01 20:56:39 +00:00
|
|
|
// Should fail decoding exception section.
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2018-10-19 08:24:38 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result, "exception signature 0 has non-void return");
|
2017-07-10 19:15:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-22 08:39:58 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Exception_invalid_attribute) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1), SIG_ENTRY_i_i),
|
|
|
|
SECTION(Exception, ENTRY_COUNT(1), 23,
|
|
|
|
SIG_INDEX(0))}; // except[0] (sig#0) [invalid-attribute]
|
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
// Should fail decoding exception section.
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result, "exception attribute 23 not supported");
|
|
|
|
}
|
|
|
|
|
2018-09-06 08:14:22 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExceptionSectionCorrectPlacement) {
|
2020-03-23 17:30:44 +00:00
|
|
|
static const byte data[] = {SECTION(Memory, ENTRY_COUNT(0)),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Exception, ENTRY_COUNT(0)),
|
2020-03-23 17:30:44 +00:00
|
|
|
SECTION(Global, ENTRY_COUNT(0))};
|
2018-09-04 13:56:54 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
}
|
|
|
|
|
2020-03-23 17:30:44 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterGlobal) {
|
|
|
|
static const byte data[] = {SECTION(Global, ENTRY_COUNT(0)),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Exception, ENTRY_COUNT(0))};
|
2018-09-06 08:14:22 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2018-10-19 08:24:38 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2018-11-29 19:23:59 +00:00
|
|
|
EXPECT_NOT_OK(result,
|
2020-03-23 17:30:44 +00:00
|
|
|
"The Exception section must appear before the Global section");
|
2018-09-06 08:14:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 17:30:44 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExceptionSectionBeforeMemory) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {SECTION(Exception, ENTRY_COUNT(0)),
|
2020-03-23 17:30:44 +00:00
|
|
|
SECTION(Memory, ENTRY_COUNT(0))};
|
2018-09-04 13:56:54 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
2018-10-19 08:24:38 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2020-03-23 17:30:44 +00:00
|
|
|
EXPECT_NOT_OK(result, "unexpected section <Memory>");
|
2018-09-04 13:56:54 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 17:30:44 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExceptionSectionAfterTableBeforeMemory) {
|
2018-11-30 10:23:48 +00:00
|
|
|
STATIC_ASSERT(kMemorySectionCode + 1 == kGlobalSectionCode);
|
2020-03-23 17:30:44 +00:00
|
|
|
static const byte data[] = {SECTION(Table, ENTRY_COUNT(0)),
|
2018-11-28 13:22:28 +00:00
|
|
|
SECTION(Exception, ENTRY_COUNT(0)),
|
2020-03-23 17:30:44 +00:00
|
|
|
SECTION(Memory, ENTRY_COUNT(0))};
|
2018-11-28 13:22:28 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2020-03-23 17:30:44 +00:00
|
|
|
EXPECT_NOT_OK(result, "unexpected section <Memory>");
|
2018-11-28 13:22:28 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 08:38:24 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExceptionImport) {
|
2018-10-22 08:39:58 +00:00
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-10-22 08:39:58 +00:00
|
|
|
SECTION(Import, // section header
|
|
|
|
ENTRY_COUNT(1), // number of imports
|
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('e', 'x'), // exception name
|
|
|
|
kExternalException, // import kind
|
|
|
|
EXCEPTION_ENTRY(SIG_INDEX(0)))}; // except[0] (sig#0)
|
2018-09-11 08:38:24 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->exceptions.size());
|
|
|
|
EXPECT_EQ(1u, result.value()->import_table.size());
|
2018-09-11 08:38:24 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 08:14:22 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExceptionExport) {
|
2018-10-22 08:39:58 +00:00
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-10-22 08:39:58 +00:00
|
|
|
SECTION(Exception, ENTRY_COUNT(1),
|
|
|
|
EXCEPTION_ENTRY(SIG_INDEX(0))), // except[0] (sig#0)
|
|
|
|
SECTION(Export, ENTRY_COUNT(1), // --
|
|
|
|
NO_NAME, // --
|
|
|
|
kExternalException, // --
|
|
|
|
EXCEPTION_INDEX(0))};
|
2018-09-06 08:14:22 +00:00
|
|
|
FAIL_IF_NO_EXPERIMENTAL_EH(data);
|
|
|
|
|
|
|
|
WASM_FEATURE_SCOPE(eh);
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->exceptions.size());
|
|
|
|
EXPECT_EQ(1u, result.value()->export_table.size());
|
2018-09-06 08:14:22 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OneSignature) {
|
2016-02-27 01:52:30 +00:00
|
|
|
{
|
2020-09-24 11:52:48 +00:00
|
|
|
static const byte data[] = {TYPE_SECTION_ONE_SIG_VOID_VOID};
|
2016-02-27 01:52:30 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {SECTION(Type, ENTRY_COUNT(1), SIG_ENTRY_i_i)};
|
2016-02-27 01:52:30 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleSignatures) {
|
|
|
|
static const byte data[] = {
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Type, // --
|
|
|
|
ENTRY_COUNT(3), // --
|
|
|
|
SIG_ENTRY_v_v, // void -> void
|
|
|
|
SIG_ENTRY_x_x(kI32Code, kF32Code), // f32 -> i32
|
|
|
|
SIG_ENTRY_x_xx(kI32Code, kF64Code, kF64Code)), // f64,f64 -> i32
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2020-04-20 18:19:12 +00:00
|
|
|
EXPECT_EQ(3u, result.value()->types.size());
|
|
|
|
if (result.value()->types.size() == 3) {
|
|
|
|
EXPECT_EQ(0u, result.value()->signature(0)->return_count());
|
|
|
|
EXPECT_EQ(1u, result.value()->signature(1)->return_count());
|
|
|
|
EXPECT_EQ(1u, result.value()->signature(2)->return_count());
|
|
|
|
|
|
|
|
EXPECT_EQ(0u, result.value()->signature(0)->parameter_count());
|
|
|
|
EXPECT_EQ(1u, result.value()->signature(1)->parameter_count());
|
|
|
|
EXPECT_EQ(2u, result.value()->signature(2)->parameter_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 1);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2020-10-05 14:43:14 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, CanonicalTypeIds) {
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Type, // --
|
|
|
|
ENTRY_COUNT(5), // --
|
|
|
|
WASM_STRUCT_DEF( // Struct definition
|
|
|
|
FIELD_COUNT(1), // --
|
|
|
|
STRUCT_FIELD(kI32Code, true)), // --
|
|
|
|
SIG_ENTRY_x_x(kI32Code, kF32Code), // f32 -> i32
|
|
|
|
SIG_ENTRY_x_x(kI32Code, kF64Code), // f64 -> i32
|
|
|
|
SIG_ENTRY_x_x(kI32Code, kF32Code), // f32 -> i32 (again)
|
|
|
|
WASM_ARRAY_DEF(kI32Code, true)) // Array definition
|
|
|
|
};
|
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
const WasmModule* module = result.value().get();
|
|
|
|
|
|
|
|
EXPECT_EQ(5u, module->types.size());
|
|
|
|
EXPECT_EQ(5u, module->type_kinds.size());
|
|
|
|
EXPECT_EQ(5u, module->canonicalized_type_ids.size());
|
|
|
|
EXPECT_EQ(2u, module->signature_map.size());
|
|
|
|
|
|
|
|
// No canonicalization for structs.
|
|
|
|
EXPECT_EQ(0u, module->canonicalized_type_ids[0]);
|
|
|
|
EXPECT_EQ(0u, module->canonicalized_type_ids[1]);
|
|
|
|
EXPECT_EQ(1u, module->canonicalized_type_ids[2]);
|
|
|
|
EXPECT_EQ(0u, module->canonicalized_type_ids[3]);
|
|
|
|
// No canonicalization for arrays.
|
|
|
|
EXPECT_EQ(0u, module->canonicalized_type_ids[4]);
|
|
|
|
}
|
|
|
|
|
2016-11-09 15:52:17 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableImportedGlobal) {
|
|
|
|
// Import 2 globals so that we can initialize data with a global index != 0.
|
|
|
|
const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import, // section header
|
|
|
|
ENTRY_COUNT(2), // number of imports
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('f'), // global name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalGlobal, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // mutability
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('n'), // module name
|
|
|
|
ADD_COUNT('g'), // global name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalGlobal, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
0), // mutability
|
2020-09-24 08:00:58 +00:00
|
|
|
SECTION(Memory, ENTRY_COUNT(1), kWithMaximum, 28, 28),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_GLOBAL(1), // dest addr
|
|
|
|
U32V_1(3), // source size
|
|
|
|
'a', 'b', 'c') // data bytes
|
2016-11-09 15:52:17 +00:00
|
|
|
};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
2020-07-09 13:21:45 +00:00
|
|
|
WasmInitExpr expr = std::move(result.value()->data_segments.back()).dest_addr;
|
|
|
|
EXPECT_EQ(WasmInitExpr::kGlobalGet, expr.kind());
|
|
|
|
EXPECT_EQ(1u, expr.immediate().index);
|
2016-11-09 15:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, DataSegmentWithMutableImportedGlobal) {
|
|
|
|
// Only an immutable imported global can be used as an init_expr.
|
|
|
|
const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import, // section header
|
|
|
|
ENTRY_COUNT(1), // number of imports
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('f'), // global name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalGlobal, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
1), // mutability
|
2020-09-24 08:00:58 +00:00
|
|
|
SECTION(Memory, ENTRY_COUNT(1), kWithMaximum, 28, 28),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_GLOBAL(0), // dest addr
|
|
|
|
U32V_1(3), // source size
|
|
|
|
'a', 'b', 'c') // data bytes
|
2016-11-09 15:52:17 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableGlobal) {
|
|
|
|
// Only an immutable imported global can be used as an init_expr.
|
|
|
|
const byte data[] = {
|
2020-09-24 08:00:58 +00:00
|
|
|
SECTION(Memory, ENTRY_COUNT(1), kWithMaximum, 28, 28),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Global, ENTRY_COUNT(1),
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // local type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // immutable
|
|
|
|
WASM_INIT_EXPR_I32V_3(0x9BBAA)), // init
|
|
|
|
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_GLOBAL(0), // dest addr
|
|
|
|
U32V_1(3), // source size
|
|
|
|
'a', 'b', 'c') // data bytes
|
2016-11-09 15:52:17 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OneDataSegment) {
|
2016-09-27 20:46:10 +00:00
|
|
|
const byte kDataSegmentSourceOffset = 24;
|
2015-12-11 12:26:16 +00:00
|
|
|
const byte data[] = {
|
2020-09-24 08:00:58 +00:00
|
|
|
SECTION(Memory, ENTRY_COUNT(1), kWithMaximum, 28, 28),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_I32V_3(0x9BBAA), // dest addr
|
|
|
|
U32V_1(3), // source size
|
|
|
|
'a', 'b', 'c') // data bytes
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
2016-01-20 15:19:58 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(0u, result.value()->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(1u, result.value()->data_segments.size());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
const WasmDataSegment* segment = &result.value()->data_segments.back();
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kI32Const, segment->dest_addr.kind());
|
|
|
|
EXPECT_EQ(0x9BBAA, segment->dest_addr.immediate().i32_const);
|
2017-06-12 11:59:14 +00:00
|
|
|
EXPECT_EQ(kDataSegmentSourceOffset, segment->source.offset());
|
|
|
|
EXPECT_EQ(3u, segment->source.length());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 14);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, TwoDataSegments) {
|
2016-09-27 20:46:10 +00:00
|
|
|
const byte kDataSegment0SourceOffset = 24;
|
|
|
|
const byte kDataSegment1SourceOffset = kDataSegment0SourceOffset + 11;
|
2016-03-09 19:43:02 +00:00
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
const byte data[] = {
|
2020-09-24 08:00:58 +00:00
|
|
|
SECTION(Memory, ENTRY_COUNT(1), kWithMaximum, 28, 28),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Data,
|
|
|
|
ENTRY_COUNT(2), // segment count
|
|
|
|
LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_I32V_3(0x7FFEE), // #0: dest addr
|
|
|
|
U32V_1(4), // source size
|
|
|
|
1, 2, 3, 4, // data bytes
|
|
|
|
LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_I32V_3(0x6DDCC), // #1: dest addr
|
|
|
|
U32V_1(10), // source size
|
|
|
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // data bytes
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(0u, result.value()->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(2u, result.value()->data_segments.size());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
const WasmDataSegment* s0 = &result.value()->data_segments[0];
|
|
|
|
const WasmDataSegment* s1 = &result.value()->data_segments[1];
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kI32Const, s0->dest_addr.kind());
|
|
|
|
EXPECT_EQ(0x7FFEE, s0->dest_addr.immediate().i32_const);
|
2017-06-12 11:59:14 +00:00
|
|
|
EXPECT_EQ(kDataSegment0SourceOffset, s0->source.offset());
|
|
|
|
EXPECT_EQ(4u, s0->source.length());
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kI32Const, s1->dest_addr.kind());
|
|
|
|
EXPECT_EQ(0x6DDCC, s1->dest_addr.immediate().i32_const);
|
2017-06-12 11:59:14 +00:00
|
|
|
EXPECT_EQ(kDataSegment1SourceOffset, s1->source.offset());
|
|
|
|
EXPECT_EQ(10u, s1->source.length());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, 14);
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 10:37:06 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DataWithoutMemory) {
|
|
|
|
const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_I32V_3(0x9BBAA), // dest addr
|
|
|
|
U32V_1(3), // source size
|
|
|
|
'a', 'b', 'c') // data bytes
|
2016-11-09 10:37:06 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-11-07 12:25:49 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, MaxMaximumMemorySize) {
|
|
|
|
{
|
|
|
|
const byte data[] = {
|
2020-09-24 08:00:58 +00:00
|
|
|
SECTION(Memory, ENTRY_COUNT(1), kWithMaximum, 0, U32V_3(65536))};
|
2016-11-07 12:25:49 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const byte data[] = {
|
2020-09-24 08:00:58 +00:00
|
|
|
SECTION(Memory, ENTRY_COUNT(1), kWithMaximum, 0, U32V_3(65537))};
|
2016-11-07 12:25:49 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 15:07:03 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, InvalidMemoryLimits) {
|
|
|
|
{
|
|
|
|
const byte kInvalidLimits = 0x15;
|
|
|
|
const byte data[] = {
|
|
|
|
SECTION(Memory, ENTRY_COUNT(1), kInvalidLimits, 0, 10)};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(data, "invalid memory limits flags 0x15");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DataSegment_wrong_init_type) {
|
|
|
|
const byte data[] = {
|
2020-09-24 08:00:58 +00:00
|
|
|
SECTION(Memory, ENTRY_COUNT(1), kWithMaximum, 28, 28),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0,
|
|
|
|
WASM_INIT_EXPR_F64(9.9), // dest addr
|
|
|
|
U32V_1(3), // source size
|
|
|
|
'a', 'b', 'c') // data bytes
|
2016-09-27 20:46:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
2016-09-23 15:56:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 14:09:39 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DataSegmentEndOverflow) {
|
|
|
|
const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Memory, // memory section
|
2020-09-24 08:00:58 +00:00
|
|
|
ENTRY_COUNT(1), kWithMaximum, 28, 28),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Data, // data section
|
|
|
|
ENTRY_COUNT(1), // one entry
|
|
|
|
LINEAR_MEMORY_INDEX_0, // mem index
|
|
|
|
WASM_INIT_EXPR_I32V_1(0), // offset
|
|
|
|
U32V_5(0xFFFFFFFF)) // size
|
2017-08-08 14:09:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-09-23 17:58:07 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OneIndirectFunction) {
|
2016-09-23 15:56:42 +00:00
|
|
|
static const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2016-09-27 20:46:10 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
2018-10-16 15:34:13 +00:00
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2016-09-27 20:46:10 +00:00
|
|
|
// table declaration ---------------------------------------------------
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 1),
|
2018-11-29 16:28:31 +00:00
|
|
|
// code ----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
2016-09-23 15:56:42 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
if (result.ok()) {
|
2020-04-20 18:19:12 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->types.size());
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(1u, result.value()->tables.size());
|
|
|
|
EXPECT_EQ(1u, result.value()->tables[0].initial_size);
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 09:53:25 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionWithInternalTable) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// table ---------------------------------------------------------------
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 1),
|
2017-08-24 09:53:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element, ENTRY_COUNT(0))};
|
2017-08-24 09:53:25 +00:00
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionWithImportedTable) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// imports -------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import, ENTRY_COUNT(1),
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('t'), // table name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalTable, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // elem_type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // no maximum field
|
|
|
|
1), // initial size
|
2017-08-24 09:53:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element, ENTRY_COUNT(0))};
|
2017-08-24 09:53:25 +00:00
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionWithoutTable) {
|
|
|
|
// Test that an element section without a table causes a validation error.
|
|
|
|
static const byte data[] = {
|
|
|
|
// elements ------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element,
|
|
|
|
ENTRY_COUNT(1), // entry count
|
|
|
|
0, // table index
|
|
|
|
0, // offset
|
|
|
|
0) // number of elements
|
2017-08-24 09:53:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2017-07-06 12:35:25 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Regression_735887) {
|
|
|
|
// Test with an invalid function index in the element section.
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2017-07-06 12:35:25 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
2018-10-16 15:34:13 +00:00
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2017-07-06 12:35:25 +00:00
|
|
|
// table declaration ---------------------------------------------------
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 1),
|
2017-07-06 12:35:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element,
|
|
|
|
ENTRY_COUNT(1), // entry count
|
2018-11-12 20:53:47 +00:00
|
|
|
TABLE_INDEX0, WASM_INIT_EXPR_I32V_1(0),
|
2018-10-17 08:43:53 +00:00
|
|
|
1, // elements count
|
|
|
|
0x9A) // invalid I32V as function index
|
2017-07-06 12:35:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OneIndirectFunction_one_entry) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2016-09-27 20:46:10 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
2018-10-16 15:34:13 +00:00
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2016-09-27 20:46:10 +00:00
|
|
|
// table declaration ---------------------------------------------------
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 1),
|
2016-09-27 20:46:10 +00:00
|
|
|
// elements ------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element,
|
|
|
|
ENTRY_COUNT(1), // entry count
|
2018-11-12 20:53:47 +00:00
|
|
|
TABLE_INDEX0, WASM_INIT_EXPR_I32V_1(0),
|
2018-10-17 08:43:53 +00:00
|
|
|
1, // elements count
|
2018-11-29 16:28:31 +00:00
|
|
|
FUNC_INDEX(0)),
|
|
|
|
// code ----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
2016-09-27 20:46:10 +00:00
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2020-04-20 18:19:12 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->types.size());
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(1u, result.value()->tables.size());
|
|
|
|
EXPECT_EQ(1u, result.value()->tables[0].initial_size);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Type,
|
2020-09-29 07:46:36 +00:00
|
|
|
ENTRY_COUNT(2), // --
|
|
|
|
SIG_ENTRY_v_v, // void -> void
|
|
|
|
SIG_ENTRY_v_x(kI32Code)), // void -> i32
|
2016-05-25 16:12:09 +00:00
|
|
|
// funcs ------------------------------------------------------
|
2018-10-16 15:34:13 +00:00
|
|
|
FOUR_EMPTY_FUNCTIONS(SIG_INDEX(0)),
|
2016-09-27 20:46:10 +00:00
|
|
|
// table declaration -------------------------------------------
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 8),
|
2016-09-27 20:46:10 +00:00
|
|
|
// table elements ----------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element,
|
|
|
|
ENTRY_COUNT(1), // entry count
|
2018-11-12 20:53:47 +00:00
|
|
|
TABLE_INDEX0, WASM_INIT_EXPR_I32V_1(0),
|
2018-10-17 12:16:05 +00:00
|
|
|
ADD_COUNT(FUNC_INDEX(0), FUNC_INDEX(1), FUNC_INDEX(2),
|
|
|
|
FUNC_INDEX(3), FUNC_INDEX(0), FUNC_INDEX(1),
|
|
|
|
FUNC_INDEX(2), FUNC_INDEX(3))),
|
2016-05-25 16:12:09 +00:00
|
|
|
FOUR_EMPTY_BODIES};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2020-04-20 18:19:12 +00:00
|
|
|
EXPECT_EQ(2u, result.value()->types.size());
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(4u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(1u, result.value()->tables.size());
|
|
|
|
EXPECT_EQ(8u, result.value()->tables[0].initial_size);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 09:56:25 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTables) {
|
|
|
|
// Test that if we have multiple tables, in the element section we can target
|
|
|
|
// and initialize all tables.
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-07-12 09:56:25 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
2018-10-16 15:34:13 +00:00
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2018-07-12 09:56:25 +00:00
|
|
|
// table declaration ---------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(2), // section header
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, 0, 5, // table 0
|
|
|
|
kFuncRefCode, 0, 9), // table 1
|
2018-07-12 09:56:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element,
|
|
|
|
ENTRY_COUNT(2), // entry count
|
2018-11-12 20:53:47 +00:00
|
|
|
TABLE_INDEX0, // element for table 0
|
2018-10-17 08:43:53 +00:00
|
|
|
WASM_INIT_EXPR_I32V_1(0), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(7), // index
|
2019-09-16 15:40:20 +00:00
|
|
|
kExternalFunction, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0)), // entry 1
|
2018-11-29 16:28:31 +00:00
|
|
|
// code ----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
2018-07-12 09:56:25 +00:00
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionMixedTables) {
|
|
|
|
// Test that if we have multiple tables, both imported and module-defined, in
|
|
|
|
// the element section we can target and initialize all tables.
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-07-12 09:56:25 +00:00
|
|
|
// imports -------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import, ENTRY_COUNT(2),
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('t'), // table name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalTable, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // elem_type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // no maximum field
|
|
|
|
5, // initial size
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('s'), // table name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalTable, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // elem_type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // no maximum field
|
|
|
|
10), // initial size
|
2018-07-12 09:56:25 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
2018-10-16 15:34:13 +00:00
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2018-07-12 09:56:25 +00:00
|
|
|
// table declaration ---------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(2), // section header
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, 0, 15, // table 0
|
|
|
|
kFuncRefCode, 0, 19), // table 1
|
2018-07-12 09:56:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element,
|
|
|
|
4, // entry count
|
2018-11-12 20:53:47 +00:00
|
|
|
TABLE_INDEX0, // element for table 0
|
2018-10-17 08:43:53 +00:00
|
|
|
WASM_INIT_EXPR_I32V_1(0), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(7), // index
|
2019-09-16 15:40:20 +00:00
|
|
|
kExternalFunction, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0), // entry 1
|
|
|
|
TABLE_INDEX(2), // element for table 2
|
|
|
|
WASM_INIT_EXPR_I32V_1(12), // index
|
2019-09-16 15:40:20 +00:00
|
|
|
kExternalFunction, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(3), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(17), // index
|
2019-09-16 15:40:20 +00:00
|
|
|
kExternalFunction, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0)), // entry 1
|
2018-11-29 16:28:31 +00:00
|
|
|
// code ----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
2018-07-12 09:56:25 +00:00
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTablesArbitraryOrder) {
|
|
|
|
// Test that the order in which tables are targeted in the element secion
|
|
|
|
// can be arbitrary.
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-07-12 09:56:25 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
2018-10-16 15:34:13 +00:00
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2018-07-12 09:56:25 +00:00
|
|
|
// table declaration ---------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(2), // section header
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, 0, 5, // table 0
|
|
|
|
kFuncRefCode, 0, 9), // table 1
|
2018-07-12 09:56:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element,
|
|
|
|
ENTRY_COUNT(3), // entry count
|
2018-11-12 20:53:47 +00:00
|
|
|
TABLE_INDEX0, // element for table 1
|
2018-10-17 08:43:53 +00:00
|
|
|
WASM_INIT_EXPR_I32V_1(0), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 0
|
|
|
|
WASM_INIT_EXPR_I32V_1(7), // index
|
2019-09-16 15:40:20 +00:00
|
|
|
kExternalFunction, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0), // entry 1
|
2018-11-12 20:53:47 +00:00
|
|
|
TABLE_INDEX0, // element for table 1
|
2018-10-17 08:43:53 +00:00
|
|
|
WASM_INIT_EXPR_I32V_1(3), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0)), // function
|
2018-11-29 16:28:31 +00:00
|
|
|
// code ----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
2018-07-12 09:56:25 +00:00
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionMixedTablesArbitraryOrder) {
|
|
|
|
// Test that the order in which tables are targeted in the element secion can
|
|
|
|
// be arbitrary. In this test, tables can be both imported and module-defined.
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-07-12 09:56:25 +00:00
|
|
|
// imports -------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import, ENTRY_COUNT(2),
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('t'), // table name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalTable, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // elem_type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // no maximum field
|
|
|
|
5, // initial size
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('s'), // table name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalTable, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // elem_type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // no maximum field
|
|
|
|
10), // initial size
|
2018-07-12 09:56:25 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
2018-10-16 15:34:13 +00:00
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2018-07-12 09:56:25 +00:00
|
|
|
// table declaration ---------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(2), // section header
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, 0, 15, // table 0
|
|
|
|
kFuncRefCode, 0, 19), // table 1
|
2018-07-12 09:56:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element,
|
|
|
|
4, // entry count
|
|
|
|
TABLE_INDEX(2), // element for table 0
|
|
|
|
WASM_INIT_EXPR_I32V_1(10), // index
|
2019-09-16 15:40:20 +00:00
|
|
|
kExternalFunction, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(3), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(17), // index
|
2019-09-16 15:40:20 +00:00
|
|
|
kExternalFunction, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0), // entry 1
|
2018-11-12 20:53:47 +00:00
|
|
|
TABLE_INDEX0, // element for table 2
|
2018-10-17 08:43:53 +00:00
|
|
|
WASM_INIT_EXPR_I32V_1(2), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(7), // index
|
2019-09-16 15:40:20 +00:00
|
|
|
kExternalFunction, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0)), // entry 1
|
2018-11-29 16:28:31 +00:00
|
|
|
// code ----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
2018-07-12 09:56:25 +00:00
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionInitExternRefTableWithFuncRef) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-07-12 09:56:25 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
2018-10-16 15:34:13 +00:00
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2018-07-12 09:56:25 +00:00
|
|
|
// table declaration ---------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(2), // section header
|
2020-09-29 07:46:36 +00:00
|
|
|
kExternRefCode, 0, 5, // table 0
|
|
|
|
kFuncRefCode, 0, 9), // table 1
|
2018-07-12 09:56:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element,
|
|
|
|
ENTRY_COUNT(2), // entry count
|
2018-11-12 20:53:47 +00:00
|
|
|
TABLE_INDEX0, // element for table 0
|
2018-10-17 08:43:53 +00:00
|
|
|
WASM_INIT_EXPR_I32V_1(0), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(7), // index
|
2019-09-16 15:40:20 +00:00
|
|
|
kExternalFunction, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0)), // entry 1
|
2019-05-23 12:25:13 +00:00
|
|
|
// code ----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY,
|
2018-07-12 09:56:25 +00:00
|
|
|
};
|
|
|
|
|
2020-05-29 15:23:27 +00:00
|
|
|
EXPECT_FAILURE_WITH_MSG(
|
|
|
|
data, "Invalid element segment. Table 0 is not a super-type of funcref");
|
2018-07-12 09:56:25 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ElementSectionDontInitExternRefImportedTable) {
|
|
|
|
// Test that imported tables of type ExternRef cannot be initialized in the
|
2018-07-12 09:56:25 +00:00
|
|
|
// elements section.
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2018-07-12 09:56:25 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 ---------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-07-12 09:56:25 +00:00
|
|
|
// imports -------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import, ENTRY_COUNT(2),
|
2020-09-29 07:46:36 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('t'), // table name
|
|
|
|
kExternalTable, // import kind
|
|
|
|
kFuncRefCode, // elem_type
|
|
|
|
0, // no maximum field
|
|
|
|
5, // initial size
|
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('s'), // table name
|
|
|
|
kExternalTable, // import kind
|
|
|
|
kExternRefCode, // elem_type
|
|
|
|
0, // no maximum field
|
|
|
|
10), // initial size
|
2018-07-12 09:56:25 +00:00
|
|
|
// funcs ---------------------------------------------------------------
|
2018-10-16 15:34:13 +00:00
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2018-07-12 09:56:25 +00:00
|
|
|
// table declaration ---------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(2), // section header
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, 0, 15, // table 0
|
|
|
|
kFuncRefCode, 0, 19), // table 1
|
2018-07-12 09:56:25 +00:00
|
|
|
// elements ------------------------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Element,
|
|
|
|
ENTRY_COUNT(4), // entry count
|
2018-11-12 20:53:47 +00:00
|
|
|
TABLE_INDEX0, // element for table 0
|
2018-10-17 08:43:53 +00:00
|
|
|
WASM_INIT_EXPR_I32V_1(10), // index
|
|
|
|
1, // elements count
|
|
|
|
FUNC_INDEX(0), // function
|
|
|
|
TABLE_INDEX(1), // element for table 1
|
|
|
|
WASM_INIT_EXPR_I32V_1(17), // index
|
2019-09-16 15:40:20 +00:00
|
|
|
kExternalFunction, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
2, // elements count
|
|
|
|
FUNC_INDEX(0), // entry 0
|
|
|
|
FUNC_INDEX(0)), // entry 1
|
2018-07-12 09:56:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, IndirectFunctionNoFunctions) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2015-12-11 12:26:16 +00:00
|
|
|
// indirect table ----------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(1), 1, 0, 0)};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, IndirectFunctionInvalidIndex) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2015-12-11 12:26:16 +00:00
|
|
|
// functions ---------------------------------------------------
|
2018-10-16 15:34:13 +00:00
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2015-12-11 12:26:16 +00:00
|
|
|
// indirect table ----------------------------------------------
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(1), 1, 1, 0)};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2018-07-10 12:14:06 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleTablesWithoutFlag) {
|
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Table, // table section
|
|
|
|
ENTRY_COUNT(2), // 2 tables
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // table 1: type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // table 1: no maximum
|
|
|
|
10, // table 1: minimum size
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // table 2: type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // table 2: no maximum
|
|
|
|
10), // table 2: minimum size
|
2018-07-10 12:14:06 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleTablesWithFlag) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
static const byte data[] = {
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Table, // table section
|
|
|
|
ENTRY_COUNT(2), // 2 tables
|
|
|
|
kFuncRefCode, // table 1: type
|
|
|
|
0, // table 1: no maximum
|
|
|
|
10, // table 1: minimum size
|
|
|
|
kExternRefCode, // table 2: type
|
|
|
|
0, // table 2: no maximum
|
|
|
|
11), // table 2: minimum size
|
2018-07-10 12:14:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(2u, result.value()->tables.size());
|
2018-07-10 12:14:06 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(10u, result.value()->tables[0].initial_size);
|
2019-07-08 20:23:30 +00:00
|
|
|
EXPECT_EQ(kWasmFuncRef, result.value()->tables[0].type);
|
2018-07-10 12:14:06 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(11u, result.value()->tables[1].initial_size);
|
2020-06-09 15:54:14 +00:00
|
|
|
EXPECT_EQ(kWasmExternRef, result.value()->tables[1].type);
|
2018-07-10 12:14:06 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 14:38:49 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, TypedFunctionTable) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
|
|
|
|
static const byte data[] = {
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Type, ENTRY_COUNT(1), SIG_ENTRY_v_x(kI32Code)),
|
|
|
|
SECTION(Table, // table section
|
|
|
|
ENTRY_COUNT(1), // 1 table
|
|
|
|
kOptRefCode, 0, // table 0: type
|
|
|
|
0, 10)}; // table 0: limits
|
2020-09-21 14:38:49 +00:00
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
EXPECT_EQ(ValueType::Ref(0, kNullable), result.value()->tables[0].type);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, IllegalTableTypes) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
|
|
|
|
using Vec = std::vector<byte>;
|
|
|
|
|
2020-09-29 07:46:36 +00:00
|
|
|
static Vec table_types[] = {{kOptRefCode, 0},
|
|
|
|
{kOptRefCode, 1},
|
|
|
|
{kOptRefCode, kI31RefCode},
|
|
|
|
{kI31RefCode},
|
Revert "[wasm-gc] Remove abstract rtts"
This reverts commit b77deeca4bd65b006a3a6c7344c2bbabd4514122.
Reason for revert: MSVC compile fails: https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Win64%20-%20msvc/16535/overview
Original change's description:
> [wasm-gc] Remove abstract rtts
>
> In the latest wasm-gc spec, rtts of abstract types are no longer
> allowed. Consequently, canonical rtts of concrete types always have
> a depth of 0.
>
> Changes:
> - Change the immediate argument of rtts to a type index over a heap
> type. Abstract it with TypeIndexImmediate in function body decoding.
> This affects:
> value_type.h, read_value_type(), decoding of relevant opcodes,
> wasm subtyping, WasmInitExpr, consume_init_expr(), and
> wasm-module-builder.cc.
> - In function-body-decoder-impl.h, update rtt.canon to always produce
> an rtt of depth 0.
> - Pass a unit32_t type index over a HeapType to all rtt-related
> utilities.
> - Remove infrastructure for abstract-type rtts from the wasm compilers,
> setup-heap-internal.cc, roots.h, and module-instantiate.cc.
> - Remove ObjectReferenceKnowledge::rtt_is_i31. Remove related branches
> from ref.test, ref.cast and br_on_cast implementations in the wasm
> compilers.
> - Remove unused 'parent' field from WasmTypeInfo.
> - Make the parent argument optional in NewWasmTypeInfo, CreateStructMap,
> and CreateArrayMap.
> - Use more convenient arguments in IsHeapSubtypeOf.
> - Update tests.
>
> Bug: v8:7748
> Change-Id: Ib45efe0741e6558c9b291fc8b4a75ae303146bdc
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2642248
> Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72321}
TBR=ulan@chromium.org,jkummerow@chromium.org,manoskouk@chromium.org
Change-Id: I2f0d97f1a34f7c81c5a97d7c37925cb84c66eea3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7748
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2650206
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72322}
2021-01-26 14:46:14 +00:00
|
|
|
{kRttCode, 2, kFuncRefCode}};
|
2020-09-21 14:38:49 +00:00
|
|
|
|
|
|
|
for (Vec type : table_types) {
|
|
|
|
Vec data = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(2),
|
2020-09-29 07:46:36 +00:00
|
|
|
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI32Code, true)),
|
|
|
|
WASM_ARRAY_DEF(kI32Code, true)),
|
2020-09-21 14:38:49 +00:00
|
|
|
kTableSectionCode, static_cast<byte>(type.size() + 3), byte{1}};
|
|
|
|
// Last elements are section size and entry count
|
|
|
|
|
|
|
|
// Add table type
|
|
|
|
data.insert(data.end(), type.begin(), type.end());
|
|
|
|
// Add table limits
|
|
|
|
data.insert(data.end(), {byte{0}, byte{10}});
|
|
|
|
|
|
|
|
auto result = DecodeModule(data.data(), data.data() + data.size());
|
|
|
|
|
2021-01-15 15:30:01 +00:00
|
|
|
EXPECT_NOT_OK(
|
|
|
|
result,
|
|
|
|
"Currently, only externref and function references are allowed "
|
|
|
|
"as table types");
|
2020-09-21 14:38:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-19 18:45:36 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, TieringCompilationHints) {
|
|
|
|
WASM_FEATURE_SCOPE(compilation_hints);
|
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(1, SIG_ENTRY_v_v),
|
|
|
|
FUNCTION_SECTION(3, 0, 0, 0),
|
2020-04-29 15:04:46 +00:00
|
|
|
SECTION_COMPILATION_HINTS(BASELINE_TIER_BASELINE | TOP_TIER_BASELINE,
|
|
|
|
BASELINE_TIER_BASELINE | TOP_TIER_OPTIMIZED,
|
|
|
|
BASELINE_TIER_OPTIMIZED | TOP_TIER_OPTIMIZED),
|
2019-03-19 18:45:36 +00:00
|
|
|
SECTION(Code, ENTRY_COUNT(3), NOP_BODY, NOP_BODY, NOP_BODY),
|
|
|
|
};
|
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
|
|
|
|
EXPECT_EQ(3u, result.value()->compilation_hints.size());
|
|
|
|
EXPECT_EQ(WasmCompilationHintStrategy::kDefault,
|
|
|
|
result.value()->compilation_hints[0].strategy);
|
2020-04-29 15:04:46 +00:00
|
|
|
EXPECT_EQ(WasmCompilationHintTier::kBaseline,
|
2019-04-03 10:15:58 +00:00
|
|
|
result.value()->compilation_hints[0].baseline_tier);
|
2019-03-19 18:45:36 +00:00
|
|
|
EXPECT_EQ(WasmCompilationHintTier::kBaseline,
|
2019-04-03 10:15:58 +00:00
|
|
|
result.value()->compilation_hints[0].top_tier);
|
2019-03-19 18:45:36 +00:00
|
|
|
EXPECT_EQ(WasmCompilationHintStrategy::kDefault,
|
|
|
|
result.value()->compilation_hints[1].strategy);
|
|
|
|
EXPECT_EQ(WasmCompilationHintTier::kBaseline,
|
2019-04-03 10:15:58 +00:00
|
|
|
result.value()->compilation_hints[1].baseline_tier);
|
2019-03-19 18:45:36 +00:00
|
|
|
EXPECT_EQ(WasmCompilationHintTier::kOptimized,
|
2019-04-03 10:15:58 +00:00
|
|
|
result.value()->compilation_hints[1].top_tier);
|
2019-03-19 18:45:36 +00:00
|
|
|
EXPECT_EQ(WasmCompilationHintStrategy::kDefault,
|
|
|
|
result.value()->compilation_hints[2].strategy);
|
2020-04-29 15:04:46 +00:00
|
|
|
EXPECT_EQ(WasmCompilationHintTier::kOptimized,
|
2019-04-03 10:15:58 +00:00
|
|
|
result.value()->compilation_hints[2].baseline_tier);
|
2020-04-29 15:04:46 +00:00
|
|
|
EXPECT_EQ(WasmCompilationHintTier::kOptimized,
|
2019-04-03 10:15:58 +00:00
|
|
|
result.value()->compilation_hints[2].top_tier);
|
2019-03-19 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 09:43:44 +00:00
|
|
|
class WasmSignatureDecodeTest : public TestWithZone {
|
|
|
|
public:
|
2019-11-26 16:25:14 +00:00
|
|
|
WasmFeatures enabled_features_ = WasmFeatures::None();
|
2018-08-08 14:54:44 +00:00
|
|
|
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* DecodeSig(const byte* start, const byte* end) {
|
2018-08-08 14:54:44 +00:00
|
|
|
return DecodeWasmSignatureForTesting(enabled_features_, zone(), start, end);
|
|
|
|
}
|
2018-03-22 09:43:44 +00:00
|
|
|
};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_v_v) {
|
2016-04-29 09:39:26 +00:00
|
|
|
static const byte data[] = {SIG_ENTRY_v_v};
|
2016-09-20 16:07:25 +00:00
|
|
|
v8::internal::AccountingAllocator allocator;
|
2016-10-17 12:12:30 +00:00
|
|
|
Zone zone(&allocator, ZONE_NAME);
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(0u, sig->return_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_t_v) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueTypePair ret_type = kValueTypes[i];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {SIG_ENTRY_x(ret_type.code)};
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(1u, sig->return_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(ret_type.type, sig->GetReturn());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_v_t) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueTypePair param_type = kValueTypes[i];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {SIG_ENTRY_v_x(param_type.code)};
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(0u, sig->return_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(param_type.type, sig->GetParam(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_t_t) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueTypePair ret_type = kValueTypes[i];
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueTypePair param_type = kValueTypes[j];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)};
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(1u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(1u, sig->return_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(param_type.type, sig->GetParam(0));
|
|
|
|
EXPECT_EQ(ret_type.type, sig->GetReturn());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_i_tt) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
2016-12-21 13:43:00 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueTypePair p0_type = kValueTypes[i];
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueTypePair p1_type = kValueTypes[j];
|
2016-04-29 09:39:26 +00:00
|
|
|
const byte data[] = {
|
2020-09-29 07:46:36 +00:00
|
|
|
SIG_ENTRY_x_xx(kI32Code, p0_type.code, p1_type.code)};
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(2u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(1u, sig->return_count());
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(p0_type.type, sig->GetParam(0));
|
|
|
|
EXPECT_EQ(p1_type.type, sig->GetParam(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, Ok_tt_tt) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2018-08-08 14:54:44 +00:00
|
|
|
WASM_FEATURE_SCOPE(mv);
|
|
|
|
for (size_t i = 0; i < arraysize(kValueTypes); i++) {
|
|
|
|
ValueTypePair p0_type = kValueTypes[i];
|
|
|
|
for (size_t j = 0; j < arraysize(kValueTypes); j++) {
|
|
|
|
ValueTypePair p1_type = kValueTypes[j];
|
|
|
|
const byte data[] = {SIG_ENTRY_xx_xx(p0_type.code, p1_type.code,
|
|
|
|
p0_type.code, p1_type.code)};
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2018-08-08 14:54:44 +00:00
|
|
|
|
|
|
|
EXPECT_TRUE(sig != nullptr);
|
|
|
|
EXPECT_EQ(2u, sig->parameter_count());
|
|
|
|
EXPECT_EQ(2u, sig->return_count());
|
|
|
|
EXPECT_EQ(p0_type.type, sig->GetParam(0));
|
|
|
|
EXPECT_EQ(p1_type.type, sig->GetParam(1));
|
|
|
|
EXPECT_EQ(p0_type.type, sig->GetReturn(0));
|
|
|
|
EXPECT_EQ(p1_type.type, sig->GetReturn(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-14 17:45:59 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, TooManyParams) {
|
2018-01-11 11:49:29 +00:00
|
|
|
static const byte data[] = {kWasmFunctionTypeCode,
|
2016-12-14 17:45:59 +00:00
|
|
|
WASM_I32V_3(kV8MaxWasmFunctionParams + 1),
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, 0};
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2016-12-14 17:45:59 +00:00
|
|
|
EXPECT_FALSE(sig != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, TooManyReturns) {
|
|
|
|
for (int i = 0; i < 2; i++) {
|
2018-08-08 14:54:44 +00:00
|
|
|
bool enable_mv = i != 0;
|
|
|
|
WASM_FEATURE_SCOPE_VAL(mv, enable_mv);
|
2017-05-31 13:31:52 +00:00
|
|
|
const int max_return_count = static_cast<int>(
|
2018-08-08 14:54:44 +00:00
|
|
|
enable_mv ? kV8MaxWasmFunctionMultiReturns : kV8MaxWasmFunctionReturns);
|
2018-01-11 11:49:29 +00:00
|
|
|
byte data[] = {kWasmFunctionTypeCode, 0, WASM_I32V_3(max_return_count + 1),
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code};
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2016-12-14 17:45:59 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_off_end) {
|
|
|
|
byte data[256];
|
|
|
|
for (int p = 0; p <= 255; p = p + 1 + p * 3) {
|
2020-09-29 07:46:36 +00:00
|
|
|
for (int i = 0; i <= p; i++) data[i] = kI32Code;
|
2015-12-11 12:26:16 +00:00
|
|
|
data[0] = static_cast<byte>(p);
|
|
|
|
|
|
|
|
for (int i = 0; i < p + 1; i++) {
|
|
|
|
// Should fall off the end for all signatures.
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + i);
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_externref_without_flag) {
|
|
|
|
// Disable ExternRef support and check that decoding fails.
|
|
|
|
WASM_FEATURE_SCOPE_VAL(reftypes, false);
|
2020-09-29 07:46:36 +00:00
|
|
|
byte ref_types[] = {kFuncRefCode, kExternRefCode};
|
2018-07-09 09:15:45 +00:00
|
|
|
for (byte invalid_type : ref_types) {
|
2018-10-17 09:31:01 +00:00
|
|
|
for (size_t i = 0;; i++) {
|
2020-09-29 07:46:36 +00:00
|
|
|
byte data[] = {SIG_ENTRY_x_xx(kI32Code, kI32Code, kI32Code)};
|
2018-10-17 09:31:01 +00:00
|
|
|
if (i >= arraysize(data)) break;
|
2018-07-09 09:15:45 +00:00
|
|
|
data[i] = invalid_type;
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2018-07-09 09:15:45 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
2018-03-22 09:43:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-11 12:26:16 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_invalid_type) {
|
|
|
|
byte kInvalidType = 76;
|
2018-10-17 09:31:01 +00:00
|
|
|
for (size_t i = 0;; i++) {
|
2020-09-29 07:46:36 +00:00
|
|
|
byte data[] = {SIG_ENTRY_x_xx(kI32Code, kI32Code, kI32Code)};
|
2018-10-17 09:31:01 +00:00
|
|
|
if (i >= arraysize(data)) break;
|
2015-12-11 12:26:16 +00:00
|
|
|
data[i] = kInvalidType;
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2015-12-11 12:26:16 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 09:39:26 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_invalid_ret_type1) {
|
2020-09-29 07:46:36 +00:00
|
|
|
static const byte data[] = {SIG_ENTRY_x_x(kVoidCode, kI32Code)};
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2016-04-29 09:39:26 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2016-04-29 09:39:26 +00:00
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type1) {
|
2020-09-29 07:46:36 +00:00
|
|
|
static const byte data[] = {SIG_ENTRY_x_x(kI32Code, kVoidCode)};
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2016-04-29 09:39:26 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type2) {
|
2020-09-29 07:46:36 +00:00
|
|
|
static const byte data[] = {SIG_ENTRY_x_xx(kI32Code, kI32Code, kVoidCode)};
|
2020-02-25 20:00:50 +00:00
|
|
|
const FunctionSig* sig = DecodeSig(data, data + sizeof(data));
|
2016-04-29 09:39:26 +00:00
|
|
|
EXPECT_EQ(nullptr, sig);
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2017-03-28 14:27:42 +00:00
|
|
|
class WasmFunctionVerifyTest : public TestWithIsolateAndZone {
|
|
|
|
public:
|
2018-08-08 14:54:44 +00:00
|
|
|
FunctionResult DecodeWasmFunction(const ModuleWireBytes& wire_bytes,
|
|
|
|
const WasmModule* module,
|
|
|
|
const byte* function_start,
|
|
|
|
const byte* function_end) {
|
2018-12-10 13:00:02 +00:00
|
|
|
WasmFeatures enabled_features;
|
|
|
|
return DecodeWasmFunctionForTesting(enabled_features, zone(), wire_bytes,
|
2018-08-08 14:54:44 +00:00
|
|
|
module, function_start, function_end,
|
|
|
|
isolate()->counters());
|
|
|
|
}
|
2017-03-28 14:27:42 +00:00
|
|
|
};
|
2015-12-11 12:26:16 +00:00
|
|
|
|
|
|
|
TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
SIG_ENTRY_v_v, // signature entry
|
|
|
|
4, // locals
|
|
|
|
3,
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // --
|
2016-04-29 09:39:26 +00:00
|
|
|
4,
|
2020-09-29 07:46:36 +00:00
|
|
|
kI64Code, // --
|
2016-04-29 09:39:26 +00:00
|
|
|
5,
|
2020-09-29 07:46:36 +00:00
|
|
|
kF32Code, // --
|
2016-04-29 09:39:26 +00:00
|
|
|
6,
|
2020-09-29 07:46:36 +00:00
|
|
|
kF64Code, // --
|
|
|
|
kExprEnd // body
|
2015-12-11 12:26:16 +00:00
|
|
|
};
|
|
|
|
|
2018-12-10 13:00:02 +00:00
|
|
|
WasmModule module;
|
|
|
|
FunctionResult result = DecodeWasmFunction(ModuleWireBytes({}), &module, data,
|
|
|
|
data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2015-12-11 12:26:16 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
if (result.value() && result.ok()) {
|
|
|
|
WasmFunction* function = result.value().get();
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, function->sig->parameter_count());
|
|
|
|
EXPECT_EQ(0u, function->sig->return_count());
|
2018-10-17 09:31:01 +00:00
|
|
|
EXPECT_EQ(COUNT_ARGS(SIG_ENTRY_v_v), function->code.offset());
|
2017-06-12 11:59:14 +00:00
|
|
|
EXPECT_EQ(sizeof(data), function->code.end_offset());
|
2016-03-07 21:04:07 +00:00
|
|
|
// TODO(titzer): verify encoding of local declarations
|
2015-12-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-08 00:35:57 +00:00
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, SectionWithoutNameLength) {
|
|
|
|
const byte data[] = {1};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2020-02-25 14:41:13 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, EmptyCustomSectionIsInvalid) {
|
|
|
|
// An empty custom section is invalid, because at least one byte for the
|
|
|
|
// length of the custom section name is required.
|
|
|
|
const byte data[] = {
|
|
|
|
0, // unknown section code.
|
|
|
|
0 // section length.
|
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, TheLoneliestOfValidModulesTheTrulyEmptyOne) {
|
2016-01-08 00:35:57 +00:00
|
|
|
const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
0, // unknown section code.
|
2020-02-25 14:41:13 +00:00
|
|
|
1, // section length, only one byte for the name length.
|
|
|
|
0, // string length of 0.
|
|
|
|
// Empty section name, no content, nothing but sadness.
|
2016-01-08 00:35:57 +00:00
|
|
|
};
|
2016-03-10 12:36:42 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-01-08 00:35:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OnlyUnknownSectionEmpty) {
|
|
|
|
const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(0),
|
2016-03-10 12:36:42 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
2016-01-08 00:35:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OnlyUnknownSectionNonEmpty) {
|
|
|
|
const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(5),
|
2017-12-02 00:30:37 +00:00
|
|
|
0xFF,
|
|
|
|
0xFF,
|
|
|
|
0xFF,
|
|
|
|
0xFF,
|
|
|
|
0xFF, // section data
|
2016-01-08 00:35:57 +00:00
|
|
|
};
|
2016-03-10 12:36:42 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-01-08 00:35:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 12:36:42 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, SignatureFollowedByEmptyUnknownSection) {
|
|
|
|
const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2016-03-10 12:36:42 +00:00
|
|
|
// -----------------------------------------------------------
|
2016-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(0)};
|
2016-03-10 12:36:42 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, SignatureFollowedByUnknownSection) {
|
|
|
|
const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2016-03-10 12:36:42 +00:00
|
|
|
// -----------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
UNKNOWN_SECTION(5),
|
|
|
|
0xFF,
|
|
|
|
0xFF,
|
|
|
|
0xFF,
|
|
|
|
0xFF,
|
|
|
|
0xFF,
|
2016-03-10 12:36:42 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
2016-01-08 00:35:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-03 16:52:10 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, UnknownSectionOverflow) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(9),
|
2016-04-29 09:39:26 +00:00
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4,
|
|
|
|
5,
|
|
|
|
6,
|
|
|
|
7,
|
|
|
|
8,
|
|
|
|
9,
|
|
|
|
10, // 10 byte section
|
2016-01-08 00:35:57 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:52:10 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, UnknownSectionUnderflow) {
|
2016-02-19 14:58:25 +00:00
|
|
|
static const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(333),
|
2016-04-29 09:39:26 +00:00
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4, // 4 byte section
|
2016-01-08 00:35:57 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:52:10 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) {
|
|
|
|
static const byte data[] = {
|
2016-09-27 20:46:10 +00:00
|
|
|
UNKNOWN_SECTION(1),
|
2016-04-29 09:39:26 +00:00
|
|
|
0, // one byte section
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Global, ENTRY_COUNT(1),
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // memory type
|
2018-10-17 08:43:53 +00:00
|
|
|
0, // exported
|
|
|
|
WASM_INIT_EXPR_I32V_1(33)), // init
|
2016-03-03 16:52:10 +00:00
|
|
|
};
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_OK(result);
|
2016-03-03 16:52:10 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->globals.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->data_segments.size());
|
2016-03-03 16:52:10 +00:00
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
const WasmGlobal* global = &result.value()->globals.back();
|
2016-03-03 16:52:10 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
EXPECT_EQ(kWasmI32, global->type);
|
2016-11-11 11:55:30 +00:00
|
|
|
EXPECT_EQ(0u, global->offset);
|
2016-03-03 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
2016-02-19 14:58:25 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_empty) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {SECTION(Type, ENTRY_COUNT(0)),
|
|
|
|
SECTION(Import, ENTRY_COUNT(0))};
|
2016-02-19 14:58:25 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2016-04-21 11:18:41 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_nosigs1) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {SECTION(Import, ENTRY_COUNT(0))};
|
2016-04-21 11:18:41 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2016-11-08 13:25:00 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_mutable_global) {
|
|
|
|
{
|
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import, // section header
|
|
|
|
ENTRY_COUNT(1), // number of imports
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('f'), // global name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalGlobal, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
0), // mutability
|
2016-11-08 13:25:00 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import, // section header
|
|
|
|
ENTRY_COUNT(1), // sig table
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('f'), // global name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalGlobal, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
1), // mutability
|
2016-11-08 13:25:00 +00:00
|
|
|
};
|
2018-06-12 22:23:35 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-11-08 13:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-17 13:35:20 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_mutability_malformed) {
|
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import,
|
|
|
|
ENTRY_COUNT(1), // --
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('g'), // global name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalGlobal, // import kind
|
2020-09-29 07:46:36 +00:00
|
|
|
kI32Code, // type
|
2018-10-17 08:43:53 +00:00
|
|
|
2), // invalid mutability
|
2017-01-17 13:35:20 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-04-21 11:18:41 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_nosigs2) {
|
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import, ENTRY_COUNT(1), // sig table
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('f'), // function name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalFunction, // import kind
|
|
|
|
SIG_INDEX(0)), // sig index
|
2016-04-21 11:18:41 +00:00
|
|
|
};
|
2016-02-19 14:58:25 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_invalid_sig) {
|
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Type, ENTRY_COUNT(0)), // --
|
|
|
|
SECTION(Import, ENTRY_COUNT(1), // --
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('f'), // function name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalFunction, // import kind
|
|
|
|
SIG_INDEX(0)), // sig index
|
2016-02-19 14:58:25 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_one_sig) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Import,
|
2018-10-17 09:31:01 +00:00
|
|
|
ENTRY_COUNT(1), // --
|
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('f'), // function name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalFunction, // import kind
|
|
|
|
SIG_INDEX(0)), // sig index
|
2016-02-19 14:58:25 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2016-03-08 19:55:36 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_invalid_module) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID, // --
|
|
|
|
SECTION(Import, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
|
|
|
NO_NAME, // module name
|
|
|
|
ADD_COUNT('f'), // function name
|
|
|
|
kExternalFunction, // import kind
|
|
|
|
SIG_INDEX(0), // sig index
|
|
|
|
0), // auxiliary data
|
2016-03-08 19:55:36 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-02-19 14:58:25 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ImportTable_off_end) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-10-17 09:31:01 +00:00
|
|
|
SECTION(Import, ENTRY_COUNT(1),
|
|
|
|
ADD_COUNT('m'), // module name
|
|
|
|
ADD_COUNT('f'), // function name
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalFunction), // import kind
|
|
|
|
SIG_INDEX(0), // sig index (outside import section!)
|
2016-02-19 14:58:25 +00:00
|
|
|
};
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, arraysize(data) - 3);
|
2016-02-19 14:58:25 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 22:50:36 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTable_empty1) {
|
2020-09-24 11:52:48 +00:00
|
|
|
static const byte data[] = { // signatures
|
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID, // --
|
2018-10-16 15:34:13 +00:00
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Export, ENTRY_COUNT(0)), // --
|
2016-05-25 16:12:09 +00:00
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-05-25 16:12:09 +00:00
|
|
|
EXPECT_OK(result);
|
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(0u, result.value()->export_table.size());
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 22:50:36 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTable_empty2) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {SECTION(Type, ENTRY_COUNT(0)),
|
|
|
|
SECTION(Export, ENTRY_COUNT(0))};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {SECTION(Export, ENTRY_COUNT(0))};
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTableOne) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// signatures
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID, ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Export,
|
|
|
|
ENTRY_COUNT(1), // exports
|
|
|
|
NO_NAME, // --
|
|
|
|
kExternalFunction, // --
|
|
|
|
FUNC_INDEX(0)), // --
|
|
|
|
ONE_EMPTY_BODY};
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-05-25 16:12:09 +00:00
|
|
|
EXPECT_OK(result);
|
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(1u, result.value()->export_table.size());
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 09:50:12 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportNameWithInvalidStringLength) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// signatures
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID, ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Export,
|
|
|
|
ENTRY_COUNT(1), // exports
|
2018-10-17 09:31:01 +00:00
|
|
|
U32V_1(84), // invalid string length
|
2018-10-17 08:43:53 +00:00
|
|
|
'e', // --
|
|
|
|
kExternalFunction, // --
|
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
0, 0, 0) // auxiliary data
|
|
|
|
};
|
2016-09-06 09:50:12 +00:00
|
|
|
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2016-02-27 01:52:30 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTableTwo) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// signatures
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID, ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Export,
|
2018-10-17 09:31:01 +00:00
|
|
|
ENTRY_COUNT(2), // exports
|
|
|
|
ADD_COUNT('n', 'a', 'm', 'e'), // --
|
2018-10-17 12:16:05 +00:00
|
|
|
kExternalFunction, // --
|
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
ADD_COUNT('n', 'o', 'm'), // --
|
|
|
|
kExternalFunction, // --
|
|
|
|
FUNC_INDEX(0)), // --
|
2018-10-17 08:43:53 +00:00
|
|
|
ONE_EMPTY_BODY};
|
2016-05-25 16:12:09 +00:00
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-05-25 16:12:09 +00:00
|
|
|
EXPECT_OK(result);
|
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(1u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(2u, result.value()->export_table.size());
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTableThree) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// signatures
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID, THREE_EMPTY_FUNCTIONS(SIG_INDEX(0)),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Export,
|
|
|
|
ENTRY_COUNT(3), // exports
|
2018-10-17 09:31:01 +00:00
|
|
|
ADD_COUNT('a'), // --
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalFunction,
|
2018-10-17 09:31:01 +00:00
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
ADD_COUNT('b'), // --
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalFunction,
|
2018-10-17 09:31:01 +00:00
|
|
|
FUNC_INDEX(1), // --
|
|
|
|
ADD_COUNT('c'), // --
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalFunction,
|
|
|
|
FUNC_INDEX(2)), // --
|
|
|
|
THREE_EMPTY_BODIES};
|
2016-09-27 20:46:10 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2016-05-25 16:12:09 +00:00
|
|
|
EXPECT_OK(result);
|
|
|
|
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(3u, result.value()->functions.size());
|
|
|
|
EXPECT_EQ(3u, result.value()->export_table.size());
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) {
|
|
|
|
for (int i = 0; i < 6; i++) {
|
2018-10-17 08:43:53 +00:00
|
|
|
const byte data[] = {
|
|
|
|
// signatures
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID, THREE_EMPTY_FUNCTIONS(SIG_INDEX(0)),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Export,
|
2018-10-17 09:31:01 +00:00
|
|
|
ENTRY_COUNT(1), // exports
|
|
|
|
ADD_COUNT('e', 'x'), // --
|
2018-10-17 08:43:53 +00:00
|
|
|
kExternalFunction,
|
|
|
|
FUNC_INDEX(i)), // --
|
|
|
|
THREE_EMPTY_BODIES};
|
2016-02-27 01:52:30 +00:00
|
|
|
|
|
|
|
if (i < 3) {
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
} else {
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, ExportTableOne_off_end) {
|
|
|
|
static const byte data[] = {
|
2016-04-29 09:39:26 +00:00
|
|
|
// signatures
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID, ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Export,
|
|
|
|
ENTRY_COUNT(1), // exports
|
|
|
|
NO_NAME, // --
|
|
|
|
kExternalFunction,
|
|
|
|
FUNC_INDEX(0), // --
|
|
|
|
0, 0, 0) // auxiliary data
|
2016-02-27 01:52:30 +00:00
|
|
|
};
|
|
|
|
|
2018-10-16 13:28:20 +00:00
|
|
|
EXPECT_OFF_END_FAILURE(data, arraysize(data) - 3);
|
2016-02-27 01:52:30 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 16:18:00 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Regression_648070) {
|
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Type, ENTRY_COUNT(0)), // --
|
|
|
|
SECTION(Function, U32V_5(3500228624)) // function count = 3500228624
|
|
|
|
}; // --
|
2016-09-21 16:18:00 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2017-07-06 13:27:57 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Regression_738097) {
|
|
|
|
// The function body size caused an integer overflow in the module decoder.
|
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SECTION(1, 0), // --
|
|
|
|
SECTION(Code, // --
|
|
|
|
ENTRY_COUNT(1), // --
|
|
|
|
U32V_5(0xFFFFFFFF), // function size,
|
|
|
|
0) // No real body
|
2017-07-06 13:27:57 +00:00
|
|
|
};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2017-10-23 13:24:15 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodySizeLimit) {
|
|
|
|
const uint32_t delta = 3;
|
|
|
|
for (uint32_t body_size = kV8MaxWasmFunctionSize - delta;
|
|
|
|
body_size < kV8MaxWasmFunctionSize + delta; body_size++) {
|
|
|
|
byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SECTION(1, 0), // --
|
|
|
|
kCodeSectionCode, // code section
|
|
|
|
U32V_5(1 + body_size + 5), // section size
|
|
|
|
1, // # functions
|
|
|
|
U32V_5(body_size) // body size
|
2017-10-23 13:24:15 +00:00
|
|
|
};
|
|
|
|
size_t total = sizeof(data) + body_size;
|
|
|
|
byte* buffer = reinterpret_cast<byte*>(calloc(1, total));
|
|
|
|
memcpy(buffer, data, sizeof(data));
|
|
|
|
ModuleResult result = DecodeModule(buffer, buffer + total);
|
|
|
|
if (body_size <= kV8MaxWasmFunctionSize) {
|
|
|
|
EXPECT_TRUE(result.ok());
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(result.ok());
|
|
|
|
}
|
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-24 11:52:48 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, IllegalTypeCode) {
|
|
|
|
static const byte data[] = {TYPE_SECTION(1, SIG_ENTRY_v_x(0x41))};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(data, "invalid value type");
|
|
|
|
}
|
|
|
|
|
2016-03-09 22:50:36 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodies_empty) {
|
2016-04-21 11:18:41 +00:00
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
EMPTY_TYPE_SECTION, // --
|
|
|
|
EMPTY_FUNCTION_SECTION, // --
|
|
|
|
EMPTY_FUNCTION_BODIES_SECTION // --
|
2016-04-21 11:18:41 +00:00
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodies_one_empty) {
|
2016-03-10 12:36:42 +00:00
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SECTION(1, 0), // --
|
|
|
|
ONE_EMPTY_BODY // --
|
2016-04-21 11:18:41 +00:00
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodies_one_nop) {
|
2016-03-10 12:36:42 +00:00
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SECTION(1, 0), // --
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Code, ENTRY_COUNT(1), NOP_BODY) // --
|
2016-04-21 11:18:41 +00:00
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodies_count_mismatch1) {
|
2016-04-21 11:18:41 +00:00
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SECTION(2, 0, 0), // --
|
|
|
|
ONE_EMPTY_BODY // --
|
2016-04-21 11:18:41 +00:00
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionBodies_count_mismatch2) {
|
2016-04-21 11:18:41 +00:00
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SECTION(1, 0), // --
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION(Code, ENTRY_COUNT(2), NOP_BODY, NOP_BODY) // --
|
2016-04-21 11:18:41 +00:00
|
|
|
};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, Names_empty) {
|
2020-09-24 11:52:48 +00:00
|
|
|
static const byte data[] = {EMPTY_TYPE_SECTION, EMPTY_FUNCTION_SECTION,
|
|
|
|
EMPTY_FUNCTION_BODIES_SECTION,
|
|
|
|
EMPTY_NAMES_SECTION};
|
2016-03-09 22:50:36 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, Names_one_empty) {
|
2018-10-17 08:43:53 +00:00
|
|
|
// TODO(wasm): This test does not test anything (corrupt name section does not
|
|
|
|
// fail validation).
|
2016-03-09 22:50:36 +00:00
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SECTION(1, 0), // --
|
2018-10-17 12:46:06 +00:00
|
|
|
ONE_EMPTY_BODY, // --
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION_NAMES(ENTRY_COUNT(1), FOO_STRING, NO_LOCAL_NAMES) // --
|
2016-03-09 22:50:36 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, Names_two_empty) {
|
2018-10-17 08:43:53 +00:00
|
|
|
// TODO(wasm): This test does not test anything (corrupt name section does not
|
|
|
|
// fail validation).
|
2016-03-09 22:50:36 +00:00
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(1, SIG_ENTRY_v_v), // --
|
|
|
|
FUNCTION_SECTION(2, 0, 0), // --
|
2018-10-17 12:46:06 +00:00
|
|
|
TWO_EMPTY_BODIES, // --
|
|
|
|
SECTION_NAMES(ENTRY_COUNT(2), // --
|
|
|
|
FOO_STRING, NO_LOCAL_NAMES, // --
|
|
|
|
FOO_STRING, NO_LOCAL_NAMES), // --
|
2016-03-09 22:50:36 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2017-02-02 08:38:34 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Regression684855) {
|
|
|
|
static const byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
SECTION_NAMES(0xFB, // functions count
|
|
|
|
0x27, // |
|
|
|
|
0x00, // function name length
|
|
|
|
0xFF, // local names count
|
|
|
|
0xFF, // |
|
|
|
|
0xFF, // |
|
|
|
|
0xFF, // |
|
|
|
|
0xFF, // |
|
|
|
|
0xFF, // error: "varint too large"
|
|
|
|
0xFF, // |
|
|
|
|
0x00, // --
|
|
|
|
0x00) // --
|
2017-02-02 08:38:34 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2018-11-29 16:28:31 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, FunctionSectionWithoutCodeSection) {
|
|
|
|
static const byte data[] = {
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(1, SIG_ENTRY_v_v), // Type section.
|
|
|
|
FUNCTION_SECTION(1, 0), // Function section.
|
2018-11-29 16:28:31 +00:00
|
|
|
};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result, "function count is 1, but code section is absent");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, CodeSectionWithoutFunctionSection) {
|
|
|
|
static const byte data[] = {ONE_EMPTY_BODY};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result, "function body count 1 mismatch (0 expected)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, EmptyFunctionSectionWithoutCodeSection) {
|
|
|
|
static const byte data[] = {SECTION(Function, ENTRY_COUNT(0))};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, EmptyCodeSectionWithoutFunctionSection) {
|
|
|
|
static const byte data[] = {SECTION(Code, ENTRY_COUNT(0))};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
class WasmInitExprDecodeTest : public TestWithZone {
|
|
|
|
public:
|
2018-09-13 09:27:26 +00:00
|
|
|
WasmInitExprDecodeTest() = default;
|
2018-08-08 14:54:44 +00:00
|
|
|
|
|
|
|
WasmFeatures enabled_features_;
|
|
|
|
|
|
|
|
WasmInitExpr DecodeInitExpr(const byte* start, const byte* end) {
|
|
|
|
return DecodeWasmInitExprForTesting(enabled_features_, start, end);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define EXPECT_INIT_EXPR(Type, type, value, ...) \
|
|
|
|
{ \
|
|
|
|
static const byte data[] = {__VA_ARGS__, kExprEnd}; \
|
|
|
|
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data)); \
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::k##Type##Const, expr.kind()); \
|
|
|
|
EXPECT_EQ(value, expr.immediate().type##_const); \
|
2016-09-27 20:46:10 +00:00
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
#define EXPECT_INIT_EXPR_FAIL(...) \
|
|
|
|
{ \
|
|
|
|
static const byte data[] = {__VA_ARGS__, kExprEnd}; \
|
|
|
|
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data)); \
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kNone, expr.kind()); \
|
2018-08-08 14:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_i32) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_INIT_EXPR(I32, i32, 33, WASM_I32V_1(33));
|
|
|
|
EXPECT_INIT_EXPR(I32, i32, -21, WASM_I32V_1(-21));
|
|
|
|
EXPECT_INIT_EXPR(I32, i32, 437, WASM_I32V_2(437));
|
|
|
|
EXPECT_INIT_EXPR(I32, i32, 77777, WASM_I32V_3(77777));
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_f32) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_INIT_EXPR(F32, f32, static_cast<float>(13.1), WASM_F32(13.1));
|
|
|
|
EXPECT_INIT_EXPR(F32, f32, static_cast<float>(-21.1), WASM_F32(-21.1));
|
|
|
|
EXPECT_INIT_EXPR(F32, f32, static_cast<float>(437.2), WASM_F32(437.2));
|
|
|
|
EXPECT_INIT_EXPR(F32, f32, static_cast<float>(77777.3), WASM_F32(77777.3));
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_i64) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_INIT_EXPR(I64, i64, 33, WASM_I64V_1(33));
|
|
|
|
EXPECT_INIT_EXPR(I64, i64, -21, WASM_I64V_2(-21));
|
|
|
|
EXPECT_INIT_EXPR(I64, i64, 437, WASM_I64V_5(437));
|
|
|
|
EXPECT_INIT_EXPR(I64, i64, 77777, WASM_I64V_7(77777));
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_f64) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_INIT_EXPR(F64, f64, 83.22, WASM_F64(83.22));
|
|
|
|
EXPECT_INIT_EXPR(F64, f64, -771.3, WASM_F64(-771.3));
|
|
|
|
EXPECT_INIT_EXPR(F64, f64, 43703.0, WASM_F64(43703.0));
|
|
|
|
EXPECT_INIT_EXPR(F64, f64, 77999.1, WASM_F64(77999.1));
|
|
|
|
}
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_ExternRef) {
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-09-29 07:46:36 +00:00
|
|
|
static const byte data[] = {kExprRefNull, kExternRefCode, kExprEnd};
|
2018-08-08 14:54:44 +00:00
|
|
|
WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data));
|
2020-07-09 13:21:45 +00:00
|
|
|
EXPECT_EQ(WasmInitExpr::kRefNullConst, expr.kind());
|
2018-04-05 10:49:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
TEST_F(WasmInitExprDecodeTest, InitExpr_illegal) {
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_INIT_EXPR_FAIL(WASM_I32V_1(0), WASM_I32V_1(0));
|
2020-12-17 16:55:33 +00:00
|
|
|
EXPECT_INIT_EXPR_FAIL(WASM_LOCAL_GET(0));
|
|
|
|
EXPECT_INIT_EXPR_FAIL(WASM_LOCAL_SET(0, WASM_I32V_1(0)));
|
2016-09-27 20:46:10 +00:00
|
|
|
EXPECT_INIT_EXPR_FAIL(WASM_I32_ADD(WASM_I32V_1(0), WASM_I32V_1(0)));
|
|
|
|
EXPECT_INIT_EXPR_FAIL(WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO));
|
|
|
|
}
|
|
|
|
|
2016-10-12 09:17:12 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Multiple_Named_Sections) {
|
|
|
|
static const byte data[] = {
|
2018-10-17 12:16:05 +00:00
|
|
|
SECTION(Unknown, ADD_COUNT('X'), 17, 18), // --
|
|
|
|
SECTION(Unknown, ADD_COUNT('f', 'o', 'o'), 5, 6, 7, 8, 9), // --
|
|
|
|
SECTION(Unknown, ADD_COUNT('o', 't', 'h', 'e', 'r'), 7, 8), // --
|
2016-10-12 09:17:12 +00:00
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
2017-01-24 15:23:02 +00:00
|
|
|
|
2017-04-11 08:28:52 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Section_Name_No_UTF8) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {SECTION(Unknown, 1, 0xFF, 17, 18)};
|
2017-04-11 08:28:52 +00:00
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2017-01-24 15:23:02 +00:00
|
|
|
class WasmModuleCustomSectionTest : public TestWithIsolateAndZone {
|
|
|
|
public:
|
|
|
|
void CheckSections(const byte* module_start, const byte* module_end,
|
2017-06-12 11:59:14 +00:00
|
|
|
const CustomSectionOffset* expected, size_t num_expected) {
|
2017-01-24 15:23:02 +00:00
|
|
|
std::vector<CustomSectionOffset> custom_sections =
|
|
|
|
DecodeCustomSections(module_start, module_end);
|
|
|
|
|
|
|
|
CHECK_EQ(num_expected, custom_sections.size());
|
|
|
|
|
|
|
|
for (size_t i = 0; i < num_expected; i++) {
|
2017-06-12 11:59:14 +00:00
|
|
|
EXPECT_EQ(expected[i].section.offset(),
|
|
|
|
custom_sections[i].section.offset());
|
|
|
|
EXPECT_EQ(expected[i].section.length(),
|
|
|
|
custom_sections[i].section.length());
|
|
|
|
EXPECT_EQ(expected[i].name.offset(), custom_sections[i].name.offset());
|
|
|
|
EXPECT_EQ(expected[i].name.length(), custom_sections[i].name.length());
|
|
|
|
EXPECT_EQ(expected[i].payload.offset(),
|
|
|
|
custom_sections[i].payload.offset());
|
|
|
|
EXPECT_EQ(expected[i].payload.length(),
|
|
|
|
custom_sections[i].payload.length());
|
2017-01-24 15:23:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(WasmModuleCustomSectionTest, ThreeUnknownSections) {
|
2017-06-12 11:59:14 +00:00
|
|
|
static constexpr byte data[] = {
|
2018-10-17 08:43:53 +00:00
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
|
|
|
SECTION(Unknown, 1, 'X', 17, 18), // --
|
|
|
|
SECTION(Unknown, 3, 'f', 'o', 'o', 5, 6, 7, 8, 9), // --
|
|
|
|
SECTION(Unknown, 5, 'o', 't', 'h', 'e', 'r', 7, 8), // --
|
2017-01-24 15:23:02 +00:00
|
|
|
};
|
|
|
|
|
2017-06-12 11:59:14 +00:00
|
|
|
static const CustomSectionOffset expected[] = {
|
|
|
|
// section, name, payload
|
|
|
|
{{10, 4}, {11, 1}, {12, 2}}, // --
|
|
|
|
{{16, 9}, {17, 3}, {20, 5}}, // --
|
|
|
|
{{27, 8}, {28, 5}, {33, 2}}, // --
|
2017-01-24 15:23:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CheckSections(data, data + sizeof(data), expected, arraysize(expected));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleCustomSectionTest, TwoKnownTwoUnknownSections) {
|
|
|
|
static const byte data[] = {
|
2018-10-17 12:16:05 +00:00
|
|
|
U32_LE(kWasmMagic), // --
|
|
|
|
U32_LE(kWasmVersion), // --
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(2, SIG_ENTRY_v_v, SIG_ENTRY_v_v), // --
|
2018-10-17 12:16:05 +00:00
|
|
|
SECTION(Unknown, ADD_COUNT('X'), 17, 18), // --
|
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)), // --
|
|
|
|
SECTION(Unknown, ADD_COUNT('o', 't', 'h', 'e', 'r'), 7, 8), // --
|
2017-01-24 15:23:02 +00:00
|
|
|
};
|
|
|
|
|
2017-06-12 11:59:14 +00:00
|
|
|
static const CustomSectionOffset expected[] = {
|
|
|
|
// section, name, payload
|
|
|
|
{{19, 4}, {20, 1}, {21, 2}}, // --
|
|
|
|
{{29, 8}, {30, 5}, {35, 2}}, // --
|
2017-01-24 15:23:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CheckSections(data, data + sizeof(data), expected, arraysize(expected));
|
|
|
|
}
|
|
|
|
|
2018-09-13 19:19:30 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, SourceMappingURLSection) {
|
2018-10-17 11:52:34 +00:00
|
|
|
static const byte data[] = {
|
2020-04-30 07:32:58 +00:00
|
|
|
WASM_MODULE_HEADER,
|
2018-10-17 11:52:34 +00:00
|
|
|
SECTION_SRC_MAP('s', 'r', 'c', '/', 'x', 'y', 'z', '.', 'c')};
|
2020-04-30 07:32:58 +00:00
|
|
|
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
|
2018-09-13 19:19:30 +00:00
|
|
|
EXPECT_TRUE(result.ok());
|
2020-04-30 07:32:58 +00:00
|
|
|
EXPECT_EQ(WasmDebugSymbols::Type::SourceMap,
|
|
|
|
result.value()->debug_symbols.type);
|
|
|
|
ModuleWireBytes wire_bytes(data, data + sizeof(data));
|
|
|
|
WasmName external_url =
|
|
|
|
wire_bytes.GetNameOrNull(result.value()->debug_symbols.external_url);
|
|
|
|
EXPECT_EQ("src/xyz.c", std::string(external_url.data(), external_url.size()));
|
2018-09-13 19:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, BadSourceMappingURLSection) {
|
2018-10-17 11:52:34 +00:00
|
|
|
static const byte data[] = {
|
2020-04-30 07:32:58 +00:00
|
|
|
WASM_MODULE_HEADER,
|
2018-10-17 11:52:34 +00:00
|
|
|
SECTION_SRC_MAP('s', 'r', 'c', '/', 'x', 0xff, 'z', '.', 'c')};
|
2020-04-30 07:32:58 +00:00
|
|
|
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
|
2018-09-13 19:19:30 +00:00
|
|
|
EXPECT_TRUE(result.ok());
|
2020-04-30 07:32:58 +00:00
|
|
|
EXPECT_EQ(WasmDebugSymbols::Type::None, result.value()->debug_symbols.type);
|
|
|
|
EXPECT_EQ(0u, result.value()->debug_symbols.external_url.length());
|
2018-09-13 19:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleSourceMappingURLSections) {
|
2020-04-30 07:32:58 +00:00
|
|
|
static const byte data[] = {WASM_MODULE_HEADER,
|
|
|
|
SECTION_SRC_MAP('a', 'b', 'c'),
|
2018-10-17 11:52:34 +00:00
|
|
|
SECTION_SRC_MAP('p', 'q', 'r')};
|
2020-04-30 07:32:58 +00:00
|
|
|
ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data));
|
2018-09-13 19:19:30 +00:00
|
|
|
EXPECT_TRUE(result.ok());
|
2020-04-30 07:32:58 +00:00
|
|
|
EXPECT_EQ(WasmDebugSymbols::Type::SourceMap,
|
|
|
|
result.value()->debug_symbols.type);
|
|
|
|
ModuleWireBytes wire_bytes(data, data + sizeof(data));
|
|
|
|
WasmName external_url =
|
|
|
|
wire_bytes.GetNameOrNull(result.value()->debug_symbols.external_url);
|
|
|
|
EXPECT_EQ("abc", std::string(external_url.data(), external_url.size()));
|
2018-09-13 19:19:30 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 19:35:50 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleNameSections) {
|
2018-10-17 08:43:53 +00:00
|
|
|
static const byte data[] = {
|
2018-10-17 12:16:05 +00:00
|
|
|
SECTION_NAMES(0, ADD_COUNT(ADD_COUNT('a', 'b', 'c'))),
|
|
|
|
SECTION_NAMES(0, ADD_COUNT(ADD_COUNT('p', 'q', 'r', 's')))};
|
2018-09-21 19:35:50 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_TRUE(result.ok());
|
2018-10-19 12:35:56 +00:00
|
|
|
EXPECT_EQ(3u, result.value()->name.length());
|
2018-09-21 19:35:50 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 18:23:54 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, BadNameSection) {
|
|
|
|
static const byte data[] = {SECTION_NAMES(
|
|
|
|
0, ADD_COUNT(ADD_COUNT('s', 'r', 'c', '/', 'x', 0xff, 'z', '.', 'c')))};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_TRUE(result.ok());
|
|
|
|
EXPECT_EQ(0u, result.value()->name.length());
|
|
|
|
}
|
|
|
|
|
2018-11-12 20:53:47 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, PassiveDataSegment) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// memory declaration ----------------------------------------------------
|
|
|
|
SECTION(Memory, ENTRY_COUNT(1), 0, 1),
|
|
|
|
// data segments --------------------------------------------------------
|
|
|
|
SECTION(Data, ENTRY_COUNT(1), PASSIVE, ADD_COUNT('h', 'i')),
|
|
|
|
};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
EXPECT_OFF_END_FAILURE(data, arraysize(data) - 5);
|
|
|
|
}
|
|
|
|
|
2019-09-16 15:40:20 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, ActiveElementSegmentWithElements) {
|
2018-11-12 20:53:47 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -----------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2018-11-12 20:53:47 +00:00
|
|
|
// funcs -----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
|
|
|
// table declaration -----------------------------------------------------
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 1),
|
2018-11-12 20:53:47 +00:00
|
|
|
// element segments -----------------------------------------------------
|
2019-09-16 15:40:20 +00:00
|
|
|
SECTION(Element, ENTRY_COUNT(1), ACTIVE_WITH_ELEMENTS, TABLE_INDEX0,
|
2020-09-29 07:46:36 +00:00
|
|
|
WASM_INIT_EXPR_I32V_1(0), kFuncRefCode, U32V_1(3),
|
2019-03-04 18:52:03 +00:00
|
|
|
REF_FUNC_ELEMENT(0), REF_FUNC_ELEMENT(0), REF_NULL_ELEMENT),
|
2018-11-29 16:28:31 +00:00
|
|
|
// code ------------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
2018-11-12 20:53:47 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
EXPECT_OFF_END_FAILURE(data, arraysize(data) - 5);
|
|
|
|
}
|
|
|
|
|
2019-09-16 15:40:20 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, PassiveElementSegment) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -----------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2019-09-16 15:40:20 +00:00
|
|
|
// funcs -----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
|
|
|
// table declaration -----------------------------------------------------
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 1),
|
2019-09-16 15:40:20 +00:00
|
|
|
// element segments -----------------------------------------------------
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Element, ENTRY_COUNT(1), PASSIVE_WITH_ELEMENTS, kFuncRefCode,
|
2019-09-16 15:40:20 +00:00
|
|
|
U32V_1(3), REF_FUNC_ELEMENT(0), REF_FUNC_ELEMENT(0),
|
|
|
|
REF_NULL_ELEMENT),
|
|
|
|
// code ------------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
EXPECT_OFF_END_FAILURE(data, arraysize(data) - 5);
|
|
|
|
}
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, PassiveElementSegmentExternRef) {
|
2019-03-04 18:52:03 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -----------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2019-03-04 18:52:03 +00:00
|
|
|
// funcs -----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
|
|
|
// table declaration -----------------------------------------------------
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 1),
|
2019-03-04 18:52:03 +00:00
|
|
|
// element segments -----------------------------------------------------
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Element, ENTRY_COUNT(1), PASSIVE_WITH_ELEMENTS, kExternRefCode,
|
2019-09-16 15:40:20 +00:00
|
|
|
U32V_1(0)),
|
2019-03-04 18:52:03 +00:00
|
|
|
// code ------------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
EXPECT_FAILURE(data);
|
|
|
|
}
|
|
|
|
|
2019-09-16 15:40:20 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, PassiveElementSegmentWithIndices) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -----------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2019-09-16 15:40:20 +00:00
|
|
|
// funcs -----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
|
|
|
// table declaration -----------------------------------------------------
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Table, ENTRY_COUNT(1), kFuncRefCode, 0, 1),
|
2020-02-17 16:21:02 +00:00
|
|
|
// element segments ------------------------------------------------------
|
2019-09-16 15:40:20 +00:00
|
|
|
SECTION(Element, ENTRY_COUNT(1), PASSIVE, kExternalFunction,
|
|
|
|
ENTRY_COUNT(3), U32V_1(0), U32V_1(0), U32V_1(0)),
|
|
|
|
// code ------------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
EXPECT_OFF_END_FAILURE(data, arraysize(data) - 5);
|
|
|
|
}
|
|
|
|
|
2020-02-17 16:21:02 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DeclarativeElementSegmentFuncRef) {
|
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -----------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2020-02-17 16:21:02 +00:00
|
|
|
// funcs -----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
|
|
|
// element segments -----------------------------------------------------
|
|
|
|
SECTION(Element, // section name
|
|
|
|
ENTRY_COUNT(1), // entry count
|
|
|
|
DECLARATIVE_WITH_ELEMENTS, // flags
|
2020-09-29 07:46:36 +00:00
|
|
|
kFuncRefCode, // local type
|
2020-02-17 16:21:02 +00:00
|
|
|
U32V_1(0)), // func ref count
|
|
|
|
// code ------------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
EXPECT_FAILURE(data);
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-02-17 16:21:02 +00:00
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, DeclarativeElementSegmentWithInvalidIndex) {
|
2020-06-09 15:54:14 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-02-17 16:21:02 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
// sig#0 -----------------------------------------------------------------
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION_ONE_SIG_VOID_VOID,
|
2020-02-17 16:21:02 +00:00
|
|
|
// funcs -----------------------------------------------------------------
|
|
|
|
ONE_EMPTY_FUNCTION(SIG_INDEX(0)),
|
|
|
|
// element segments -----------------------------------------------------
|
|
|
|
SECTION(Element, // section name
|
|
|
|
ENTRY_COUNT(1), // entry count
|
|
|
|
DECLARATIVE, // flags
|
|
|
|
kExternalFunction, // type
|
|
|
|
ENTRY_COUNT(2), // func index count
|
|
|
|
U32V_1(0), // func index
|
|
|
|
U32V_1(1)), // func index
|
|
|
|
// code ------------------------------------------------------------------
|
|
|
|
ONE_EMPTY_BODY};
|
|
|
|
EXPECT_FAILURE_WITH_MSG(data, "element function index 1 out of bounds");
|
|
|
|
}
|
|
|
|
|
2018-11-29 19:23:59 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, DataCountSectionCorrectPlacement) {
|
|
|
|
static const byte data[] = {SECTION(Element, ENTRY_COUNT(0)),
|
|
|
|
SECTION(DataCount, ENTRY_COUNT(0)),
|
|
|
|
SECTION(Code, ENTRY_COUNT(0))};
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, DataCountSectionAfterCode) {
|
|
|
|
static const byte data[] = {SECTION(Code, ENTRY_COUNT(0)),
|
|
|
|
SECTION(DataCount, ENTRY_COUNT(0))};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result,
|
|
|
|
"The DataCount section must appear before the Code section");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, DataCountSectionBeforeElement) {
|
|
|
|
static const byte data[] = {SECTION(DataCount, ENTRY_COUNT(0)),
|
|
|
|
SECTION(Element, ENTRY_COUNT(0))};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2019-01-30 14:53:47 +00:00
|
|
|
EXPECT_NOT_OK(result, "unexpected section <Element>");
|
2018-11-29 19:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, DataCountSectionAfterStartBeforeElement) {
|
|
|
|
STATIC_ASSERT(kStartSectionCode + 1 == kElementSectionCode);
|
|
|
|
static const byte data[] = {
|
|
|
|
// We need the start section for this test, but the start section must
|
|
|
|
// reference a valid function, which requires the type and function
|
|
|
|
// sections too.
|
2020-09-24 11:52:48 +00:00
|
|
|
TYPE_SECTION(1, SIG_ENTRY_v_v), // Type section.
|
|
|
|
FUNCTION_SECTION(1, 0), // Function section.
|
2018-11-29 19:23:59 +00:00
|
|
|
SECTION(Start, U32V_1(0)), // Start section.
|
|
|
|
SECTION(DataCount, ENTRY_COUNT(0)), // DataCount section.
|
|
|
|
SECTION(Element, ENTRY_COUNT(0)) // Element section.
|
|
|
|
};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2019-01-30 14:53:47 +00:00
|
|
|
EXPECT_NOT_OK(result, "unexpected section <Element>");
|
2018-11-29 19:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, MultipleDataCountSections) {
|
|
|
|
static const byte data[] = {SECTION(DataCount, ENTRY_COUNT(0)),
|
|
|
|
SECTION(DataCount, ENTRY_COUNT(0))};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result, "Multiple DataCount sections not allowed");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, DataCountSegmentCountMatch) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Memory, ENTRY_COUNT(1), 0, 1), // Memory section.
|
|
|
|
SECTION(DataCount, ENTRY_COUNT(1)), // DataCount section.
|
|
|
|
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0, // Data section.
|
|
|
|
WASM_INIT_EXPR_I32V_1(12), ADD_COUNT('h', 'i'))};
|
|
|
|
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, DataCountSegmentCount_greater) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Memory, ENTRY_COUNT(1), 0, 1), // Memory section.
|
|
|
|
SECTION(DataCount, ENTRY_COUNT(3)), // DataCount section.
|
|
|
|
SECTION(Data, ENTRY_COUNT(0))}; // Data section.
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result, "data segments count 0 mismatch (3 expected)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, DataCountSegmentCount_less) {
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Memory, ENTRY_COUNT(1), 0, 1), // Memory section.
|
|
|
|
SECTION(DataCount, ENTRY_COUNT(0)), // DataCount section.
|
|
|
|
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0, // Data section.
|
|
|
|
WASM_INIT_EXPR_I32V_1(12), ADD_COUNT('a', 'b', 'c'))};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result, "data segments count 1 mismatch (0 expected)");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WasmModuleVerifyTest, DataCountSegmentCount_omitted) {
|
|
|
|
static const byte data[] = {SECTION(Memory, ENTRY_COUNT(1), 0, 1),
|
|
|
|
SECTION(DataCount, ENTRY_COUNT(1))};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_NOT_OK(result, "data segments count 0 mismatch (1 expected)");
|
|
|
|
}
|
|
|
|
|
2020-07-07 12:12:23 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, GcStructIdsPass) {
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
|
|
|
|
static const byte data[] = {SECTION(
|
|
|
|
Type, ENTRY_COUNT(3),
|
2020-09-29 07:46:36 +00:00
|
|
|
WASM_STRUCT_DEF(FIELD_COUNT(3), STRUCT_FIELD(kI32Code, true),
|
2020-07-07 12:12:23 +00:00
|
|
|
STRUCT_FIELD(WASM_OPT_REF(0), true),
|
|
|
|
STRUCT_FIELD(WASM_OPT_REF(1), true)),
|
|
|
|
WASM_STRUCT_DEF(FIELD_COUNT(2), STRUCT_FIELD(WASM_OPT_REF(0), true),
|
|
|
|
STRUCT_FIELD(WASM_OPT_REF(2), true)),
|
|
|
|
WASM_ARRAY_DEF(WASM_OPT_REF(0), true))};
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
EXPECT_OK(result);
|
|
|
|
}
|
|
|
|
|
2020-08-05 11:12:29 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OutOfBoundsTypeInGlobal) {
|
2020-07-07 12:12:23 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
2020-09-29 07:46:36 +00:00
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Global, ENTRY_COUNT(1), kRefCode, 0, WASM_REF_NULL(0), kExprEnd)};
|
2020-07-07 12:12:23 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2020-08-05 11:12:29 +00:00
|
|
|
EXPECT_NOT_OK(result, "Type index 0 is out of bounds");
|
2020-07-07 12:12:23 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 11:12:29 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, OutOfBoundsTypeInType) {
|
2020-07-07 12:12:23 +00:00
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
2020-08-05 11:12:29 +00:00
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
static const byte data[] = {
|
|
|
|
SECTION(Type, ENTRY_COUNT(1),
|
2020-09-29 07:46:36 +00:00
|
|
|
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kRefCode, true)))};
|
2020-07-07 12:12:23 +00:00
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
2020-08-05 11:12:29 +00:00
|
|
|
EXPECT_NOT_OK(result, "Type index 1 is out of bounds");
|
2020-07-07 12:12:23 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 13:09:27 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, IllegalPackedFields) {
|
|
|
|
WASM_FEATURE_SCOPE(gc);
|
|
|
|
WASM_FEATURE_SCOPE(typed_funcref);
|
|
|
|
WASM_FEATURE_SCOPE(reftypes);
|
|
|
|
|
|
|
|
static const byte data[] = {
|
2020-09-29 07:46:36 +00:00
|
|
|
SECTION(Global, ENTRY_COUNT(1), kI16Code, 0, WASM_INIT_EXPR_I32V_1(13))};
|
2020-07-07 13:09:27 +00:00
|
|
|
|
|
|
|
ModuleResult result = DecodeModule(data, data + sizeof(data));
|
|
|
|
|
|
|
|
EXPECT_NOT_OK(result, "invalid value type");
|
|
|
|
}
|
|
|
|
|
2020-12-14 14:05:48 +00:00
|
|
|
TEST_F(WasmModuleVerifyTest, Memory64DataSegment) {
|
|
|
|
WASM_FEATURE_SCOPE(memory64);
|
|
|
|
for (bool enable_memory64 : {false, true}) {
|
|
|
|
for (bool use_memory64 : {false, true}) {
|
|
|
|
byte const_opcode = use_memory64 ? kExprI64Const : kExprI32Const;
|
|
|
|
const byte data[] = {
|
|
|
|
SECTION(Memory, ENTRY_COUNT(1),
|
|
|
|
enable_memory64 ? kMemory64WithMaximum : kWithMaximum, 28,
|
|
|
|
28),
|
|
|
|
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0, // -
|
|
|
|
const_opcode, 0, kExprEnd, // dest addr
|
|
|
|
U32V_1(3), // source size
|
|
|
|
'a', 'b', 'c') // data bytes
|
|
|
|
};
|
|
|
|
|
|
|
|
if (enable_memory64 == use_memory64) {
|
|
|
|
EXPECT_VERIFIES(data);
|
|
|
|
} else if (enable_memory64) {
|
|
|
|
EXPECT_FAILURE_WITH_MSG(data, "expected i64, got i32");
|
|
|
|
} else {
|
|
|
|
EXPECT_FAILURE_WITH_MSG(data, "expected i32, got i64");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-08 14:54:44 +00:00
|
|
|
#undef EXPECT_INIT_EXPR
|
|
|
|
#undef EXPECT_INIT_EXPR_FAIL
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef WASM_INIT_EXPR_I32V_1
|
|
|
|
#undef WASM_INIT_EXPR_I32V_2
|
|
|
|
#undef WASM_INIT_EXPR_I32V_3
|
|
|
|
#undef WASM_INIT_EXPR_I32V_4
|
|
|
|
#undef WASM_INIT_EXPR_I32V_5
|
|
|
|
#undef WASM_INIT_EXPR_F32
|
|
|
|
#undef WASM_INIT_EXPR_I64
|
|
|
|
#undef WASM_INIT_EXPR_F64
|
2020-06-09 15:54:14 +00:00
|
|
|
#undef WASM_INIT_EXPR_EXTERN_REF_NULL
|
2020-06-03 12:48:16 +00:00
|
|
|
#undef WASM_INIT_EXPR_FUNC_REF_NULL
|
2019-05-13 11:35:43 +00:00
|
|
|
#undef WASM_INIT_EXPR_REF_FUNC
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef WASM_INIT_EXPR_GLOBAL
|
2019-03-04 18:52:03 +00:00
|
|
|
#undef REF_NULL_ELEMENT
|
|
|
|
#undef REF_FUNC_ELEMENT
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef EMPTY_BODY
|
|
|
|
#undef NOP_BODY
|
|
|
|
#undef SIG_ENTRY_i_i
|
|
|
|
#undef UNKNOWN_SECTION
|
2018-10-17 08:43:53 +00:00
|
|
|
#undef COUNT_ARGS
|
|
|
|
#undef CHECK_LEB1
|
|
|
|
#undef ADD_COUNT
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef SECTION
|
2020-09-24 11:52:48 +00:00
|
|
|
#undef TYPE_SECTION
|
|
|
|
#undef FUNCTION_SECTION
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef FOO_STRING
|
|
|
|
#undef NO_LOCAL_NAMES
|
2020-09-24 11:52:48 +00:00
|
|
|
#undef EMPTY_TYPE_SECTION
|
|
|
|
#undef EMPTY_FUNCTION_SECTION
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef EMPTY_FUNCTION_BODIES_SECTION
|
|
|
|
#undef SECTION_NAMES
|
|
|
|
#undef EMPTY_NAMES_SECTION
|
2018-10-17 11:52:34 +00:00
|
|
|
#undef SECTION_SRC_MAP
|
2019-03-19 18:45:36 +00:00
|
|
|
#undef SECTION_COMPILATION_HINTS
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef FAIL_IF_NO_EXPERIMENTAL_EH
|
|
|
|
#undef X1
|
|
|
|
#undef X2
|
|
|
|
#undef X3
|
|
|
|
#undef X4
|
|
|
|
#undef ONE_EMPTY_FUNCTION
|
|
|
|
#undef TWO_EMPTY_FUNCTIONS
|
|
|
|
#undef THREE_EMPTY_FUNCTIONS
|
|
|
|
#undef FOUR_EMPTY_FUNCTIONS
|
|
|
|
#undef ONE_EMPTY_BODY
|
|
|
|
#undef TWO_EMPTY_BODIES
|
|
|
|
#undef THREE_EMPTY_BODIES
|
|
|
|
#undef FOUR_EMPTY_BODIES
|
2020-09-24 11:52:48 +00:00
|
|
|
#undef TYPE_SECTION_ONE_SIG_VOID_VOID
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef LINEAR_MEMORY_INDEX_0
|
2020-07-07 12:12:23 +00:00
|
|
|
|
|
|
|
#undef FIELD_COUNT
|
|
|
|
#undef STRUCT_FIELD
|
|
|
|
#undef WASM_REF
|
|
|
|
#undef WASM_OPT_REF
|
|
|
|
#undef WASM_STRUCT_DEF
|
|
|
|
#undef WASM_ARRAY_DEF
|
|
|
|
#undef WASM_FUNCTION_DEF
|
2018-10-22 08:39:58 +00:00
|
|
|
#undef EXCEPTION_ENTRY
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef EXPECT_VERIFIES
|
|
|
|
#undef EXPECT_FAILURE_LEN
|
|
|
|
#undef EXPECT_FAILURE
|
|
|
|
#undef EXPECT_OFF_END_FAILURE
|
|
|
|
#undef EXPECT_OK
|
2018-10-19 08:24:38 +00:00
|
|
|
#undef EXPECT_NOT_OK
|
2017-09-08 13:59:05 +00:00
|
|
|
|
2017-09-28 17:55:52 +00:00
|
|
|
} // namespace module_decoder_unittest
|
2015-12-11 12:26:16 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|