This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

protect __dso_handle


Mark added some time back support for destructors running when DSOs
get unloaded.  But it is know that this has major problems as it is.

With some recent changes in GNU ld we can now finish the work.  To do
this we have to use the .protected pseudo-op (of course this only
works on ELF).

The correct solution is to introduce an attribute which then can be
used for functions and variables.  But this is more than I can do in
the moment.

So Mark mentioned that he would accept a patch which simply emits the
pseudo-op in an asm().  This is what the patch below does.

A configure test determines whether the pseudo-op is available and
this information is then used in the defintion of the __dso_handle
variable.  I've left out the meaningless patch for configure.  Just
regenerate it.

Oh, before I forget it.  This only works with the dynamic loader of
glibc 2.2 in the moment.  Future versions of dynamic loaders on other
OSes will support this too since we are using an extension to the
generic ELF ABI.

The patch is against the current mainline compiler.

-- 
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2000-04-04  Ulrich Drepper  <drepper@cygnus.com>

	* acconfig.h: Add HAVE_GAS_PROTECTED.
	* config.h: Regenerated.
	* configure.in: Add test for .protected pseudo-op in gas.
	* crtstuff.c: Include auto-host.h.
	Emit additional .protected pseudo-op for __dso_handle if the
	assembler knows about it.

Index: acconfig.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/acconfig.h,v
retrieving revision 1.43
diff -u -u -r1.43 acconfig.h
--- acconfig.h	2000/03/16 01:58:12	1.43
+++ acconfig.h	2000/04/04 22:32:44
@@ -72,6 +72,9 @@
 /* Define if your assembler supports .weak.  */
 #undef HAVE_GAS_WEAK
 
+/* Define if your assembler supports .protected.  */
+#undef HAVE_GAS_PROTECTED
+
 /* Define if your assembler uses the old HImode fild and fist notation.  */
 #undef HAVE_GAS_FILDS_FISTS
 
Index: config.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config.in,v
retrieving revision 1.62
diff -u -u -r1.62 config.in
--- config.in	2000/03/16 01:58:13	1.62
+++ config.in	2000/04/04 22:32:46
@@ -73,6 +73,9 @@
 /* Define if your assembler supports .weak.  */
 #undef HAVE_GAS_WEAK
 
+/* Define if your assembler supports .protected.  */
+#undef HAVE_GAS_PROTECTED
+
 /* Define if your assembler uses the old HImode fild and fist notation.  */
 #undef HAVE_GAS_FILDS_FISTS
 
Index: configure.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/configure.in,v
retrieving revision 1.349
diff -u -u -r1.349 configure.in
--- configure.in	2000/03/30 22:31:36	1.349
+++ configure.in	2000/04/04 22:33:18
@@ -4414,6 +4414,20 @@
 fi
 AC_MSG_RESULT($gcc_cv_as_weak)
 
+AC_MSG_CHECKING(assembler protected support)
+gcc_cv_as_protected=
+if test x$gcc_cv_as != x; then
+	# Check if we have .protected
+	echo "	.protected symbol" > conftest.s
+	echo "symbol:" >> conftest.s
+	if $gcc_cv_as -o conftest.o conftest.s > /dev/null 2>&1; then
+		AC_DEFINE(HAVE_GAS_PROTECTED)
+		gcc_cv_as_protected="yes"
+	fi
+	rm -f conftest.s conftest.o conftest.nm1 conftest.nm2
+fi
+AC_MSG_RESULT($gcc_cv_as_protected)
+
 case "$target" in 
   sparc*-*-*)
     AC_CACHE_CHECK([assembler .register pseudo-op support],
Index: crtstuff.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/crtstuff.c,v
retrieving revision 1.26
diff -u -u -r1.26 crtstuff.c
--- crtstuff.c	2000/02/26 05:59:31	1.26
+++ crtstuff.c	2000/04/04 22:33:20
@@ -52,6 +52,7 @@
    compiled for the target, and hence definitions concerning only the host
    do not apply.  */
 
+#include "auto-host.h"
 #include "tm.h"
 #include "tsystem.h"
 
@@ -132,7 +133,17 @@
 #ifdef OBJECT_FORMAT_ELF
 
 /* Declare the __dso_handle variable.  It should have a unique value
-   in every shared-object; in a main program its value is zero.  */
+   in every shared-object; in a main program its value is zero.  The
+   object should in any case be protected.  This means the instance
+   in one DSO or the main program is not used in another object.  The
+   dynamic linker takes care of this.  */
+
+/* XXX Ideally the following should be implemented using
+	__attribute__ ((__visibility__ ("protected")))
+   but the __attribute__ support is not yet there.  */
+#ifdef HAVE_GAS_PROTECTED
+asm (".protected\t__dso_handle");
+#endif
 
 #ifdef CRTSTUFFS_O
 void *__dso_handle = &__dso_handle;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]