tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pthread_getspecific without prior pthread_setspecific



Trying to trace down lots of failures of mips N32 userland running on a N64
kernel, I found that many calls to pthread_getspecific() happen without
any prior pthread_setspecific().

So I added an assertion and found this firing on lots of programs,
two simple examples:

	/usr/tests/libexec/ld.elf_so/h_df_1_noopen2
or
	gdb

This is the patch I used:

Index: pthread_specific.c
===================================================================
RCS file: /cvsroot/src/lib/libpthread/pthread_specific.c,v
retrieving revision 1.26
diff -u -r1.26 pthread_specific.c
--- pthread_specific.c	21 Mar 2013 16:49:12 -0000	1.26
+++ pthread_specific.c	17 May 2015 15:13:30 -0000
@@ -75,6 +75,8 @@
 	if (__predict_false(__uselibcstub))
 		return __libc_thr_getspecific_stub(key);
 
+	pthread__assert(pthread__self()->pt_havespecific);
+
 	return pthread__self()->pt_specific[key].pts_value;
 }
 


Now a simple fix is below, but I am not sure it is not just papering
over something else (binutils bug? libpthread bug?)

With this patch my N32 userland is pretty happy, and sparc userland on
sparc64 gets a bit further.

Index: pthread_specific.c
===================================================================
RCS file: /cvsroot/src/lib/libpthread/pthread_specific.c,v
retrieving revision 1.26
diff -u -r1.26 pthread_specific.c
--- pthread_specific.c	21 Mar 2013 16:49:12 -0000	1.26
+++ pthread_specific.c	17 May 2015 15:16:48 -0000
@@ -75,6 +75,9 @@
 	if (__predict_false(__uselibcstub))
 		return __libc_thr_getspecific_stub(key);
 
+	if (!pthread__self()->pt_havespecific)
+		return NULL;
+
 	return pthread__self()->pt_specific[key].pts_value;
 }
 

Should I commit the second, or is someone fixing the underlying issue
and we'll commit the first?

Martin


Home | Main Index | Thread Index | Old Index