forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 62
wasm: add v8 runtime. #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b76eae4
build: update ninja to version 1.8.2.
PiotrSikora 5f7bf10
wasm: add v8 runtime.
PiotrSikora a3f153a
review: address Yuchen's comments.
PiotrSikora c98a52c
Merge remote-tracking branch 'istio/wasm' into PiotrSikora/wasm-v8
PiotrSikora 2f8a050
build: update wasm-c-api to latest.
PiotrSikora ff8c565
v8: disable DEBUG, since it seems to be broken.
PiotrSikora 4bcf3ea
v8: fix typo.
PiotrSikora 3eea9ff
v8: more template magic.
PiotrSikora d32353f
v8: implement getMemoryOffset().
PiotrSikora 18e4dee
v8: remove unnecessary includes.
PiotrSikora 0027504
v8: even more template magic.
PiotrSikora 0bef0e7
v8: even more template magic.
PiotrSikora e20e042
v8: verify type of each argument in module functions.
PiotrSikora 51de647
v8: add more reasons for disabled DEBUG.
PiotrSikora 998a80c
v8: guard reads when parsing binary WASM module.
PiotrSikora 09306b8
v8: mark callModuleFunction() args as const.
PiotrSikora 20ee24d
v8: re-enable NaN test, since it was fixed upstream.
PiotrSikora 36a7064
v8: add proxy for globals.
PiotrSikora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Get wasm-c-api. | ||
|
|
||
| COMMIT=111a3e4a0962fae4da2428b8680f7dfbc8deef47 # Mon May 13 11:10:04 2019 +0200 | ||
| SHA256=4eb700586902d0f6ebdcbc0147f5674df95743cc831495191b7df4cb32fb3ef0 | ||
|
|
||
| curl https://github.com/WebAssembly/wasm-c-api/archive/"$COMMIT".tar.gz -sLo wasm-c-api-"$COMMIT".tar.gz \ | ||
| && echo "$SHA256" wasm-c-api-"$COMMIT".tar.gz | sha256sum --check | ||
| tar xf wasm-c-api-"$COMMIT".tar.gz | ||
| cd wasm-c-api-"$COMMIT" | ||
|
|
||
| # Build v8 inside v8 subdirectory to match wasm-c-api's Makefile. | ||
|
|
||
| mkdir v8 | ||
| cd v8 | ||
|
|
||
| # Get depot_tools. | ||
|
|
||
| git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git | ||
| export PATH="$PATH:$PWD/depot_tools" | ||
|
|
||
| # Get v8. | ||
|
|
||
| VERSION=7.4.288.28 # match wasm-c-api (branch-heads/7.4) | ||
|
|
||
| fetch v8 | ||
| cd v8 | ||
| git checkout "$VERSION" | ||
| gclient sync | ||
|
|
||
| # Patch v8 for wasm-c-api. | ||
|
|
||
| patch -p1 < ../../patch/0001-BUILD.gn-add-wasm-v8-lowlevel.patch | ||
| cp -p ../../src/wasm-v8-lowlevel.cc src/wasm-v8-lowlevel.cc | ||
| cp -p ../../src/wasm-v8-lowlevel.hh include/wasm-v8-lowlevel.hh | ||
|
|
||
| # Build v8 static library. | ||
|
|
||
| tools/dev/v8gen.py x64.release -- v8_monolithic=true v8_use_external_startup_data=false v8_enable_i18n_support=false v8_enable_gdbjit=false use_custom_libcxx=false | ||
| ninja -v -C out.gn/x64.release v8_monolith | ||
|
|
||
| # Install v8. | ||
|
|
||
| mkdir -p "$THIRDPARTY_BUILD/include/v8/libplatform" | ||
| cp -p include/v8*.h "$THIRDPARTY_BUILD/include/v8/" | ||
| cp -p include/libplatform/*.h "$THIRDPARTY_BUILD/include/v8/libplatform/" | ||
| cp -p out.gn/x64.release/obj/libv8_monolith.a "$THIRDPARTY_BUILD/lib/" | ||
|
|
||
| cd ../.. | ||
|
|
||
| # Patch wasm-c-api. | ||
|
|
||
| # 1. Disable DEBUG (alloc/free accounting), since it seems to be broken | ||
| # in optimized builds and/or when using sanitizers. | ||
| # 2. Disable hardcoded sanitizers. | ||
|
|
||
| cat <<\EOF | patch -p1 | ||
| --- a/Makefile | ||
| +++ b/Makefile | ||
| @@ -7,10 +7,10 @@ V8_VERSION = branch-heads/7.4 | ||
| V8_ARCH = x64 | ||
| V8_MODE = release | ||
|
|
||
| -WASM_FLAGS = -DDEBUG # -DDEBUG_LOG | ||
| -C_FLAGS = ${WASM_FLAGS} -Wall -Werror -ggdb -O -fsanitize=address | ||
| +WASM_FLAGS = | ||
| +C_FLAGS = ${WASM_FLAGS} -Wall -Werror -ggdb -O | ||
| CC_FLAGS = ${C_FLAGS} | ||
| -LD_FLAGS = -fsanitize-memory-track-origins -fsanitize-memory-use-after-dtor | ||
| +LD_FLAGS = | ||
|
|
||
| C_COMP = clang | ||
| EOF | ||
|
|
||
| # 3. Enable "wasm_bulk_memory" required to load WASM modules with DataCount | ||
| # section, even when DataCount = 1. | ||
| # 4. Force full GC when destroying VMs. | ||
|
|
||
| cat <<\EOF | patch -p1 | ||
| --- a/src/wasm-v8.cc | ||
| +++ b/src/wasm-v8.cc | ||
| @@ -296,7 +296,7 @@ auto Engine::make(own<Config*>&& config) -> own<Engine*> { | ||
| v8::internal::FLAG_experimental_wasm_bigint = true; | ||
| v8::internal::FLAG_experimental_wasm_mv = true; | ||
| // v8::internal::FLAG_experimental_wasm_anyref = true; | ||
| - // v8::internal::FLAG_experimental_wasm_bulk_memory = true; | ||
| + v8::internal::FLAG_experimental_wasm_bulk_memory = true; | ||
| // v8::V8::SetFlagsFromCommandLine(&argc, const_cast<char**>(argv), false); | ||
| auto engine = new(std::nothrow) EngineImpl; | ||
| if (!engine) return own<Engine*>(); | ||
| @@ -349,7 +349,7 @@ public: | ||
| } | ||
|
|
||
| ~StoreImpl() { | ||
| -#ifdef DEBUG | ||
| +#if 1 //def DEBUG | ||
| isolate_->RequestGarbageCollectionForTesting( | ||
| v8::Isolate::kFullGarbageCollection); | ||
| #endif | ||
| EOF | ||
|
|
||
| # Build wasm-c-api. | ||
|
|
||
| # TODO(PiotrSikora): respect CC/CXX/CFLAGS/CXXFLAGS/LDFLAGS upstream. | ||
|
|
||
| make wasm | ||
|
|
||
| # Install wasm-c-api. | ||
|
|
||
| mkdir -p "$THIRDPARTY_BUILD/include/wasm-c-api" | ||
| cp -p include/wasm.hh "$THIRDPARTY_BUILD/include/wasm-c-api/" | ||
| cp -p src/wasm-bin.hh "$THIRDPARTY_BUILD/include/wasm-c-api/" | ||
| ar -r -c -s "$THIRDPARTY_BUILD/lib/libwasm.a" out/wasm-bin.o out/wasm-v8.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "v8_lib", | ||
| srcs = ["v8.cc"], | ||
| hdrs = ["v8.h"], | ||
| external_deps = [ | ||
| "v8", | ||
| ], | ||
| deps = [ | ||
| "//include/envoy/server:wasm_interface", | ||
| "//include/envoy/thread_local:thread_local_interface", | ||
| "//source/common/common:assert_lib", | ||
| "//source/common/common:c_smart_ptr_lib", | ||
| "//source/common/protobuf", | ||
| "//source/extensions/common/wasm:wasm_hdr", | ||
| "//source/extensions/common/wasm:well_known_names", | ||
| "@envoy_api//envoy/config/wasm/v2:wasm_cc", | ||
| ], | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.