Commit 3363adbe authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

cppgc: TSAN support for stack scanning

We cannot rely on the clang compiler to generate the trampoline entry
and the right mangling because `__attribute__((naked))` does not
prevent clang from generating TSAN function entry stub
(`__tsan_func_entry`). Even with `__attribute__((no_sanitize_thread)`
annotation clang generates the entry stub.

Upstream bug: https://bugs.llvm.org/show_bug.cgi?id=45400

Bug: chromium:1056170
Change-Id: I7a2063d7d205ee071e6a41ce4d9cb2d8d6423987
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2132797Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarAnton Bikineev <bikineev@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66976}
parent 1e132398
...@@ -5,12 +5,13 @@ ...@@ -5,12 +5,13 @@
// Push all callee-saved registers to get them on the stack for conservative // Push all callee-saved registers to get them on the stack for conservative
// stack scanning. // stack scanning.
// //
// Do not add any C code to the function. The function is naked to avoid // We cannot rely on clang generating the function and right symbol mangling
// emitting a prologue/epilogue that could violate alginment computations. // as `__attribite__((naked))` does not prevent clang from generating TSAN
extern "C" __attribute__((naked, noinline)) void // function entry stubs (`__tsan_func_entry`). Even with
PushAllRegistersAndIterateStack(void* /* {Stack*} */, // `__attribute__((no_sanitize_thread)` annotation clang generates the entry
void* /* {StackVisitor*} */, // stub.
void* /* {IterateStackCallback} */) { // See https://bugs.llvm.org/show_bug.cgi?id=45400.
// Do not depend on V8_TARGET_OS_* defines as some embedders may override the // Do not depend on V8_TARGET_OS_* defines as some embedders may override the
// GN toolchain (e.g. ChromeOS) and not provide them. // GN toolchain (e.g. ChromeOS) and not provide them.
// _WIN64 Defined as 1 when the compilation target is 64-bit ARM or x64. // _WIN64 Defined as 1 when the compilation target is 64-bit ARM or x64.
...@@ -21,7 +22,8 @@ PushAllRegistersAndIterateStack(void* /* {Stack*} */, ...@@ -21,7 +22,8 @@ PushAllRegistersAndIterateStack(void* /* {Stack*} */,
// on the stack and we push 72 bytes which maintains 16-byte stack alignment // on the stack and we push 72 bytes which maintains 16-byte stack alignment
// at the call. // at the call.
// Source: https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention // Source: https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention
asm volatile( asm(".globl PushAllRegistersAndIterateStack \n"
"PushAllRegistersAndIterateStack: \n"
// rbp is callee-saved. Maintain proper frame pointer for debugging. // rbp is callee-saved. Maintain proper frame pointer for debugging.
" push %rbp \n" " push %rbp \n"
" mov %rsp, %rbp \n" " mov %rsp, %rbp \n"
...@@ -54,7 +56,16 @@ PushAllRegistersAndIterateStack(void* /* {Stack*} */, ...@@ -54,7 +56,16 @@ PushAllRegistersAndIterateStack(void* /* {Stack*} */,
// on the stack and we push 56 bytes which maintains 16-byte stack alignment // on the stack and we push 56 bytes which maintains 16-byte stack alignment
// at the call. // at the call.
// Source: https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf // Source: https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf
asm volatile( asm(
#ifdef __APPLE__
".globl _PushAllRegistersAndIterateStack \n"
".private_extern _PushAllRegistersAndIterateStack \n"
"_PushAllRegistersAndIterateStack: \n"
#else // !__APPLE__
".globl PushAllRegistersAndIterateStack \n"
".hidden PushAllRegistersAndIterateStack \n"
"PushAllRegistersAndIterateStack: \n"
#endif // !__APPLE__
// rbp is callee-saved. Maintain proper frame pointer for debugging. // rbp is callee-saved. Maintain proper frame pointer for debugging.
" push %rbp \n" " push %rbp \n"
" mov %rsp, %rbp \n" " mov %rsp, %rbp \n"
...@@ -80,4 +91,3 @@ PushAllRegistersAndIterateStack(void* /* {Stack*} */, ...@@ -80,4 +91,3 @@ PushAllRegistersAndIterateStack(void* /* {Stack*} */,
" ret \n"); " ret \n");
#endif // !_WIN64 #endif // !_WIN64
}
...@@ -47,7 +47,6 @@ TEST_F(GCStackTest, IsOnStackForHeapValue) { ...@@ -47,7 +47,6 @@ TEST_F(GCStackTest, IsOnStackForHeapValue) {
} }
#ifdef CPPGC_SUPPORTS_CONSERVATIVE_STACK_SCAN #ifdef CPPGC_SUPPORTS_CONSERVATIVE_STACK_SCAN
#ifndef THREAD_SANITIZER
namespace { namespace {
...@@ -357,7 +356,6 @@ TEST_F(GCStackTest, StackAlignment) { ...@@ -357,7 +356,6 @@ TEST_F(GCStackTest, StackAlignment) {
#endif // V8_OS_LINUX && (V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64) #endif // V8_OS_LINUX && (V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64)
#endif // CPPGC_SUPPORTS_CONSERVATIVE_STACK_SCAN #endif // CPPGC_SUPPORTS_CONSERVATIVE_STACK_SCAN
#endif // !THREAD_SANITIZER
} // namespace internal } // namespace internal
} // namespace cppgc } // namespace cppgc
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