[PATCH] gold: Implement --exclude-libs option

Doug Kwan (關振德) dougkwan@google.com
Tue May 19 08:19:00 GMT 2009


Hi,

    This patch implements an --exclude-libs option similar to the one
in gnu-ld.   The patch was tested using the gold testsuite, including
a new test including in the patch, on x86_64-unknown-linux-gnu.

-Doug

2009-05-19  Doug Kwan  <dougkwan@google.com>

        * archive.cc (Archive::get_elf_object_for_member): Set no_export
        flag of object.
        * archive.h (option.h, parameters.h): New includes.
        (Archive::Archive): Set no_explort_.
        (Archive::no_export): New method.
        (Archive::no_export_): New field.
        * object.h (Object::Object): Initialize no_export_ to false.
        (Object::no_export, Object::set_no_export): New methods.
        (Object::no_export_): New field.
        * options.cc (General_options::parse_exclude_libs): New method.
        (General_options::check_excluded_libs) Same.
        * options.h (exclude_libs): New option.
        (General_options::check_excluded_libs): New method declaration.
        (General_options::excluded_libs_): New field.
        * symtab.cc (Symbol_table::add_from_relobj): Hide symbols with
        default or protected visibility if an object has no-export flag set.
        testsuite/Makefile.am (check_PROGRAMS): Add exclude_lib_test.
        (check_SCRIPTS): Add exclude_libs_test.sh.
        (check_DATA): Add exclude_libs_test.syms.
        (MOSTLYCLEANFILES): Add exlude_libs_test.syms,
        libexclude_libs_test_1.a and libexclude_libs_test_2.a.
        (exclude_libs_test_SOURCES, exclude_libs_test_DEPENDENDICES,
        exclude_libs_test_LDFLAGS and exclude_libs_test_LDADD): Define.
        (exclude_libs_test.syms, libexclude_libs_test_1.a,
        libexclude_libs_test_2.a): New rules.
        * testsuite/Makefile.in: Regenerate.
        * testsuite/exclude_libs_test.c: New file.
        * testsuite/exclude_libs_test_1.c: Ditto.
        * testsuite/exclude_libs_test_2.c: Ditto.
        * testsuite/exclude_libs_test_2.sh: Ditto.
-------------- next part --------------
diff -Nrpu gold-cvs-3/src/gold/archive.cc gold-cvs-2/src/gold/archive.cc
--- gold-cvs-3/src/gold/archive.cc	2009-03-24 11:42:10.000000000 -0700
+++ gold-cvs-2/src/gold/archive.cc	2009-05-18 16:42:37.360972000 -0700
@@ -549,10 +549,12 @@ Archive::get_elf_object_for_member(off_t
       return NULL;
     }
 
-  return make_elf_object((std::string(this->input_file_->filename())
-			  + "(" + member_name + ")"),
-			 input_file, memoff, ehdr, read_size,
-			 punconfigured);
+  Object *obj = make_elf_object((std::string(this->input_file_->filename())
+				 + "(" + member_name + ")"),
+				input_file, memoff, ehdr, read_size,
+				punconfigured);
+  obj->set_no_export(no_export());
+  return obj;
 }
 
 // Read the symbols from all the archive members in the link.
diff -Nrpu gold-cvs-3/src/gold/archive.h gold-cvs-2/src/gold/archive.h
--- gold-cvs-3/src/gold/archive.h	2009-03-13 22:56:46.000000000 -0700
+++ gold-cvs-2/src/gold/archive.h	2009-05-19 00:06:45.165003000 -0700
@@ -27,6 +27,8 @@
 #include <vector>
 
 #include "fileread.h"
+#include "options.h"
+#include "parameters.h"
 #include "workqueue.h"
 
 namespace gold
@@ -54,7 +56,10 @@ class Archive
       extended_names_(), armap_checked_(), seen_offsets_(), members_(),
       is_thin_archive_(is_thin_archive), included_member_(false),
       nested_archives_(), dirpath_(dirpath), task_(task), num_members_(0)
-  { }
+  {
+    no_export_ =
+      parameters->options().check_excluded_libs(input_file->found_name());
+  }
 
   // The length of the magic string at the start of an archive.
   static const int sarmag = 8;
@@ -148,6 +153,11 @@ class Archive
   size_t
   count_members();
 
+  // Return the no-export flag.
+  bool
+  no_export()
+  { return this->no_export_; }
+
  private:
   Archive(const Archive&);
   Archive& operator=(const Archive&);
@@ -293,6 +303,8 @@ class Archive
   Task *task_;
   // Number of members in this archive;
   unsigned int num_members_;
+  // True if we exclude this library archive from automatic export.
+  bool no_export_;
 };
 
 // This class is used to read an archive and pick out the desired
diff -Nrpu gold-cvs-3/src/gold/object.h gold-cvs-2/src/gold/object.h
--- gold-cvs-3/src/gold/object.h	2009-03-24 11:42:10.000000000 -0700
+++ gold-cvs-2/src/gold/object.h	2009-05-18 16:41:56.664567000 -0700
@@ -195,7 +195,7 @@ class Object
   Object(const std::string& name, Input_file* input_file, bool is_dynamic,
 	 off_t offset = 0)
     : name_(name), input_file_(input_file), offset_(offset), shnum_(-1U),
-      is_dynamic_(is_dynamic), target_(NULL), xindex_(NULL)
+      is_dynamic_(is_dynamic), target_(NULL), xindex_(NULL), no_export_(false)
   { input_file->file().add_object(); }
 
   virtual ~Object()
@@ -463,6 +463,14 @@ class Object
   searched_for() const
   { return this->input_file()->will_search_for(); }
 
+  bool
+  no_export() const
+  { return this->no_export_; }
+
+  void
+  set_no_export(bool value)
+  { this->no_export_ = value; }
+
  protected:
   // Returns NULL for Objects that are not plugin objects.  This method
   // is overridden in the Pluginobj class.
@@ -581,6 +589,9 @@ class Object
   Target* target_;
   // Many sections for objects with more than SHN_LORESERVE sections.
   Xindex* xindex_;
+  // True if exclude this object from automatic symbol export.
+  // This is used only for archive objects.
+  bool no_export_;
 };
 
 // Implement sized_target inline for efficiency.  This approach breaks
diff -Nrpu gold-cvs-3/src/gold/options.cc gold-cvs-2/src/gold/options.cc
--- gold-cvs-3/src/gold/options.cc	2009-03-06 15:12:37.000000000 -0800
+++ gold-cvs-2/src/gold/options.cc	2009-05-19 00:51:04.321598000 -0700
@@ -402,6 +402,59 @@ General_options::parse_end_group(const c
   cmdline->inputs().end_group();
 }
 
+void
+General_options::parse_exclude_libs(const char*, const char* arg,
+                                    Command_line*)
+{
+  const char *p = arg, *end;
+
+  while (*p != '\0')
+    {
+      end = strpbrk(p, ",:");
+      if (end == NULL)
+        end = p + strlen(p);
+      size_t length = end - p;
+      std::string s(p, length);
+      excluded_libs_.insert(s);
+      if (*end == '\0')
+        break;
+      p = end + 1;
+    }
+}
+
+bool
+General_options::check_excluded_libs (const std::string &name) const
+{
+  Unordered_set<std::string>::const_iterator p;
+
+  // Exit early for the most common case.
+  if (excluded_libs_.empty())
+    return false;
+
+  // If we see "ALL", all archives are excluded from automatic export.
+  p = excluded_libs_.find(std::string("ALL"));
+  if (p != excluded_libs_.end())
+    return true;
+
+  // Try finding an exact match.
+  p = excluded_libs_.find(name);
+  if (p != excluded_libs_.end())
+    return true;
+
+  // Try matching NAME without ".a" at the end.
+  size_t length = name.length();
+  if ((length >= 2)
+      && (name[length-2] == '.')
+      && (name[length-1] == 'a'))
+    {
+      p = excluded_libs_.find(name.substr(0, length - 2));
+      if (p != excluded_libs_.end())
+	return true;
+    }
+
+  return false;
+}
+
 } // End namespace gold.
 
 namespace
diff -Nrpu gold-cvs-3/src/gold/options.h gold-cvs-2/src/gold/options.h
--- gold-cvs-3/src/gold/options.h	2009-05-15 10:01:04.000000000 -0700
+++ gold-cvs-2/src/gold/options.h	2009-05-18 16:47:08.153456000 -0700
@@ -660,6 +660,10 @@ class General_options
   DEFINE_string(entry, options::TWO_DASHES, 'e', NULL,
                 N_("Set program start address"), N_("ADDRESS"));
 
+  DEFINE_special(exclude_libs, options::TWO_DASHES, '\0',
+		 N_("Exclude libraries from automatic export"),
+		 N_(("lib,lib ...")));
+
   DEFINE_bool(export_dynamic, options::TWO_DASHES, 'E', false,
               N_("Export all dynamic symbols"),
 	      N_("Do not export all dynamic symbols (default)"));
@@ -1022,6 +1026,11 @@ class General_options
   incremental_disposition() const
   { return this->incremental_disposition_; }
 
+  // Return true if S is the name of a library excluded from automatic
+  // symbol export.
+  bool
+  check_excluded_libs (const std::string &s) const;
+
  private:
   // Don't copy this structure.
   General_options(const General_options&);
@@ -1087,6 +1096,8 @@ class General_options
   // build (--incremental-changed, --incremental-unchanged or
   // --incremental-unknown)
   bool implicit_incremental_;
+  // Libraries excluded from automatic export via --exclude-libs
+  Unordered_set<std::string> excluded_libs_;
 };
 
 // The position-dependent options.  We use this to store the state of
diff -Nrpu gold-cvs-3/src/gold/symtab.cc gold-cvs-2/src/gold/symtab.cc
--- gold-cvs-3/src/gold/symtab.cc	2009-03-17 00:07:21.000000000 -0700
+++ gold-cvs-2/src/gold/symtab.cc	2009-05-19 00:22:05.559397000 -0700
@@ -1126,6 +1126,26 @@ Symbol_table::add_from_relobj(
 	  psym = &sym2;
 	}
 
+      // Fix up visibility if object has no-export set.
+      if (relobj->no_export())
+        {
+	  // We may have copied symbol already above.
+	  if (psym != &sym2)
+	    {
+	      memcpy(symbuf, p, sym_size);
+	      psym = &sym2;
+	    }
+
+	  elfcpp::STV visibility = sym2.get_st_visibility();
+	  if (visibility == elfcpp::STV_DEFAULT
+	      || visibility == elfcpp::STV_PROTECTED)
+	    {
+	      elfcpp::Sym_write<size, big_endian> sw(symbuf);
+	      unsigned char nonvis = sym2.get_st_nonvis();
+	      sw.put_st_other(elfcpp::STV_HIDDEN, nonvis);
+	    }
+        }
+
       Stringpool::Key name_key;
       name = this->namepool_.add_with_length(name, namelen, true,
 					     &name_key);
diff -Nrpu gold-cvs-3/src/gold/testsuite/Makefile.am gold-cvs-2/src/gold/testsuite/Makefile.am
--- gold-cvs-3/src/gold/testsuite/Makefile.am	2009-03-17 22:09:52.000000000 -0700
+++ gold-cvs-2/src/gold/testsuite/Makefile.am	2009-05-19 00:32:46.905726000 -0700
@@ -1038,5 +1038,23 @@ empty.syms:
 
 endif PLUGINS
 
+check_PROGRAMS += exclude_libs_test
+check_SCRIPTS += exclude_libs_test.sh
+check_DATA += exclude_libs_test.syms
+MOSTLYCLEANFILES += exclude_libs_test.syms libexclude_libs_test_1.a \
+        libexclude_libs_test_2.a
+exclude_libs_test_SOURCES = exclude_libs_test.c
+exclude_libs_test_DEPENDENCIES = gcctestdir/ld libexclude_libs_test_1.a \
+	libexclude_libs_test_2.a
+exclude_libs_test_LDFLAGS = -Bgcctestdir/ -L. \
+	-Wl,--exclude-libs,libexclude_libs_test_1
+exclude_libs_test_LDADD = -lexclude_libs_test_1 -lexclude_libs_test_2
+exclude_libs_test.syms: exclude_libs_test
+	$(TEST_READELF) -sW $< >$@ 2>/dev/null
+libexclude_libs_test_1.a: exclude_libs_test_1.o
+	$(TEST_AR) rc $@ $^
+libexclude_libs_test_2.a: exclude_libs_test_2.o
+	$(TEST_AR) rc $@ $^
+
 endif GCC
 endif NATIVE_LINKER
diff -Nrpu gold-cvs-3/src/gold/testsuite/Makefile.in gold-cvs-2/src/gold/testsuite/Makefile.in
--- gold-cvs-3/src/gold/testsuite/Makefile.in	2009-03-17 22:09:52.000000000 -0700
+++ gold-cvs-2/src/gold/testsuite/Makefile.in	2009-05-19 00:47:57.041177000 -0700
@@ -48,7 +48,7 @@ check_PROGRAMS = object_unittest$(EXEEXT
 	$(am__EXEEXT_7) $(am__EXEEXT_8) $(am__EXEEXT_9) \
 	$(am__EXEEXT_10) $(am__EXEEXT_11) $(am__EXEEXT_12) \
 	$(am__EXEEXT_13) $(am__EXEEXT_14) $(am__EXEEXT_15) \
-	$(am__EXEEXT_16)
+	$(am__EXEEXT_16) $(am__EXEEXT_17)
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_1 = basic_test \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	basic_static_test basic_pic_test \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	basic_static_pic_test \
@@ -317,6 +317,14 @@ check_PROGRAMS = object_unittest$(EXEEXT
 @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@	plugin_test_4.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_24 = exclude_libs_test
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_25 = exclude_libs_test.sh
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_26 = exclude_libs_test.syms
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_27 = exclude_libs_test.syms libexclude_libs_test_1.a \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@        libexclude_libs_test_2.a
+
+@GCC_FALSE@exclude_libs_test_DEPENDENCIES =
+@NATIVE_LINKER_FALSE@exclude_libs_test_DEPENDENCIES =
 subdir = testsuite
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -421,6 +429,8 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_2$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_3$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	plugin_test_4$(EXEEXT)
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_17 =  \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	exclude_libs_test$(EXEEXT)
 basic_pic_test_SOURCES = basic_pic_test.c
 basic_pic_test_OBJECTS = basic_pic_test.$(OBJEXT)
 basic_pic_test_LDADD = $(LDADD)
@@ -528,6 +538,10 @@ am__exception_test_SOURCES_DIST = except
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	exception_test_2.$(OBJEXT)
 exception_test_OBJECTS = $(am_exception_test_OBJECTS)
 exception_test_LDADD = $(LDADD)
+am__exclude_libs_test_SOURCES_DIST = exclude_libs_test.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am_exclude_libs_test_OBJECTS =  \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	exclude_libs_test.$(OBJEXT)
+exclude_libs_test_OBJECTS = $(am_exclude_libs_test_OBJECTS)
 flagstest_compress_debug_sections_SOURCES =  \
 	flagstest_compress_debug_sections.c
 flagstest_compress_debug_sections_OBJECTS =  \
@@ -884,6 +898,7 @@ SOURCES = $(libgoldtest_a_SOURCES) basic
 	$(exception_shared_1_test_SOURCES) \
 	$(exception_shared_2_test_SOURCES) \
 	$(exception_static_test_SOURCES) $(exception_test_SOURCES) \
+	$(exclude_libs_test_SOURCES) \
 	flagstest_compress_debug_sections.c flagstest_o_specialfile.c \
 	flagstest_o_specialfile_and_compress_debug_sections.c \
 	$(initpri1_SOURCES) $(justsyms_SOURCES) many_sections_r_test.c \
@@ -937,6 +952,7 @@ DIST_SOURCES = $(libgoldtest_a_SOURCES) 
 	$(am__exception_shared_2_test_SOURCES_DIST) \
 	$(am__exception_static_test_SOURCES_DIST) \
 	$(am__exception_test_SOURCES_DIST) \
+	$(am__exclude_libs_test_SOURCES_DIST) \
 	flagstest_compress_debug_sections.c flagstest_o_specialfile.c \
 	flagstest_o_specialfile_and_compress_debug_sections.c \
 	$(am__initpri1_SOURCES_DIST) $(am__justsyms_SOURCES_DIST) \
@@ -1158,13 +1174,14 @@ TEST_AR = $(top_builddir)/../binutils/ar
 # .o's), but not all of them (such as .so's and .err files).  We
 # improve on that here.  automake-1.9 info docs say "mostlyclean" is
 # the right choice for files 'make' builds that people rebuild.
-MOSTLYCLEANFILES = *.so $(am__append_16) $(am__append_23)
+MOSTLYCLEANFILES = *.so $(am__append_16) $(am__append_23) \
+	$(am__append_27)
 
 # We will add to these later, for each individual test.  Note
 # that we add each test under check_SCRIPTS or check_PROGRAMS;
 # the TESTS variable is automatically populated from these.
-check_SCRIPTS = $(am__append_2) $(am__append_21)
-check_DATA = $(am__append_3) $(am__append_22)
+check_SCRIPTS = $(am__append_2) $(am__append_21) $(am__append_25)
+check_DATA = $(am__append_3) $(am__append_22) $(am__append_26)
 BUILT_SOURCES = $(am__append_14)
 TESTS = $(check_SCRIPTS) $(check_PROGRAMS)
 
@@ -1491,6 +1508,14 @@ binary_unittest_SOURCES = binary_unittes
 @GCC_TRUE@@NATIVE_LINKER_TRUE@thin_archive_test_2_DEPENDENCIES = gcctestdir/ld libthinall.a
 @GCC_TRUE@@NATIVE_LINKER_TRUE@thin_archive_test_2_LDFLAGS = -Bgcctestdir/ -L.
 @GCC_TRUE@@NATIVE_LINKER_TRUE@thin_archive_test_2_LDADD = -lthinall
+@GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test_SOURCES = exclude_libs_test.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test_DEPENDENCIES = gcctestdir/ld libexclude_libs_test_1.a \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	libexclude_libs_test_2.a
+
+@GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test_LDFLAGS = -Bgcctestdir/ -L. \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	-Wl,--exclude-libs,libexclude_libs_test_1
+
+@GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test_LDADD = -lexclude_libs_test_1 -lexclude_libs_test_2
 all: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) all-am
 
@@ -1505,9 +1530,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_
 	      exit 1;; \
 	  esac; \
 	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  testsuite/Makefile'; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  testsuite/Makefile'; \
 	cd $(top_srcdir) && \
-	  $(AUTOMAKE) --foreign  testsuite/Makefile
+	  $(AUTOMAKE) --gnu  testsuite/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	@case '$?' in \
@@ -1598,6 +1623,9 @@ exception_static_test$(EXEEXT): $(except
 exception_test$(EXEEXT): $(exception_test_OBJECTS) $(exception_test_DEPENDENCIES) 
 	@rm -f exception_test$(EXEEXT)
 	$(CXXLINK) $(exception_test_LDFLAGS) $(exception_test_OBJECTS) $(exception_test_LDADD) $(LIBS)
+exclude_libs_test$(EXEEXT): $(exclude_libs_test_OBJECTS) $(exclude_libs_test_DEPENDENCIES) 
+	@rm -f exclude_libs_test$(EXEEXT)
+	$(LINK) $(exclude_libs_test_LDFLAGS) $(exclude_libs_test_OBJECTS) $(exclude_libs_test_LDADD) $(LIBS)
 @GCC_FALSE@flagstest_compress_debug_sections$(EXEEXT): $(flagstest_compress_debug_sections_OBJECTS) $(flagstest_compress_debug_sections_DEPENDENCIES) 
 @GCC_FALSE@	@rm -f flagstest_compress_debug_sections$(EXEEXT)
 @GCC_FALSE@	$(LINK) $(flagstest_compress_debug_sections_LDFLAGS) $(flagstest_compress_debug_sections_OBJECTS) $(flagstest_compress_debug_sections_LDADD) $(LIBS)
@@ -1854,6 +1882,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exception_test_1.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exception_test_2.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exception_test_main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exclude_libs_test.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flagstest_compress_debug_sections.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flagstest_o_specialfile.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flagstest_o_specialfile_and_compress_debug_sections.Po@am__quote@
@@ -2564,6 +2593,12 @@ uninstall-am: uninstall-info-am
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@empty.syms:
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	@echo "" >empty.syms
 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@	@echo "Symbol table" >>empty.syms
+@GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test.syms: exclude_libs_test
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	$(TEST_READELF) -sW $< >$@ 2>/dev/null
+@GCC_TRUE@@NATIVE_LINKER_TRUE@libexclude_libs_test_1.a: exclude_libs_test_1.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	$(TEST_AR) rc $@ $^
+@GCC_TRUE@@NATIVE_LINKER_TRUE@libexclude_libs_test_2.a: exclude_libs_test_2.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	$(TEST_AR) rc $@ $^
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff -Nrpu gold-cvs-3/src/gold/testsuite/exclude_libs_test.c gold-cvs-2/src/gold/testsuite/exclude_libs_test.c
--- gold-cvs-3/src/gold/testsuite/exclude_libs_test.c	1969-12-31 16:00:00.000000000 -0800
+++ gold-cvs-2/src/gold/testsuite/exclude_libs_test.c	2009-05-19 00:13:26.728575000 -0700
@@ -0,0 +1,12 @@
+extern void lib1_default (void);
+extern void lib2_default (void);
+
+int
+main (int argc __attribute__ ((unused)),
+      char** argv __attribute__ ((unused)))
+{
+  lib1_default ();
+  lib2_default ();
+  return 0;
+}
+
diff -Nrpu gold-cvs-3/src/gold/testsuite/exclude_libs_test.sh gold-cvs-2/src/gold/testsuite/exclude_libs_test.sh
--- gold-cvs-3/src/gold/testsuite/exclude_libs_test.sh	1969-12-31 16:00:00.000000000 -0800
+++ gold-cvs-2/src/gold/testsuite/exclude_libs_test.sh	2009-05-19 00:47:31.639588000 -0700
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+# exclude_libs_test.sh -- test that library symbols are not exported.
+
+# Copyright 2009 Free Software Foundation, Inc.
+# Written by Doug Kwan <dougkwan@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 exclude_libs_test.c, a C source file
+# linked with option -Wl,--exclude-libs. We run readelf on
+# the resulting executable and check that symbols from two test library
+# archives are correctly hidden or left unmodified.
+
+check()
+{
+    file=$1
+    sym=$2
+    vis=$3
+
+    found=`grep " $sym\$" $file`
+    if test -z "$found"; then
+	echo "Symbol $sym not found."
+	exit 1
+    fi
+
+    match_vis=`grep " $sym\$" $file | grep " $vis "`
+    if test -z "$match_vis"; then
+	echo "Expected symbol $sym to have visibility $vis but found"
+	echo "$found"
+	exit 1
+    fi
+}
+
+check "exclude_libs_test.syms" "lib1_default" "HIDDEN"
+check "exclude_libs_test.syms" "lib1_protected" "HIDDEN"
+check "exclude_libs_test.syms" "lib1_internal" "INTERNAL"
+check "exclude_libs_test.syms" "lib1_hidden" "HIDDEN"
+check "exclude_libs_test.syms" "lib2_default" "DEFAULT"
+check "exclude_libs_test.syms" "lib2_protected" "PROTECTED"
+check "exclude_libs_test.syms" "lib2_internal" "INTERNAL"
+check "exclude_libs_test.syms" "lib2_hidden" "HIDDEN"
+
+exit 0
diff -Nrpu gold-cvs-3/src/gold/testsuite/exclude_libs_test_1.c gold-cvs-2/src/gold/testsuite/exclude_libs_test_1.c
--- gold-cvs-3/src/gold/testsuite/exclude_libs_test_1.c	1969-12-31 16:00:00.000000000 -0800
+++ gold-cvs-2/src/gold/testsuite/exclude_libs_test_1.c	2009-05-18 23:43:05.588466000 -0700
@@ -0,0 +1,24 @@
+void lib1_default (void);
+void lib1_hidden (void);
+void lib1_internal (void);
+void lib1_protected (void);
+
+void __attribute__((visibility ("default")))
+lib1_default (void)
+{
+}
+
+void __attribute__((visibility ("hidden")))
+lib1_hidden (void)
+{
+}
+
+void __attribute__((visibility ("internal")))
+lib1_internal (void)
+{
+}
+
+void __attribute__((visibility ("protected")))
+lib1_protected (void)
+{
+}
diff -Nrpu gold-cvs-3/src/gold/testsuite/exclude_libs_test_2.c gold-cvs-2/src/gold/testsuite/exclude_libs_test_2.c
--- gold-cvs-3/src/gold/testsuite/exclude_libs_test_2.c	1969-12-31 16:00:00.000000000 -0800
+++ gold-cvs-2/src/gold/testsuite/exclude_libs_test_2.c	2009-05-18 23:43:39.245517000 -0700
@@ -0,0 +1,24 @@
+void lib2_default (void);
+void lib2_hidden (void);
+void lib2_internal (void);
+void lib2_protected (void);
+
+void __attribute__((visibility ("default")))
+lib2_default (void)
+{
+}
+
+void __attribute__((visibility ("hidden")))
+lib2_hidden (void)
+{
+}
+
+void __attribute__((visibility ("internal")))
+lib2_internal (void)
+{
+}
+
+void __attribute__((visibility ("protected")))
+lib2_protected (void)
+{
+}


More information about the Binutils mailing list