Bug 1532502 - Update ASan thread unpoisoning patch to latest upstream version r=froydnj
☠☠ backed out by fc3a2f173e66 ☠ ☠
authorDavid Major <dmajor@mozilla.com>
Thu, 07 Mar 2019 16:04:17 +0000
changeset 524263 5bc7479ef4a1d60e014bfe4759374d2d00e53ffb
parent 524262 654492de5212c9ee50796d77c62287b0db26424d
child 524264 e0c39e6d8d2c77b51118d388515c37628277f2a6
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1532502
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1532502 - Update ASan thread unpoisoning patch to latest upstream version r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D22325
build/build-clang/clang-win64.json
build/build-clang/r354836-unpoison-thread-stacks-callback.patch
build/build-clang/unpoison-thread-stacks.patch
--- a/build/build-clang/clang-win64.json
+++ b/build/build-clang/clang-win64.json
@@ -10,13 +10,13 @@
     "compiler_repo": "https://llvm.org/svn/llvm-project/compiler-rt/tags/RELEASE_800/rc3",
     "libcxx_repo": "https://llvm.org/svn/llvm-project/libcxx/tags/RELEASE_800/rc3",
     "python_path": "c:/mozilla-build/python/python.exe",
     "cc": "cl.exe",
     "cxx": "cl.exe",
     "ml": "ml64.exe",
     "patches": [
       "workaround-issue38586.patch",
-      "unpoison-thread-stacks.patch",
+      "r354836-unpoison-thread-stacks-callback.patch",
       "downgrade-mangling-error.patch",
       "loosen-msvc-detection.patch"
     ]
 }
new file mode 100644
--- /dev/null
+++ b/build/build-clang/r354836-unpoison-thread-stacks-callback.patch
@@ -0,0 +1,34 @@
+[winasan] Unpoison stack memory when threads exit (redux)
+
+This is a second attempt at r342652 using a TLS callback instead of an
+interceptor.
+
+In long-running builds we've seen some ASan complaints during thread creation
+that we suspect are due to leftover poisoning from previous threads whose
+stacks occupied that memory. This patch adds a callback that unpoisons the
+stack memory when a thread exits.
+
+Differential Revision: https://reviews.llvm.org/D58641
+
+--- a/compiler-rt/lib/asan/asan_win.cc
++++ b/compiler-rt/lib/asan/asan_win.cc
+@@ -354,6 +354,19 @@
+     unsigned long, void *) = asan_thread_init;
+ #endif
+ 
++static void NTAPI asan_thread_exit(void *module, DWORD reason, void *reserved) {
++  if (reason == DLL_THREAD_DETACH) {
++    // Unpoison the thread's stack because the memory may be re-used.
++    NT_TIB *tib = (NT_TIB *)NtCurrentTeb();
++    uptr stackSize = (uptr)tib->StackBase - (uptr)tib->StackLimit;
++    __asan_unpoison_memory_region(tib->StackLimit, stackSize);
++  }
++}
++
++#pragma section(".CRT$XLY", long, read)  // NOLINT
++__declspec(allocate(".CRT$XLY")) void (NTAPI *__asan_tls_exit)(void *,
++    unsigned long, void *) = asan_thread_exit;
++
+ WIN_FORCE_LINK(__asan_dso_reg_hook)
+ 
+ // }}}
deleted file mode 100644
--- a/build/build-clang/unpoison-thread-stacks.patch
+++ /dev/null
@@ -1,34 +0,0 @@
-[winasan] Unpoison the stack in NtTerminateThread
-
-In long-running builds we've seen some ASan complaints during thread creation that we suspect are due to leftover poisoning from previous threads whose stacks occupied that memory. This patch adds a hook that unpoisons the stack just before the NtTerminateThread syscall.
-
-Differential Revision: https://reviews.llvm.org/D52091
-
---- a/compiler-rt/lib/asan/asan_win.cc	(revision 342651)
-+++ b/compiler-rt/lib/asan/asan_win.cc	(revision 342652)
-@@ -154,6 +154,14 @@
-                             asan_thread_start, t, thr_flags, tid);
- }
- 
-+INTERCEPTOR_WINAPI(void, NtTerminateThread, void *rcx) {
-+  // Unpoison the terminating thread's stack because the memory may be re-used.
-+  NT_TIB *tib = (NT_TIB *)NtCurrentTeb();
-+  uptr stackSize = (uptr)tib->StackBase - (uptr)tib->StackLimit;
-+  __asan_unpoison_memory_region(tib->StackLimit, stackSize);
-+  return REAL(NtTerminateThread(rcx));
-+}
-+
- // }}}
- 
- namespace __asan {
-@@ -169,7 +177,9 @@
- 
-   ASAN_INTERCEPT_FUNC(CreateThread);
-   ASAN_INTERCEPT_FUNC(SetUnhandledExceptionFilter);
--
-+  CHECK(::__interception::OverrideFunction("NtTerminateThread",
-+                                           (uptr)WRAP(NtTerminateThread),
-+                                           (uptr *)&REAL(NtTerminateThread)));
- #ifdef _WIN64
-   ASAN_INTERCEPT_FUNC(__C_specific_handler);
- #else