]> granicus.if.org Git - gc/commitdiff
Eliminate TSan false positive for stop_info.stack_ptr (v2)
authorIvan Maidanski <ivmai@mail.ru>
Wed, 29 Nov 2017 08:46:05 +0000 (11:46 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 29 Nov 2017 12:52:14 +0000 (15:52 +0300)
Without this patch, Thread Sanitizer reports a data race between
GC_has_other_debug_info() and the code which sets stop_info.stack_ptr.

* include/private/pthread_support.h [THREAD_SANITIZER]: Include
dbg_mlc.h file.
* include/private/pthread_support.h [THREAD_SANITIZER] (GC_Thread_Rep):
Add dummy field (as the first field of the structure).
* pthread_support.c [THREAD_SANITIZER && CPPCHECK] (GC_new_thread):
Call GC_noop1(first_thread.dummy[0]) (to suppress cppcheck warning
about unused field).

include/private/pthread_support.h
pthread_support.c

index 233b59d7b5db032c8d6536953c1ca7c79d8d613c..12c3f1af1a58d343d2bcedfcd5c47d1eb7247494 100644 (file)
 # include "thread_local_alloc.h"
 #endif
 
+#ifdef THREAD_SANITIZER
+# include "dbg_mlc.h" /* for oh type */
+#endif
+
 /* We use the allocation lock to protect thread-related data structures. */
 
 /* The set of all known threads.  We intercept thread creation and      */
 /* Some of this should be declared volatile, but that's inconsistent    */
 /* with some library routine declarations.                              */
 typedef struct GC_Thread_Rep {
+#   ifdef THREAD_SANITIZER
+      char dummy[sizeof(oh)];     /* A dummy field to avoid TSan false  */
+                                  /* positive about the race between    */
+                                  /* GC_has_other_debug_info and        */
+                                  /* GC_suspend_handler_inner (which    */
+                                  /* sets store_stop.stack_ptr).        */
+#   endif
+
     struct GC_Thread_Rep * next;  /* More recently allocated threads    */
                                   /* with a given pthread id come       */
                                   /* first.  (All but the first are     */
index 2d68293e99a3cba9ba252c391c651345447eff10..b6489fc17ab7034a5237a1dbbcb9ed3a32fa768b 100644 (file)
@@ -548,6 +548,9 @@ STATIC GC_thread GC_new_thread(pthread_t id)
     if (!EXPECT(first_thread_used, TRUE)) {
         result = &first_thread;
         first_thread_used = TRUE;
+#       if defined(THREAD_SANITIZER) && defined(CPPCHECK)
+          GC_noop1(result->dummy[0]);
+#       endif
     } else {
         result = (struct GC_Thread_Rep *)
                  GC_INTERNAL_MALLOC(sizeof(struct GC_Thread_Rep), NORMAL);