tech-toolchain archive

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

Fix -static with -lpthread



Hi all,
attached is a patch to fix PR 37454 (segmentation fault when using
libpthread in static linked programs). I can't find a cleaner way to
force initfini.o to pulled in. The approach of the patch is to reference
it from exit.o as crt0.o calls exit and there by pulls in exit.o.

Joerg
Index: misc/initfini.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/lib/libc/misc/initfini.c,v
retrieving revision 1.5
diff -u -p -r1.5 initfini.c
--- misc/initfini.c     28 Apr 2008 20:23:00 -0000      1.5
+++ misc/initfini.c     25 Jun 2010 13:37:30 -0000
@@ -36,7 +36,7 @@ __RCSID("$NetBSD: initfini.c,v 1.5 2008/
 #include "namespace.h"
 #endif
 
-static void    __libc_init(void) __attribute__((__constructor__, __used__));
+void   __libc_init(void) __attribute__((__constructor__, __used__));
 
 void   __guard_setup(void);
 void   __libc_thr_init(void);
@@ -44,7 +44,7 @@ void  __libc_atomic_init(void);
 void   __libc_atexit_init(void);
 
 /* LINTED used */
-static void
+void
 __libc_init(void)
 {
 
Index: stdlib/exit.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/lib/libc/stdlib/exit.c,v
retrieving revision 1.11
diff -u -p -r1.11 exit.c
--- stdlib/exit.c       30 Oct 2007 17:19:59 -0000      1.11
+++ stdlib/exit.c       25 Jun 2010 20:09:50 -0000
@@ -45,14 +45,18 @@ __RCSID("$NetBSD: exit.c,v 1.11 2007/10/
 #include "atexit.h"
 #endif
 
+extern void __libc_init(void);
+#ifndef __lint
+static void (*force_ref)(void) __used = __libc_init;
+#endif
+
 void (*__cleanup) __P((void));
 
 /*
  * Exit, flushing stdio buffers if necessary.
  */
 void
-exit(status)
-       int status;
+exit(int status)
 {
 
 #ifdef _LIBC


Home | Main Index | Thread Index | Old Index