[all-commits] [llvm/llvm-project] e33446: tsan: make obtaining current PC faster

Dmitry Vyukov via All-commits all-commits at lists.llvm.org
Thu Jul 15 08:34:15 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e33446ea58b8357dd8b79eb39140a1de2baff1ae
      https://github.com/llvm/llvm-project/commit/e33446ea58b8357dd8b79eb39140a1de2baff1ae
  Author: Dmitry Vyukov <dvyukov at google.com>
  Date:   2021-07-15 (Thu, 15 Jul 2021)

  Changed paths:
    M compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp
    M compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
    M compiler-rt/lib/tsan/rtl/tsan_interceptors.h
    M compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp

  Log Message:
  -----------
  tsan: make obtaining current PC faster

We obtain the current PC is all interceptors and collectively
common interceptor code contributes to overall slowdown
(in particular cheaper str/mem* functions).

The current way to obtain the current PC involves:

  4493e1:       e8 3a f3 fe ff          callq  438720 <_ZN11__sanitizer10StackTrace12GetCurrentPcEv>
  4493e9:       48 89 c6                mov    %rax,%rsi

and the called function is:

uptr StackTrace::GetCurrentPc() {
  438720:       48 8b 04 24             mov    (%rsp),%rax
  438724:       c3                      retq

The new way uses address of a local label and involves just:

  44a888:       48 8d 35 fa ff ff ff    lea    -0x6(%rip),%rsi

I am not switching all uses of StackTrace::GetCurrentPc to GET_CURRENT_PC
because it may lead some differences in produced reports and break tests.
The difference comes from the fact that currently we have PC pointing
to the CALL instruction, but the new way does not yield any code on its own
so the PC points to a random instruction in the function and symbolizing
that instruction can produce additional inlined frames (if the random
instruction happen to relate to some inlined function).

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D106046




More information about the All-commits mailing list