summaryrefslogtreecommitdiff
path: root/src/buildtool/main/main.cpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-05-12 13:14:26 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-05-15 12:09:53 +0200
commit09402100946e6892ebd1e75773eb390cdd7f28ab (patch)
tree62b162afe521174372b4c00088e91ffe86b055e9 /src/buildtool/main/main.cpp
parentdbb20365198bd171aec9035c9108b310c5f0d82d (diff)
downloadjustbuild-09402100946e6892ebd1e75773eb390cdd7f28ab.tar.gz
memcheck: fix race in libgit2...
...caused by incorrectly setting and resetting the library internal state and the misuse of pthreads in libgit2. Normally, git_libgit2_init and git_libgit2_shutdown should span the life of a worker thread in order to be safely used. However, due to an incorrect implementation of libgit2's threadstate with pthreads, on unix systems there is a race condition. Until the use of pthread_key_t is corrected in libgit2, we need to apply a workaround by always ensuring that the main thread is the first thread reaching the GitContext constructor.
Diffstat (limited to 'src/buildtool/main/main.cpp')
-rw-r--r--src/buildtool/main/main.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 81a932a1..79c7c0cb 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -1264,7 +1264,16 @@ auto main(int argc, char* argv[]) -> int {
Evaluator::SetExpressionLogLimit(
*arguments.analysis.expression_log_limit);
}
+
#ifndef BOOTSTRAP_BUILD_TOOL
+ /**
+ * The current implementation of libgit2 uses pthread_key_t incorrectly
+ * on POSIX systems to handle thread-specific data, which requires us to
+ * explicitly make sure the main thread is the first one to call
+ * git_libgit2_init. Future versions of libgit2 will hopefully fix this.
+ */
+ GitContext::Create();
+
SetupHashFunction();
SetupExecutionConfig(
arguments.endpoint, arguments.build, arguments.rebuild);