about summary refs log tree commit diff
path: root/linuxthreads
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2002-11-15 03:37:24 +0000
committerRoland McGrath <roland@gnu.org>2002-11-15 03:37:24 +0000
commit53da80ab8870138b81b212c540c32b5c1eeccaf4 (patch)
tree99cc0b072130164fccc123c707675c82b8dd8224 /linuxthreads
parent3fa5f1fa0a4973c6915fbfe0a43cbbe57c9b8ca9 (diff)
downloadglibc-53da80ab8870138b81b212c540c32b5c1eeccaf4.tar.gz
glibc-53da80ab8870138b81b212c540c32b5c1eeccaf4.tar.xz
glibc-53da80ab8870138b81b212c540c32b5c1eeccaf4.zip
* sysdeps/generic/errno.c (__libc_errno): Remove alias.
	* inet/herrno.c (__libc_h_errno): Likewise.
	* resolv/res_libc.c (__libc_res): Likewise.
	[USE___THREAD]: Use this in place of [USE_TLS && HAVE___THREAD].
	(__res_state) [! USE___THREAD]: Don't define as weak.
	* csu/Versions: Revert last change.
	* resolv/Versions: Revert last change.

	* Makerules ($(common-objpfx)%.make): New pattern rule.
	* tls.make.c: New file.
	* Makefile (distribute): Add it.
Diffstat (limited to 'linuxthreads')
-rw-r--r--linuxthreads/ChangeLog19
-rw-r--r--linuxthreads/Makefile47
-rw-r--r--linuxthreads/libc-tls-loc.c49
-rw-r--r--linuxthreads/libc-tsd.c34
4 files changed, 145 insertions, 4 deletions
diff --git a/linuxthreads/ChangeLog b/linuxthreads/ChangeLog
index 77b40b35c1..5e5e0f851e 100644
--- a/linuxthreads/ChangeLog
+++ b/linuxthreads/ChangeLog
@@ -1,3 +1,22 @@
+2002-11-14  Roland McGrath  <roland@redhat.com>
+
+	* libc-tsd.c: New file.
+	* Makefile (distribute): Add it.
+	(libc-link.so): New variable.
+	($(objpfx)libpthread.so): Depend on that instead of libc.so file name.
+	(libc-ok-for-link): New variable.
+	[$(versioning) = yes]: Include $(common-objpfx)tls.make and define
+	libc-ok-for-link to $(use-thread).
+	[$(libc-ok-for-link) = no]
+	(libc-link.so): Set to $(objpfx)libc.so, not $(common-objpfx)libc.so.
+	($(objpfx)libc_pic_lite.a,$(objpfx)libc_pic_lite.os, $(objpfx)libc.so):
+	New targets.
+	(generated): Append them.
+	(extra-objs): Append libc-tsd.os.
+
+	* libc-tls-loc.c: New file.
+	* Makefile (libpthread-routines): Add it.
+
 2002-11-14  Andreas Schwab  <schwab@suse.de>
 
 	* sysdeps/unix/sysv/linux/ia64/pt-initfini.c: Fix unterminated
diff --git a/linuxthreads/Makefile b/linuxthreads/Makefile
index 772c691475..41bb8fff31 100644
--- a/linuxthreads/Makefile
+++ b/linuxthreads/Makefile
@@ -25,7 +25,8 @@ linuxthreads-version := $(shell sed -n 's/^.*$(subdir)-\([0-9.]*\).*$$/\1/p' \
 				    Banner)
 
 headers := pthread.h semaphore.h
-distribute := internals.h queue.h restart.h spinlock.h smp.h tst-signal.sh
+distribute := internals.h queue.h restart.h spinlock.h smp.h tst-signal.sh \
+	      libc-tsd.c
 
 routines := weaks no-tsd
 
@@ -37,7 +38,7 @@ libpthread-routines := attr cancel condvar join manager mutex ptfork \
 		       semaphore spinlock wrapsyscall rwlock pt-machine \
 		       oldsemaphore events getcpuclockid pspinlock barrier \
 		       ptclock_gettime ptclock_settime sighandler \
-		       pthandles
+		       pthandles libc-tls-loc
 
 nodelete-yes = -Wl,--enable-new-dtags,-z,nodelete
 initfirst-yes = -Wl,--enable-new-dtags,-z,initfirst
@@ -89,11 +90,49 @@ CFLAGS-cancel.c += -D__NO_WEAK_PTHREAD_ALIASES -D_RPC_THREAD_SAFE_
 CFLAGS-unload.c += -DPREFIX=\"$(objpfx)\"
 CFLAGS-sighandler.c += $(exceptions)
 
+ifeq (yes,$(versioning))
+-include $(common-objpfx)tls.make
+libc-ok-for-link = $(use-thread)
+else
+libc-ok-for-link = yes
+endif
+
+ifeq (no,$(libc-ok-for-link))
+# These hacks are necessary to let us link against a libc.so that exports
+# the symbols _errno, _h_errno, and _res.  Those symbols are accessible
+# in libc at runtime (dynamic linkable), but are not exported at link time
+# so that applications cannot link against them.  However, libpthread.so
+# needs to link against them for its __errno_location et al functions to
+# find the locations that libc's symbols resolve to.  We cannot do this
+# with aliases in libc.so(GLIBC_PRIVATE), because we need to refer to an
+# executable's symbols when it defines them with copy relocs.
+libc-link.so = $(objpfx)libc.so
+
+$(objpfx)libc_pic_lite.a: $(common-objpfx)libc_pic.a
+	cp $< $@T
+	$(AR) d $@T errno.os herrno.os res_libc.os
+	mv -f $@T $@
+
+extra-objs += libc-tsd.os
+$(objpfx)libc_pic_lite.os: $(objpfx)libc_pic_lite.a $(objpfx)libc-tsd.os
+	$(LINK.o) -nostdlib -nostartfiles -r -o $@ \
+		  $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
+
+$(objpfx)libc.so: $(elfobjdir)/soinit.os \
+		  $(objpfx)libc_pic_lite.os \
+		  $(elfobjdir)/sofini.os \
+		  $(elfobjdir)/interp.os $(elfobjdir)/ld.so
+	$(build-shlib)
+
+generated += libc_pic_lite.a libc_pic_lite.os libc.so
+else
+libc-link.so = $(common-objpfx)libc.so
+endif
+
 # Depend on libc.so so a DT_NEEDED is generated in the shared objects.
 # This ensures they will load libc.so for needed symbols if loaded by
 # a statically-linked program that hasn't already loaded it.
-$(objpfx)libpthread.so: $(common-objpfx)libc.so \
-			$(common-objpfx)libc_nonshared.a
+$(objpfx)libpthread.so: $(libc-link.so) $(common-objpfx)libc_nonshared.a
 
 # Make sure we link with the thread library.
 ifeq ($(build-shared),yes)
diff --git a/linuxthreads/libc-tls-loc.c b/linuxthreads/libc-tls-loc.c
new file mode 100644
index 0000000000..a8d1b4e7fd
--- /dev/null
+++ b/linuxthreads/libc-tls-loc.c
@@ -0,0 +1,49 @@
+/* Special definitions for libc's own exposed thread-specific variables.
+   Copyright (C) 2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <tls.h>
+
+#if USE___THREAD
+# include <errno.h>
+# include <netdb.h>
+# include <resolv.h>
+
+/* These functions have identical definitions in libc.  But the versioned
+   dependencies in executables bind them to libpthread.so definitions,
+   so we must have some here.  */
+
+int *
+__errno_location (void)
+{
+  return &errno;
+}
+
+int *
+__h_errno_location (void)
+{
+  return &h_errno;
+}
+
+struct __res_state *
+__res_state (void)
+{
+  return &_res;
+}
+
+#endif
diff --git a/linuxthreads/libc-tsd.c b/linuxthreads/libc-tsd.c
new file mode 100644
index 0000000000..ea2497a65d
--- /dev/null
+++ b/linuxthreads/libc-tsd.c
@@ -0,0 +1,34 @@
+/* Special hack used to build link-time libc.so object for linking libpthread.
+   Copyright (C) 2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <tls.h>
+
+#if ! USE___THREAD
+
+/* Special hack used to build link-time libc.so object for linking libpthread.
+   See Makefile comments near libc_pic_lite.os rule for what this is for.  */
+
+# include <resolv.h>
+# undef _res
+
+int _errno;
+int _h_errno;
+struct __res_state _res;
+
+#endif