From: Teresa Johnson Date: Wed, 20 Sep 2017 22:43:37 +0000 (-0700) Subject: Check for export dynamic symbol options when doing symbol resolution in plugins. X-Git-Tag: users/ARM/embedded-binutils-master-2017q4~1011 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca464aac1b0a444f7debb8fc1e5e8b3f30602a35;p=external%2Fbinutils.git Check for export dynamic symbol options when doing symbol resolution in plugins. 2017-09-20 Teresa Johnson * plugin.cc (is_visible_from_outside): Check for export dynamic symbol option and list. * testsuite/Makefile.am (plugin_test_12): New test. * testsuite/Makefile.in: Regenerate. * testsuite/export_dynamic_plugin.cc: New test source. * testsuite/plugin_test_12.sh: New test script. --- diff --git a/gold/ChangeLog b/gold/ChangeLog index 4faf195..7e62ccb 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,12 @@ +2017-09-20 Teresa Johnson + + * plugin.cc (is_visible_from_outside): Check for export dynamic symbol + option and list. + * testsuite/Makefile.am (plugin_test_12): New test. + * testsuite/Makefile.in: Regenerate. + * testsuite/export_dynamic_plugin.cc: New test source. + * testsuite/plugin_test_12.sh: New test script. + 2017-09-20 Alan Modra * powerpc.cc (Target_powerpc::Branch_info::make_stub): Put diff --git a/gold/Makefile.in b/gold/Makefile.in index 9a51247..a3c8b03 100644 --- a/gold/Makefile.in +++ b/gold/Makefile.in @@ -87,8 +87,8 @@ subdir = . DIST_COMMON = NEWS README ChangeLog $(srcdir)/Makefile.in \ $(srcdir)/Makefile.am $(top_srcdir)/configure \ $(am__configure_deps) $(srcdir)/config.in \ - $(srcdir)/../mkinstalldirs $(top_srcdir)/po/Make-in pread.c \ - ffsll.c mremap.c ftruncate.c yyscript.h yyscript.c \ + $(srcdir)/../mkinstalldirs $(top_srcdir)/po/Make-in ffsll.c \ + ftruncate.c mremap.c pread.c yyscript.h yyscript.c \ $(srcdir)/../depcomp $(srcdir)/../ylwrap ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \ diff --git a/gold/plugin.cc b/gold/plugin.cc index c051805..5ea23b5 100644 --- a/gold/plugin.cc +++ b/gold/plugin.cc @@ -930,7 +930,9 @@ is_visible_from_outside(Symbol* lsym) { if (lsym->in_dyn()) return true; - if (parameters->options().export_dynamic() || parameters->options().shared()) + if (parameters->options().export_dynamic() || parameters->options().shared() + || parameters->options().in_dynamic_list(lsym->name()) + || parameters->options().is_export_dynamic_symbol(lsym->name())) return lsym->is_externally_visible(); return false; } diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index b9d9c8c..cae47f1 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -2295,6 +2295,18 @@ plugin_test_thin.a: two_file_test_1.o two_file_test_1b.o two_file_test_2.o rm -f $@ $(TEST_AR) crT $@ $^ +check_PROGRAMS += plugin_test_12 +check_SCRIPTS += plugin_test_12.sh +check_DATA += plugin_test_12.err +MOSTLYCLEANFILES += plugin_test_12.err +export_dynamic_plugin.o.syms: export_dynamic_plugin.o + $(TEST_READELF) -sW $< >$@ 2>/dev/null +export_dynamic_plugin.o: export_dynamic_plugin.cc + $(COMPILE) -c -o $@ $< +plugin_test_12: export_dynamic_plugin.o gcctestdir/ld plugin_test.so export_dynamic_plugin.o.syms + $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so",--plugin-opt,"_Z3foov" -Wl,--export-dynamic-symbol,"_Z3foov" export_dynamic_plugin.o.syms 2>plugin_test_12.err +plugin_test_12.err: plugin_test_12 + @touch plugin_test_12.err check_PROGRAMS += plugin_test_start_lib check_SCRIPTS += plugin_test_start_lib.sh diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 8e71ba7..0169fce 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -518,6 +518,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_8 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_10 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_11 \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_12 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_start_lib @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_45 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1.sh \ @@ -528,6 +529,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_7.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_10.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_11.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_12.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_start_lib.sh # Test that symbols known in the IR file but not in the replacement file @@ -547,6 +549,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_9b.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_10.sections \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_11.err \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_12.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_start_lib.err # Make a copy of two_file_test_1.o, which does not define the symbol _Z4t16av. @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_47 = \ @@ -563,6 +566,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_10.sections \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_11.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_thin.a \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_12.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_start_lib.err @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@@TLS_TRUE@am__append_48 = plugin_test_tls @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@@TLS_TRUE@am__append_49 = plugin_test_tls.sh @@ -1174,6 +1178,7 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS) @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_8$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_10$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_11$(EXEEXT) \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_12$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_start_lib$(EXEEXT) @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@@TLS_TRUE@am__EXEEXT_25 = plugin_test_tls$(EXEEXT) @GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_26 = \ @@ -1838,6 +1843,13 @@ plugin_test_11_DEPENDENCIES = libgoldtest.a ../libgold.a \ ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) +plugin_test_12_SOURCES = plugin_test_12.c +plugin_test_12_OBJECTS = plugin_test_12.$(OBJEXT) +plugin_test_12_LDADD = $(LDADD) +plugin_test_12_DEPENDENCIES = libgoldtest.a ../libgold.a \ + ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) plugin_test_2_SOURCES = plugin_test_2.c plugin_test_2_OBJECTS = plugin_test_2.$(OBJEXT) plugin_test_2_LDADD = $(LDADD) @@ -2420,20 +2432,21 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \ $(many_sections_test_SOURCES) $(object_unittest_SOURCES) \ $(overflow_unittest_SOURCES) permission_test.c \ $(pie_copyrelocs_test_SOURCES) plugin_test_1.c \ - plugin_test_10.c plugin_test_11.c plugin_test_2.c \ - plugin_test_3.c plugin_test_4.c plugin_test_5.c \ - plugin_test_6.c plugin_test_7.c plugin_test_8.c \ - plugin_test_start_lib.c plugin_test_tls.c pr17704a_test.c \ - $(pr20216a_test_SOURCES) $(pr20216b_test_SOURCES) \ - $(pr20216c_test_SOURCES) $(pr20216d_test_SOURCES) \ - $(pr20216e_test_SOURCES) $(pr20308a_test_SOURCES) \ - $(pr20308b_test_SOURCES) $(pr20308c_test_SOURCES) \ - $(pr20308d_test_SOURCES) $(pr20308e_test_SOURCES) pr20976.c \ - $(protected_1_SOURCES) $(protected_2_SOURCES) \ - $(relro_now_test_SOURCES) $(relro_script_test_SOURCES) \ - $(relro_strip_test_SOURCES) $(relro_test_SOURCES) \ - $(script_test_1_SOURCES) script_test_11.c script_test_12.c \ - script_test_12i.c $(script_test_2_SOURCES) script_test_3.c \ + plugin_test_10.c plugin_test_11.c plugin_test_12.c \ + plugin_test_2.c plugin_test_3.c plugin_test_4.c \ + plugin_test_5.c plugin_test_6.c plugin_test_7.c \ + plugin_test_8.c plugin_test_start_lib.c plugin_test_tls.c \ + pr17704a_test.c $(pr20216a_test_SOURCES) \ + $(pr20216b_test_SOURCES) $(pr20216c_test_SOURCES) \ + $(pr20216d_test_SOURCES) $(pr20216e_test_SOURCES) \ + $(pr20308a_test_SOURCES) $(pr20308b_test_SOURCES) \ + $(pr20308c_test_SOURCES) $(pr20308d_test_SOURCES) \ + $(pr20308e_test_SOURCES) pr20976.c $(protected_1_SOURCES) \ + $(protected_2_SOURCES) $(relro_now_test_SOURCES) \ + $(relro_script_test_SOURCES) $(relro_strip_test_SOURCES) \ + $(relro_test_SOURCES) $(script_test_1_SOURCES) \ + script_test_11.c script_test_12.c script_test_12i.c \ + $(script_test_2_SOURCES) script_test_3.c \ $(searched_file_test_SOURCES) start_lib_test.c \ $(thin_archive_test_1_SOURCES) $(thin_archive_test_2_SOURCES) \ $(tls_phdrs_script_test_SOURCES) $(tls_pic_test_SOURCES) \ @@ -3983,6 +3996,15 @@ pie_copyrelocs_test$(EXEEXT): $(pie_copyrelocs_test_OBJECTS) $(pie_copyrelocs_te @PLUGINS_FALSE@plugin_test_11$(EXEEXT): $(plugin_test_11_OBJECTS) $(plugin_test_11_DEPENDENCIES) $(EXTRA_plugin_test_11_DEPENDENCIES) @PLUGINS_FALSE@ @rm -f plugin_test_11$(EXEEXT) @PLUGINS_FALSE@ $(LINK) $(plugin_test_11_OBJECTS) $(plugin_test_11_LDADD) $(LIBS) +@GCC_FALSE@plugin_test_12$(EXEEXT): $(plugin_test_12_OBJECTS) $(plugin_test_12_DEPENDENCIES) $(EXTRA_plugin_test_12_DEPENDENCIES) +@GCC_FALSE@ @rm -f plugin_test_12$(EXEEXT) +@GCC_FALSE@ $(LINK) $(plugin_test_12_OBJECTS) $(plugin_test_12_LDADD) $(LIBS) +@NATIVE_LINKER_FALSE@plugin_test_12$(EXEEXT): $(plugin_test_12_OBJECTS) $(plugin_test_12_DEPENDENCIES) $(EXTRA_plugin_test_12_DEPENDENCIES) +@NATIVE_LINKER_FALSE@ @rm -f plugin_test_12$(EXEEXT) +@NATIVE_LINKER_FALSE@ $(LINK) $(plugin_test_12_OBJECTS) $(plugin_test_12_LDADD) $(LIBS) +@PLUGINS_FALSE@plugin_test_12$(EXEEXT): $(plugin_test_12_OBJECTS) $(plugin_test_12_DEPENDENCIES) $(EXTRA_plugin_test_12_DEPENDENCIES) +@PLUGINS_FALSE@ @rm -f plugin_test_12$(EXEEXT) +@PLUGINS_FALSE@ $(LINK) $(plugin_test_12_OBJECTS) $(plugin_test_12_LDADD) $(LIBS) @GCC_FALSE@plugin_test_2$(EXEEXT): $(plugin_test_2_OBJECTS) $(plugin_test_2_DEPENDENCIES) $(EXTRA_plugin_test_2_DEPENDENCIES) @GCC_FALSE@ @rm -f plugin_test_2$(EXEEXT) @GCC_FALSE@ $(LINK) $(plugin_test_2_OBJECTS) $(plugin_test_2_LDADD) $(LIBS) @@ -4444,6 +4466,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_10.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_11.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_12.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)/plugin_test_4.Po@am__quote@ @@ -5215,6 +5238,8 @@ plugin_test_10.sh.log: plugin_test_10.sh @p='plugin_test_10.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) plugin_test_11.sh.log: plugin_test_11.sh @p='plugin_test_11.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +plugin_test_12.sh.log: plugin_test_12.sh + @p='plugin_test_12.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) plugin_test_start_lib.sh.log: plugin_test_start_lib.sh @p='plugin_test_start_lib.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) plugin_test_tls.sh.log: plugin_test_tls.sh @@ -5577,6 +5602,8 @@ plugin_test_10.log: plugin_test_10$(EXEEXT) @p='plugin_test_10$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) plugin_test_11.log: plugin_test_11$(EXEEXT) @p='plugin_test_11$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +plugin_test_12.log: plugin_test_12$(EXEEXT) + @p='plugin_test_12$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) plugin_test_start_lib.log: plugin_test_start_lib$(EXEEXT) @p='plugin_test_start_lib$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) plugin_test_tls.log: plugin_test_tls$(EXEEXT) @@ -6915,6 +6942,14 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_thin.a: two_file_test_1.o two_file_test_1b.o two_file_test_2.o @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ rm -f $@ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(TEST_AR) crT $@ $^ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@export_dynamic_plugin.o.syms: export_dynamic_plugin.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(TEST_READELF) -sW $< >$@ 2>/dev/null +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@export_dynamic_plugin.o: export_dynamic_plugin.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(COMPILE) -c -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_12: export_dynamic_plugin.o gcctestdir/ld plugin_test.so export_dynamic_plugin.o.syms +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so",--plugin-opt,"_Z3foov" -Wl,--export-dynamic-symbol,"_Z3foov" export_dynamic_plugin.o.syms 2>plugin_test_12.err +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_12.err: plugin_test_12 +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ @touch plugin_test_12.err @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_start_lib: unused.o plugin_start_lib_test.o plugin_start_lib_test_2.syms gcctestdir/ld plugin_test.so @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so" plugin_start_lib_test.o \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ -Wl,--start-lib plugin_start_lib_test_2.syms -Wl,--end-lib 2>plugin_test_start_lib.err diff --git a/gold/testsuite/export_dynamic_plugin.cc b/gold/testsuite/export_dynamic_plugin.cc new file mode 100644 index 0000000..6d151c0 --- /dev/null +++ b/gold/testsuite/export_dynamic_plugin.cc @@ -0,0 +1,29 @@ +/* export_dynamic_plugin.c -- a test case for gold + + Copyright (C) 2017 onwards Free Software Foundation, Inc. + Written by Teresa Johnson . + + 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. */ + +int foo(void) { + return 0; +} + +int main(void) { + return 0; +} diff --git a/gold/testsuite/plugin_test_12.sh b/gold/testsuite/plugin_test_12.sh new file mode 100755 index 0000000..f34f248 --- /dev/null +++ b/gold/testsuite/plugin_test_12.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# plugin_test_12.sh -- a test case for the plugin API. + +# Copyright (C) 2017 onwards Free Software Foundation, Inc. +# Written by Teresa Johnson . + +# 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. + +# This checks if the symbol resolution withe export dynamic symbol is +# as expected. + +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_12.err "API version:" +check plugin_test_12.err "gold version:" +check plugin_test_12.err "option: _Z3foov" +check plugin_test_12.err "export_dynamic_plugin.o.syms: claim file hook called" +check plugin_test_12.err "export_dynamic_plugin.o.syms: _Z3foov: PREVAILING_DEF_IRONLY_EXP" +check plugin_test_12.err "cleanup hook called" + +exit 0