[PATCH] Fix -static -lpthread
Jakub Jelinek
jakub@redhat.com
Tue Aug 14 04:03:00 GMT 2001
Hi!
Linking with -static -lpthread results in no thread-safety in libio, so e.g.
gcc -static linuxthreads/Examples/ex7.c -lpthread sometimes prints correct
21 lines, sometimes even 24. The problem is that as _IO_flockfile etc.
aren't referenced normally from programs, libpthread.a(lockfile.o) will not
be brought in and then when libio is seen in libc.a, _IO_flockfile will be
satisfied by libc.a(lockfile.o), ie. dummy stubs from
sysdeps/generic/lockfile.c.
2001-08-14 Jakub Jelinek <jakub@redhat.com>
* lockfile.c (__pthread_provide_lockfile): New.
* pthread.c (__pthread_require_lockfile): New.
* cancel.c (__pthread_require_lockfile): New.
--- libc/linuxthreads/pthread.c.jj Wed Jul 18 13:51:58 2001
+++ libc/linuxthreads/pthread.c Tue Aug 14 06:21:18 2001
@@ -1158,9 +1158,12 @@ void __pthread_message(char * fmt, ...)
#ifndef SHARED
-/* We need a hook to force the cancelation wrappers to be linked in when
- static libpthread is used. */
+/* We need a hook to force the cancelation wrappers and file locking
+ to be linked in when static libpthread is used. */
extern const int __pthread_provide_wrappers;
static const int *const __pthread_require_wrappers =
&__pthread_provide_wrappers;
+extern const int __pthread_provide_lockfile;
+static const int *const __pthread_require_lockfile =
+ &__pthread_provide_lockfile;
#endif
--- libc/linuxthreads/lockfile.c.jj Mon Jan 8 13:42:30 2001
+++ libc/linuxthreads/lockfile.c Tue Aug 14 06:23:28 2001
@@ -26,6 +26,12 @@
#include "../libio/libioP.h"
#endif
+#ifndef SHARED
+/* We need a hook to force this file to be linked in when static
+ libpthread is used. */
+const int __pthread_provide_lockfile = 0;
+#endif
+
void
__flockfile (FILE *stream)
{
--- libc/linuxthreads/cancel.c.jj Mon Jun 25 08:04:11 2001
+++ libc/linuxthreads/cancel.c Tue Aug 14 06:21:49 2001
@@ -207,9 +207,12 @@ void __pthread_perform_cleanup(char *cur
}
#ifndef SHARED
-/* We need a hook to force the cancelation wrappers to be linked in when
- static libpthread is used. */
+/* We need a hook to force the cancelation wrappers and file locking
+ to be linked in when static libpthread is used. */
extern const int __pthread_provide_wrappers;
-static const int * const __pthread_require_wrappers =
+static const int *const __pthread_require_wrappers =
&__pthread_provide_wrappers;
+extern const int __pthread_provide_lockfile;
+static const int *const __pthread_require_lockfile =
+ &__pthread_provide_lockfile;
#endif
Jakub
More information about the Libc-hacker
mailing list