[compiler-rt] r340350 - [tsan] Adjust setjmp/longjmp handling on Darwin for macOS Mojave
Kuba Mracek via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 21 15:35:53 PDT 2018
Author: kuba.brecka
Date: Tue Aug 21 15:35:52 2018
New Revision: 340350
URL: http://llvm.org/viewvc/llvm-project?rev=340350&view=rev
Log:
[tsan] Adjust setjmp/longjmp handling on Darwin for macOS Mojave
On macOS Mojave, the OS started using the XOR-by-a-secret-key scheme (same as glibc is alread doing) for storing the SP value in setjmp environment. We need to adjust for that to keep supporting setjmp/longjmp on latest Darwin. The patch is basically doing the same what we're already doing for glibc.
rdar://problem/43542596
Differential Revision: https://reviews.llvm.org/D51064
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_aarch64.S
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_amd64.S
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=340350&r1=340349&r2=340350&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Tue Aug 21 15:35:52 2018
@@ -511,6 +511,10 @@ MacosVersion GetMacosVersionInternal() {
case '2': return MACOS_VERSION_MOUNTAIN_LION;
case '3': return MACOS_VERSION_MAVERICKS;
case '4': return MACOS_VERSION_YOSEMITE;
+ case '5': return MACOS_VERSION_EL_CAPITAN;
+ case '6': return MACOS_VERSION_SIERRA;
+ case '7': return MACOS_VERSION_HIGH_SIERRA;
+ case '8': return MACOS_VERSION_MOJAVE;
default:
if (IsDigit(version[1]))
return MACOS_VERSION_UNKNOWN_NEWER;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h?rev=340350&r1=340349&r2=340350&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.h Tue Aug 21 15:35:52 2018
@@ -40,6 +40,10 @@ enum MacosVersion {
MACOS_VERSION_MOUNTAIN_LION,
MACOS_VERSION_MAVERICKS,
MACOS_VERSION_YOSEMITE,
+ MACOS_VERSION_EL_CAPITAN,
+ MACOS_VERSION_SIERRA,
+ MACOS_VERSION_HIGH_SIERRA,
+ MACOS_VERSION_MOJAVE,
MACOS_VERSION_UNKNOWN_NEWER
};
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=340350&r1=340349&r2=340350&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Tue Aug 21 15:35:52 2018
@@ -508,7 +508,8 @@ static void LongJmp(ThreadState *thr, up
uptr mangled_sp = env[6];
#elif SANITIZER_MAC
# ifdef __aarch64__
- uptr mangled_sp = env[13];
+ uptr mangled_sp =
+ (GetMacosVersion() >= MACOS_VERSION_MOJAVE) ? env[12] : env[13];
# else
uptr mangled_sp = env[2];
# endif
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc?rev=340350&r1=340349&r2=340350&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc Tue Aug 21 15:35:52 2018
@@ -240,6 +240,9 @@ void InitializePlatformEarly() {
#endif
}
+static const uptr kPthreadSetjmpXorKeySlot = 0x7;
+extern "C" uptr __tsan_darwin_setjmp_xor_key = 0;
+
void InitializePlatform() {
DisableCoreDumperIfNecessary();
#if !SANITIZER_GO
@@ -251,6 +254,11 @@ void InitializePlatform() {
prev_pthread_introspection_hook =
pthread_introspection_hook_install(&my_pthread_introspection_hook);
#endif
+
+ if (GetMacosVersion() >= MACOS_VERSION_MOJAVE) {
+ __tsan_darwin_setjmp_xor_key =
+ (uptr)pthread_getspecific(kPthreadSetjmpXorKeySlot);
+ }
}
#if !SANITIZER_GO
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_aarch64.S
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_aarch64.S?rev=340350&r1=340349&r2=340350&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_aarch64.S (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_aarch64.S Tue Aug 21 15:35:52 2018
@@ -120,8 +120,10 @@ ASM_SYMBOL_INTERCEPTOR(setjmp):
add x0, x29, 32
eor x1, x2, x0
#else
+ adrp x2, ___tsan_darwin_setjmp_xor_key at page
+ ldr x2, [x2, ___tsan_darwin_setjmp_xor_key at pageoff]
add x0, x29, 32
- mov x1, x0
+ eor x1, x2, x0
#endif
// call tsan interceptor
@@ -178,8 +180,10 @@ ASM_SYMBOL_INTERCEPTOR(_setjmp):
add x0, x29, 32
eor x1, x2, x0
#else
+ adrp x2, ___tsan_darwin_setjmp_xor_key at page
+ ldr x2, [x2, ___tsan_darwin_setjmp_xor_key at pageoff]
add x0, x29, 32
- mov x1, x0
+ eor x1, x2, x0
#endif
// call tsan interceptor
@@ -238,8 +242,10 @@ ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
add x0, x29, 32
eor x1, x2, x0
#else
+ adrp x2, ___tsan_darwin_setjmp_xor_key at page
+ ldr x2, [x2, ___tsan_darwin_setjmp_xor_key at pageoff]
add x0, x29, 32
- mov x1, x0
+ eor x1, x2, x0
#endif
// call tsan interceptor
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_amd64.S
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_amd64.S?rev=340350&r1=340349&r2=340350&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_amd64.S (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_amd64.S Tue Aug 21 15:35:52 2018
@@ -196,6 +196,7 @@ ASM_SYMBOL_INTERCEPTOR(setjmp):
#elif defined(__APPLE__)
lea 16(%rsp), %rdi
mov %rdi, %rsi
+ xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
#elif defined(__linux__)
lea 16(%rsp), %rdi
mov %rdi, %rsi
@@ -244,6 +245,7 @@ ASM_SYMBOL_INTERCEPTOR(_setjmp):
#elif defined(__APPLE__)
lea 16(%rsp), %rdi
mov %rdi, %rsi
+ xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
#elif defined(__linux__)
lea 16(%rsp), %rdi
mov %rdi, %rsi
@@ -299,6 +301,7 @@ ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
#elif defined(__APPLE__)
lea 32(%rsp), %rdi
mov %rdi, %rsi
+ xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
#elif defined(__linux__)
lea 32(%rsp), %rdi
mov %rdi, %rsi
More information about the llvm-commits
mailing list