Commit 5da083ab authored by Shu-yu Guo's avatar Shu-yu Guo Committed by Commit Bot

Revert "[wasm] Re-exported globals preserve their identity"

This reverts commit f7a1932e.

Reason for revert: Breaking wasm wpt tests: https://ci.chromium.org/p/v8/builders/ci/V8%20Blink%20Linux/5408

Original change's description:
> [wasm] Re-exported globals preserve their identity
> 
> V8 fails a recently added spec test that when an imported global get
> re-exported, it should preserve its identity. This CL fixes the behavior
> in V8.
> 
> Drive-by change: fix the object printer of globals: a global which
> stores a reference type only has a tagged buffer, a global which stores
> a value type only has an untagged buffer.
> 
> R=​clemensb@chromium.org
> 
> Bug: v8:10556
> Change-Id: I949d147fe4395610cfec6cf60082e1faecb23036
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2235702
> Commit-Queue: Andreas Haas <ahaas@chromium.org>
> Reviewed-by: Clemens Backes <clemensb@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#68513}

TBR=ahaas@chromium.org,clemensb@chromium.org

Change-Id: I06eb1996cafe7d4e93a7e59d21679fea239cf961
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:10556
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2264956Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68528}
parent 6c8d9ad0
......@@ -1815,11 +1815,8 @@ void WasmTableObject::WasmTableObjectPrint(std::ostream& os) { // NOLINT
void WasmGlobalObject::WasmGlobalObjectPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "WasmGlobalObject");
if (type().is_reference_type()) {
os << "\n - tagged_buffer: " << Brief(tagged_buffer());
} else {
os << "\n - untagged_buffer: " << Brief(untagged_buffer());
}
os << "\n - untagged_buffer: " << Brief(untagged_buffer());
os << "\n - tagged_buffer: " << Brief(tagged_buffer());
os << "\n - offset: " << offset();
os << "\n - raw_type: " << raw_type();
os << "\n - is_mutable: " << is_mutable();
......
......@@ -259,6 +259,9 @@ class InstanceBuilder {
// Process initialization of globals.
void InitGlobals(Handle<WasmInstanceObject> instance);
bool NeedsWrappers() const;
// Process the exports, creating wrappers for functions, tables, memories,
// and globals.
void ProcessExports(Handle<WasmInstanceObject> instance);
......@@ -1476,29 +1479,31 @@ bool InstanceBuilder::AllocateMemory() {
return true;
}
bool InstanceBuilder::NeedsWrappers() const {
if (module_->num_exported_functions > 0) return true;
for (auto& table : module_->tables) {
if (table.type.heap_type() == kHeapFunc) return true;
}
return false;
}
// Process the exports, creating wrappers for functions, tables, memories,
// globals, and exceptions.
void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
std::unordered_map<int, Handle<Object>> imported_globals;
// If an imported WebAssembly function or global gets exported, the export
// has to be identical to to import. Therefore we cache all imported
// WebAssembly functions in the instance, and all imported globals in a map
// here.
for (int index = 0, end = static_cast<int>(module_->import_table.size());
index < end; ++index) {
const WasmImport& import = module_->import_table[index];
if (import.kind == kExternalFunction) {
Handle<Object> value = sanitized_imports_[index].value;
if (WasmExternalFunction::IsWasmExternalFunction(*value)) {
WasmInstanceObject::SetWasmExternalFunction(
isolate_, instance, import.index,
Handle<WasmExternalFunction>::cast(value));
}
} else if (import.kind == kExternalGlobal) {
Handle<Object> value = sanitized_imports_[index].value;
if (value->IsWasmGlobalObject()) {
imported_globals[import.index] = value;
if (NeedsWrappers()) {
// If an imported WebAssembly function gets exported, the exported function
// has to be identical to to imported function. Therefore we cache all
// imported WebAssembly functions in the instance.
for (int index = 0, end = static_cast<int>(module_->import_table.size());
index < end; ++index) {
const WasmImport& import = module_->import_table[index];
if (import.kind == kExternalFunction) {
Handle<Object> value = sanitized_imports_[index].value;
if (WasmExternalFunction::IsWasmExternalFunction(*value)) {
WasmInstanceObject::SetWasmExternalFunction(
isolate_, instance, import.index,
Handle<WasmExternalFunction>::cast(value));
}
}
}
}
......@@ -1558,13 +1563,6 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
}
case kExternalGlobal: {
const WasmGlobal& global = module_->globals[exp.index];
if (global.imported) {
auto cached_global = imported_globals.find(exp.index);
if (cached_global != imported_globals.end()) {
desc.set_value(cached_global->second);
break;
}
}
Handle<JSArrayBuffer> untagged_buffer;
Handle<FixedArray> tagged_buffer;
uint32_t offset;
......
// Copyright 2020 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.
load('test/mjsunit/wasm/wasm-module-builder.js');
const global1 = new WebAssembly.Global({value: 'i32', mutable: true}, 14);
const global2 = new WebAssembly.Global({value: 'i32', mutable: true}, 15);
const global3 = new WebAssembly.Global({value: 'i32', mutable: true}, 32);
const builder = new WasmModuleBuilder();
// Two additional globals, so that global-index != export-index.
builder.addImportedGlobal('module', 'global1', kWasmI32, true);
builder.addImportedGlobal('module', 'global2', kWasmI32, true);
const globalIndex =
builder.addImportedGlobal('module', 'global3', kWasmI32, true);
builder.addExportOfKind('exportedGlobal', kExternalGlobal, globalIndex);
const buffer = builder.toBuffer();
const module = new WebAssembly.Module(buffer);
const instance = new WebAssembly.Instance(module, {
'module': {
'global1': global1,
'global2': global2,
'global3': global3,
}
});
assertEquals(global3, instance.exports.exportedGlobal);
This diff is collapsed.
......@@ -7,6 +7,7 @@
[ALWAYS, {
# TODO(v8:10556): Remove sub-typing in the reference-types implementation
'constructor/instantiate': [FAIL],
'instance/constructor-caching': [FAIL],
'instance/constructor': [FAIL],
'proposals/js-types/constructor/instantiate': [FAIL],
'proposals/js-types/global/constructor': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment