Commit 13209a75 authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

Reland "[no-wasm] Exclude trap-handler implementation"

This is a reland of 5d84b6cb. PS2 contains
the fix for a copy&paste error in a preprocessor condition.

Original change's description:
> [no-wasm] Exclude trap-handler implementation
>
> The trap handler is only needed for WebAssembly, hence it can be
> excluded in no-wasm builds (v8_enable_webassembly = false).
> This makes it easier to port WebAssembly to platforms that do not need
> to support WebAssembly.
>
> R=ahaas@chromium.org, jkummerow@chromium.org
> CC=johnx@google.com
>
> Bug: v8:11877
> Change-Id: I25c34c2c4f1122227047e13add532ee2b9f73d2f
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2953285
> Reviewed-by: Andreas Haas <ahaas@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Commit-Queue: Clemens Backes <clemensb@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#75101}

Bug: v8:11877
Change-Id: I70dba5dc8762c65a9c751ff6619a3b0ebb542837
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2960214Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75138}
parent 5913deec
...@@ -3103,8 +3103,6 @@ v8_header_set("v8_internal_headers") { ...@@ -3103,8 +3103,6 @@ v8_header_set("v8_internal_headers") {
"src/tracing/trace-event.h", "src/tracing/trace-event.h",
"src/tracing/traced-value.h", "src/tracing/traced-value.h",
"src/tracing/tracing-category-observer.h", "src/tracing/tracing-category-observer.h",
"src/trap-handler/trap-handler-internal.h",
"src/trap-handler/trap-handler.h",
"src/utils/address-map.h", "src/utils/address-map.h",
"src/utils/allocation.h", "src/utils/allocation.h",
"src/utils/bit-vector.h", "src/utils/bit-vector.h",
...@@ -3152,6 +3150,8 @@ v8_header_set("v8_internal_headers") { ...@@ -3152,6 +3150,8 @@ v8_header_set("v8_internal_headers") {
"src/compiler/wasm-compiler.h", "src/compiler/wasm-compiler.h",
"src/debug/debug-wasm-objects-inl.h", "src/debug/debug-wasm-objects-inl.h",
"src/debug/debug-wasm-objects.h", "src/debug/debug-wasm-objects.h",
"src/trap-handler/trap-handler-internal.h",
"src/trap-handler/trap-handler.h",
"src/wasm/baseline/liftoff-assembler-defs.h", "src/wasm/baseline/liftoff-assembler-defs.h",
"src/wasm/baseline/liftoff-assembler.h", "src/wasm/baseline/liftoff-assembler.h",
"src/wasm/baseline/liftoff-compiler.h", "src/wasm/baseline/liftoff-compiler.h",
...@@ -3294,16 +3294,19 @@ v8_header_set("v8_internal_headers") { ...@@ -3294,16 +3294,19 @@ v8_header_set("v8_internal_headers") {
"src/wasm/baseline/x64/liftoff-assembler-x64.h", "src/wasm/baseline/x64/liftoff-assembler-x64.h",
] ]
# iOS Xcode simulator builds run on an x64 target. iOS and macOS are both
# based on Darwin and thus POSIX-compliant to a similar degree.
if (is_linux || is_chromeos || is_mac || is_ios || target_os == "freebsd") {
sources += [ "src/trap-handler/handler-inside-posix.h" ]
}
if (is_win) { if (is_win) {
sources += [ sources += [ "src/diagnostics/unwinding-info-win64.h" ]
"src/diagnostics/unwinding-info-win64.h", }
"src/trap-handler/handler-inside-win.h",
] if (v8_enable_webassembly) {
# iOS Xcode simulator builds run on an x64 target. iOS and macOS are both
# based on Darwin and thus POSIX-compliant to a similar degree.
if (is_linux || is_chromeos || is_mac || is_ios ||
target_os == "freebsd") {
sources += [ "src/trap-handler/handler-inside-posix.h" ]
} else if (is_win) {
sources += [ "src/trap-handler/handler-inside-win.h" ]
}
} }
} else if (v8_current_cpu == "arm") { } else if (v8_current_cpu == "arm") {
sources += [ ### gcmole(arch:arm) ### sources += [ ### gcmole(arch:arm) ###
...@@ -3348,7 +3351,7 @@ v8_header_set("v8_internal_headers") { ...@@ -3348,7 +3351,7 @@ v8_header_set("v8_internal_headers") {
if (v8_control_flow_integrity) { if (v8_control_flow_integrity) {
sources += [ "src/execution/arm64/pointer-authentication-arm64.h" ] sources += [ "src/execution/arm64/pointer-authentication-arm64.h" ]
} }
if (current_cpu == "arm64" && is_mac) { if (v8_enable_webassembly && current_cpu == "arm64" && is_mac) {
sources += [ "src/trap-handler/handler-inside-posix.h" ] sources += [ "src/trap-handler/handler-inside-posix.h" ]
} }
if (is_win) { if (is_win) {
...@@ -4069,9 +4072,6 @@ v8_source_set("v8_base_without_compiler") { ...@@ -4069,9 +4072,6 @@ v8_source_set("v8_base_without_compiler") {
"src/tracing/trace-event.cc", "src/tracing/trace-event.cc",
"src/tracing/traced-value.cc", "src/tracing/traced-value.cc",
"src/tracing/tracing-category-observer.cc", "src/tracing/tracing-category-observer.cc",
"src/trap-handler/handler-inside.cc",
"src/trap-handler/handler-outside.cc",
"src/trap-handler/handler-shared.cc",
"src/utils/address-map.cc", "src/utils/address-map.cc",
"src/utils/allocation.cc", "src/utils/allocation.cc",
"src/utils/bit-vector.cc", "src/utils/bit-vector.cc",
...@@ -4098,6 +4098,9 @@ v8_source_set("v8_base_without_compiler") { ...@@ -4098,6 +4098,9 @@ v8_source_set("v8_base_without_compiler") {
"src/debug/debug-wasm-objects.cc", "src/debug/debug-wasm-objects.cc",
"src/runtime/runtime-test-wasm.cc", "src/runtime/runtime-test-wasm.cc",
"src/runtime/runtime-wasm.cc", "src/runtime/runtime-wasm.cc",
"src/trap-handler/handler-inside.cc",
"src/trap-handler/handler-outside.cc",
"src/trap-handler/handler-shared.cc",
"src/wasm/baseline/liftoff-assembler.cc", "src/wasm/baseline/liftoff-assembler.cc",
"src/wasm/baseline/liftoff-compiler.cc", "src/wasm/baseline/liftoff-compiler.cc",
"src/wasm/function-body-decoder.cc", "src/wasm/function-body-decoder.cc",
...@@ -4194,20 +4197,25 @@ v8_source_set("v8_base_without_compiler") { ...@@ -4194,20 +4197,25 @@ v8_source_set("v8_base_without_compiler") {
"src/regexp/x64/regexp-macro-assembler-x64.cc", "src/regexp/x64/regexp-macro-assembler-x64.cc",
] ]
# iOS Xcode simulator builds run on an x64 target. iOS and macOS are both
# based on Darwin and thus POSIX-compliant to a similar degree.
if (is_linux || is_chromeos || is_mac || is_ios || target_os == "freebsd") {
sources += [
"src/trap-handler/handler-inside-posix.cc",
"src/trap-handler/handler-outside-posix.cc",
]
}
if (is_win) { if (is_win) {
sources += [ sources += [ "src/diagnostics/unwinding-info-win64.cc" ]
"src/diagnostics/unwinding-info-win64.cc", }
"src/trap-handler/handler-inside-win.cc",
"src/trap-handler/handler-outside-win.cc", if (v8_enable_webassembly) {
] # iOS Xcode simulator builds run on an x64 target. iOS and macOS are both
# based on Darwin and thus POSIX-compliant to a similar degree.
if (is_linux || is_chromeos || is_mac || is_ios ||
target_os == "freebsd") {
sources += [
"src/trap-handler/handler-inside-posix.cc",
"src/trap-handler/handler-outside-posix.cc",
]
} else if (is_win) {
sources += [
"src/trap-handler/handler-inside-win.cc",
"src/trap-handler/handler-outside-win.cc",
]
}
} }
} else if (v8_current_cpu == "arm") { } else if (v8_current_cpu == "arm") {
sources += [ ### gcmole(arch:arm) ### sources += [ ### gcmole(arch:arm) ###
...@@ -4251,7 +4259,7 @@ v8_source_set("v8_base_without_compiler") { ...@@ -4251,7 +4259,7 @@ v8_source_set("v8_base_without_compiler") {
"src/execution/arm64/simulator-logic-arm64.cc", "src/execution/arm64/simulator-logic-arm64.cc",
"src/regexp/arm64/regexp-macro-assembler-arm64.cc", "src/regexp/arm64/regexp-macro-assembler-arm64.cc",
] ]
if (current_cpu == "arm64" && is_mac) { if (v8_enable_webassembly && current_cpu == "arm64" && is_mac) {
sources += [ sources += [
"src/trap-handler/handler-inside-posix.cc", "src/trap-handler/handler-inside-posix.cc",
"src/trap-handler/handler-outside-posix.cc", "src/trap-handler/handler-outside-posix.cc",
......
...@@ -109,11 +109,11 @@ ...@@ -109,11 +109,11 @@
#include "src/strings/string-hasher.h" #include "src/strings/string-hasher.h"
#include "src/strings/unicode-inl.h" #include "src/strings/unicode-inl.h"
#include "src/tracing/trace-event.h" #include "src/tracing/trace-event.h"
#include "src/trap-handler/trap-handler.h"
#include "src/utils/detachable-vector.h" #include "src/utils/detachable-vector.h"
#include "src/utils/version.h" #include "src/utils/version.h"
#if V8_ENABLE_WEBASSEMBLY #if V8_ENABLE_WEBASSEMBLY
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/streaming-decoder.h" #include "src/wasm/streaming-decoder.h"
#include "src/wasm/value-type.h" #include "src/wasm/value-type.h"
#include "src/wasm/wasm-engine.h" #include "src/wasm/wasm-engine.h"
...@@ -5862,8 +5862,9 @@ bool TryHandleWebAssemblyTrapPosix(int sig_code, siginfo_t* info, ...@@ -5862,8 +5862,9 @@ bool TryHandleWebAssemblyTrapPosix(int sig_code, siginfo_t* info,
// code rather than the wasm code, so the trap handler cannot find the landing // code rather than the wasm code, so the trap handler cannot find the landing
// pad and lets the process crash. Therefore, only enable trap handlers if // pad and lets the process crash. Therefore, only enable trap handlers if
// the host and target arch are the same. // the host and target arch are the same.
#if (V8_TARGET_ARCH_X64 && !V8_OS_ANDROID) || \ #if V8_ENABLE_WEBASSEMBLY && \
(V8_HOST_ARCH_ARM64 && V8_TARGET_ARCH_ARM64 && V8_OS_MACOSX) ((V8_TARGET_ARCH_X64 && !V8_OS_ANDROID) || \
(V8_HOST_ARCH_ARM64 && V8_TARGET_ARCH_ARM64 && V8_OS_MACOSX))
return i::trap_handler::TryHandleSignal(sig_code, info, context); return i::trap_handler::TryHandleSignal(sig_code, info, context);
#else #else
return false; return false;
...@@ -5878,15 +5879,20 @@ bool V8::TryHandleSignal(int signum, void* info, void* context) { ...@@ -5878,15 +5879,20 @@ bool V8::TryHandleSignal(int signum, void* info, void* context) {
#if V8_OS_WIN #if V8_OS_WIN
bool TryHandleWebAssemblyTrapWindows(EXCEPTION_POINTERS* exception) { bool TryHandleWebAssemblyTrapWindows(EXCEPTION_POINTERS* exception) {
#if V8_TARGET_ARCH_X64 #if V8_ENABLE_WEBASSEMBLY && V8_TARGET_ARCH_X64
return i::trap_handler::TryHandleWasmTrap(exception); return i::trap_handler::TryHandleWasmTrap(exception);
#endif #else
return false; return false;
#endif
} }
#endif #endif
bool V8::EnableWebAssemblyTrapHandler(bool use_v8_signal_handler) { bool V8::EnableWebAssemblyTrapHandler(bool use_v8_signal_handler) {
#if V8_ENABLE_WEBASSEMBLY
return v8::internal::trap_handler::EnableTrapHandler(use_v8_signal_handler); return v8::internal::trap_handler::EnableTrapHandler(use_v8_signal_handler);
#else
return false;
#endif
} }
#if defined(V8_OS_WIN) #if defined(V8_OS_WIN)
......
...@@ -92,7 +92,6 @@ ...@@ -92,7 +92,6 @@
#include "src/strings/string-stream.h" #include "src/strings/string-stream.h"
#include "src/tasks/cancelable-task.h" #include "src/tasks/cancelable-task.h"
#include "src/tracing/tracing-category-observer.h" #include "src/tracing/tracing-category-observer.h"
#include "src/trap-handler/trap-handler.h"
#include "src/utils/address-map.h" #include "src/utils/address-map.h"
#include "src/utils/ostreams.h" #include "src/utils/ostreams.h"
#include "src/utils/version.h" #include "src/utils/version.h"
...@@ -103,6 +102,7 @@ ...@@ -103,6 +102,7 @@
#endif // V8_INTL_SUPPORT #endif // V8_INTL_SUPPORT
#if V8_ENABLE_WEBASSEMBLY #if V8_ENABLE_WEBASSEMBLY
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/wasm-code-manager.h" #include "src/wasm/wasm-code-manager.h"
#include "src/wasm/wasm-engine.h" #include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
...@@ -1582,8 +1582,8 @@ Handle<JSMessageObject> Isolate::CreateMessageOrAbort( ...@@ -1582,8 +1582,8 @@ Handle<JSMessageObject> Isolate::CreateMessageOrAbort(
Object Isolate::ThrowInternal(Object raw_exception, MessageLocation* location) { Object Isolate::ThrowInternal(Object raw_exception, MessageLocation* location) {
DCHECK(!has_pending_exception()); DCHECK(!has_pending_exception());
DCHECK_IMPLIES(trap_handler::IsTrapHandlerEnabled(), IF_WASM(DCHECK_IMPLIES, trap_handler::IsTrapHandlerEnabled(),
!trap_handler::IsThreadInWasm()); !trap_handler::IsThreadInWasm());
HandleScope scope(this); HandleScope scope(this);
Handle<Object> exception(raw_exception, this); Handle<Object> exception(raw_exception, this);
...@@ -1678,6 +1678,7 @@ Object Isolate::ReThrow(Object exception) { ...@@ -1678,6 +1678,7 @@ Object Isolate::ReThrow(Object exception) {
} }
namespace { namespace {
#if V8_ENABLE_WEBASSEMBLY
// This scope will set the thread-in-wasm flag after the execution of all // This scope will set the thread-in-wasm flag after the execution of all
// destructors. The thread-in-wasm flag is only set when the scope gets enabled. // destructors. The thread-in-wasm flag is only set when the scope gets enabled.
class SetThreadInWasmFlagScope { class SetThreadInWasmFlagScope {
...@@ -1696,9 +1697,11 @@ class SetThreadInWasmFlagScope { ...@@ -1696,9 +1697,11 @@ class SetThreadInWasmFlagScope {
private: private:
bool enabled_ = false; bool enabled_ = false;
}; };
#endif // V8_ENABLE_WEBASSEMBLY
} // namespace } // namespace
Object Isolate::UnwindAndFindHandler() { Object Isolate::UnwindAndFindHandler() {
#if V8_ENABLE_WEBASSEMBLY
// Create the {SetThreadInWasmFlagScope} first in this function so that its // Create the {SetThreadInWasmFlagScope} first in this function so that its
// destructor gets called after all the other destructors. It is important // destructor gets called after all the other destructors. It is important
// that the destructor sets the thread-in-wasm flag after all other // that the destructor sets the thread-in-wasm flag after all other
...@@ -1706,6 +1709,7 @@ Object Isolate::UnwindAndFindHandler() { ...@@ -1706,6 +1709,7 @@ Object Isolate::UnwindAndFindHandler() {
// Windows, which would invalidate the thread-in-wasm flag when the wasm trap // Windows, which would invalidate the thread-in-wasm flag when the wasm trap
// handler handles such non-wasm exceptions. // handler handles such non-wasm exceptions.
SetThreadInWasmFlagScope set_thread_in_wasm_flag_scope; SetThreadInWasmFlagScope set_thread_in_wasm_flag_scope;
#endif // V8_ENABLE_WEBASSEMBLY
Object exception = pending_exception(); Object exception = pending_exception();
auto FoundHandler = [&](Context context, Address instruction_start, auto FoundHandler = [&](Context context, Address instruction_start,
......
...@@ -42,8 +42,10 @@ void ThreadLocalTop::Initialize(Isolate* isolate) { ...@@ -42,8 +42,10 @@ void ThreadLocalTop::Initialize(Isolate* isolate) {
Clear(); Clear();
isolate_ = isolate; isolate_ = isolate;
thread_id_ = ThreadId::Current(); thread_id_ = ThreadId::Current();
#if V8_ENABLE_WEBASSEMBLY
thread_in_wasm_flag_address_ = reinterpret_cast<Address>( thread_in_wasm_flag_address_ = reinterpret_cast<Address>(
trap_handler::GetThreadInWasmThreadLocalAddress()); trap_handler::GetThreadInWasmThreadLocalAddress());
#endif // V8_ENABLE_WEBASSEMBLY
#ifdef USE_SIMULATOR #ifdef USE_SIMULATOR
simulator_ = Simulator::current(isolate); simulator_ = Simulator::current(isolate);
#endif #endif
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
#include "src/execution/isolate.h" #include "src/execution/isolate.h"
#include "src/handles/global-handles.h" #include "src/handles/global-handles.h"
#include "src/logging/counters.h" #include "src/logging/counters.h"
#include "src/trap-handler/trap-handler.h"
#if V8_ENABLE_WEBASSEMBLY #if V8_ENABLE_WEBASSEMBLY
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/wasm-constants.h" #include "src/wasm/wasm-constants.h"
#include "src/wasm/wasm-engine.h" #include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-limits.h" #include "src/wasm/wasm-limits.h"
...@@ -349,7 +349,12 @@ std::unique_ptr<BackingStore> BackingStore::TryAllocateAndPartiallyCommitMemory( ...@@ -349,7 +349,12 @@ std::unique_ptr<BackingStore> BackingStore::TryAllocateAndPartiallyCommitMemory(
TRACE_BS("BSw:try %zu pages, %zu max\n", initial_pages, maximum_pages); TRACE_BS("BSw:try %zu pages, %zu max\n", initial_pages, maximum_pages);
#if V8_ENABLE_WEBASSEMBLY
bool guards = is_wasm_memory && trap_handler::IsTrapHandlerEnabled(); bool guards = is_wasm_memory && trap_handler::IsTrapHandlerEnabled();
#else
CHECK(!is_wasm_memory);
bool guards = false;
#endif // V8_ENABLE_WEBASSEMBLY
// For accounting purposes, whether a GC was necessary. // For accounting purposes, whether a GC was necessary.
bool did_retry = false; bool did_retry = false;
......
...@@ -341,12 +341,12 @@ int main(int argc, char* argv[]) { ...@@ -341,12 +341,12 @@ int main(int argc, char* argv[]) {
v8::V8::Initialize(); v8::V8::Initialize();
v8::V8::InitializeExternalStartupData(argv[0]); v8::V8::InitializeExternalStartupData(argv[0]);
#if V8_ENABLE_WEBASSEMBLY #if V8_ENABLE_WEBASSEMBLY && V8_TRAP_HANDLER_SUPPORTED
if (V8_TRAP_HANDLER_SUPPORTED && i::FLAG_wasm_trap_handler) { if (i::FLAG_wasm_trap_handler) {
constexpr bool use_default_signal_handler = true; constexpr bool use_default_signal_handler = true;
CHECK(v8::V8::EnableWebAssemblyTrapHandler(use_default_signal_handler)); CHECK(v8::V8::EnableWebAssemblyTrapHandler(use_default_signal_handler));
} }
#endif // V8_ENABLE_WEBASSEMBLY #endif // V8_TRAP_HANDLER_SUPPORTED && V8_ENABLE_WEBASSEMBLY
CcTest::set_array_buffer_allocator( CcTest::set_array_buffer_allocator(
v8::ArrayBuffer::Allocator::NewDefaultAllocator()); v8::ArrayBuffer::Allocator::NewDefaultAllocator());
......
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