Browse Source

nptl: fix dynamic initialization of libpthread

If libpthread get's pulled in via dlopen(), we need to do libpthread
initialization in dlopen(). Achieve this by making initializer function
out of __pthread_initialize_minimal_internal. Add the proper linker
flags and make it callable multiple times.

Add also nodelete flag which ensures that libpthread will not get
unmapped after it's been loading. Though, ld.so does not yet
support this.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
Timo Teräs 14 years ago
parent
commit
cfa1d49e87
2 changed files with 7 additions and 1 deletions
  1. 1 1
      libpthread/nptl/Makefile.in
  2. 6 0
      libpthread/nptl/init.c

+ 1 - 1
libpthread/nptl/Makefile.in

@@ -220,7 +220,7 @@ else
 LDFLAGS-libpthread.so := $(LDFLAGS)
 endif
 
-LDFLAGS-libpthread.so += $(top_builddir)lib/$(UCLIBC_LDSO_NAME)-$(VERSION).so $(top_builddir)lib/libdl-$(VERSION).so
+LDFLAGS-libpthread.so += $(top_builddir)lib/$(UCLIBC_LDSO_NAME)-$(VERSION).so $(top_builddir)lib/libdl-$(VERSION).so -Wl,-z,nodelete,-z,initfirst,-init=__pthread_initialize_minimal_internal
 
 LIBS-libpthread.so := $(LIBS)
 

+ 6 - 0
libpthread/nptl/init.c

@@ -260,6 +260,12 @@ static bool __nptl_initial_report_events __attribute_used__;
 void
 __pthread_initialize_minimal_internal (void)
 {
+  static int initialized = 0;
+
+  if (initialized)
+    return;
+  initialized = 1;
+
 #ifndef SHARED
   /* Unlike in the dynamically linked case the dynamic linker has not
      taken care of initializing the TLS data structures.  */