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]
Other format: [Raw text]

[PATCH] Support anonymous versions in version scripts


Hi!

The following patch adds anonymous version nodes (per Ulrich's request
anonymous version nodes are allowed only if there are no other nodes in the
version script).
Thus one can write:
x.map

{ global: foo; bar; local: *; };

-Wl,--version-script,x.map
and have all but foo and bar symbols not visible in .dynsym.
Ok to commit?

2001-12-12  Jakub Jelinek  <jakub@redhat.com>

	* ldgram.y (vers_node): Support anonymous version tags.
	* ldlang.c (lang_register_vers_node): Ensure anonymous version
	tag is not defined together with non-anonymous versions.
	* ld.texinfo: Document it.

	* elflink.h (size_dynamic_sections): Skip anonymous version tag.
	(elf_link_assign_sym_version): Don't count anonymous version tag.

--- bfd/elflink.h.jj	Wed Dec 12 20:10:29 2001
+++ bfd/elflink.h	Wed Dec 12 22:57:17 2001
@@ -3179,6 +3179,10 @@ NAME(bfd_elf,size_dynamic_sections) (out
          just linking a regular application.  */
       verdefs = asvinfo.verdefs;
 
+      /* Skip anonymous version tag.  */
+      if (verdefs != NULL && verdefs->vernum == 0)
+	verdefs = verdefs->next;
+
       if (verdefs == NULL)
 	_bfd_strip_section_from_output (info, s);
       else
@@ -4241,6 +4245,9 @@ elf_link_assign_sym_version (h, data)
 	  t->used = true;
 
 	  version_index = 1;
+	  /* Don't count anonymous version tag.  */
+	  if (sinfo->verdefs != NULL && sinfo->verdefs->vernum == 0)
+	    version_index = 0;
 	  for (pp = &sinfo->verdefs; *pp != NULL; pp = &(*pp)->next)
 	    ++version_index;
 	  t->vernum = version_index;
--- ld/ldgram.y.jj	Tue Nov 13 18:26:43 2001
+++ ld/ldgram.y	Wed Dec 12 22:13:05 2001
@@ -1061,7 +1061,11 @@ vers_nodes:
 	;
 
 vers_node:
-		VERS_TAG '{' vers_tag '}' ';'
+		'{' vers_tag '}' ';'
+		{
+		  lang_register_vers_node (NULL, $2, NULL);
+		}
+	|	VERS_TAG '{' vers_tag '}' ';'
 		{
 		  lang_register_vers_node ($1, $3, NULL);
 		}
--- ld/ldlang.c.jj	Thu Nov 22 11:05:04 2001
+++ ld/ldlang.c	Wed Dec 12 22:48:39 2001
@@ -5031,6 +5031,16 @@ lang_register_vers_node (name, version, 
   struct bfd_elf_version_tree *t, **pp;
   struct bfd_elf_version_expr *e1;
 
+  if (name == NULL)
+    name = "";
+
+  if ((name[0] == '\0' && lang_elf_version_info != NULL)
+      || (lang_elf_version_info && lang_elf_version_info->name[0] == '\0'))
+    {
+      einfo (_("%X%P: anonymous version tag cannot be combined with other version tags\n"));
+      return;
+    }
+
   /* Make sure this node has a unique name.  */
   for (t = lang_elf_version_info; t != NULL; t = t->next)
     if (strcmp (t->name, name) == 0)
@@ -5067,8 +5077,13 @@ lang_register_vers_node (name, version, 
 
   version->deps = deps;
   version->name = name;
-  ++version_index;
-  version->vernum = version_index;
+  if (name[0] != '\0')
+    {
+      ++version_index;
+      version->vernum = version_index;
+    }
+  else
+    version->vernum = 0;
 
   for (pp = &lang_elf_version_info; *pp != NULL; pp = &(*pp)->next)
     ;
--- ld/ld.texinfo.jj	Tue Nov 13 18:26:43 2001
+++ ld/ld.texinfo	Wed Dec 12 23:32:34 2001
@@ -3685,6 +3685,15 @@ they might suggest to the person reading
 could just as well have appeared in between @samp{1.1} and @samp{1.2}.
 However, this would be a confusing way to write a version script.
 
+Node name can be ommited, provided it is the only version node
+in the version script.  Such version script doesn't assign any versions to
+symbols, only selects which symbols will be globally visible out and which
+won't.
+
+@smallexample
+@{ global: foo; bar; local: *; @}
+#end smallexample
+
 When you link an application against a shared library that has versioned
 symbols, the application itself knows which version of each symbol it
 requires, and it also knows which version nodes it needs from each

	Jakub


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