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 ld.gold option "--dynamic-list-only"


Hi,

  I'd like to propose additional option for ld linker that will limit
dynamic symbol exports to the specified by dynamic list file. All
other symbols will not be exported.
  This will allow fine grained control of exports for big projects
(chromium) which link statically several 3rd party libraries and do
not want export symbols from those 3rd party libraries.

  Attached patch implements this option for the gold linker.

  Can this be added to trunk?
  I'm also planning to implement this option for the bfd linker.

Thanks,
  Slava
commit 23872463d2fddc3e4cab160ab84f7fddc7f82539
Author: Viatcheslav Ostapenko <sl.ostapenko@samsung.com>
Date:   Mon Mar 10 17:48:11 2014 -0400

    Add --dynamic-list-only option to gold linker.

diff --git a/gold/options.cc b/gold/options.cc
index 000e6d0..1d2b027 100644
--- a/gold/options.cc
+++ b/gold/options.cc
@@ -1277,6 +1277,11 @@ General_options::finalize()
   if (this->user_set_rosegment_gap())
     this->set_rosegment(true);
 
+  if (this->dynamic_list_only()
+      && (!this->dynamic_list_.version_script_info()
+          || this->dynamic_list_.version_script_info()->empty())) {
+    gold_fatal(_("--dynamic_list_only requires dynamic list"));
+  }
   // FIXME: we can/should be doing a lot more sanity checking here.
 }
 
diff --git a/gold/options.h b/gold/options.h
index a2f5a88..91c5619 100644
--- a/gold/options.h
+++ b/gold/options.h
@@ -764,6 +764,9 @@ class General_options
   DEFINE_special(dynamic_list, options::TWO_DASHES, '\0',
 		 N_("Read a list of dynamic symbols"), N_("FILE"));
 
+  DEFINE_bool(dynamic_list_only, options::TWO_DASHES, '\0', false,
+        N_("Export only symbols found in dynamic list"), NULL);
+
   DEFINE_string(entry, options::TWO_DASHES, 'e', NULL,
 		N_("Set program start address"), N_("ADDRESS"));
 
diff --git a/gold/symtab.cc b/gold/symtab.cc
index 2e17529..0d73dd7 100644
--- a/gold/symtab.cc
+++ b/gold/symtab.cc
@@ -367,12 +367,12 @@ Symbol::should_add_dynsym_entry(Symbol_table* symtab) const
   // or an --export-dynamic-symbol option, add it.
   if (!this->is_from_dynobj()
       && (parameters->options().in_dynamic_list(this->name())
-	  || parameters->options().is_export_dynamic_symbol(this->name())))
+    || parameters->options().is_export_dynamic_symbol(this->name())))
     {
       if (!this->is_forced_local())
         return true;
       gold_warning(_("Cannot export local symbol '%s'"),
-		   this->demangled_name().c_str());
+        this->demangled_name().c_str());
       return false;
     }
 
@@ -418,6 +418,10 @@ Symbol::should_add_dynsym_entry(Symbol_table* symtab) const
         free(demangled_name);
     }
 
+  // Don't export other symbols if dynamic list only option specified
+  if (parameters->options().dynamic_list_only())
+    return false;
+
   // If exporting all symbols or building a shared library,
   // and the symbol is defined in a regular object and is
   // externally visible, we need to add it.
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index 0d40e3f..342bba1 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -1465,6 +1465,16 @@ dynamic_list: basic_test.o gcctestdir/ld $(srcdir)/dynamic_list.t
 dynamic_list.stdout: dynamic_list
 	$(TEST_READELF) -W --dyn-syms dynamic_list > dynamic_list.stdout
 
+check_SCRIPTS += dynamic_list_only.sh
+check_DATA += dynamic_list_only.stdout
+MOSTLYCLEANFILES += dynamic_list_only dynamic_list_only.stdout
+dynamic_list_only: basic_test.o gcctestdir/ld $(srcdir)/dynamic_list.t
+	$(CXXLINK) -Bgcctestdir/ basic_test.o \
+	  -Wl,--dynamic-list $(srcdir)/dynamic_list.t \
+	  -Wl,--dynamic-list-only
+dynamic_list_only.stdout: dynamic_list_only
+	$(TEST_READELF) -W --dyn-syms dynamic_list_only > dynamic_list_only.stdout
+
 check_PROGRAMS += thin_archive_test_1
 MOSTLYCLEANFILES += libthin1.a libthin3.a libthinall.a \
 	alt/thin_archive_test_2.o alt/thin_archive_test_4.o \
diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
index 07bb534..70f748a 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -102,7 +102,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	script_test_6.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	script_test_7.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	script_test_8.sh \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@	script_test_9.sh dynamic_list.sh
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	script_test_9.sh dynamic_list.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	dynamic_list_only.sh
 
 # Create the data files that debug_msg.sh analyzes.
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_3 = incremental_test.stdout \
@@ -272,7 +273,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	script_test_7.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	script_test_8.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	script_test_9.stdout \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@	dynamic_list.stdout
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	dynamic_list.stdout \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	dynamic_list_only.stdout
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_30 = debug_msg_so.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	debug_msg_ndebug.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	undef_symbol.err \
@@ -285,6 +287,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	script_test_6 script_test_7 \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	script_test_8 script_test_9 \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	dynamic_list dynamic_list.stdout \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	dynamic_list_only \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	dynamic_list_only.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	libthin1.a libthin3.a \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	libthinall.a \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	alt/thin_archive_test_2.o \
@@ -3855,6 +3859,8 @@ script_test_9.sh.log: script_test_9.sh
 	@p='script_test_9.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 dynamic_list.sh.log: dynamic_list.sh
 	@p='dynamic_list.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+dynamic_list_only.sh.log: dynamic_list_only.sh
+	@p='dynamic_list_only.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 plugin_test_1.sh.log: plugin_test_1.sh
 	@p='plugin_test_1.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 plugin_test_2.sh.log: plugin_test_2.sh
@@ -4960,6 +4966,12 @@ uninstall-am:
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	  -Wl,--dynamic-list-cpp-typeinfo
 @GCC_TRUE@@NATIVE_LINKER_TRUE@dynamic_list.stdout: dynamic_list
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	$(TEST_READELF) -W --dyn-syms dynamic_list > dynamic_list.stdout
+@GCC_TRUE@@NATIVE_LINKER_TRUE@dynamic_list_only: basic_test.o gcctestdir/ld $(srcdir)/dynamic_list.t
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	$(CXXLINK) -Bgcctestdir/ basic_test.o \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	  -Wl,--dynamic-list $(srcdir)/dynamic_list.t \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	  -Wl,--dynamic-list-only
+@GCC_TRUE@@NATIVE_LINKER_TRUE@dynamic_list_only.stdout: dynamic_list_only
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	$(TEST_READELF) -W --dyn-syms dynamic_list_only > dynamic_list_only.stdout
 
 @GCC_TRUE@@NATIVE_LINKER_TRUE@libthin1.a: thin_archive_test_1.o alt/thin_archive_test_2.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	rm -f $@
diff --git a/gold/testsuite/dynamic_list_only.sh b/gold/testsuite/dynamic_list_only.sh
new file mode 100755
index 0000000..1a4a284
--- /dev/null
+++ b/gold/testsuite/dynamic_list_only.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# dynamic_list_.sh -- test --dynamic-list and --dynamic-list-only
+
+# Copyright 2014 Free Software Foundation, Inc.
+# Written by Viatcheslav Ostapenko <sl.ostapenko@samsung.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 dynamic_list.t, which is a dynamic-list script.
+
+check()
+{
+    if ! grep -qw "$2" "$1"
+    then
+	echo "Did not find expected text in $1:"
+	echo "   $2"
+	echo ""
+	echo "Actual output below:"
+	cat "$1"
+	exit 1
+    fi
+}
+
+check_missing()
+{
+    if grep -qw "$2" "$1"
+    then
+	echo "Found text expected to be missing in $1:"
+	echo "   $2"
+	echo ""
+	echo "Actual output below:"
+	cat "$1"
+	exit 1
+    fi
+}
+
+check dynamic_list_only.stdout "main"            # comes via --dynamic-list
+check dynamic_list_only.stdout "_Z4t1_6v"        # t1_6()
+check dynamic_list_only.stdout "_ZN4t16aC2Ev"    # t16a:t16a()
+check dynamic_list_only.stdout "_ZN4t16aD1Ev"    # t16a:~t16a()
+check dynamic_list_only.stdout "_ZN4t16a1tEv"    # t16a:t()
+
+# excluded by --dynamic-list-only
+check_missing dynamic_list_only.stdout "_ZdlPv"          # "operator delete(void*)"

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