From c54a744cff8917f50a698212cba5a0bfeac1e31d Mon Sep 17 00:00:00 2001 From: Andreea Pavel Date: Sat, 9 Mar 2019 22:34:50 +0200 Subject: [PATCH] Backed out changeset 5bc7479ef4a1 (bug 1532502) for very frequent win asan failures with exit code 1 --HG-- extra : rebase_source : 636c7036385ef42ec755c78d86eb34799d2e0bcb extra : amend_source : ec830eafb0ef96dad8229f078ce27166ab9ef876 --- build/build-clang/clang-win64.json | 2 +- ...4836-unpoison-thread-stacks-callback.patch | 34 ------------------- .../build-clang/unpoison-thread-stacks.patch | 34 +++++++++++++++++++ 3 files changed, 35 insertions(+), 35 deletions(-) delete mode 100644 build/build-clang/r354836-unpoison-thread-stacks-callback.patch create mode 100644 build/build-clang/unpoison-thread-stacks.patch diff --git a/build/build-clang/clang-win64.json b/build/build-clang/clang-win64.json index a7184099959c..039c58a75296 100644 --- a/build/build-clang/clang-win64.json +++ b/build/build-clang/clang-win64.json @@ -15,7 +15,7 @@ "ml": "ml64.exe", "patches": [ "workaround-issue38586.patch", - "r354836-unpoison-thread-stacks-callback.patch", + "unpoison-thread-stacks.patch", "downgrade-mangling-error.patch", "loosen-msvc-detection.patch" ] diff --git a/build/build-clang/r354836-unpoison-thread-stacks-callback.patch b/build/build-clang/r354836-unpoison-thread-stacks-callback.patch deleted file mode 100644 index a874ea8a8f6b..000000000000 --- a/build/build-clang/r354836-unpoison-thread-stacks-callback.patch +++ /dev/null @@ -1,34 +0,0 @@ -[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) - - // }}} diff --git a/build/build-clang/unpoison-thread-stacks.patch b/build/build-clang/unpoison-thread-stacks.patch new file mode 100644 index 000000000000..375732b91d2f --- /dev/null +++ b/build/build-clang/unpoison-thread-stacks.patch @@ -0,0 +1,34 @@ +[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