Commit b1dec60b authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Remove obsolete function name table

The function name table is not used any more since
https://chromiumcodereview.appspot.com/2424623002, so remove it.

R=titzer@chromium.org,ahaas@chromium.org

Review-Url: https://codereview.chromium.org/2451693002
Cr-Commit-Position: refs/heads/master@{#40552}
parent 532c16ec
......@@ -1722,8 +1722,6 @@ v8_source_set("v8_base") {
"src/wasm/wasm-debug.h",
"src/wasm/wasm-external-refs.cc",
"src/wasm/wasm-external-refs.h",
"src/wasm/wasm-function-name-table.cc",
"src/wasm/wasm-function-name-table.h",
"src/wasm/wasm-interpreter.cc",
"src/wasm/wasm-interpreter.h",
"src/wasm/wasm-js.cc",
......
......@@ -1262,8 +1262,6 @@
'wasm/wasm-debug.h',
'wasm/wasm-external-refs.cc',
'wasm/wasm-external-refs.h',
'wasm/wasm-function-name-table.cc',
'wasm/wasm-function-name-table.h',
'wasm/wasm-js.cc',
'wasm/wasm-js.h',
'wasm/wasm-macro-gen.h',
......
// Copyright 2016 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 "src/wasm/wasm-function-name-table.h"
#include "src/wasm/wasm-module.h"
namespace v8 {
namespace internal {
namespace wasm {
// Build an array with all function names. If there are N functions in the
// module, then the first (kIntSize * (N+1)) bytes are integer entries.
// The first integer entry encodes the number of functions in the module.
// The entries 1 to N contain offsets into the second part of this array.
// If a function is unnamed (not to be confused with an empty name), then the
// integer entry is the negative offset of the next function name.
// After these N+1 integer entries, the second part begins, which holds a
// concatenation of all function names.
Handle<ByteArray> BuildFunctionNamesTable(Isolate* isolate,
const WasmModule* module) {
uint64_t func_names_length = 0;
for (auto& func : module->functions) func_names_length += func.name_length;
int num_funcs_int = static_cast<int>(module->functions.size());
int current_offset = (num_funcs_int + 1) * kIntSize;
uint64_t total_array_length = current_offset + func_names_length;
int total_array_length_int = static_cast<int>(total_array_length);
// Check for overflow.
CHECK(total_array_length_int == total_array_length && num_funcs_int >= 0 &&
num_funcs_int == module->functions.size());
Handle<ByteArray> func_names_array =
isolate->factory()->NewByteArray(total_array_length_int, TENURED);
func_names_array->set_int(0, num_funcs_int);
int func_index = 0;
for (const WasmFunction& fun : module->functions) {
WasmName name = module->GetNameOrNull(&fun);
if (name.start() == nullptr) {
func_names_array->set_int(func_index + 1, -current_offset);
} else {
func_names_array->copy_in(current_offset,
reinterpret_cast<const byte*>(name.start()),
name.length());
func_names_array->set_int(func_index + 1, current_offset);
current_offset += name.length();
}
++func_index;
}
return func_names_array;
}
MaybeHandle<String> GetWasmFunctionNameFromTable(
Handle<ByteArray> func_names_array, uint32_t func_index) {
uint32_t num_funcs = static_cast<uint32_t>(func_names_array->get_int(0));
DCHECK(static_cast<int>(num_funcs) >= 0);
Factory* factory = func_names_array->GetIsolate()->factory();
DCHECK(func_index < num_funcs);
int offset = func_names_array->get_int(func_index + 1);
if (offset < 0) return {};
int next_offset = func_index == num_funcs - 1
? func_names_array->length()
: abs(func_names_array->get_int(func_index + 2));
ScopedVector<byte> buffer(next_offset - offset);
func_names_array->copy_out(offset, buffer.start(), next_offset - offset);
if (!unibrow::Utf8::Validate(buffer.start(), buffer.length())) return {};
return factory->NewStringFromUtf8(Vector<const char>::cast(buffer));
}
} // namespace wasm
} // namespace internal
} // namespace v8
// Copyright 2016 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.
#ifndef V8_WASM_FUNCTION_NAME_TABLE_H_
#define V8_WASM_FUNCTION_NAME_TABLE_H_
#include "src/handles.h"
#include "src/objects.h"
namespace v8 {
namespace internal {
namespace wasm {
// Forward declarations for some WASM data structures.
struct WasmModule;
// Encode all function names of the WasmModule into one ByteArray.
Handle<ByteArray> BuildFunctionNamesTable(Isolate* isolate,
const WasmModule* module);
// Extract the function name for the given func_index from the function name
// table.
// Returns a null handle if the respective function is unnamed (not to be
// confused with empty names) or the function name is not a valid UTF-8 string.
MaybeHandle<String> GetWasmFunctionNameFromTable(
Handle<ByteArray> wasm_names_table, uint32_t func_index);
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_WASM_FUNCTION_NAME_TABLE_H_
......@@ -17,7 +17,6 @@
#include "src/wasm/ast-decoder.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-debug.h"
#include "src/wasm/wasm-function-name-table.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-result.h"
......
......@@ -190,7 +190,6 @@ v8_executable("cctest") {
"wasm/test-run-wasm-module.cc",
"wasm/test-run-wasm-relocation.cc",
"wasm/test-run-wasm.cc",
"wasm/test-wasm-function-name-table.cc",
"wasm/test-wasm-stack.cc",
"wasm/test-wasm-trap-position.cc",
"wasm/wasm-run-utils.h",
......
......@@ -211,7 +211,6 @@
'wasm/test-run-wasm-js.cc',
'wasm/test-run-wasm-module.cc',
'wasm/test-run-wasm-relocation.cc',
'wasm/test-wasm-function-name-table.cc',
'wasm/test-wasm-stack.cc',
'wasm/test-wasm-trap-position.cc',
'wasm/wasm-run-utils.h',
......
// Copyright 2016 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 "src/wasm/wasm-function-name-table.h"
#include "src/wasm/wasm-module.h"
#include "test/cctest/cctest.h"
using namespace v8::internal;
using namespace v8::internal::wasm;
namespace {
#define CHECK_STREQ(exp, found) \
do { \
Vector<const char> exp_ = (exp); \
Vector<const char> found_ = (found); \
if (V8_UNLIKELY(exp_.length() != found_.length() || \
memcmp(exp_.start(), found_.start(), exp_.length()))) { \
V8_Fatal(__FILE__, __LINE__, \
"Check failed: (%s) != (%s) ('%.*s' vs '%.*s').", #exp, #found, \
exp_.length(), exp_.start(), found_.length(), found_.start()); \
} \
} while (0)
void testFunctionNameTable(Vector<Vector<const char>> names) {
Isolate *isolate = CcTest::InitIsolateOnce();
HandleAndZoneScope scope;
WasmModule module;
std::vector<char> all_names;
// No name should have offset 0, because that encodes unnamed functions.
// In real wasm binary, offset 0 is impossible anyway.
all_names.push_back('\0');
uint32_t func_index = 0;
for (Vector<const char> name : names) {
size_t name_offset = name.start() ? all_names.size() : 0;
all_names.insert(all_names.end(), name.start(),
name.start() + name.length());
// Make every second function name null-terminated.
if (func_index % 2) all_names.push_back('\0');
module.functions.push_back(
{nullptr, 0, 0, static_cast<uint32_t>(name_offset),
static_cast<uint32_t>(name.length()), 0, 0, false, false});
++func_index;
}
module.module_start = reinterpret_cast<byte *>(all_names.data());
module.module_end = module.module_start + all_names.size();
Handle<Object> wasm_function_name_table =
BuildFunctionNamesTable(isolate, &module);
CHECK(wasm_function_name_table->IsByteArray());
func_index = 0;
for (Vector<const char> name : names) {
MaybeHandle<String> string = GetWasmFunctionNameFromTable(
Handle<ByteArray>::cast(wasm_function_name_table), func_index);
if (name.start()) {
CHECK(string.ToHandleChecked()->IsUtf8EqualTo(name));
} else {
CHECK(string.is_null());
}
++func_index;
}
}
void testFunctionNameTable(Vector<const char *> names) {
std::vector<Vector<const char>> names_vec;
for (const char *name : names)
names_vec.push_back(name ? CStrVector(name) : Vector<const char>());
testFunctionNameTable(Vector<Vector<const char>>(
names_vec.data(), static_cast<int>(names_vec.size())));
}
} // namespace
TEST(NoFunctions) { testFunctionNameTable(Vector<Vector<const char>>()); }
TEST(OneFunctions) {
const char *names[] = {"foo"};
testFunctionNameTable(ArrayVector(names));
}
TEST(ThreeFunctions) {
const char *names[] = {"foo", "bar", "baz"};
testFunctionNameTable(ArrayVector(names));
}
TEST(OneUnnamedFunction) {
const char *names[] = {""};
testFunctionNameTable(ArrayVector(names));
}
TEST(UnnamedFirstFunction) {
const char *names[] = {"", "bar", "baz"};
testFunctionNameTable(ArrayVector(names));
}
TEST(UnnamedLastFunction) {
const char *names[] = {"bar", "baz", ""};
testFunctionNameTable(ArrayVector(names));
}
TEST(ThreeUnnamedFunctions) {
const char *names[] = {"", "", ""};
testFunctionNameTable(ArrayVector(names));
}
TEST(UTF8Names) {
const char *names[] = {"↱fun↰", "↺", "alpha:α beta:β"};
testFunctionNameTable(ArrayVector(names));
}
TEST(UnnamedVsEmptyNames) {
const char *names[] = {"", nullptr, nullptr, ""};
testFunctionNameTable(ArrayVector(names));
}
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