[PATCH] D74071: [Profile] Avoid deadlock in multithreaded context when forking with coverage enabled

calixte via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 5 09:55:53 PST 2020


calixte created this revision.
calixte added a reviewer: marco-c.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits, jfb, hiraditya.
Herald added projects: clang, Sanitizers, LLVM.

When a program is forked with code coverage enabled, all the counters are flushed.
To avoid data race, a critical section has been added around `__gcov_flush` (https://reviews.llvm.org/D70910) but when forking the mutex is just duplicated and if it was in a locked state (in the parent process) then it's locked in the child process which leads to a deadlock when the child is trying to flush counters.
This patch aims to initialize the mutex in the child process when forking.
So a custom fork (`__gcov_fork`) is called from instrumented code and the mutex is then initialized in the child process.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74071

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  compiler-rt/lib/profile/GCDAProfiling.c
  llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74071.242671.patch
Type: text/x-patch
Size: 4008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200205/9d376de7/attachment-0001.bin>


More information about the cfe-commits mailing list