Bug 1602482 - Remove use of ___custom_llvm_gcov_flush r=marco,dmajor

Because of conflicts between gcov_flush from gcc and the one from llvm, we renamed llvm one into ___custom_llvm_gcov_flush.
Since we switched to clang for linux ccov builds, this workaround is now useless.

Differential Revision: https://phabricator.services.mozilla.com/D104990
This commit is contained in:
Calixte Denizet 2021-02-12 20:37:25 +00:00
Родитель 5f86b697af
Коммит a0b66fc1c7
13 изменённых файлов: 0 добавлений и 225 удалений

Просмотреть файл

@ -14,8 +14,6 @@
"patches": [
"static-llvm-symbolizer.patch",
"find_symbolizer_linux_clang_10.patch",
"rename_gcov_flush_clang_10.patch",
"critical_section_on_gcov_flush-rG02ce9d8ef5a8.patch",
"rG7e18aeba5062_clang_10.patch",
"llvmorg-11-init-4265-g2dcbdba8540_clang_10.patch",
"android-mangling-error.patch",

Просмотреть файл

@ -49,7 +49,6 @@
"patches": [
"static-llvm-symbolizer.patch",
"find_symbolizer_linux_clang_10.patch",
"rename_gcov_flush_clang_11.patch",
"revert-r362047-and-r362065.patch"
]
}

Просмотреть файл

@ -14,7 +14,6 @@
"patches": [
"static-llvm-symbolizer.patch",
"find_symbolizer_linux_clang_10.patch",
"rename_gcov_flush_clang_11.patch",
"android-mangling-error.patch",
"unpoison-thread-stacks_clang_10.patch",
"downgrade-mangling-error.patch",

Просмотреть файл

@ -15,7 +15,6 @@
"ld": "{MOZ_FETCHES_DIR}/clang/bin/clang",
"patches": [
"static-llvm-symbolizer.patch",
"rename_gcov_flush_clang_11.patch",
"compiler-rt-cross-compile.patch",
"compiler-rt-no-codesign.patch"
]

Просмотреть файл

@ -11,8 +11,6 @@
"patches": [
"static-llvm-symbolizer.patch",
"find_symbolizer_linux.patch",
"rename_gcov_flush_7.patch",
"critical_section_on_gcov_flush-rG02ce9d8ef5a8.patch",
"r350774.patch",
"android-mangling-error.patch"
]

Просмотреть файл

@ -14,8 +14,6 @@
"patches": [
"static-llvm-symbolizer.patch",
"find_symbolizer_linux.patch",
"rename_gcov_flush.patch",
"critical_section_on_gcov_flush-rG02ce9d8ef5a8.patch",
"rG7e18aeba5062.patch",
"llvmorg-11-init-4265-g2dcbdba8540.patch",
"android-mangling-error.patch",

Просмотреть файл

@ -1,75 +0,0 @@
From 02ce9d8ef5a84bc884de4105eae5f8736ef67634 Mon Sep 17 00:00:00 2001
From: Calixte Denizet <calixte.denizet@gmail.com>
Date: Tue, 10 Dec 2019 13:22:33 +0100
Subject: [PATCH] [compiler-rt] Add a critical section when flushing gcov
counters
Summary:
Counters can be flushed in a multi-threaded context for example when the process is forked in different threads (https://github.com/llvm/llvm-project/blob/master/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp#L632-L663).
In order to avoid pretty bad things, a critical section is needed around the flush.
We had a lot of crashes in this code in Firefox CI when we switched to clang for linux ccov builds and those crashes disappeared with this patch.
Reviewers: marco-c, froydnj, dmajor, davidxl, vsk
Reviewed By: marco-c, dmajor
Subscribers: ahatanak, froydnj, dmajor, dberris, jfb, #sanitizers, llvm-commits, sylvestre.ledru
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D70910
---
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c
index b7257db10e7..d4abc4181ed 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -62,8 +62,27 @@ typedef unsigned long long uint64_t;
#include "InstrProfiling.h"
#include "InstrProfilingUtil.h"
-/* #define DEBUG_GCDAPROFILING */
+#ifndef _WIN32
+#include <pthread.h>
+static pthread_mutex_t gcov_flush_mutex = PTHREAD_MUTEX_INITIALIZER;
+static __inline void gcov_flush_lock() {
+ pthread_mutex_lock(&gcov_flush_mutex);
+}
+static __inline void gcov_flush_unlock() {
+ pthread_mutex_unlock(&gcov_flush_mutex);
+}
+#else
+#include <windows.h>
+static SRWLOCK gcov_flush_mutex = SRWLOCK_INIT;
+static __inline void gcov_flush_lock() {
+ AcquireSRWLockExclusive(&gcov_flush_mutex);
+}
+static __inline void gcov_flush_unlock() {
+ ReleaseSRWLockExclusive(&gcov_flush_mutex);
+}
+#endif
+/* #define DEBUG_GCDAPROFILING */
/*
* --- GCOV file format I/O primitives ---
*/
@@ -620,12 +639,16 @@ void llvm_register_flush_function(fn_ptr fn) {
}
void __custom_llvm_gcov_flush() {
+ gcov_flush_lock();
+
struct fn_node* curr = flush_fn_list.head;
while (curr) {
curr->fn();
curr = curr->next;
}
+
+ gcov_flush_unlock();
}
COMPILER_RT_VISIBILITY
--
2.24.0

Просмотреть файл

@ -1,40 +0,0 @@
Index: compiler-rt/lib/profile/GCDAProfiling.c
===================================================================
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -619,7 +619,7 @@
fn_list_insert(&flush_fn_list, fn);
}
-void __gcov_flush() {
+void __custom_llvm_gcov_flush() {
struct fn_node* curr = flush_fn_list.head;
while (curr) {
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index 9af64ed332c..bcebe303ff4 100644
--- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -647,7 +647,7 @@
for (auto I : ForkAndExecs) {
IRBuilder<> Builder(I);
FunctionType *FTy = FunctionType::get(Builder.getVoidTy(), {}, false);
- FunctionCallee GCOVFlush = M->getOrInsertFunction("__gcov_flush", FTy);
+ FunctionCallee GCOVFlush = M->getOrInsertFunction("__custom_llvm_gcov_flush", FTy);
Builder.CreateCall(GCOVFlush);
I->getParent()->splitBasicBlock(I);
}
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index e113f9a679..b3a07b18c0 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1122,7 +1122,7 @@
// runtime's functionality.
if (hasExportSymbolDirective(Args)) {
if (needsGCovInstrumentation(Args)) {
- addExportedSymbol(CmdArgs, "___gcov_flush");
+ addExportedSymbol(CmdArgs, "___custom_llvm_gcov_flush");
addExportedSymbol(CmdArgs, "_flush_fn_list");
addExportedSymbol(CmdArgs, "_writeout_fn_list");
} else {

Просмотреть файл

@ -1,14 +0,0 @@
Index: compiler-rt/lib/profile/GCDAProfiling.c
===================================================================
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c
--- a/compiler-rt/lib/profile/GCDAProfiling.c (revisione 336380)
+++ b/compiler-rt/lib/profile/GCDAProfiling.c (copia locale)
@@ -555,7 +555,7 @@
fn_list_insert(&flush_fn_list, fn);
}
-void __gcov_flush() {
+void __custom_llvm_gcov_flush() {
struct fn_node* curr = flush_fn_list.head;
while (curr) {

Просмотреть файл

@ -1,42 +0,0 @@
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 220bc8f9835..4f7ce485777 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1143,7 +1143,7 @@ void Darwin::addProfileRTLibs(const ArgList &Args,
// runtime's functionality.
if (hasExportSymbolDirective(Args)) {
if (ForGCOV) {
- addExportedSymbol(CmdArgs, "___gcov_flush");
+ addExportedSymbol(CmdArgs, "___custom_llvm_gcov_flush");
addExportedSymbol(CmdArgs, "_flush_fn_list");
addExportedSymbol(CmdArgs, "_writeout_fn_list");
} else {
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c
index 498c05900bf..b7257db10e7 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -619,7 +619,7 @@ void llvm_register_flush_function(fn_ptr fn) {
fn_list_insert(&flush_fn_list, fn);
}
-void __gcov_flush() {
+void __custom_llvm_gcov_flush() {
struct fn_node* curr = flush_fn_list.head;
while (curr) {
diff --git a/compiler-rt/test/tsan/pthread_atfork_deadlock2.c b/compiler-rt/test/tsan/pthread_atfork_deadlock2.c
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index bf3e4ed3e31..37bdcfaeab8 100644
--- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -656,7 +656,7 @@ void GCOVProfiler::AddFlushBeforeForkAndExec() {
for (auto I : ForkAndExecs) {
IRBuilder<> Builder(I);
FunctionType *FTy = FunctionType::get(Builder.getVoidTy(), {}, false);
- FunctionCallee GCOVFlush = M->getOrInsertFunction("__gcov_flush", FTy);
+ FunctionCallee GCOVFlush = M->getOrInsertFunction("__custom_llvm_gcov_flush", FTy);
Builder.CreateCall(GCOVFlush);
I->getParent()->splitBasicBlock(I);
}

Просмотреть файл

@ -1,26 +0,0 @@
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 7b879f8cb65..3810a2ceec2 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1196,7 +1196,7 @@ void Darwin::addProfileRTLibs(const ArgList &Args,
// runtime's functionality.
if (hasExportSymbolDirective(Args)) {
if (ForGCOV) {
- addExportedSymbol(CmdArgs, "___gcov_flush");
+ addExportedSymbol(CmdArgs, "___custom_llvm_gcov_flush");
addExportedSymbol(CmdArgs, "_flush_fn_list");
addExportedSymbol(CmdArgs, "_writeout_fn_list");
addExportedSymbol(CmdArgs, "_reset_fn_list");
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c
index 57d8dec423c..2edfb6e19e9 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -644,7 +644,7 @@ void llvm_register_flush_function(fn_ptr fn) {
fn_list_insert(&flush_fn_list, fn);
}
-void __gcov_flush() {
+void __custom_llvm_gcov_flush() {
struct fn_node* curr = flush_fn_list.head;
while (curr) {

Просмотреть файл

@ -18,10 +18,8 @@ linux64-aarch64-compiler-rt-11:
arguments:
- aarch64-unknown-linux-gnu
- 'build/build-clang/find_symbolizer_linux_clang_10.patch'
- 'build/build-clang/rename_gcov_flush_clang_11.patch'
resources:
- 'build/build-clang/find_symbolizer_linux_clang_10.patch'
- 'build/build-clang/rename_gcov_flush_clang_11.patch'
toolchain-artifact: public/build/compiler-rt.tar.zst
fetches:
fetch:
@ -40,9 +38,6 @@ macosx64-x64-compiler-rt-11:
script: build-compiler-rt.sh
arguments:
- x86_64-apple-darwin
- 'build/build-clang/rename_gcov_flush_clang_11.patch'
resources:
- 'build/build-clang/rename_gcov_flush_clang_11.patch'
toolchain-artifact: public/build/compiler-rt.tar.zst
fetches:
fetch:
@ -61,9 +56,6 @@ macosx64-aarch64-compiler-rt-11:
script: build-compiler-rt.sh
arguments:
- aarch64-apple-darwin
- 'build/build-clang/rename_gcov_flush_clang_11.patch'
resources:
- 'build/build-clang/rename_gcov_flush_clang_11.patch'
toolchain-artifact: public/build/compiler-rt.tar.zst
fetches:
fetch:

Просмотреть файл

@ -31,17 +31,6 @@ using namespace mozilla;
// __gcov_flush is protected by a mutex in GCC, but not in LLVM, so we are using
// a CrossProcessMutex to protect it.
// We rename __gcov_flush to __custom_llvm_gcov_flush in our build of LLVM for
// Linux, to avoid naming clashes in builds which mix GCC and LLVM. So, when we
// are building with LLVM exclusively, we need to use __custom_llvm_gcov_flush
// instead.
#if !defined(XP_WIN) && defined(__clang__)
# define __gcov_flush __custom_llvm_gcov_flush
// In clang 12, __gcov_flush was split into __gcov_dump and __gcov_reset.
# define __gcov_dump __custom_llvm_gcov_dump
# define __gcov_reset __custom_llvm_gcov_reset
#endif
extern "C" void __gcov_flush();
extern "C" void __gcov_dump();
extern "C" void __gcov_reset();