]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
* target-reloc.h (visibility_error): New inline function.
authorIan Lance Taylor <ian@airs.com>
Tue, 12 Jan 2010 19:12:40 +0000 (19:12 +0000)
committerIan Lance Taylor <ian@airs.com>
Tue, 12 Jan 2010 19:12:40 +0000 (19:12 +0000)
(relocate_section): Call visibility_error.
* testsuite/Makefile.am (check_DATA): Add protected_3.err.
(MOSTLYCLEANFILES): Likewise.
(protected_4_pic.o, protected_3.err): New targets.
* testsuite/protected_4.cc: New file.

gold/target-reloc.h
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/protected_4.cc [new file with mode: 0644]

index 06597e2124fcab4154a1be8ea35dbf67a682fdd5..4cb331536fe132ba53ba273ed107ef4eed52be0a 100644 (file)
@@ -144,6 +144,31 @@ get_comdat_behavior(const char* name)
   return CB_WARNING;
 }
 
+// Give an error for a symbol with non-default visibility which is not
+// defined locally.
+
+inline void
+visibility_error(const Symbol* sym)
+{
+  const char* v;
+  switch (sym->visibility())
+    {
+    case elfcpp::STV_INTERNAL:
+      v = _("internal");
+      break;
+    case elfcpp::STV_HIDDEN:
+      v = _("hidden");
+      break;
+    case elfcpp::STV_PROTECTED:
+      v = _("protected");
+      break;
+    default:
+      gold_unreachable();
+    }
+  gold_error(_("%s symbol '%s' is not defined locally"),
+            v, sym->name());
+}
+
 // This function implements the generic part of relocation processing.
 // The template parameter Relocate must be a class type which provides
 // a single function, relocate(), which implements the machine
@@ -323,6 +348,10 @@ relocate_section(
          && (!parameters->options().shared()       // -shared
               || parameters->options().defs()))     // -z defs
        gold_undefined_symbol_at_location(sym, relinfo, i, offset);
+      else if (sym != NULL
+              && sym->visibility() != elfcpp::STV_DEFAULT
+              && (sym->is_undefined() || sym->is_from_dynobj()))
+       visibility_error(sym);
 
       if (sym != NULL && sym->has_warning())
        relinfo->symtab->issue_warning(sym, relinfo, i, offset);
index 2b40a85adf49806be256552e4758411baf1c486c..05c6539bcf3e00e59a93e29ff1c041ae42ffe3fb 100644 (file)
@@ -973,6 +973,18 @@ protected_2_DEPENDENCIES = gcctestdir/ld protected_1.so
 protected_2_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
 protected_2_LDADD = protected_1.so
 
+check_DATA += protected_3.err
+MOSTLYCLEANFILES += protected_3.err
+protected_4_pic.o: protected_4.cc
+       $(CXXCOMPILE) -c -fpic -o $@ $<
+protected_3.err: protected_4_pic.o gcctestdir/ld
+       @echo $(CXXLINK) -Bgcctestdir/ -shared -o protected_4.so protected_4_pic.o "2>$@"
+       @if $(CXXLINK) -Bgcctestdir/ -shared -o protected_4.so protected_4_pic.o 2>$@; then \
+         echo 1>&2 "Link of protected_4.so should have failed"; \
+         rm -f $@; \
+         exit 1; \
+       fi
+
 check_PROGRAMS += relro_test
 relro_test_SOURCES = relro_test_main.cc
 relro_test_DEPENDENCIES = gcctestdir/ld relro_test.so
index 9f6f1def2173a0c1cea8d20fac42d28dd3f0b1b0..bcffc90012b7f9dff138ca7a809d72f5ca8b700e 100644 (file)
@@ -94,7 +94,7 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ undef_symbol.err ver_test_1.syms \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_2.syms ver_test_4.syms \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_5.syms ver_test_7.syms \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_10.syms \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_10.syms protected_3.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4.stdout \
@@ -183,7 +183,7 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ debug_msg.err debug_msg_so.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ debug_msg_ndebug.err \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ undef_symbol.err ver_test_11.a \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ binary.txt \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_3.err binary.txt \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4 script_test_5 \
@@ -2905,6 +2905,15 @@ uninstall-am:
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $<
 @GCC_TRUE@@NATIVE_LINKER_TRUE@protected_3_pic.o: protected_3.cc
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@protected_4_pic.o: protected_4.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@protected_3.err: protected_4_pic.o gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ @echo $(CXXLINK) -Bgcctestdir/ -shared -o protected_4.so protected_4_pic.o "2>$@"
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ @if $(CXXLINK) -Bgcctestdir/ -shared -o protected_4.so protected_4_pic.o 2>$@; then \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@   echo 1>&2 "Link of protected_4.so should have failed"; \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@   rm -f $@; \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@   exit 1; \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ fi
 @GCC_TRUE@@NATIVE_LINKER_TRUE@relro_test.so: gcctestdir/ld relro_test_pic.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared -Wl,-z,relro relro_test_pic.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@relro_test_pic.o: relro_test.cc
diff --git a/gold/testsuite/protected_4.cc b/gold/testsuite/protected_4.cc
new file mode 100644 (file)
index 0000000..58e3e2b
--- /dev/null
@@ -0,0 +1,32 @@
+// protected_4.cc -- a test case for gold
+
+// Copyright 2010 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@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.
+
+// The function f1 is protected but not defined.
+
+int
+f1() __attribute__ ((__visibility__ ("protected")));
+
+int
+f2()
+{
+  return f1();
+}