This is the mail archive of the binutils@sources.redhat.com 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]

PATCH: Re: Partial symbol export vs --export-dynamic


On Sun, Jun 17, 2001 at 03:48:02AM -0400, Jean-Francois Panisset wrote:
> >
> >If you know something about bfd, it shouldn't be too hard to implement.
> >Personally, I think it is a useful feature. I may do it myself if we all
> >agree it is a good feature to have and how it should work.
> >
> >
> >H.J.
> 

It turned out it was quite easy to do. Here is a patch. I just expanded
the symbol versioning to executables. You can use

# gcc -Wl,-export-dynamic,--version-script,version.map ...

You can use the version-script to control what you want to export. It
supports regular expression, C++ symbol, Java, ... among other things.


H.J.
----
2001-06-17  H.J. Lu  <hjl@gnu.org>

	* elflink.h (elf_info_failed): Add a new field, verdefs.
	(NAME(bfd_elf,size_dynamic_sections): Pass verdefs to
	elf_export_symbol.
	(elf_export_symbol): Check eif->verdefs to decide if a symbol
	should be exported.

Index: elflink.h
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elflink.h,v
retrieving revision 1.65
diff -u -p -r1.65 elflink.h
--- elflink.h	2001/06/16 07:22:57	1.65
+++ elflink.h	2001/06/18 00:48:23
@@ -27,6 +27,7 @@ struct elf_info_failed
 {
   boolean failed;
   struct bfd_link_info *info;
+  struct bfd_elf_version_tree *verdefs;
 };
 
 static boolean elf_link_add_object_symbols
@@ -3135,6 +3136,7 @@ NAME(bfd_elf,size_dynamic_sections) (out
 	}
 
       eif.info = info;
+      eif.verdefs = verdefs;
       eif.failed = false;
 
       /* If we are supposed to export all symbols into the dynamic symbol
@@ -3873,11 +3875,39 @@ elf_export_symbol (h, data)
       && (h->elf_link_hash_flags
 	  & (ELF_LINK_HASH_DEF_REGULAR | ELF_LINK_HASH_REF_REGULAR)) != 0)
     {
-      if (! _bfd_elf_link_record_dynamic_symbol (eif->info, h))
+      struct bfd_elf_version_tree *t;
+      struct bfd_elf_version_expr *d;
+
+      for (t = eif->verdefs; t != NULL; t = t->next)
 	{
-	  eif->failed = true;
-	  return false;
+	  if (t->globals != NULL)
+	    {
+	      for (d = t->globals; d != NULL; d = d->next)
+		{
+		  if ((*d->match) (d, h->root.root.string))
+		    goto doit;
+		}
+	    }
+
+	  if (t->locals != NULL)
+	    {
+	      for (d = t->locals ; d != NULL; d = d->next)
+		{
+		  if ((*d->match) (d, h->root.root.string))
+		    return true;
+		}
+	    }
 	}
+
+      if (!eif->verdefs)
+        {
+doit:
+	  if (! _bfd_elf_link_record_dynamic_symbol (eif->info, h))
+	    {
+	      eif->failed = true;
+	      return false;
+	    }
+        }
     }
 
   return true;


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