[PATCH] D70910: [compiler-rt] Add a critical section when flushing gcov counters

calixte via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 10 01:29:03 PST 2019


calixte added a comment.

@ahatanak it's probably a problem with Darwin.cpp where I need to add some exported symbols.
@jfb sorry but it fixes issues with fork:

- we had a lot of crashes in Firefox CI when dumping the GCDAs and so I tried this patch on the CI and no more weird crashes.
- and a minimal test case to reproduce it:

  #include <iostream>
  #include <thread>
  #include <vector>
  #include <unistd.h>
  
  void foo()
  {
      fork();
  }
  
  int main()  
  {
      std::vector<std::thread> pool;
  
      for (int i = 0; i < 10; i++) {
           pool.emplace_back(std::thread(foo));
      }
  
      for (auto & t : pool) {
          t.join();
      }
      
      return 0;
  }

If I compile and run it (`clang++-9 -std=c++11 foo.cpp -oo -lpthread --coverage && ./o`) I get systematically a SEGFAULT and with the patch no more crashes.
The problem is not with `flush_fn_list` itself but it's when the functions in the list (gcda dumper) are called concurrently.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70910/new/

https://reviews.llvm.org/D70910





More information about the llvm-commits mailing list