]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
helgrind reports false races for printfs using mempcpy on FILE* state
authorMark Wielaard <mark@klomp.org>
Fri, 8 Apr 2022 12:58:38 +0000 (14:58 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 8 Apr 2022 12:58:38 +0000 (14:58 +0200)
We already have a suppression for helgrind which is for when glibc
uses __GI_mempcpy to manipulate internal FILE state (this was bug
352130). But since glibc-2.26 mempcpy is used instead __GI_mempcpy,
making the suppresion from the original bug obsolete.

This patch adds a new suppression using mempcpy but doesn't replace
the original suppression for older systems.

Patch adding suppression + testcase by Jesus Checa <jcheca@redhat.com>

https://bugs.kde.org/show_bug.cgi?id=450962

.gitignore
glibc-2.X-helgrind.supp.in
helgrind/tests/Makefile.am
helgrind/tests/pth_mempcpy_false_races.c [new file with mode: 0644]
helgrind/tests/pth_mempcpy_false_races.stderr.exp [new file with mode: 0644]
helgrind/tests/pth_mempcpy_false_races.vgtest [new file with mode: 0644]

index 5026fcbc788b4ea3405ee08bab9be02c622589d0..94ff17d299507f00f40fe46b87fee86c66efe907 100644 (file)
 /helgrind/tests/Makefile.in
 /helgrind/tests/pth_barrier
 /helgrind/tests/pth_destroy_cond
+/helgrind/tests/pth_mempcpy_false_races
 /helgrind/tests/rwlock_race
 /helgrind/tests/rwlock_test
 /helgrind/tests/shmem_abits
index cecf3ceab9c1060607aa5ec1921107b653443240..8e1a10fa550153a6a1961c860c0f48ecfb7046ae 100644 (file)
    obj:@GLIBC_LIBC_PATH@
 }
 
+{
+   helgrind-glibc-io-xsputn-mempcpy-glibc2-26+
+   Helgrind:Race
+   fun:mempcpy
+   fun:_IO_*xsputn*
+   obj:@GLIBC_LIBC_PATH@
+}
+
 {
    helgrind-glibc2X-005
    Helgrind:Race
index cf7f76d46af2cddec3fe0270b617d0915505fa56..05e145f7b858cb513e46926ea3de2508dc404291 100755 (executable)
@@ -58,6 +58,7 @@ EXTRA_DIST = \
                pth_cond_destroy_busy.stderr.exp-ppc64 \
                pth_cond_destroy_busy.stderr.exp-solaris \
                pth_cond_destroy_busy.stderr.exp-freebsd \
+       pth_mempcpy_false_races.vgtest pth_mempcpy_false_races.stderr.exp \
        pth_spinlock.vgtest pth_spinlock.stdout.exp pth_spinlock.stderr.exp \
        rwlock_race.vgtest rwlock_race.stdout.exp rwlock_race.stderr.exp \
        rwlock_test.vgtest rwlock_test.stdout.exp rwlock_test.stderr.exp \
@@ -152,6 +153,7 @@ check_PROGRAMS = \
        locked_vs_unlocked2 \
        locked_vs_unlocked3 \
        pth_destroy_cond \
+       pth_mempcpy_false_races \
        shmem_abits \
        stackteardown \
        t2t \
diff --git a/helgrind/tests/pth_mempcpy_false_races.c b/helgrind/tests/pth_mempcpy_false_races.c
new file mode 100644 (file)
index 0000000..9071643
--- /dev/null
@@ -0,0 +1,50 @@
+/* Related bugs:
+ *   https://bugs.kde.org/show_bug.cgi?id=352130
+ *   https://bugs.kde.org/show_bug.cgi?id=450962
+ * This reproducer has no real race conditions but since helgrind doesn't see
+ * or know about the glibc internal locking done for FILE *state, it will report
+ * a race when several threads run printf due to this fact.
+ */
+
+#include <stdio.h>
+#include <pthread.h>
+
+pthread_t thread;
+
+void* thread3 (void* d)
+{
+  int count3 = 0;
+
+  while(count3 < 100){
+    printf("Thread 3: %d\n", count3++);
+  }
+  return NULL;
+}
+
+void* thread2 (void* d)
+{
+  int count2 = 0;
+
+  while(count2 < 1000){
+         //
+    printf("Thread 2: %d\n", count2++);
+  }
+  return NULL;
+}
+
+int main (){
+
+  pthread_create (&thread, NULL, thread2, NULL);
+  pthread_create (&thread, NULL, thread3, NULL);
+
+  //Thread 1
+  int count1 = 0;
+
+  while(count1 < 10){
+    printf("Thread 1: %d\n", count1++);
+  }
+
+  pthread_join(thread,NULL);
+  return 0;
+}
+
diff --git a/helgrind/tests/pth_mempcpy_false_races.stderr.exp b/helgrind/tests/pth_mempcpy_false_races.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/helgrind/tests/pth_mempcpy_false_races.vgtest b/helgrind/tests/pth_mempcpy_false_races.vgtest
new file mode 100644 (file)
index 0000000..9e3c6d4
--- /dev/null
@@ -0,0 +1,3 @@
+prog: pth_mempcpy_false_races
+vgopts: -q
+stdout_filter: ../../gdbserver_tests/filter_make_empty