From: Ian Lance Taylor Date: Tue, 12 Jan 2010 19:12:40 +0000 (+0000) Subject: * target-reloc.h (visibility_error): New inline function. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=837504c42dbf7cb67ee328fb0bdf594b70c90209;p=binutils-gdb.git * target-reloc.h (visibility_error): New inline function. (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. --- diff --git a/gold/target-reloc.h b/gold/target-reloc.h index 06597e2124f..4cb331536fe 100644 --- a/gold/target-reloc.h +++ b/gold/target-reloc.h @@ -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); diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 2b40a85adf4..05c6539bcf3 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -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 diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 9f6f1def217..bcffc90012b 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -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 index 00000000000..58e3e2b0833 --- /dev/null +++ b/gold/testsuite/protected_4.cc @@ -0,0 +1,32 @@ +// protected_4.cc -- a test case for gold + +// Copyright 2010 Free Software Foundation, Inc. +// Written by Ian Lance Taylor . + +// 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(); +}