[all-commits] [llvm/llvm-project] 5f149e: compiler-rt: allow golang race detector to run on ...

Dmitry Vyukov via All-commits all-commits at lists.llvm.org
Wed Mar 25 09:05:55 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 5f149ef51fcf08d52dd0977d54e7b3e4f15bede7
      https://github.com/llvm/llvm-project/commit/5f149ef51fcf08d52dd0977d54e7b3e4f15bede7
  Author: Dmitry Vyukov <dvyukov at google.com>
  Date:   2020-03-25 (Wed, 25 Mar 2020)

  Changed paths:
    M compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp
    M compiler-rt/lib/sanitizer_common/sanitizer_common.cpp
    M compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
    M compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
    M compiler-rt/lib/tsan/go/buildgo.sh

  Log Message:
  -----------
  compiler-rt: allow golang race detector to run on musl-c

tsan while used by golang's race detector was not working on alpine
linux, since it is using musl-c instead of glibc. Since alpine is very
popular distribution for container deployments, having working race
detector would be nice. This commits adds some ifdefs to get it working.

It fixes https://github.com/golang/go/issues/14481 on golang's issue tracker.

Reviewed-in: https://reviews.llvm.org/D75849
Author: graywolf-at-work (Tomas Volf)


  Commit: d8a0f76de7bd98dc7a271bc15b39a4cdbfdf6ecb
      https://github.com/llvm/llvm-project/commit/d8a0f76de7bd98dc7a271bc15b39a4cdbfdf6ecb
  Author: Dmitry Vyukov <dvyukov at google.com>
  Date:   2020-03-25 (Wed, 25 Mar 2020)

  Changed paths:
    M compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
    M compiler-rt/lib/tsan/rtl/tsan_platform.h
    M compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
    M compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp
    M compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
    A compiler-rt/test/tsan/fiber_cleanup.cpp

  Log Message:
  -----------
  tsan: fix leak of ThreadSignalContext for fibers

When creating and destroying fibers in tsan a thread state
is created and destroyed. Currently, a memory mapping is
leaked with each fiber (in __tsan_destroy_fiber).
This causes applications with many short running fibers
to crash or hang because of linux vm.max_map_count.

The root of this is that ThreadState holds a pointer to
ThreadSignalContext for handling signals. The initialization
and destruction of it is tied to platform specific events
in tsan_interceptors_posix and missed when destroying a fiber
(specifically, SigCtx is used to lazily create the
ThreadSignalContext in tsan_interceptors_posix). This patch
cleans up the memory by inverting the control from the
platform specific code calling the generic ThreadFinish to
ThreadFinish calling a platform specific clean-up routine
after finishing a thread.

The relevant code causing the leak with fibers is the fiber destruction:

void FiberDestroy(ThreadState *thr, uptr pc, ThreadState *fiber) {
  FiberSwitchImpl(thr, fiber);
  ThreadFinish(fiber);
  FiberSwitchImpl(fiber, thr);
  internal_free(fiber);
}

I would appreciate feedback if this way of fixing the leak is ok.
Also, I think it would be worthwhile to more closely look at the
lifecycle of ThreadState (i.e. it uses no constructor/destructor,
thus requiring manual callbacks for cleanup) and how OS-Threads/user
level fibers are differentiated in the codebase. I would be happy to
contribute more if someone could point me at the right place to
discuss this issue.

Reviewed-in: https://reviews.llvm.org/D76073
Author: Florian (Florian)


Compare: https://github.com/llvm/llvm-project/compare/c72675394a85...d8a0f76de7bd


More information about the All-commits mailing list