(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.
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
&& (!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);
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
@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 \
@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 \
@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
--- /dev/null
+// 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();
+}