[profile] Don't crash when forking in several threads
authorCalixte Denizet <calixte.denizet@gmail.com>
Mon, 20 Apr 2020 08:50:30 +0000 (10:50 +0200)
committerCalixte Denizet <calixte.denizet@gmail.com>
Thu, 7 May 2020 12:13:11 +0000 (14:13 +0200)
commitbec223a9bc4eb9747993ee9a4c1aa135c32123e6
tree86c319b99d584b89307a3eab37302b05996f0b8a
parentddfe58822eca2ea9b279a01a512d49f736789fca
[profile] Don't crash when forking in several threads

Summary:
When forking in several threads, the counters were written out in using the same global static variables (see GCDAProfiling.c): that leads to crashes.
So when there is a fork, the counters are resetted in the child process and they will be dumped at exit using the interprocess file locking.
When there is an exec, the counters are written out and in case of failures they're resetted.

Reviewers: jfb, vsk, marco-c, serge-sans-paille

Reviewed By: marco-c, serge-sans-paille

Subscribers: llvm-commits, serge-sans-paille, dmajor, cfe-commits, hiraditya, dexonsmith, #sanitizers, marco-c, sylvestre.ledru

Tags: #sanitizers, #clang, #llvm

Differential Revision: https://reviews.llvm.org/D78477
clang/lib/Driver/ToolChains/Darwin.cpp
compiler-rt/lib/profile/GCDAProfiling.c
compiler-rt/test/profile/Inputs/instrprof-gcov-multithread_fork.cpp [new file with mode: 0644]
compiler-rt/test/profile/instrprof-gcov-multithread_fork.test [new file with mode: 0644]
llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp