This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
gold patch committed: Output correct version information with -r
- From: Ian Lance Taylor <iant at google dot com>
- To: binutils at sourceware dot org
- Date: Mon, 27 Jun 2011 22:40:49 -0700
- Subject: gold patch committed: Output correct version information with -r
When generating a relocatable object file, gold was erroneously dropping
all version information, which for a .o file must be encoded in the
symbol name. This patch fixes the problem. Committed to mainline.
Ian
2011-06-27 Ian Lance Taylor <iant@google.com>
* symtab.cc (Symbol::versioned_name): New function.
(Symbol_table::add_to_final_symtab): Use versioned_name when
appropriate.
(Symbol_table::sized_write_symbol): Likewise.
* symtab.h (class Symbol): Declare versioned_name.
* stringpool.h (class Stringpool_template): Add variant of add
which takes a std::basic_string.
* testsuite/Makefile.am (check_PROGRAMS): Add ver_test_12.
(ver_test_12_SOURCES, ver_test_12_DEPENDENCIES): New variables.
(ver_test_12_LDFLAGS, ver_test_12_LDADD): New variables.
(ver_test_12.o): New target.
* testsuite/Makefile.in: Rebuild.
Index: symtab.h
===================================================================
RCS file: /cvs/src/src/gold/symtab.h,v
retrieving revision 1.122
diff -p -u -r1.122 symtab.h
--- symtab.h 8 Jun 2011 04:05:25 -0000 1.122
+++ symtab.h 28 Jun 2011 05:36:12 -0000
@@ -1,6 +1,6 @@
// symtab.h -- the gold symbol table -*- C++ -*-
-// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
@@ -136,6 +136,10 @@ class Symbol
set_is_default()
{ this->is_def_ = true; }
+ // Return the symbol's name as name@version (or name@@version).
+ std::string
+ versioned_name() const;
+
// Return the symbol source.
Source
source() const
Index: symtab.cc
===================================================================
RCS file: /cvs/src/src/gold/symtab.cc,v
retrieving revision 1.154
diff -p -u -r1.154 symtab.cc
--- symtab.cc 16 Jun 2011 17:55:48 -0000 1.154
+++ symtab.cc 28 Jun 2011 05:36:12 -0000
@@ -293,6 +293,21 @@ Sized_symbol<size>::init_undefined(const
this->symsize_ = 0;
}
+// Return an allocated string holding the symbol's name as
+// name@version. This is used for relocatable links.
+
+std::string
+Symbol::versioned_name() const
+{
+ gold_assert(this->version_ != NULL);
+ std::string ret = this->name_;
+ ret.push_back('@');
+ if (this->is_def_)
+ ret.push_back('@');
+ ret += this->version_;
+ return ret;
+}
+
// Return true if SHNDX represents a common symbol.
bool
@@ -2416,7 +2431,10 @@ Symbol_table::add_to_final_symtab(Symbol
unsigned int* pindex, off_t* poff)
{
sym->set_symtab_index(*pindex);
- pool->add(sym->name(), false, NULL);
+ if (sym->version() == NULL || !parameters->options().relocatable())
+ pool->add(sym->name(), false, NULL);
+ else
+ pool->add(sym->versioned_name(), true, NULL);
++*pindex;
*poff += elfcpp::Elf_sizes<size>::sym_size;
}
@@ -2925,7 +2943,10 @@ Symbol_table::sized_write_symbol(
unsigned char* p) const
{
elfcpp::Sym_write<size, big_endian> osym(p);
- osym.put_st_name(pool->get_offset(sym->name()));
+ if (sym->version() == NULL || !parameters->options().relocatable())
+ osym.put_st_name(pool->get_offset(sym->name()));
+ else
+ osym.put_st_name(pool->get_offset(sym->versioned_name()));
osym.put_st_value(value);
// Use a symbol size of zero for undefined symbols from shared libraries.
if (shndx == elfcpp::SHN_UNDEF && sym->is_from_dynobj())
Index: stringpool.h
===================================================================
RCS file: /cvs/src/src/gold/stringpool.h,v
retrieving revision 1.26
diff -p -u -r1.26 stringpool.h
--- stringpool.h 3 Aug 2010 20:38:09 -0000 1.26
+++ stringpool.h 28 Jun 2011 05:36:12 -0000
@@ -1,6 +1,6 @@
// stringpool.h -- a string pool for gold -*- C++ -*-
-// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
@@ -219,6 +219,11 @@ class Stringpool_template
const Stringpool_char*
add(const Stringpool_char* s, bool copy, Key* pkey);
+ // Add the string S to the pool.
+ const Stringpool_char*
+ add(const std::basic_string<Stringpool_char>& s, bool copy, Key* pkey)
+ { return this->add_with_length(s.data(), s.size(), copy, pkey); }
+
// Add string S of length LEN characters to the pool. If COPY is
// true, S need not be null terminated.
const Stringpool_char*
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.167
diff -p -u -r1.167 Makefile.am
--- testsuite/Makefile.am 27 Jun 2011 17:53:32 -0000 1.167
+++ testsuite/Makefile.am 28 Jun 2011 05:36:12 -0000
@@ -1089,6 +1089,14 @@ ver_test_11_LDADD = ver_test_11.a
ver_test_11.a: ver_test_1.o ver_test_2.o ver_test_4.o
$(TEST_AR) rc $@ $^
+check_PROGRAMS += ver_test_12
+ver_test_12_SOURCES = ver_test_main_2.cc
+ver_test_12_DEPENDENCIES = gcctestdir/ld ver_test_12.o
+ver_test_12_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
+ver_test_12_LDADD = ver_test_12.o
+ver_test_12.o: gcctestdir/ld ver_test_1.o ver_test_2.o ver_test_4.o
+ gcctestdir/ld -r -o $@ ver_test_1.o ver_test_2.o ver_test_4.o
+
check_PROGRAMS += protected_1
protected_1_SOURCES = \
protected_main_1.cc protected_main_2.cc protected_main_3.cc