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.
This commit is contained in:
Cary Coutant 2008-04-04 17:24:47 +00:00
parent 594ab6a333
commit 86925eef33
7 changed files with 227 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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_;
}

View File

@ -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_;
}

View File

@ -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;
}