diff mbox series

[committed] Fix argument to pthread_join

Message ID 3ce0ef8c-3a2d-65c8-081b-48a4150ffb06@tachyum.com
State New
Headers show
Series [committed] Fix argument to pthread_join | expand

Commit Message

Jeff Law July 27, 2021, 6:16 p.m. UTC
This showed up as a segfault running the gcov-threads-1.C test in qemu 
system mode on our internal port.

We're passing the address of an int to pthread_join.  That int object is 
only guaranteed 4 byte alignment.  Later when pthread_join wants to 
store a pointer into that location, we naturally fault due to 
misalignment.  This is also a stack overrun since the pointer is 64 
bits, but we've only got 32 bits of stack space allocated.

pthread_join really wants a pointer to a pointer.   So instead of 
passing &int_var, we can just pass &pointer_var.  That also avoids the 
silly cast.  We never use the value anyway, so we could just as easily 
pass NULL.

This may also be the root cause of the riscv64 gcov-threads-1 failure 
that you can find in the gcc-testresults archives.

Bootstrapped and tested on x86, also verified that gcov-threads-1.C now 
works with our internal port.

Committed to the trunk.

Jeff
commit 0853f392a213ef2cecc71ef5349aab079e30f5a0
Author: Jeff Law <jlaw@localhost.localdomain>
Date:   Tue Jul 27 14:14:05 2021 -0400

    Fix argument to pthread_join
    
    gcc/testsuite
            * g++.dg/gcov/gcov-threads-1.C: Fix argument to pthread_join.
diff mbox series

Patch

diff --git a/gcc/testsuite/g++.dg/gcov/gcov-threads-1.C b/gcc/testsuite/g++.dg/gcov/gcov-threads-1.C
index b020dd87d4c..3ae00789439 100644
--- a/gcc/testsuite/g++.dg/gcov/gcov-threads-1.C
+++ b/gcc/testsuite/g++.dg/gcov/gcov-threads-1.C
@@ -36,7 +36,7 @@  int main(int argc, char **argv) {
     assert (r == 0);				/* count(5*) */
   }
 
-  int ret;
+  void *ret;
   for (int i = 0; i < NR; i++)
     {
       int r = pthread_join (t[i], (void**)&ret);