+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.
+
2011-06-27 Doug Kwan <dougkwan@google.com>
* arm.cc (Arm_relocate_functions::thm_jump8,
// 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.
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*
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
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;
}
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())
# Test symbol versioning.
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_24 = ver_test ver_test_2 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_6 ver_test_8 ver_test_9 \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_11 protected_1 \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_2 relro_test \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_strip_test \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_11 ver_test_12 \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_1 protected_2 \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test relro_strip_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_script_test script_test_1 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2 justsyms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ binary_test script_test_3 \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_8$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_9$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_11$(EXEEXT) \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_12$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_1$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_2$(EXEEXT) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ relro_test$(EXEEXT) \
ver_test_11_OBJECTS = $(am_ver_test_11_OBJECTS)
ver_test_11_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(ver_test_11_LDFLAGS) $(LDFLAGS) -o $@
+@GCC_TRUE@@NATIVE_LINKER_TRUE@am_ver_test_12_OBJECTS = \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_main_2.$(OBJEXT)
+ver_test_12_OBJECTS = $(am_ver_test_12_OBJECTS)
+ver_test_12_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
+ $(ver_test_12_LDFLAGS) $(LDFLAGS) -o $@
@GCC_TRUE@@NATIVE_LINKER_TRUE@am_ver_test_2_OBJECTS = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_main_2.$(OBJEXT)
ver_test_2_OBJECTS = $(am_ver_test_2_OBJECTS)
$(two_file_shared_2_test_SOURCES) \
$(two_file_static_test_SOURCES) two_file_strip_test.c \
$(two_file_test_SOURCES) $(ver_test_SOURCES) \
- $(ver_test_11_SOURCES) $(ver_test_2_SOURCES) \
- $(ver_test_6_SOURCES) $(ver_test_8_SOURCES) \
- $(ver_test_9_SOURCES) $(weak_alias_test_SOURCES) weak_plt.c \
- $(weak_test_SOURCES) $(weak_undef_nonpic_test_SOURCES) \
- $(weak_undef_test_SOURCES)
+ $(ver_test_11_SOURCES) $(ver_test_12_SOURCES) \
+ $(ver_test_2_SOURCES) $(ver_test_6_SOURCES) \
+ $(ver_test_8_SOURCES) $(ver_test_9_SOURCES) \
+ $(weak_alias_test_SOURCES) weak_plt.c $(weak_test_SOURCES) \
+ $(weak_undef_nonpic_test_SOURCES) $(weak_undef_test_SOURCES)
ETAGS = etags
CTAGS = ctags
am__tty_colors = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_11_DEPENDENCIES = gcctestdir/ld ver_test_11.a
@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_11_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_11_LDADD = ver_test_11.a
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_12_SOURCES = ver_test_main_2.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_12_DEPENDENCIES = gcctestdir/ld ver_test_12.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_12_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_12_LDADD = ver_test_12.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@protected_1_SOURCES = \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_main_1.cc protected_main_2.cc protected_main_3.cc
ver_test_11$(EXEEXT): $(ver_test_11_OBJECTS) $(ver_test_11_DEPENDENCIES)
@rm -f ver_test_11$(EXEEXT)
$(ver_test_11_LINK) $(ver_test_11_OBJECTS) $(ver_test_11_LDADD) $(LIBS)
+ver_test_12$(EXEEXT): $(ver_test_12_OBJECTS) $(ver_test_12_DEPENDENCIES)
+ @rm -f ver_test_12$(EXEEXT)
+ $(ver_test_12_LINK) $(ver_test_12_OBJECTS) $(ver_test_12_LDADD) $(LIBS)
ver_test_2$(EXEEXT): $(ver_test_2_OBJECTS) $(ver_test_2_DEPENDENCIES)
@rm -f ver_test_2$(EXEEXT)
$(ver_test_2_LINK) $(ver_test_2_OBJECTS) $(ver_test_2_LDADD) $(LIBS)
@p='ver_test_9$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
ver_test_11.log: ver_test_11$(EXEEXT)
@p='ver_test_11$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+ver_test_12.log: ver_test_12$(EXEEXT)
+ @p='ver_test_12$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
protected_1.log: protected_1$(EXEEXT)
@p='protected_1$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
protected_2.log: protected_2$(EXEEXT)
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared -Wl,--version-script,$(srcdir)/ver_test_10.script ver_test_2.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_11.a: ver_test_1.o ver_test_2.o ver_test_4.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AR) rc $@ $^
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ver_test_12.o: gcctestdir/ld ver_test_1.o ver_test_2.o ver_test_4.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -r -o $@ ver_test_1.o ver_test_2.o ver_test_4.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@protected_1.so: gcctestdir/ld protected_1_pic.o protected_2_pic.o protected_3_pic.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -shared protected_1_pic.o protected_2_pic.o protected_3_pic.o