Commit 896b1db493245f5ecbbb328b4d1485e44d4a1e27

lhchavez 2020-08-03T07:17:52

Add a ThreadSanitizer build This change adds a ThreadSanitizer CI build rule. It's informative for now because there are still known places where there are races. Part of: #5592

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 29507c8..9c16127 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -109,6 +109,18 @@ jobs:
             SKIP_NEGOTIATE_TESTS: true
             ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10
           os: ubuntu-latest
+        - # Focal, Clang 10, OpenSSL, ThreadSanitizer
+          image: focal
+          env:
+            CC: clang-10
+            CFLAGS: -fsanitize=thread -fno-optimize-sibling-calls -fno-omit-frame-pointer
+            CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON
+            CMAKE_GENERATOR: Ninja
+            SKIP_SSH_TESTS: true
+            SKIP_NEGOTIATE_TESTS: true
+            ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10
+            TSAN_OPTIONS: suppressions=/home/libgit2/source/script/thread-sanitizer.supp second_deadlock_stack=1
+          os: ubuntu-latest
         - # macOS
           os: macos-10.15
           env:
@@ -197,6 +209,7 @@ jobs:
               -e PKG_CONFIG_PATH \
               -e SKIP_NEGOTIATE_TESTS \
               -e SKIP_SSH_TESTS \
+              -e TSAN_OPTIONS \
               ${{ env.docker-registry-container-sha }} \
               /bin/bash -c "mkdir build && cd build && ../azure-pipelines/build.sh && ../azure-pipelines/test.sh"
         else
diff --git a/script/thread-sanitizer.supp b/script/thread-sanitizer.supp
new file mode 100644
index 0000000..757a0e7
--- /dev/null
+++ b/script/thread-sanitizer.supp
@@ -0,0 +1,18 @@
+# In attr_file_free, the locks are acquired in the opposite order in which they
+# are normally acquired. This is probably something worth fixing to have a
+# consistent lock hierarchy that is easy to understand.
+deadlock:attr_cache_lock
+
+# When invoking the time/timezone functions from git_signature_now(), they
+# access libc methods that need to be instrumented to correctly analyze the
+# data races.
+called_from_lib:libc.so.6
+
+# TODO(#5595): Remove these once the fixes land.
+race:src/odb.c
+race:git_repository_odb__weakptr
+race:cache_store
+
+# TODO(#5595): Investigate and fix this. It can be triggered by the `thread`
+# test suite.
+race:git_filter_list__load_ext