This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
gold patch: Don't warn if an ABI-defined symbol is undefined
- From: Ian Lance Taylor <iant at google dot com>
- To: binutils at sourceware dot org
- Date: Tue, 16 Sep 2008 10:38:49 -0700
- Subject: gold patch: Don't warn if an ABI-defined symbol is undefined
When using an older glibc, one without the AS_NEEDED clause in libc.so
pointing to the dynamic linker, when building a shared library which
uses TLS variables, when using -z defs, gold can report an error about
an undefined __tls_get_addr symbol. This is probably not a
particularly common set of circumstances, but gold already knows about
the magic __tls_get_addr symbol anyhow. I committed this patch to
extend that knowledge to reports about undefined symbols in regular
objects.
Ian
2008-09-16 Ian Lance Taylor <iant@google.com>
* target-reloc.h (relocate_section): Check whether a symbol is
defined by the ABI before reporting an undefined symbol error.
* target.h (Target::is_defined_by_abi): Make parameter const.
(Target::do_is_defined_by_abi): Likewise.
* i386.cc (Target_i386::do_is_defined_by_abi): Likewise.
* powerpc.cc (Target_powerpc::do_is_defined_by_abi): Likewise.
* sparc.cc (Target_sparc::do_is_defined_by_abi): Likewise.
* x86_64.cc (Target_x86_64::do_is_defined_by_abi): Likewise.
* testsuite/Makefile.am (tls_test_shared.so): Add -Wl,-z,defs.
* testsuite/Makefile.in: Rebuild.
Index: i386.cc
===================================================================
RCS file: /cvs/src/src/gold/i386.cc,v
retrieving revision 1.81
diff -u -u -p -r1.81 i386.cc
--- i386.cc 16 Sep 2008 04:31:25 -0000 1.81
+++ i386.cc 16 Sep 2008 17:20:17 -0000
@@ -135,7 +135,7 @@ class Target_i386 : public Sized_target<
// Return whether SYM is defined by the ABI.
bool
- do_is_defined_by_abi(Symbol* sym) const
+ do_is_defined_by_abi(const Symbol* sym) const
{ return strcmp(sym->name(), "___tls_get_addr") == 0; }
// Return the size of the GOT section.
Index: powerpc.cc
===================================================================
RCS file: /cvs/src/src/gold/powerpc.cc,v
retrieving revision 1.6
diff -u -u -p -r1.6 powerpc.cc
--- powerpc.cc 4 Aug 2008 22:22:13 -0000 1.6
+++ powerpc.cc 16 Sep 2008 17:20:17 -0000
@@ -129,7 +129,7 @@ class Target_powerpc : public Sized_targ
// Return whether SYM is defined by the ABI.
bool
- do_is_defined_by_abi(Symbol* sym) const
+ do_is_defined_by_abi(const Symbol* sym) const
{
return strcmp(sym->name(), "___tls_get_addr") == 0;
}
Index: sparc.cc
===================================================================
RCS file: /cvs/src/src/gold/sparc.cc,v
retrieving revision 1.10
diff -u -u -p -r1.10 sparc.cc
--- sparc.cc 4 Aug 2008 22:22:13 -0000 1.10
+++ sparc.cc 16 Sep 2008 17:20:17 -0000
@@ -130,7 +130,7 @@ class Target_sparc : public Sized_target
section_size_type reloc_view_size);
// Return whether SYM is defined by the ABI.
bool
- do_is_defined_by_abi(Symbol* sym) const
+ do_is_defined_by_abi(const Symbol* sym) const
{
// XXX Really need to support this better...
if (sym->type() == elfcpp::STT_SPARC_REGISTER)
Index: target-reloc.h
===================================================================
RCS file: /cvs/src/src/gold/target-reloc.h,v
retrieving revision 1.27
diff -u -u -p -r1.27 target-reloc.h
--- target-reloc.h 10 Jul 2008 23:01:20 -0000 1.27
+++ target-reloc.h 16 Sep 2008 17:20:17 -0000
@@ -283,6 +283,7 @@ relocate_section(
if (sym != NULL
&& sym->is_undefined()
&& sym->binding() != elfcpp::STB_WEAK
+ && !target->is_defined_by_abi(sym)
&& (!parameters->options().shared() // -shared
|| parameters->options().defs())) // -z defs
gold_undefined_symbol(sym, relinfo, i, offset);
Index: target.h
===================================================================
RCS file: /cvs/src/src/gold/target.h,v
retrieving revision 1.29
diff -u -u -p -r1.29 target.h
--- target.h 9 Apr 2008 00:48:13 -0000 1.29
+++ target.h 16 Sep 2008 17:20:17 -0000
@@ -164,7 +164,7 @@ class Target
// Return whether SYM is known to be defined by the ABI. This is
// used to avoid inappropriate warnings about undefined symbols.
bool
- is_defined_by_abi(Symbol* sym) const
+ is_defined_by_abi(const Symbol* sym) const
{ return this->do_is_defined_by_abi(sym); }
protected:
@@ -222,7 +222,7 @@ class Target
// Virtual function which may be implemented by the child class.
virtual bool
- do_is_defined_by_abi(Symbol*) const
+ do_is_defined_by_abi(const Symbol*) const
{ return false; }
private:
Index: x86_64.cc
===================================================================
RCS file: /cvs/src/src/gold/x86_64.cc,v
retrieving revision 1.75
diff -u -u -p -r1.75 x86_64.cc
--- x86_64.cc 16 Sep 2008 04:31:25 -0000 1.75
+++ x86_64.cc 16 Sep 2008 17:20:17 -0000
@@ -139,7 +139,7 @@ class Target_x86_64 : public Sized_targe
// Return whether SYM is defined by the ABI.
bool
- do_is_defined_by_abi(Symbol* sym) const
+ do_is_defined_by_abi(const Symbol* sym) const
{ return strcmp(sym->name(), "__tls_get_addr") == 0; }
// Return the size of the GOT section.
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.75
diff -u -u -p -r1.75 Makefile.am
--- testsuite/Makefile.am 13 Aug 2008 07:37:46 -0000 1.75
+++ testsuite/Makefile.am 16 Sep 2008 17:20:17 -0000
@@ -468,7 +468,7 @@ tls_test_file2_pic.o: tls_test_file2.cc
tls_test_c_pic.o: tls_test_c.c
$(COMPILE) -c -fpic $(TLS_TEST_C_CFLAGS) -o $@ $<
tls_test_shared.so: tls_test_pic.o tls_test_file2_pic.o tls_test_c_pic.o gcctestdir/ld
- $(CXXLINK) -Bgcctestdir/ -shared tls_test_pic.o tls_test_file2_pic.o tls_test_c_pic.o
+ $(CXXLINK) -Bgcctestdir/ -shared tls_test_pic.o tls_test_file2_pic.o tls_test_c_pic.o -Wl,-z,defs
tls_test_shared2.so: tls_test_file2_pic.o gcctestdir/ld
$(CXXLINK) -Bgcctestdir/ -shared tls_test_file2_pic.o