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]

[PATCH] Add plugin interface to LD [0/4] Support ELF symbol visibility


On 23/09/2010 17:18, Richard Henderson wrote:
> On 09/22/2010 10:29 PM, Dave Korn wrote:
>> - ELF visibility handling doesn't need to be a first priority because ELF
>> targets should be using GOLD for best results anyway; this patch is sufficient
>> for non-ELF targets that don't have the option of using GOLD and don't need
>> visibility support anyway.
> 
> "Should be", but there's a whole collection of elf targets that
> are unlikely to ever be re-written for GOLD.
> 
> But you're right that it needn't be a first priority.
> 
> 
> r~


  Yeah, but it's like about /four/ extra statements or so... so here it is!

  ld/ChangeLog:

	* plugin.c (asymbol_from_plugin_symbol): If the bfd is an ELF bfd,
	find the elf symbol data and set the visibility in the st_other field.

  ld/testsuite/ChangeLog:

	* plugin-ignore.d: New dump test control script.
	* plugin-vis-1.d: Likewise.
	* plugin.exp: Add list of ELF-only tests and run them if testing on
	an ELF target.

    cheers,
      DaveK

>From 34fd3199e5edc9a3f283741a21bd7e832e5a56c6 Mon Sep 17 00:00:00 2001
From: Dave Korn <dave.korn.cygwin@gmail.com>
Date: Fri, 24 Sep 2010 01:41:15 +0100
Subject: [PATCH] Add ELF symbol visibility support to plugin interface.

  ld/ChangeLog:

	* plugin.c (asymbol_from_plugin_symbol): If the bfd is an ELF bfd,
	find the elf symbol data and set the visibility in the st_other field.

  ld/testsuite/ChangeLog:

	* plugin-ignore.d: New dump test control script.
	* plugin-vis-1.d: Likewise.
	* plugin.exp: Add list of ELF-only tests and run them if testing on
	an ELF target.
---
 ld/plugin.c                            |   10 ++++++++++
 ld/testsuite/ld-plugin/plugin-ignore.d |    1 +
 ld/testsuite/ld-plugin/plugin-vis-1.d  |    9 +++++++++
 ld/testsuite/ld-plugin/plugin.exp      |   22 ++++++++++++++++++++++
 4 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/ld/plugin.c b/ld/plugin.c
index a33e907..e0177f1 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -31,6 +31,7 @@
 #include "ldfile.h"
 #include "plugin.h"
 #include "plugin-api.h"
+#include "elf-bfd.h"
 /* Don't include std headers until after config.h, sysdeps.h etc.,
    or you may end up with the wrong bitsize of off_t.  */
 #include <dlfcn.h>
@@ -495,6 +496,15 @@ asymbol_from_plugin_symbol (bfd *abfd, asymbol *asym,
 	: (ldsym->def == LDPK_UNDEF || ldsym->def == LDPK_WEAKUNDEF
 		? bfd_und_section_ptr
 		: bfd_get_section_by_name (abfd, ".text"));
+  /* Visibility only applies on ELF targets.  */
+  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+    {
+      elf_symbol_type *elfsym = elf_symbol_from (abfd, asym);
+      if (!elfsym)
+	einfo (_("%P%F: %s: non-ELF symbol in ELF BFD!"), asym->name);
+      elfsym->internal_elf_sym.st_other &= ~3;
+      elfsym->internal_elf_sym.st_other |= ldsym->visibility;
+    }
   return LDPS_OK;
 }
 
diff --git a/ld/testsuite/ld-plugin/plugin-ignore.d b/ld/testsuite/ld-plugin/plugin-ignore.d
new file mode 100644
index 0000000..875ac51
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-ignore.d
@@ -0,0 +1 @@
+#pass
diff --git a/ld/testsuite/ld-plugin/plugin-vis-1.d b/ld/testsuite/ld-plugin/plugin-vis-1.d
new file mode 100644
index 0000000..41f4971
--- /dev/null
+++ b/ld/testsuite/ld-plugin/plugin-vis-1.d
@@ -0,0 +1,9 @@
+#...
+.*(PROTECTED.*func3|DEFAULT.*func|HIDDEN.*func2|INTERNAL.*func1)
+#...
+.*(PROTECTED.*func3|DEFAULT.*func|HIDDEN.*func2|INTERNAL.*func1)
+#...
+.*(PROTECTED.*func3|DEFAULT.*func|HIDDEN.*func2|INTERNAL.*func1)
+#...
+.*(PROTECTED.*func3|DEFAULT.*func|HIDDEN.*func2|INTERNAL.*func1)
+#...
diff --git a/ld/testsuite/ld-plugin/plugin.exp b/ld/testsuite/ld-plugin/plugin.exp
index 32f396c..6072e3b 100644
--- a/ld/testsuite/ld-plugin/plugin.exp
+++ b/ld/testsuite/ld-plugin/plugin.exp
@@ -108,11 +108,33 @@ set plugin_tests [list \
     $testobjfiles $libs" "" "" {{ld plugin-9.d}} "main.x" ] \
 ]
 
+set plugin_extra_elf_tests [list \
+    [list "plugin set symbol visibility" "-plugin $plugin_path $regclm \
+			$regas $regcln -plugin-arg claim:tmpdir/func.o \
+			-plugin-arg sym:${_}func::0:0:0 \
+			-plugin-arg sym:${_}func1::0:1:0 \
+			-plugin-arg sym:${_}func2::0:2:0 \
+			-plugin-arg sym:${_}func3::0:3:0 \
+			-plugin-arg dumpresolutions \
+    $testobjfiles $libs" "" "" {{ld plugin-ignore.d} \
+				{readelf -s plugin-vis-1.d}} "main.x" ] \
+]
+
 if { $failed_compile != 0 } {
     foreach testitem $plugin_tests {
 	unresolved [lindex $testitem 0]
     }
+    if { [is_elf_format] } {
+	foreach testitem $plugin_extra_elf_tests {
+	    unresolved [lindex $testitem 0]
+	}
+    }
     return
 }
 
 run_ld_link_tests $plugin_tests
+
+if { [is_elf_format] } {
+    run_ld_link_tests $plugin_extra_elf_tests
+}
+

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