diff --git a/bazel/external/wee8.genrule_cmd b/bazel/external/wee8.genrule_cmd index 9656e70d8cb8..5a37d85b04dc 100644 --- a/bazel/external/wee8.genrule_cmd +++ b/bazel/external/wee8.genrule_cmd @@ -45,8 +45,8 @@ fi WEE8_BUILD_ARGS+=" is_debug=false" # Clang or not Clang, that is the question. WEE8_BUILD_ARGS+=" is_clang=$$IS_CLANG" -# Disable custom compiler plugins. -WEE8_BUILD_ARGS+=" clang_use_chrome_plugins=false" +# Hack to disable bleeding-edge compiler flags. +WEE8_BUILD_ARGS+=" use_xcode_clang=true" # Use local toolchain. WEE8_BUILD_ARGS+=" custom_toolchain=\"//build/toolchain/linux/unbundle:default\"" # Use local stdlibc++ / libc++. @@ -62,6 +62,9 @@ WEE8_BUILD_ARGS+=" is_component_build=false" WEE8_BUILD_ARGS+=" v8_enable_i18n_support=false" WEE8_BUILD_ARGS+=" v8_enable_gdbjit=false" WEE8_BUILD_ARGS+=" v8_use_external_startup_data=false" +# Disable read-only heap, since it's leaky and HEAPCHECK complains about it. +# TODO(PiotrSikora): remove when fixed upstream. +WEE8_BUILD_ARGS+=" v8_enable_shared_ro_heap=false" # Build wee8. third_party/depot_tools/gn gen out/wee8 --args="$$WEE8_BUILD_ARGS" diff --git a/bazel/external/wee8.patch b/bazel/external/wee8.patch index cde188ba68f5..b087cc7052bb 100644 --- a/bazel/external/wee8.patch +++ b/bazel/external/wee8.patch @@ -1,8 +1,6 @@ # 1. Force full GC when destroying VMs. -# 2. Fix build with -DDEBUG. -# 3. Fix for VMs with overlapping lifetimes (https://crrev.com/c/1698387). -# 4. Fix linking with unbundled toolchain on macOS. -# 5. Increase VSZ limit to 4TiB (allows us to start up to 370 VMs). +# 3. Fix linking with unbundled toolchain on macOS. +# 4. Increase VSZ limit to 4TiB (allows us to start up to 370 VMs). --- a/wee8/build/toolchain/gcc_toolchain.gni +++ b/wee8/build/toolchain/gcc_toolchain.gni @@ -355,6 +355,8 @@ template("gcc_toolchain") { @@ -25,16 +23,7 @@ end_group_flag = "-Wl,--end-group " --- a/wee8/src/wasm/c-api.cc +++ b/wee8/src/wasm/c-api.cc -@@ -633,7 +633,7 @@ auto seal(const typename implement::type* x) -> const C* { - return reinterpret_cast(x); - } - --#ifdef DEBUG -+#if 0 - template - void vec::make_data() {} - -@@ -708,13 +708,12 @@ auto Engine::make(own&& config) -> own { +@@ -260,7 +260,7 @@ auto Engine::make(own&& config) -> own { // Stores StoreImpl::~StoreImpl() { @@ -43,36 +32,9 @@ reinterpret_cast(isolate_)->heap()->PreciseCollectAllGarbage( i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting, v8::kGCCallbackFlagForced); - #endif - context()->Exit(); -- isolate_->Exit(); - isolate_->Dispose(); - delete create_params_.array_buffer_allocator; - } -@@ -739,7 +738,6 @@ auto Store::make(Engine*) -> own { - if (!isolate) return own(); - - { -- v8::Isolate::Scope isolate_scope(isolate); - v8::HandleScope handle_scope(isolate); - - // Create context. -@@ -750,8 +748,10 @@ auto Store::make(Engine*) -> own { - store->isolate_ = isolate; - store->context_ = v8::Eternal(isolate, context); - } -- -- store->isolate()->Enter(); -+ // We intentionally do not call isolate->Enter() here, because that would -+ // prevent embedders from using stores with overlapping but non-nested -+ // lifetimes. The consequence is that Isolate::Current() is dysfunctional -+ // and hence must not be called by anything reachable via this file. - store->context()->Enter(); - isolate->SetData(0, store.get()); - --- a/wee8/src/wasm/wasm-memory.cc +++ b/wee8/src/wasm/wasm-memory.cc -@@ -139,7 +139,7 @@ void* TryAllocateBackingStore(WasmMemoryTracker* memory_tracker, Heap* heap, +@@ -142,7 +142,7 @@ void* TryAllocateBackingStore(WasmMemoryTracker* memory_tracker, Heap* heap, // address space limits needs to be smaller. constexpr size_t kAddressSpaceLimit = 0x8000000000L; // 512 GiB #elif V8_TARGET_ARCH_64_BIT @@ -81,14 +43,3 @@ #else constexpr size_t kAddressSpaceLimit = 0xC0000000; // 3 GiB #endif ---- a/wee8/third_party/wasm-api/wasm.hh -+++ b/wee8/third_party/wasm-api/wasm.hh -@@ -111,7 +111,7 @@ class vec { - size_t size_; - std::unique_ptr data_; - --#ifdef DEBUG -+#if 0 - void make_data(); - void free_data(); - #else diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index d0b571290765..008a71337892 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -244,8 +244,8 @@ REPOSITORY_LOCATIONS = dict( com_googlesource_chromium_v8 = dict( # This archive was created using https://storage.googleapis.com/envoyproxy-wee8/wee8-archive.sh # and contains complete checkout of v8 with all dependencies necessary to build wee8. - sha256 = "690ca8e3460362fba8e95d94c9325211ad477a4d71a392461f899ec91afd1292", - urls = ["https://storage.googleapis.com/envoyproxy-wee8/wee8-7.6.303.20.tar.gz"], + sha256 = "c1249a98036861f0fd1a200d0dd18f0d6f681a7c5221dcf25764d58053fbf380", + urls = ["https://storage.googleapis.com/envoyproxy-wee8/wee8-7.8.188.tar.gz"], ), io_opencensus_cpp = dict( sha256 = "8d6016e47c2e19e7acbadb6f905b8c422748c64299d71101ac8f28151677e195", diff --git a/source/extensions/common/wasm/v8/v8.cc b/source/extensions/common/wasm/v8/v8.cc index 8af904808033..66a0dba49e0d 100644 --- a/source/extensions/common/wasm/v8/v8.cc +++ b/source/extensions/common/wasm/v8/v8.cc @@ -27,7 +27,7 @@ struct FuncData { FuncData(std::string name) : name(name) {} std::string name; - wasm::own callback; + wasm::own callback; void* raw_func; }; @@ -112,15 +112,15 @@ class V8 : public WasmVm { std::function* function); wasm::vec source_ = wasm::vec::invalid(); - wasm::own store_; - wasm::own module_; - wasm::own instance_; - wasm::own memory_; - wasm::own table_; + wasm::own store_; + wasm::own module_; + wasm::own instance_; + wasm::own memory_; + wasm::own table_; - absl::flat_hash_map> host_globals_; + absl::flat_hash_map> host_globals_; absl::flat_hash_map host_functions_; - absl::flat_hash_map> module_functions_; + absl::flat_hash_map> module_functions_; uint32_t memory_stack_base_; uint32_t memory_heap_base_; @@ -150,7 +150,7 @@ static const char* printValKind(wasm::ValKind kind) { } } -static std::string printValTypes(const wasm::vec& types) { +static std::string printValTypes(const wasm::ownvec& types) { if (types.size() == 0) { return "void"; } @@ -166,8 +166,8 @@ static std::string printValTypes(const wasm::vec& types) { return s; } -static bool equalValTypes(const wasm::vec& left, - const wasm::vec& right) { +static bool equalValTypes(const wasm::ownvec& left, + const wasm::ownvec& right) { if (left.size() != right.size()) { return false; } @@ -222,7 +222,7 @@ template struct V8ProxyForGlobal : Global { template constexpr auto convertArgsTupleToValTypesImpl(absl::index_sequence) { - return wasm::vec::make( + return wasm::ownvec::make( wasm::ValType::make(convertArgToValKind::type>())...); } @@ -396,7 +396,7 @@ void V8::link(absl::string_view debug_name, bool needs_emscripten) { for (size_t i = 0; i < export_types.size(); i++) { absl::string_view name(export_types[i]->name().get(), export_types[i]->name().size()); auto export_type = export_types[i]->type(); - auto export_item = exports[i]; + auto export_item = exports[i].get(); ASSERT(export_type->kind() == export_item->kind()); switch (export_type->kind()) { @@ -556,7 +556,7 @@ void V8::registerHostFunctionImpl(absl::string_view moduleName, absl::string_vie convertArgsTupleToValTypes>()); auto func = wasm::Func::make( store_.get(), type.get(), - [](void* data, const wasm::Val params[], wasm::Val[]) -> wasm::own { + [](void* data, const wasm::Val params[], wasm::Val[]) -> wasm::own { auto func_data = reinterpret_cast(data); ENVOY_LOG(trace, "[wasm] callHostFunction(\"{}\")", func_data->name); auto args_tuple = convertValTypesToArgsTuple>(params); @@ -580,7 +580,7 @@ void V8::registerHostFunctionImpl(absl::string_view moduleName, absl::string_vie convertArgsTupleToValTypes>()); auto func = wasm::Func::make( store_.get(), type.get(), - [](void* data, const wasm::Val params[], wasm::Val results[]) -> wasm::own { + [](void* data, const wasm::Val params[], wasm::Val results[]) -> wasm::own { auto func_data = reinterpret_cast(data); ENVOY_LOG(trace, "[wasm] callHostFunction(\"{}\")", func_data->name); auto args_tuple = convertValTypesToArgsTuple>(params);