From: Ian Lance Taylor Date: Tue, 28 Jun 2011 05:39:45 +0000 (+0000) Subject: * symtab.cc (Symbol::versioned_name): New function. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6d1c4efb9c89fcaca4c24f0ef0535a706136d544;p=binutils-gdb.git * 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. --- diff --git a/gold/ChangeLog b/gold/ChangeLog index 6400f0a9158..1ec3942f688 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,18 @@ +2011-06-27 Ian Lance Taylor + + * 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 * arm.cc (Arm_relocate_functions::thm_jump8, diff --git a/gold/stringpool.h b/gold/stringpool.h index 2f9a3139358..c51b143bea2 100644 --- a/gold/stringpool.h +++ b/gold/stringpool.h @@ -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 . // 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& 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* diff --git a/gold/symtab.cc b/gold/symtab.cc index 5d8c163504c..3df86b55c8f 100644 --- a/gold/symtab.cc +++ b/gold/symtab.cc @@ -293,6 +293,21 @@ Sized_symbol::init_undefined(const char* name, const char* version, 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* sym, Stringpool* pool, 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::sym_size; } @@ -2925,7 +2943,10 @@ Symbol_table::sized_write_symbol( unsigned char* p) const { elfcpp::Sym_write 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()) diff --git a/gold/symtab.h b/gold/symtab.h index 51c31d52d6c..9ba9c08fc38 100644 --- a/gold/symtab.h +++ b/gold/symtab.h @@ -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 . // 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 diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 739523ab2e3..5cd808f898d 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -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 diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 971d8c4c21f..1ec5b872e9b 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -248,9 +248,9 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ # 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 \ @@ -638,6 +638,7 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS) @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) \ @@ -1467,6 +1468,11 @@ ver_test_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ 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) @@ -1595,11 +1601,11 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \ $(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 = \ @@ -2164,6 +2170,10 @@ LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \ @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 @@ -2980,6 +2990,9 @@ ver_test$(EXEEXT): $(ver_test_OBJECTS) $(ver_test_DEPENDENCIES) 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) @@ -3629,6 +3642,8 @@ ver_test_9.log: ver_test_9$(EXEEXT) @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) @@ -4330,6 +4345,8 @@ uninstall-am: @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