Skip to content
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

wasm: Add Wasmtime as a new runtime #13932

Merged
merged 33 commits into from
Nov 12, 2020
Merged

Conversation

mathetake
Copy link
Member

@mathetake mathetake commented Nov 7, 2020

Signed-off-by: mathetake takeshi@tetrate.io

Commit Message: wasm: Add Wasmtime(https://github.com/bytecodealliance/wasmtime) as a new runtime for Wasm filter
Additional Description: add a new wasm runtime, named Wasmtime, in addition to existing runtimes like V8 and WAVM.
Risk Level: low
Testing: run in bazel.compile_time_options build target as WAVM.
Docs Changes: Docs will be provided in subsequent PRs.
Release Notes: enable Wasmtime as a Wasm filter runtime optionally.
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]

ref: proxy-wasm/proxy-wasm-cpp-host#73

Signed-off-by: mathetake <takeshi@tetrate.io>
@repokitteh-read-only repokitteh-read-only bot added the deps Approval required for changes to Envoy's external dependencies label Nov 7, 2020
@repokitteh-read-only
Copy link

CC @envoyproxy/dependency-shepherds: Your approval is needed for changes made to (bazel/.*repos.*\.bzl)|(bazel/dependency_imports\.bzl)|(api/bazel/.*\.bzl)|(.*/requirements\.txt)|(.*\.patch).

🐱

Caused by: #13932 was opened by mathetake.

see: more, trace.

Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: mathetake <takeshi@tetrate.io>
@antoniovicente antoniovicente requested review from PiotrSikora and lizan and removed request for PiotrSikora November 9, 2020 21:04
@antoniovicente
Copy link
Contributor

Thanks for the pull request. Is there some particular aspect of this change that you'ld like early feedback on? What additional changes you think are needed before this draft PR is ready for review and merge?

Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: mathetake <takeshi@tetrate.io>
exclude = [
# TODO: currently we cannot link wasmtime with (v8, WAVM) due to symbol collision:
# - V8: wasm-c-api symbols
# - WAVM: LLVM's gdb JIT interface related symbols
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is possible now that you removed jit-dump option?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, perhaps we should remove the "all" option altogether, since it no longer represents all runtimes?

Multiple runtimes can be selected individually anyway, e.g.:

bazel build --config=libc++ --define=wasm=v8 --define=wasm=wavm //source/exe:envoy-static

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple runtimes can be selected individually anyway, e.g.:

I didn't know that. Thanks! I'll remove all option

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and, let me see if the collision with WAVM has been resolved

Copy link
Member Author

@mathetake mathetake Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could observe the same collision with jit-dump=disabled:

se --sandbox_debug to see verbose messages from the sandbox
ld.lld: error: duplicate symbol: __jit_debug_descriptor
>>> defined at GDBRegistrationListener.cpp
>>>            GDBRegistrationListener.cpp.o:(__jit_debug_descriptor) in archive bazel-out/k8-fastbuild/bin/bazel/foreign_cc/llvm/lib/libLLVMExecutionEngine.a
>>> defined at wasmtime_runtime.849cvge1-cgu.15
>>>            wasmtime_runtime-361389515.wasmtime_runtime.849cvge1-cgu.15.rcgu.o:(.data.__jit_debug_descriptor+0x0) in archive bazel-out/k8-fastbuild/bin/external/com_github_wasmtime/librust_c_api-220117231.a

ld.lld: error: duplicate symbol: __jit_debug_register_code
>>> defined at GDBRegistrationListener.cpp
>>>            GDBRegistrationListener.cpp.o:(__jit_debug_register_code) in archive bazel-out/k8-fastbuild/bin/bazel/foreign_cc/llvm/lib/libLLVMExecutionEngine.a
>>> defined at wasmtime_runtime.849cvge1-cgu.15
>>>            wasmtime_runtime-361389515.wasmtime_runtime.849cvge1-cgu.15.rcgu.o:(.text.__jit_debug_register_code+0x0) in archive bazel-out/k8-fastbuild/bin/external/com_github_wasmtime/librust_c_api-220117231.a

It's defined in the runtime package which is nothing to do with jit-dump feature https://github.com/bytecodealliance/wasmtime/blob/v0.21.0/crates/runtime/src/jit_int.rs#L32-L41

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I realized that the V8 defines the same symbol but disable it by default https://chromium.googlesource.com/v8/v8/+/4.10.71/src/gdb-jit.cc#24 , that's why luckily we have not encountered symbol collision in conjunction with V8 and WAVM

Copy link
Member Author

@mathetake mathetake Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ugly patch seems to work...

wavm.patch
diff --git a/CMakeLists.txt b/CMakeLists.txt
index eb5d7c2c..2bd2c748 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -720,7 +720,6 @@ if(WAVM_ENABLE_RUNTIME)
 	add_subdirectory(Lib/Runtime)
 	add_subdirectory(Lib/ThreadTest)
 	add_subdirectory(Lib/WASI)
-	add_subdirectory(Lib/wavm-c)
 endif()
 
 if(WAVM_ENABLE_UNWIND)
diff --git a/Lib/LLVMJIT/LLVMModule.cpp b/Lib/LLVMJIT/LLVMModule.cpp
index 5f830959..0e222f36 100644
--- a/Lib/LLVMJIT/LLVMModule.cpp
+++ b/Lib/LLVMJIT/LLVMModule.cpp
@@ -61,9 +61,6 @@ using namespace WAVM::LLVMJIT;
 
 struct LLVMJIT::GlobalModuleState
 {
-	Platform::Mutex gdbRegistrationListenerMutex;
-	llvm::JITEventListener* gdbRegistrationListener = nullptr;
-
 	// A map from address to loaded JIT symbols.
 	Platform::RWMutex addressToModuleMapMutex;
 	std::map<Uptr, LLVMJIT::Module*> addressToModuleMap;
@@ -76,11 +73,8 @@ struct LLVMJIT::GlobalModuleState
 
 	// These constructor and destructor should not be called directly, but must be public in order
 	// to be accessible by std::make_shared.
-	GlobalModuleState()
-	{
-		gdbRegistrationListener = llvm::JITEventListener::createGDBRegistrationListener();
-	}
-	~GlobalModuleState() { delete gdbRegistrationListener; }
+	GlobalModuleState() {}
+	~GlobalModuleState() {}
 };
 
 // Allocates memory for the LLVM object loader.
@@ -516,13 +510,6 @@ Module::Module(const std::vector<U8>& objectBytes,
 
 	// Notify GDB of the new object.
 	{
-		Platform::Mutex::Lock lock(globalModuleState->gdbRegistrationListenerMutex);
-#if LLVM_VERSION_MAJOR >= 8
-		globalModuleState->gdbRegistrationListener->notifyObjectLoaded(
-			reinterpret_cast<Uptr>(this), *object, *loadedObject);
-#else
-		globalModuleState->gdbRegistrationListener->NotifyObjectEmitted(*object, *loadedObject);
-#endif
 	}
 
 	// Create a DWARF context to interpret the debug information in this compilation unit.
@@ -616,15 +603,7 @@ Module::Module(const std::vector<U8>& objectBytes,
 Module::~Module()
 {
 	// Notify GDB that the object is being unloaded.
-	{
-		Platform::Mutex::Lock lock(globalModuleState->gdbRegistrationListenerMutex);
-#if LLVM_VERSION_MAJOR >= 8
-		globalModuleState->gdbRegistrationListener->notifyFreeingObject(
-			reinterpret_cast<Uptr>(this));
-#else
-		globalModuleState->gdbRegistrationListener->NotifyFreeingObject(*object);
-#endif
-	}
+	{}
 
 	// Remove the module from the global address to module map.
 	{
diff --git a/Programs/wavm/CMakeLists.txt b/Programs/wavm/CMakeLists.txt
index 3d00c1df..e3445c13 100644
--- a/Programs/wavm/CMakeLists.txt
+++ b/Programs/wavm/CMakeLists.txt
@@ -13,7 +13,6 @@ set(NonRuntimeSources Testing/DumpTestModules.cpp
 set(RuntimeOnlySources
 			Testing/Benchmark.cpp
 			Testing/RunTestScript.cpp
-			Testing/TestCAPI.c
 			wavm-compile.cpp
 			wavm-run.cpp)
 
@@ -37,6 +36,3 @@ add_test(NAME HashMap COMMAND $<TARGET_FILE:wavm> test hashmap)
 add_test(NAME HashSet COMMAND $<TARGET_FILE:wavm> test hashset)
 add_test(NAME I128 COMMAND $<TARGET_FILE:wavm> test i128)
 
-if(WAVM_ENABLE_RUNTIME)
-	add_test(NAME C-API COMMAND $<TARGET_FILE:wavm> test c-api)
-endif()
diff --git a/Programs/wavm/Testing/wavm-test.cpp b/Programs/wavm/Testing/wavm-test.cpp
index eed47d13..61ef1189 100644
--- a/Programs/wavm/Testing/wavm-test.cpp
+++ b/Programs/wavm/Testing/wavm-test.cpp
@@ -99,7 +99,7 @@ int execTestCommand(int argc, char** argv)
 		case TestCommand::hashSet: return execHashSetTest(argc - 1, argv + 1);
 		case TestCommand::i128: return execI128Test(argc - 1, argv + 1);
 #if WAVM_ENABLE_RUNTIME
-		case TestCommand::cAPI: return execCAPITest(argc - 1, argv + 1);
+		case TestCommand::cAPI: return 0;
 		case TestCommand::benchmark: return execBenchmark(argc - 1, argv + 1);
 		case TestCommand::script: return execRunTestScript(argc - 1, argv + 1);
 #endif

Copy link
Member Author

@mathetake mathetake Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this patch, I could link both WAVM and Wasmtime at the same time, but when I run extension with wasmtime, I see weird error (I am completely not sure where this is coming from)

2020-11-10 15:11:32.316][576526][debug][wasm] [source/extensions/common/wasm/wasm.cc:126] Thread-Local Wasm created 3 now active
libunwind: _unw_add_dynamic_fde: bad fde: FDE is really a CIE
libunwind: _unw_add_dynamic_fde: bad fde: FDE is really a CIE
libunwind: _unw_add_dynamic_fde: bad fde: FDE is really a CIE
libunwind: _unw_add_dynamic_fde: bad fde: FDE is really a CIE
libunwind: _unw_add_dynamic_fde: bad fde: FDE is really a CIE

This is not observed when we link Wasmtime alone, so something's broken

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't think we want to maintain that big of a patch. Removing single directory from CMakeLists.txt is acceptable, but modifying code to link multiple runtimes is probably not a good idea.

Thanks for looking, though!

source/extensions/common/wasm/well_known_names.h Outdated Show resolved Hide resolved
ci/do_ci.sh Outdated Show resolved Hide resolved
mathetake and others added 7 commits November 10, 2020 15:30
Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
review: drop "all", cleanup BUILD file.
@mathetake
Copy link
Member Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Check envoy-presubmit isn't fully completed, but will still attempt retrying.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #13932 (comment) was created by @mathetake.

see: more, trace.

@mathetake
Copy link
Member Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #13932 (comment) was created by @mathetake.

see: more, trace.

lizan
lizan previously approved these changes Nov 11, 2020
Signed-off-by: mathetake <takeshi@tetrate.io>
@lizan
Copy link
Member

lizan commented Nov 11, 2020

Should be good to go but need @envoyproxy/dependency-shepherds review.

PiotrSikora
PiotrSikora previously approved these changes Nov 11, 2020
Copy link
Contributor

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@envoyproxy/dependency-shepherds friendly ping.

Copy link
Contributor

@moderation moderation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brings in two more deps - would be good to have @htuch review. Would like to bring in latest commits as per comments

bazel/repository_locations.bzl Show resolved Hide resolved
bazel/repository_locations.bzl Show resolved Hide resolved
Copy link
Contributor

@moderation moderation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment as to why we need to pin to old commit

bazel/repository_locations.bzl Show resolved Hide resolved
Signed-off-by: mathetake <takeshi@tetrate.io>
@mathetake mathetake dismissed stale reviews from PiotrSikora and lizan via 0210faa November 12, 2020 01:52
@moderation
Copy link
Contributor

/lgtm deps

@repokitteh-read-only repokitteh-read-only bot removed the deps Approval required for changes to Envoy's external dependencies label Nov 12, 2020
@mathetake mathetake changed the title wasm: add wasmtime runtime wasm: Add Wasmtime as a new runtime Nov 12, 2020
@lizan lizan merged commit 3b4d165 into envoyproxy:master Nov 12, 2020
@mathetake mathetake deleted the wasmtime-runtime branch November 12, 2020 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants