Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
ddfe588
commit bec223a
Showing
5 changed files
with
204 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
compiler-rt/test/profile/Inputs/instrprof-gcov-multithread_fork.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <sys/types.h> | ||
#include <thread> | ||
#include <unistd.h> | ||
#include <vector> | ||
|
||
template <typename T> | ||
void launcher(T func) { | ||
std::vector<std::thread> pool; | ||
|
||
for (int i = 0; i < 10; i++) { | ||
pool.emplace_back(std::thread(func)); | ||
} | ||
|
||
for (auto &t : pool) { | ||
t.join(); | ||
} | ||
} | ||
|
||
void h() {} | ||
|
||
void g() { | ||
fork(); | ||
launcher<>(h); | ||
} | ||
|
||
void f() { | ||
fork(); | ||
launcher<>(g); | ||
} | ||
|
||
int main() { | ||
launcher<>(f); | ||
|
||
return 0; | ||
} |
11 changes: 11 additions & 0 deletions
11
compiler-rt/test/profile/instrprof-gcov-multithread_fork.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
UNSUPPORTED: windows | ||
|
||
RUN: mkdir -p %t.d | ||
RUN: cd %t.d | ||
|
||
RUN: %clangxx --coverage -lpthread -o %t %S/Inputs/instrprof-gcov-multithread_fork.cpp | ||
RUN: test -f instrprof-gcov-multithread_fork.gcno | ||
|
||
RUN: rm -f instrprof-gcov-multithread_fork.gcda | ||
RUN: %run %t | ||
RUN: llvm-cov gcov instrprof-gcov-multithread_fork.gcda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters