ThreadSanitizer: add suppressions

Add a file .tsan-suppressions and list two functions in it: want_color() and transfer_debug(). Both of these use the pattern static int foo = -1; if (foo < 0) foo = bar(); where bar always returns the same non-negative value. This can cause ThreadSanitizer to diagnose a race when foo is written from two threads. That is indeed a race, although it arguably doesn't matter in practice since it's always the same value that is written. Add NEEDSWORK-comments to the functions so that this problem is not forever swept way under the carpet. The suppressions-file is used by setting the environment variable TSAN_OPTIONS to, e.g., "suppressions=$(pwd)/.tsan-suppressions". Observe that relative paths such as ".tsan-suppressions" might not work. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Ågren committed Aug 21, 2017 at 19:43 UTC 6cdf8a7929688ea5702ab53f450d038e973e64e1
3 files changed +24
.tsan-suppressions new
+10
@@ -0,0 +1,10 @@
1 +# Suppressions for ThreadSanitizer (tsan).
2 +#
3 +# This file is used by setting the environment variable TSAN_OPTIONS to, e.g.,
4 +# "suppressions=$(pwd)/.tsan-suppressions". Observe that relative paths such as
5 +# ".tsan-suppressions" might not work.
6 +
7 +# A static variable is written to racily, but we always write the same value, so
8 +# in practice it (hopefully!) doesn't matter.
9 +race:^want_color$
10 +race:^transfer_debug$
color.c
+7
@@ -338,6 +338,13 @@ static int check_auto_color(void)
338
339 int want_color(int var)
340 {
341 + /*
342 + * NEEDSWORK: This function is sometimes used from multiple threads, and
343 + * we end up using want_auto racily. That "should not matter" since
344 + * we always write the same value, but it's still wrong. This function
345 + * is listed in .tsan-suppressions for the time being.
346 + */
347 +
348 static int want_auto = -1;
349
350 if (var < 0)
transport-helper.c
+7
@@ -1117,6 +1117,13 @@ int transport_helper_init(struct transport *transport, const char *name)
1117 __attribute__((format (printf, 1, 2)))
1118 static void transfer_debug(const char *fmt, ...)
1119 {
1120 + /*
1121 + * NEEDSWORK: This function is sometimes used from multiple threads, and
1122 + * we end up using debug_enabled racily. That "should not matter" since
1123 + * we always write the same value, but it's still wrong. This function
1124 + * is listed in .tsan-suppressions for the time being.
1125 + */
1126 +
1127 va_list args;
1128 char msgbuf[PBUFFERSIZE];
1129 static int debug_enabled = -1;