diff options
author | Cary Coutant <ccoutant@google.com> | 2008-04-04 17:24:47 +0000 |
---|---|---|
committer | Cary Coutant <ccoutant@google.com> | 2008-04-04 17:24:47 +0000 |
commit | 86925eef33811b6ca76006e539314a7de652b5c8 (patch) | |
tree | 860e974f6df678882727d8b0a9fd35c227e86fa7 | |
parent | 594ab6a333bf85639e6839a924534fa264616c39 (diff) | |
download | gdb-86925eef33811b6ca76006e539314a7de652b5c8.zip gdb-86925eef33811b6ca76006e539314a7de652b5c8.tar.gz gdb-86925eef33811b6ca76006e539314a7de652b5c8.tar.bz2 |
2008-04-04 Cary Coutant <ccoutant@google.com>
* symtab.h (Symbol::is_weak_undefined): New function.
(Symbol::is_strong_undefined): New function.
(Symbol::is_absolute): New function.
(Symbol::needs_plt_entry): Exclude weak undefined symbols.
(Symbol::needs_dynamic_reloc): Exclude weak undefined and
absolute symbols.
* testsuite/Makefile.am (check_PROGRAMS): Add weak_undef_test.
(weak_undef_test): New target.
* testsuite/Makefile.in: Rebuild.
* testsuite/weak_undef_file1.cc: New file.
* testsuite/weak_undef_file2.cc: New file.
* testsuite/weak_undef_test.cc: New file.
-rw-r--r-- | gold/ChangeLog | 15 | ||||
-rw-r--r-- | gold/symtab.h | 32 | ||||
-rw-r--r-- | gold/testsuite/Makefile.am | 14 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 32 | ||||
-rw-r--r-- | gold/testsuite/weak_undef_file1.cc | 45 | ||||
-rw-r--r-- | gold/testsuite/weak_undef_file2.cc | 46 | ||||
-rw-r--r-- | gold/testsuite/weak_undef_test.cc | 48 |
7 files changed, 227 insertions, 5 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog index ecd4e55..be2da35 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,18 @@ +2008-04-04 Cary Coutant <ccoutant@google.com> + + * symtab.h (Symbol::is_weak_undefined): New function. + (Symbol::is_strong_undefined): New function. + (Symbol::is_absolute): New function. + (Symbol::needs_plt_entry): Exclude weak undefined symbols. + (Symbol::needs_dynamic_reloc): Exclude weak undefined and + absolute symbols. + * testsuite/Makefile.am (check_PROGRAMS): Add weak_undef_test. + (weak_undef_test): New target. + * testsuite/Makefile.in: Rebuild. + * testsuite/weak_undef_file1.cc: New file. + * testsuite/weak_undef_file2.cc: New file. + * testsuite/weak_undef_test.cc: New file. + 2008-04-03 Craig Silverstein <csilvers@google.com> * compressed_output.h (class Output_compressed_section): Use diff --git a/gold/symtab.h b/gold/symtab.h index bd41794..e262cd4 100644 --- a/gold/symtab.h +++ b/gold/symtab.h @@ -405,6 +405,31 @@ class Symbol return this->source_ == FROM_OBJECT && this->shndx() == elfcpp::SHN_UNDEF; } + // Return whether this is a weak undefined symbol. + bool + is_weak_undefined() const + { + return (this->source_ == FROM_OBJECT + && this->binding() == elfcpp::STB_WEAK + && this->shndx() == elfcpp::SHN_UNDEF); + } + + // Return whether this is a strong (i.e., not weak) undefined symbol. + bool + is_strong_undefined() const + { + return (this->source_ == FROM_OBJECT + && this->binding() != elfcpp::STB_WEAK + && this->shndx() == elfcpp::SHN_UNDEF); + } + + // Return whether this is an absolute symbol. + bool + is_absolute() const + { + return this->source_ == FROM_OBJECT && this->shndx() == elfcpp::SHN_ABS; + } + // Return whether this is a common symbol. bool is_common() const @@ -453,7 +478,7 @@ class Symbol return (!parameters->doing_static_link() && this->type() == elfcpp::STT_FUNC && (this->is_from_dynobj() - || this->is_undefined() + || this->is_strong_undefined() || this->is_preemptible())); } @@ -481,6 +506,11 @@ class Symbol if (parameters->doing_static_link()) return false; + // A reference to a weak undefined symbol or to an absolute symbol + // does not need a dynamic relocation. + if (this->is_weak_undefined() || this->is_absolute()) + return false; + // An absolute reference within a position-independent output file // will need a dynamic relocation. if ((flags & ABSOLUTE_REF) diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index d478ed4..35c7d14 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -347,6 +347,20 @@ weak_test_SOURCES = weak_test.cc weak_test_DEPENDENCIES = gcctestdir/ld weak_test_LDFLAGS = -Bgcctestdir/ +check_PROGRAMS += weak_undef_test +weak_undef_test_SOURCES = weak_undef_test.cc +weak_undef_test_DEPENDENCIES = gcctestdir/ld weak_undef_lib.so alt/weak_undef_lib.so +weak_undef_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,alt +weak_undef_test_LDADD = -L . weak_undef_lib.so +weak_undef_file1.o: weak_undef_file1.cc + $(CXXCOMPILE) -c -fpic -o $@ $< +weak_undef_file2.o: weak_undef_file2.cc + $(CXXCOMPILE) -c -fpic -o $@ $< +weak_undef_lib.so: weak_undef_file1.o + $(CXXLINK) -Bgcctestdir/ -shared weak_undef_file1.o +alt/weak_undef_lib.so: weak_undef_file2.o + test -d alt || mkdir -p alt + $(CXXLINK) -Bgcctestdir/ -shared weak_undef_file2.o if TLS diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index dfa6bfb..05e5c5e 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -110,7 +110,7 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_same_shared_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_separate_shared_12_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_separate_shared_21_test \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_test +@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_test weak_undef_test @GCC_FALSE@common_test_1_DEPENDENCIES = libgoldtest.a ../libgold.a \ @GCC_FALSE@ ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ @GCC_FALSE@ $(am__DEPENDENCIES_1) @@ -297,7 +297,8 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS) @GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_same_shared_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_separate_shared_12_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ exception_separate_shared_21_test$(EXEEXT) \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_test$(EXEEXT) +@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_test$(EXEEXT) \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test$(EXEEXT) @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@am__EXEEXT_4 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@ tls_test$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@ tls_pic_test$(EXEEXT) \ @@ -635,6 +636,10 @@ am__weak_test_SOURCES_DIST = weak_test.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_test.$(OBJEXT) weak_test_OBJECTS = $(am_weak_test_OBJECTS) weak_test_LDADD = $(LDADD) +am__weak_undef_test_SOURCES_DIST = weak_undef_test.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@am_weak_undef_test_OBJECTS = \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ weak_undef_test.$(OBJEXT) +weak_undef_test_OBJECTS = $(am_weak_undef_test_OBJECTS) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/../depcomp am__depfiles_maybe = depfiles @@ -684,7 +689,8 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c \ $(two_file_shared_2_test_SOURCES) \ $(two_file_static_test_SOURCES) $(two_file_test_SOURCES) \ $(ver_test_SOURCES) $(ver_test_2_SOURCES) \ - $(ver_test_6_SOURCES) $(weak_test_SOURCES) + $(ver_test_6_SOURCES) $(weak_test_SOURCES) \ + $(weak_undef_test_SOURCES) DIST_SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c \ basic_static_pic_test.c basic_static_test.c basic_test.c \ $(am__binary_test_SOURCES_DIST) $(binary_unittest_SOURCES) \ @@ -729,7 +735,8 @@ DIST_SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c \ $(am__two_file_static_test_SOURCES_DIST) \ $(am__two_file_test_SOURCES_DIST) $(am__ver_test_SOURCES_DIST) \ $(am__ver_test_2_SOURCES_DIST) $(am__ver_test_6_SOURCES_DIST) \ - $(am__weak_test_SOURCES_DIST) + $(am__weak_test_SOURCES_DIST) \ + $(am__weak_undef_test_SOURCES_DIST) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -1070,6 +1077,10 @@ binary_unittest_SOURCES = binary_unittest.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@weak_test_SOURCES = weak_test.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@weak_test_DEPENDENCIES = gcctestdir/ld @GCC_TRUE@@NATIVE_LINKER_TRUE@weak_test_LDFLAGS = -Bgcctestdir/ +@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_SOURCES = weak_undef_test.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_DEPENDENCIES = gcctestdir/ld weak_undef_lib.so alt/weak_undef_lib.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,alt +@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_test_LDADD = -L . weak_undef_lib.so @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@tls_test_SOURCES = tls_test.cc tls_test_file2.cc tls_test_main.cc tls_test.h @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@tls_test_DEPENDENCIES = gcctestdir/ld @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@tls_test_LDFLAGS = -Bgcctestdir/ @@ -1357,6 +1368,9 @@ ver_test_6$(EXEEXT): $(ver_test_6_OBJECTS) $(ver_test_6_DEPENDENCIES) weak_test$(EXEEXT): $(weak_test_OBJECTS) $(weak_test_DEPENDENCIES) @rm -f weak_test$(EXEEXT) $(CXXLINK) $(weak_test_LDFLAGS) $(weak_test_OBJECTS) $(weak_test_LDADD) $(LIBS) +weak_undef_test$(EXEEXT): $(weak_undef_test_OBJECTS) $(weak_undef_test_DEPENDENCIES) + @rm -f weak_undef_test$(EXEEXT) + $(CXXLINK) $(weak_undef_test_LDFLAGS) $(weak_undef_test_OBJECTS) $(weak_undef_test_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -1400,6 +1414,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ver_test_main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ver_test_main_2.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/weak_test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/weak_undef_test.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ @@ -1743,6 +1758,15 @@ uninstall-am: uninstall-info-am @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared exception_test_2_pic.o @GCC_TRUE@@NATIVE_LINKER_TRUE@exception_shared.so: exception_test_1_pic.o exception_test_2_pic.o gcctestdir/ld @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared exception_test_1_pic.o exception_test_2_pic.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_file1.o: weak_undef_file1.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_file2.o: weak_undef_file2.cc +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@weak_undef_lib.so: weak_undef_file1.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared weak_undef_file1.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@alt/weak_undef_lib.so: weak_undef_file2.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@ test -d alt || mkdir -p alt +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared weak_undef_file2.o @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@tls_test_pic.o: tls_test.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@ $(CXXCOMPILE) -c -fpic -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@tls_test_file2_pic.o: tls_test_file2.cc diff --git a/gold/testsuite/weak_undef_file1.cc b/gold/testsuite/weak_undef_file1.cc new file mode 100644 index 0000000..58ab53b --- /dev/null +++ b/gold/testsuite/weak_undef_file1.cc @@ -0,0 +1,45 @@ +// weak_undef_file1.cc -- test handling of weak undefined symbols for gold + +// Copyright 2008 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. + +// We test that we correctly deal with weak undefined symbols. +// We need to make sure that the symbol is resolved to zero +// by the linker and that no dynamic relocation is generated. + +// This source is used to build a shared library that defines +// an arbitrary symbol other than the weak undefined symbol +// referenced by the main program. The main program will be +// linked with this library so that the symbol remains undefined. +// Through the use of the embedded RPATH, the program will load +// an alternate shared library that does define the symbol, +// so that we can detect whether the symbol was left for runtime +// resolution. + + +#include <cstdio> + +int is_such_symbol_ = 0; + +int +t1() +{ + return is_such_symbol_; +} diff --git a/gold/testsuite/weak_undef_file2.cc b/gold/testsuite/weak_undef_file2.cc new file mode 100644 index 0000000..69629ad --- /dev/null +++ b/gold/testsuite/weak_undef_file2.cc @@ -0,0 +1,46 @@ +// weak_undef_file1.cc -- test handling of weak undefined symbols for gold + +// Copyright 2008 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. + +// We test that we correctly deal with weak undefined symbols. +// We need to make sure that the symbol is resolved to zero +// by the linker and that no dynamic relocation is generated. + +// This source is used to build a shared library that defines +// the weak undefined symbol referenced by the main program. +// The main program will be linked with a library that does not +// provide this definition, so that the symbol remains undefined. +// Through the use of the embedded RPATH, the program will load +// this alternate shared library that does define the symbol, +// so that we can detect whether the symbol was left for runtime +// resolution. + + +#include <cstdio> + +int is_such_symbol_ = 0; +int no_such_symbol_ = 1; + +int +t1() +{ + return no_such_symbol_; +} diff --git a/gold/testsuite/weak_undef_test.cc b/gold/testsuite/weak_undef_test.cc new file mode 100644 index 0000000..1a6e17f --- /dev/null +++ b/gold/testsuite/weak_undef_test.cc @@ -0,0 +1,48 @@ +// weak_undef_test.cc -- test handling of weak undefined symbols for gold + +// Copyright 2008 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. + +// We test that we correctly deal with weak undefined symbols. +// We need to make sure that the symbol is resolved to zero +// by the linker and that no dynamic relocation is generated. + +// This file will be linked with a shared library that does not +// define the symbol, so that the symbol remains undefined. +// Through the use of LD_LIBRARY_PATH, the program will load +// an alternate shared library that does define the symbol, +// so that we can detect whether the symbol was left for runtime +// resolution. + + +#include <cstdio> + +extern int no_such_symbol_ __attribute__ ((weak)); + +int +main() +{ + if (&no_such_symbol_ != NULL) + { + fprintf(stderr, "FAILED the weak undef test: &no_such_symbol_ is not NULL\n"); + return 1; + } + return 0; +} |