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]

[gold][patch] Fix plugin API so that "IR only" status isn't returned for exported symbols


I'm committing this patch to fix the gold plugin API so that the
LDPR_PREVAILING_DEF_IRONLY status, which is meant to indicate that the
symbol is reachable only from within the closed world of IR objects,
is not returned for symbols that may be reachable from outside the
link unit. If we're doing a -r link, or if the symbol is being
exported from a shared library or executable, we can't claim that the
symbol isn't reachable from outside.

-cary


	* plugin.cc (is_visible_from_outside): New function.
	(Pluginobj::get_symbol_resolution_info): Call is_visible_from_outside
	so we don't return "IR only" status for exported symbols or -r links.

	* testsuite/Makefile.am (plugin_test_3): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/plugin_test_3.sh: New file.


Index: plugin.cc
===================================================================
RCS file: /cvs/src/src/gold/plugin.cc,v
retrieving revision 1.6
diff -u -p -r1.6 plugin.cc
--- plugin.cc	23 Dec 2008 02:02:20 -0000	1.6
+++ plugin.cc	23 Dec 2008 23:01:40 -0000
@@ -372,6 +372,21 @@ Pluginobj::Pluginobj(const std::string&
 {
 }

+// Return TRUE if a defined symbol might be reachable from outside the
+// universe of claimed objects.
+
+static inline bool
+is_visible_from_outside(Symbol* lsym)
+{
+  if (lsym->in_real_elf())
+    return true;
+  if (parameters->options().relocatable())
+    return true;
+  if (parameters->options().export_dynamic() || parameters->options().shared())
+    return lsym->is_externally_visible();
+  return false;
+}
+
 // Get symbol resolution info.

 ld_plugin_status
@@ -408,7 +423,7 @@ Pluginobj::get_symbol_resolution_info(in
           if (lsym->source() != Symbol::FROM_OBJECT)
             res = LDPR_PREEMPTED_REG;
           else if (lsym->object() == static_cast<const Object*>(this))
-            res = (lsym->in_real_elf()
+            res = (is_visible_from_outside(lsym)
                    ? LDPR_PREVAILING_DEF
                    : LDPR_PREVAILING_DEF_IRONLY);
           else
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.81
diff -u -p -r1.81 Makefile.am
--- testsuite/Makefile.am	16 Dec 2008 19:19:16 -0000	1.81
+++ testsuite/Makefile.am	23 Dec 2008 23:01:40 -0000
@@ -972,6 +972,15 @@ plugin_test_2: two_file_test_main.o two_
 plugin_test_2.err: plugin_test_2
 	@touch plugin_test_2.err

+check_PROGRAMS += plugin_test_3
+check_SCRIPTS += plugin_test_3.sh
+check_DATA += plugin_test_3.err
+MOSTLYCLEANFILES += plugin_test_3.err
+plugin_test_3: two_file_test_main.o two_file_test_1.syms
two_file_test_1b.syms two_file_test_2.syms empty.syms gcctestdir/ld
plugin_test.so
+	$(CXXLINK) -Bgcctestdir/ -Wl,--export-dynamic
-Wl,--no-demangle,--plugin,"./plugin_test.so",--plugin-opt,"_Z4f13iv"
two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms
two_file_test_2.syms empty.syms 2>plugin_test_3.err
+plugin_test_3.err: plugin_test_3
+	@touch plugin_test_3.err
+
 plugin_test.so: plugin_test.o
 	$(LINK) -Bgcctestdir/ -shared plugin_test.o
 plugin_test.o: plugin_test.c
Index: testsuite/Makefile.in
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.in,v
retrieving revision 1.86
diff -u -p -r1.86 Makefile.in
--- testsuite/Makefile.in	16 Dec 2008 19:19:16 -0000	1.86
+++ testsuite/Makefile.in	23 Dec 2008 23:01:40 -0000
@@ -292,16 +292,20 @@ check_PROGRAMS = object_unittest$(EXEEXT
 @NATIVE_LINKER_FALSE@thin_archive_test_2_DEPENDENCIES =
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_20 =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_1 \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_2
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_2 \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_3
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_21 =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_1.sh \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_2.sh
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_2.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_3.sh
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_22 =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_1.err \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_2.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_2.err \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_3.err
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_23 =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_1.err \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_2.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_2.err \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_3.err
 subdir = testsuite
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -402,7 +406,8 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	thin_archive_test_1$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	thin_archive_test_2$(EXEEXT)
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__EXEEXT_16 =
plugin_test_1$(EXEEXT) \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_2$(EXEEXT)
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_2$(EXEEXT) \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_3$(EXEEXT)
 basic_pic_test_SOURCES = basic_pic_test.c
 basic_pic_test_OBJECTS = basic_pic_test.$(OBJEXT)
 basic_pic_test_LDADD = $(LDADD)
@@ -571,6 +576,12 @@ plugin_test_2_LDADD = $(LDADD)
 plugin_test_2_DEPENDENCIES = libgoldtest.a ../libgold.a \
 	../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+plugin_test_3_SOURCES = plugin_test_3.c
+plugin_test_3_OBJECTS = plugin_test_3.$(OBJEXT)
+plugin_test_3_LDADD = $(LDADD)
+plugin_test_3_DEPENDENCIES = libgoldtest.a ../libgold.a \
+	../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 am__protected_1_SOURCES_DIST = protected_main_1.cc protected_main_2.cc \
 	protected_main_3.cc
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am_protected_1_OBJECTS =  \
@@ -854,12 +865,13 @@ SOURCES = $(libgoldtest_a_SOURCES) basic
 	flagstest_o_specialfile_and_compress_debug_sections.c \
 	$(initpri1_SOURCES) $(justsyms_SOURCES) many_sections_r_test.c \
 	$(many_sections_test_SOURCES) $(object_unittest_SOURCES) \
-	plugin_test_1.c plugin_test_2.c $(protected_1_SOURCES) \
-	$(protected_2_SOURCES) $(relro_script_test_SOURCES) \
-	$(relro_test_SOURCES) $(script_test_1_SOURCES) \
-	$(script_test_2_SOURCES) script_test_3.c \
-	$(thin_archive_test_1_SOURCES) $(thin_archive_test_2_SOURCES) \
-	$(tls_pic_test_SOURCES) $(tls_shared_gd_to_ie_test_SOURCES) \
+	plugin_test_1.c plugin_test_2.c plugin_test_3.c \
+	$(protected_1_SOURCES) $(protected_2_SOURCES) \
+	$(relro_script_test_SOURCES) $(relro_test_SOURCES) \
+	$(script_test_1_SOURCES) $(script_test_2_SOURCES) \
+	script_test_3.c $(thin_archive_test_1_SOURCES) \
+	$(thin_archive_test_2_SOURCES) $(tls_pic_test_SOURCES) \
+	$(tls_shared_gd_to_ie_test_SOURCES) \
 	$(tls_shared_gnu2_gd_to_ie_test_SOURCES) \
 	$(tls_shared_gnu2_test_SOURCES) $(tls_shared_ie_test_SOURCES) \
 	$(tls_shared_nonpic_test_SOURCES) $(tls_shared_test_SOURCES) \
@@ -906,7 +918,7 @@ DIST_SOURCES = $(libgoldtest_a_SOURCES)
 	$(am__initpri1_SOURCES_DIST) $(am__justsyms_SOURCES_DIST) \
 	many_sections_r_test.c $(am__many_sections_test_SOURCES_DIST) \
 	$(object_unittest_SOURCES) plugin_test_1.c plugin_test_2.c \
-	$(am__protected_1_SOURCES_DIST) \
+	plugin_test_3.c $(am__protected_1_SOURCES_DIST) \
 	$(am__protected_2_SOURCES_DIST) \
 	$(am__relro_script_test_SOURCES_DIST) \
 	$(am__relro_test_SOURCES_DIST) \
@@ -1616,6 +1628,15 @@ object_unittest$(EXEEXT): $(object_unitt
 @PLUGINS_FALSE@plugin_test_2$(EXEEXT): $(plugin_test_2_OBJECTS)
$(plugin_test_2_DEPENDENCIES)
 @PLUGINS_FALSE@	@rm -f plugin_test_2$(EXEEXT)
 @PLUGINS_FALSE@	$(LINK) $(plugin_test_2_LDFLAGS)
$(plugin_test_2_OBJECTS) $(plugin_test_2_LDADD) $(LIBS)
+@GCC_FALSE@plugin_test_3$(EXEEXT): $(plugin_test_3_OBJECTS)
$(plugin_test_3_DEPENDENCIES)
+@GCC_FALSE@	@rm -f plugin_test_3$(EXEEXT)
+@GCC_FALSE@	$(LINK) $(plugin_test_3_LDFLAGS) $(plugin_test_3_OBJECTS)
$(plugin_test_3_LDADD) $(LIBS)
+@NATIVE_LINKER_FALSE@plugin_test_3$(EXEEXT): $(plugin_test_3_OBJECTS)
$(plugin_test_3_DEPENDENCIES)
+@NATIVE_LINKER_FALSE@	@rm -f plugin_test_3$(EXEEXT)
+@NATIVE_LINKER_FALSE@	$(LINK) $(plugin_test_3_LDFLAGS)
$(plugin_test_3_OBJECTS) $(plugin_test_3_LDADD) $(LIBS)
+@PLUGINS_FALSE@plugin_test_3$(EXEEXT): $(plugin_test_3_OBJECTS)
$(plugin_test_3_DEPENDENCIES)
+@PLUGINS_FALSE@	@rm -f plugin_test_3$(EXEEXT)
+@PLUGINS_FALSE@	$(LINK) $(plugin_test_3_LDFLAGS)
$(plugin_test_3_OBJECTS) $(plugin_test_3_LDADD) $(LIBS)
 protected_1$(EXEEXT): $(protected_1_OBJECTS) $(protected_1_DEPENDENCIES)
 	@rm -f protected_1$(EXEEXT)
 	$(CXXLINK) $(protected_1_LDFLAGS) $(protected_1_OBJECTS)
$(protected_1_LDADD) $(LIBS)
@@ -1801,6 +1822,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/object_unittest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_1.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_2.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_3.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_3.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_1.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_2.Po@am__quote@
@@ -2461,6 +2483,10 @@ uninstall-am: uninstall-info-am
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	$(CXXLINK) -Bgcctestdir/
-Wl,--no-demangle,-R,.,--plugin,"./plugin_test.so"
two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms
two_file_shared_2.so 2>plugin_test_2.err
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_2.err: plugin_test_2
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	@touch plugin_test_2.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_3:
two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms
two_file_test_2.syms empty.syms gcctestdir/ld plugin_test.so
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	$(CXXLINK) -Bgcctestdir/
-Wl,--export-dynamic
-Wl,--no-demangle,--plugin,"./plugin_test.so",--plugin-opt,"_Z4f13iv"
two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms
two_file_test_2.syms empty.syms 2>plugin_test_3.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_3.err: plugin_test_3
+@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	@touch plugin_test_3.err

 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test.so: plugin_test.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	$(LINK) -Bgcctestdir/
-shared plugin_test.o
Index: testsuite/plugin_test_3.sh
===================================================================
RCS file: testsuite/plugin_test_3.sh
diff -N testsuite/plugin_test_3.sh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/plugin_test_3.sh	23 Dec 2008 23:01:40 -0000
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+# plugin_test_3.sh -- a test case for the plugin API.
+
+# Copyright 2008 Free Software Foundation, Inc.
+# Written by Cary Coutant <ccoutant@google.com>.
+
+# This file is part of gold.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+# This file goes with plugin_test.c, a simple plug-in library that
+# exercises the basic interfaces and prints out version numbers and
+# options passed to the plugin.
+
+check()
+{
+    if ! grep -q "$2" "$1"
+    then
+	echo "Did not find expected output in $1:"
+	echo "   $2"
+	echo ""
+	echo "Actual output below:"
+	cat "$1"
+	exit 1
+    fi
+}
+
+check plugin_test_3.err "API version:"
+check plugin_test_3.err "gold version:"
+check plugin_test_3.err "option: _Z4f13iv"
+check plugin_test_3.err "two_file_test_main.o: claim file hook called"
+check plugin_test_3.err "two_file_test_1.syms: claim file hook called"
+check plugin_test_3.err "two_file_test_1b.syms: claim file hook called"
+check plugin_test_3.err "two_file_test_2.syms: claim file hook called"
+check plugin_test_3.err "two_file_test_1.syms: _Z4f13iv: PREVAILING_DEF_REG"
+check plugin_test_3.err "two_file_test_1.syms: _Z2t2v: PREVAILING_DEF_REG"
+check plugin_test_3.err "two_file_test_1.syms: v2: RESOLVED_IR"
+check plugin_test_3.err "two_file_test_1.syms: t17data: RESOLVED_IR"
+check plugin_test_3.err "two_file_test_2.syms: _Z4f13iv: PREEMPTED_IR"
+check plugin_test_3.err "cleanup hook called"
+
+exit 0


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