PR 10471
authorCary Coutant <ccoutant@google.com>
Wed, 12 Aug 2009 18:30:39 +0000 (18:30 +0000)
committerCary Coutant <ccoutant@google.com>
Wed, 12 Aug 2009 18:30:39 +0000 (18:30 +0000)
* resolve.cc (Symbol_table::resolve): Check for references from
dynamic objects to hidden and internal symbols.
* testsuite/Makefile.am (hidden_test.sh): New test.
* testsuite/Makefile.in: Regenerate.
* testsuite/hidden_test.sh: New script.
* testsuite/hidden_test_1.c: New test source.
* testsuite/hidden_test_main.c: New test source.

gold/ChangeLog
gold/resolve.cc
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/hidden_test.sh [new file with mode: 0755]
gold/testsuite/hidden_test_1.c [new file with mode: 0644]
gold/testsuite/hidden_test_main.c [new file with mode: 0644]

index 754938264c6a4494b730663ad8950056da6ad0da..9c5518e4a102dd15a6a1c36ca41f89fda3f28bf6 100644 (file)
@@ -1,3 +1,14 @@
+2009-08-12  Cary Coutant  <ccoutant@google.com>
+
+       PR 10471
+       * resolve.cc (Symbol_table::resolve): Check for references from
+       dynamic objects to hidden and internal symbols.
+       * testsuite/Makefile.am (hidden_test.sh): New test.
+       * testsuite/Makefile.in: Regenerate.
+       * testsuite/hidden_test.sh: New script.
+       * testsuite/hidden_test_1.c: New test source.
+       * testsuite/hidden_test_main.c: New test source.
+
 2009-08-11  Doug Kwan  <dougkwan@google.com>
 
        * arm.cc: Update comments.
index 9da963f0abb9de1cbc10de57d302d41f6d980bfd..7299c5589a27bf15f16842fe25847f2bf75eaad8 100644 (file)
@@ -257,6 +257,20 @@ Symbol_table::resolve(Sized_symbol<size>* to,
       // Record that we've seen this symbol in a regular object.
       to->set_in_reg();
     }
+  else if (to->visibility() == elfcpp::STV_HIDDEN
+           || to->visibility() == elfcpp::STV_INTERNAL)
+    {
+      // A dynamic object cannot reference a hidden or internal symbol
+      // defined in another object.
+      gold_warning(_("%s symbol '%s' in %s is referenced by DSO %s"),
+                   (to->visibility() == elfcpp::STV_HIDDEN
+                    ? "hidden"
+                    : "internal"),
+                   to->demangled_name().c_str(),
+                   to->object()->name().c_str(),
+                   object->name().c_str());
+      return;
+    }
   else
     {
       // Record that we've seen this symbol in a dynamic object.
index 6693f00666152767b3798ecb600bc8f8331777fb..6e3169d1778a5d531a028a95dfd98a54386c1ec5 100644 (file)
@@ -1118,5 +1118,17 @@ large_DEPENDENCIES = gcctestdir/ld
 large_LDFLAGS = -Bgcctestdir/
 endif MCMODEL_MEDIUM
 
+# Test that hidden and internal symbols in the main program cannot be
+# referenced by a shared library.
+check_SCRIPTS += hidden_test.sh
+check_DATA += hidden_test.err
+MOSTLYCLEANFILES += hidden_test hidden_test.err
+libhidden.so: hidden_test_1.c gcctestdir/ld
+       $(COMPILE) -Bgcctestdir/ -g -shared -fPIC -w -o $@ $(srcdir)/hidden_test_1.c
+hidden_test: hidden_test_main.o libhidden.so gcctestdir/ld
+       $(LINK) -Bgcctestdir/ -Wl,-R,. hidden_test_main.o libhidden.so 2>hidden_test.err
+hidden_test.err: hidden_test
+       @touch hidden_test.err
+
 endif GCC
 endif NATIVE_LINKER
index 7458f3fc45925b99c63c2a463d78c1b192b312bb..d3a547ee06249ece08fb96015f30d3bf922302d0 100644 (file)
@@ -324,15 +324,21 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_24 = exclude_libs_test \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ local_labels_test \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_test
+
+# Test that hidden and internal symbols in the main program cannot be
+# referenced by a shared library.
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_25 = exclude_libs_test.sh \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_test.sh
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_test.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ hidden_test.sh
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_26 = exclude_libs_test.syms \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_test.syms
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_test.syms \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ hidden_test.err
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_27 = exclude_libs_test.syms \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ libexclude_libs_test_1.a \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ libexclude_libs_test_2.a \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ alt/libexclude_libs_test_3.a \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_test.syms
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_test.syms \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ hidden_test hidden_test.err
 @GCC_TRUE@@MCMODEL_MEDIUM_TRUE@@NATIVE_LINKER_TRUE@am__append_28 = large
 @GCC_FALSE@large_DEPENDENCIES = libgoldtest.a ../libgold.a \
 @GCC_FALSE@    ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
@@ -2719,6 +2725,12 @@ uninstall-am: uninstall-info-am
 # '-Wa,-L' is required to preserve the local label used for testing.
 @GCC_TRUE@@NATIVE_LINKER_TRUE@discard_locals_test.o: discard_locals_test.c
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -c -Wa,-L -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@libhidden.so: hidden_test_1.c gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -Bgcctestdir/ -g -shared -fPIC -w -o $@ $(srcdir)/hidden_test_1.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@hidden_test: hidden_test_main.o libhidden.so gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -Wl,-R,. hidden_test_main.o libhidden.so 2>hidden_test.err
+@GCC_TRUE@@NATIVE_LINKER_TRUE@hidden_test.err: hidden_test
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ @touch hidden_test.err
 # 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 --git a/gold/testsuite/hidden_test.sh b/gold/testsuite/hidden_test.sh
new file mode 100755 (executable)
index 0000000..df51b37
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+# hidden_test.sh -- a test case for hidden and internal symbols.
+
+# Copyright 2009 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 hidden_test_main.c and hidden_test_1.c.
+# The main program defines several symbols with each of the ELF
+# visibilities, and the shared library attempts to reference the
+# symbols.  We try to link the program and check that the expected
+# error messages are issued for the references to internal and
+# hidden symbols.  The errors will be found in hidden_test.err.
+
+check()
+{
+    if ! grep -q "$2" "$1"
+    then
+       echo "Did not find expected error in $1:"
+       echo "   $2"
+       echo ""
+       echo "Actual error output below:"
+       cat "$1"
+       exit 1
+    fi
+}
+
+check_missing()
+{
+    if grep -q "$2" "$1"
+    then
+       echo "Found unexpected error in $1:"
+       echo "   $2"
+       echo ""
+       echo "Actual error output below:"
+       cat "$1"
+       exit 1
+    fi
+}
+
+# We should see errors for hidden and internal symbols.
+check hidden_test.err "hidden symbol 'main_hidden' in hidden_test_main.o is referenced by DSO libhidden.so"
+check hidden_test.err "internal symbol 'main_internal' in hidden_test_main.o is referenced by DSO libhidden.so"
+
+# We shouldn't see errors for the default and protected symbols.
+check_missing hidden_test.err "main_default"
+check_missing hidden_test.err "main_protected"
+
+exit 0
diff --git a/gold/testsuite/hidden_test_1.c b/gold/testsuite/hidden_test_1.c
new file mode 100644 (file)
index 0000000..f685cab
--- /dev/null
@@ -0,0 +1,41 @@
+/* hidden_test_1.c -- test hidden and internal symbols
+
+   Copyright 2009 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 is a test of symbols of various visibilities in the main program
+   and attempts to reference those symbols from a shared library.
+   The linker should issue an error message for references to hidden
+   and internal symbols.  */
+
+extern void main_default (void);
+extern void main_hidden (void);
+extern void main_internal (void);
+extern void main_protected (void);
+
+int
+lib1 (void)
+{
+  main_default ();
+  main_hidden ();
+  main_internal ();
+  main_protected ();
+  return 0;
+}
diff --git a/gold/testsuite/hidden_test_main.c b/gold/testsuite/hidden_test_main.c
new file mode 100644 (file)
index 0000000..c54864d
--- /dev/null
@@ -0,0 +1,61 @@
+/* hidden_test_main.c -- test hidden and internal symbols
+
+   Copyright 2009 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 is a test of symbols of various visibilities in the main program
+   and attempts to reference those symbols from a shared library.
+   The linker should issue an error message for references to hidden
+   and internal symbols.  */
+
+extern void lib1 (void);
+
+void main_default (void);
+void main_hidden (void);
+void main_internal (void);
+void main_protected (void);
+
+void __attribute__((visibility ("default")))
+main_default (void)
+{
+}
+
+void __attribute__((visibility ("hidden")))
+main_hidden (void)
+{
+}
+
+void __attribute__((visibility ("internal")))
+main_internal (void)
+{
+}
+
+void __attribute__((visibility ("protected")))
+main_protected (void)
+{
+}
+
+int
+main (int argc __attribute__ ((unused)),
+      char** argv __attribute__ ((unused)))
+{
+  lib1 ();
+  return 0;
+}
This page took 0.038329 seconds and 4 git commands to generate.