diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h @@ -76,6 +76,7 @@ } static uptr GetCurrentPc(); + static uptr GetCurrentPcFast(); static inline uptr GetPreviousInstructionPc(uptr pc); static uptr GetNextInstructionPc(uptr pc); }; @@ -139,6 +140,12 @@ #endif } +ALWAYS_INLINE +uptr StackTrace::GetCurrentPcFast() { +here: + return GetNextInstructionPc((uptr) && here); +} + // StackTrace that owns the buffer used to store the addresses. struct BufferedStackTrace : public StackTrace { uptr trace_buffer[kStackTraceMax]; @@ -229,10 +236,4 @@ uptr local_stack; \ uptr sp = (uptr)&local_stack -#define GET_CURRENT_PC() \ - ({ \ - this_pc: \ - StackTrace::GetNextInstructionPc((uptr) && this_pc); \ - }) - #endif // SANITIZER_STACKTRACE_H diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp @@ -265,6 +265,7 @@ stack.Unwind(pc, bp, nullptr, false, /*max_depth=*/0); EXPECT_EQ(0U, stack.size); EXPECT_EQ(0U, stack.top_frame_bp); + pc = StackTrace::GetCurrentPcFast(); stack.Unwind(pc, bp, nullptr, false, /*max_depth=*/1); EXPECT_EQ(1U, stack.size); EXPECT_EQ(pc, stack.trace[0]); diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.h b/compiler-rt/lib/tsan/rtl/tsan_interceptors.h --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.h +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.h @@ -30,13 +30,13 @@ } // namespace __tsan -#define SCOPED_INTERCEPTOR_RAW(func, ...) \ - cur_thread_init(); \ - ThreadState *thr = cur_thread(); \ - const uptr caller_pc = GET_CALLER_PC(); \ - ScopedInterceptor si(thr, #func, caller_pc); \ - const uptr pc = GET_CURRENT_PC(); \ - (void)pc; \ +#define SCOPED_INTERCEPTOR_RAW(func, ...) \ + cur_thread_init(); \ + ThreadState *thr = cur_thread(); \ + const uptr caller_pc = GET_CALLER_PC(); \ + ScopedInterceptor si(thr, #func, caller_pc); \ + const uptr pc = StackTrace::GetCurrentPcFast(); \ + (void)pc; \ /**/ #define SCOPED_TSAN_INTERCEPTOR(func, ...) \ diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp @@ -2157,7 +2157,7 @@ if (in_symbolizer()) return; ThreadState *thr = cur_thread(); - const uptr pc = GET_CURRENT_PC(); + const uptr pc = StackTrace::GetCurrentPcFast(); ForkBefore(thr, pc); } @@ -2165,7 +2165,7 @@ if (in_symbolizer()) return; ThreadState *thr = cur_thread(); - const uptr pc = GET_CURRENT_PC(); + const uptr pc = StackTrace::GetCurrentPcFast(); ForkParentAfter(thr, pc); } @@ -2173,7 +2173,7 @@ if (in_symbolizer()) return; ThreadState *thr = cur_thread(); - const uptr pc = GET_CURRENT_PC(); + const uptr pc = StackTrace::GetCurrentPcFast(); ForkChildAfter(thr, pc); FdOnFork(thr, pc); }