summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Lettner <jlettner@apple.com>2019-07-09 18:42:01 +0000
committerJulian Lettner <jlettner@apple.com>2019-07-09 18:42:01 +0000
commit95176d72c7e8846e1382323b5e180f3f3d835b42 (patch)
tree4d163c622cf301d4739fc162efb756b121e4e455
parent20ecec6116b367cbf9fe2ed978656ed117665bf9 (diff)
downloadbcm5719-llvm-95176d72c7e8846e1382323b5e180f3f3d835b42.tar.gz
bcm5719-llvm-95176d72c7e8846e1382323b5e180f3f3d835b42.zip
Revert "[TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.8"
This reverts commit 521f77e6351fd921f5a81027c7c72addca378989. llvm-svn: 365534
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc50
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc11
2 files changed, 10 insertions, 51 deletions
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
index 1373037ed4a..71f6f4872a3 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
@@ -68,17 +68,12 @@ void *__libc_stack_end = 0;
#endif
#if SANITIZER_LINUX && defined(__aarch64__)
-__tsan::uptr InitializeGuardPtr() __attribute__((visibility("hidden")));
+void InitializeGuardPtr() __attribute__((visibility("hidden")));
extern "C" __tsan::uptr _tsan_pointer_chk_guard;
#endif
namespace __tsan {
-#if SANITIZER_LINUX && defined(__aarch64__)
-static void InitializeLongjmpXorKey();
-static uptr longjmp_xor_key;
-#endif
-
#ifdef TSAN_RUNTIME_VMA
// Runtime detected VMA size.
uptr vmaSize;
@@ -290,25 +285,7 @@ void InitializePlatform() {
reexec = true;
}
// Initialize the guard pointer used in {sig}{set,long}jump.
- longjmp_xor_key = InitializeGuardPtr();
- uptr old_value = longjmp_xor_key;
- InitializeLongjmpXorKey();
- CHECK_EQ(longjmp_xor_key, old_value);
- // If the above check fails for you, please contact me (jlettner@apple.com)
- // and let me know the values of the two differing keys. Please also set a
- // breakpoint on `InitializeGuardPtr` and `InitializeLongjmpXorKey` and tell
- // me the stack pointer (SP) values that go into the XOR operation (where we
- // derive the key):
- //
- // InitializeLongjmpXorKey:
- // uptr sp = (uptr)__builtin_frame_address(0);
- //
- // InitializeGuardPtr (in tsan_rtl_aarch64.S):
- // mov x0, sp
- // ...
- // eor x0, x0, x1
- //
- // Then feel free to comment out the call to `InitializeLongjmpXorKey`.
+ InitializeGuardPtr();
#endif
if (reexec)
ReExec();
@@ -376,7 +353,9 @@ static uptr UnmangleLongJmpSp(uptr mangled_sp) {
# endif
#elif defined(__aarch64__)
# if SANITIZER_LINUX
- return mangled_sp ^ longjmp_xor_key;
+ // TODO(yln): fix this
+ // return mangled_sp ^ _tsan_pointer_chk_guard;
+ return mangled_sp;
# else
return mangled_sp;
# endif
@@ -415,25 +394,6 @@ uptr ExtractLongJmpSp(uptr *env) {
return UnmangleLongJmpSp(mangled_sp);
}
-#if SANITIZER_LINUX && defined(__aarch64__)
-// GLIBC mangles the function pointers in jmp_buf (used in {set,long}*jmp
-// functions) by XORing them with a random key. For AArch64 it is a global
-// variable rather than a TCB one (as for x86_64/powerpc). We obtain the key by
-// issuing a setjmp and XORing the SP pointer values to derive the key.
-static void InitializeLongjmpXorKey() {
- // 1. Call REAL(setjmp), which stores the mangled SP in env.
- jump_buf env;
- REAL(setjmp)(env);
-
- // 2. Retrieve mangled/vanilla SP.
- uptr mangled_sp = ((uptr *)&env)[LONG_JMP_SP_ENV_SLOT];
- uptr sp = (uptr)__builtin_frame_address(0);
-
- // 3. xor SPs to obtain key.
- longjmp_xor_key = mangled_sp ^ sp;
-}
-#endif
-
void ImitateTlsWrite(ThreadState *thr, uptr tls_addr, uptr tls_size) {
// Check that the thr object is in tls;
const uptr thr_beg = (uptr)thr;
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc b/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc
index 0c2d2aa9338..e43a9ec34a8 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc
@@ -238,7 +238,8 @@ void InitializePlatformEarly() {
#endif
}
-static uptr longjmp_xor_key = 0;
+static const uptr kPthreadSetjmpXorKeySlot = 0x7;
+extern "C" uptr __tsan_darwin_setjmp_xor_key = 0;
void InitializePlatform() {
DisableCoreDumperIfNecessary();
@@ -253,9 +254,8 @@ void InitializePlatform() {
#endif
if (GetMacosVersion() >= MACOS_VERSION_MOJAVE) {
- // Libsystem currently uses a process-global key; this might change.
- const unsigned kTLSLongjmpXorKeySlot = 0x7;
- longjmp_xor_key = (uptr)pthread_getspecific(kTLSLongjmpXorKeySlot);
+ __tsan_darwin_setjmp_xor_key =
+ (uptr)pthread_getspecific(kPthreadSetjmpXorKeySlot);
}
}
@@ -268,8 +268,7 @@ void InitializePlatform() {
uptr ExtractLongJmpSp(uptr *env) {
uptr mangled_sp = env[LONG_JMP_SP_ENV_SLOT];
- uptr sp = mangled_sp ^ longjmp_xor_key;
- return sp;
+ return mangled_sp ^ __tsan_darwin_setjmp_xor_key;
}
#if !SANITIZER_GO
OpenPOWER on IntegriCloud