This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

More Solaris 2 ABI fixes: emit _DYNAMIC etc. into .dynsym


When regtesting current GCC mainline with CVS gas and gld, I found a
couple of errors compared to a bootstrap with Sun ld.  The worst one was
that the boehm-gc gctest program randomly crashed with a SEGV due to
memory corruption.  As a consequence, every libjava execution test hangs
indefinitely, which is especially bad since for yet unknown reasons the
DejaGnu timeout mechanism doesn't work here.

It took me almost a day to investigate this problem, but ultimately it
turned out that shared libraries weren't registered as static roots
(boehm-gc/dyn_load.c (GC_FirstDLOpenedLinkMap)), so GC memory pointed to
by variables in those libraries could be freed prematurely.

The reason for this is that GNU ld doesn't follow the Solaris 2 ABI: it
requires that (among others) _DYNAMIC be emitted into the .dynsym table,
and boehm-gc relies on that, cf.

	Linker and Libraries Guide
        Chapter 2, Link-Editor, Generating the Output File
	http://docs.sun.com/app/docs/doc/819-0690/chapter2-88783?a=view

While this already happens for versioned shared objects since my patch

	PATCH: Properly support Solaris 2 ABI for symbol versioning in GNU ld
	http://sourceware.org/ml/binutils/2010-02/msg00457.html

I had overlooked that this requirement exists for dynamic executables
and unversioned shared objects alike.

The patch below implements this, allows the boehm-gc tests to work and
test results for libjava now match those found with Sun ld.

Ok for mainline?

	Rainer


2010-09-25  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* emultempl/solaris2.em (elf_solaris2_before_allocation): Renamed
	basever_syms to abi_syms.
	Emit abi_syms into .dynamic section for all executables and shared
	objects.

Index: ld/emultempl/solaris2.em
===================================================================
RCS file: /vol/gnu/src/binutils/src-cvs/src/ld/emultempl/solaris2.em,v
retrieving revision 1.1
diff -u -p -r1.1 solaris2.em
--- ld/emultempl/solaris2.em	5 Mar 2010 19:49:00 -0000	1.1
+++ ld/emultempl/solaris2.em	25 Sep 2010 22:33:53 -0000
@@ -31,16 +31,17 @@ fragment <<EOF
 
 #define TARGET_IS_${EMULATION_NAME}
 
-/* The Solaris 2 ABI requires some symbols to always be bound to the base
-   version in a shared object.
+/* The Solaris 2 ABI requires some global symbols to be present in the
+   .dynsym table of executables and shared objects.  If generating a shared
+   object, they must always be bound to the base version.
 
    Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
    File, p.63.  */
 static void
 elf_solaris2_before_allocation (void)
 {
-  /* Symbols required to be bound to the base version.  */
-  static const char *basever_syms[] = {
+  /* Global symbols required by the Solaris 2 ABI.  */
+  static const char *abi_syms[] = {
     "_DYNAMIC",
     "_GLOBAL_OFFSET_TABLE_",
     "_PROCEDURE_LINKAGE_TABLE_",
@@ -51,6 +52,28 @@ elf_solaris2_before_allocation (void)
   };
   const char **sym;
 
+  /* Do this for both executables and shared objects.  */
+  if (!link_info.relocatable)
+    {
+      for (sym = abi_syms; *sym != NULL; sym++)
+	{
+	  struct elf_link_hash_entry *h;
+
+	  /* Lookup symbol.  */
+	  h = elf_link_hash_lookup (elf_hash_table (&link_info), *sym,
+				    FALSE, FALSE, FALSE);
+	  if (h == NULL)
+	    continue;
+
+	  /* Undo the hiding done by _bfd_elf_define_linkage_sym.  */
+	  h->forced_local = 0;
+	  h->other &= ~STV_HIDDEN;
+
+	  /* Emit it into the .dynamic section, too.  */
+	  bfd_elf_link_record_dynamic_symbol (&link_info, h);
+	}
+    }
+
   /* Only do this if emitting a shared object and versioning is in place. */
   if (link_info.shared
       && (lang_elf_version_info != NULL || link_info.create_default_symver))
@@ -59,7 +82,7 @@ elf_solaris2_before_allocation (void)
       struct bfd_elf_version_tree *basever;
       const char *soname;
 
-      for (sym = basever_syms; *sym != NULL; sym++)
+      for (sym = abi_syms; *sym != NULL; sym++)
 	{
 	  /* Create a version pattern for this symbol.  Some of them start
 	     off as local, others as global, so try both.  */
@@ -80,24 +103,6 @@ elf_solaris2_before_allocation (void)
       lang_register_vers_node (soname, basever, NULL);
       /* Enforce base version.  The encoded vd_ndx is vernum + 1.  */
       basever->vernum = 0;
-
-      for (sym = basever_syms; *sym != NULL; sym++)
-	{
-	  struct elf_link_hash_entry *h;
-
-	  /* Lookup symbol.  */
-	  h = elf_link_hash_lookup (elf_hash_table (&link_info), *sym,
-				    FALSE, FALSE, FALSE);
-	  if (h == NULL)
-	    continue;
-
-	  /* Undo the hiding done by _bfd_elf_define_linkage_sym.  */
-	  h->forced_local = 0;
-	  h->other &= ~STV_HIDDEN;
-
-	  /* Emit it into the .dynamic section, too.  */
-	  bfd_elf_link_record_dynamic_symbol (&link_info, h);
-	}
     }
 
   gld${EMULATION_NAME}_before_allocation ();


-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


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