This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[gold patch] Fix usage of invalidated version string in Symbol_table::define_special_symbol
- From: Viktor Kutuzov <vkutuzov at accesssoftek dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Fri, 16 Sep 2011 14:05:13 -0700
- Subject: [gold patch] Fix usage of invalidated version string in Symbol_table::define_special_symbol
- Reply-to: <vkutuzov at accesssoftek dot com>
Hi Ian,
I found that the Symbol_table::define_special_symbol method can return a
pointer to an invalidated version string from the local std::string
object (v) in case of condition only_if_ref == true. This patch should
fix this problem.
-Viktor.
* symtab.cc (Symbol_table::define_special_symbol): Fix usage of
the invalidated version string.
Index: symtab.cc
===================================================================
RCS file: /cvs/src/src/gold/symtab.cc,v
retrieving revision 1.159
diff -u -r1.159 symtab.cc
--- symtab.cc 1 Aug 2011 18:25:21 -0000 1.159
+++ symtab.cc 16 Sep 2011 20:35:16 -0000
@@ -1656,13 +1656,9 @@
bool is_global;
if (this->version_script_.get_symbol_version(*pname, &v, &is_global))
{
- if (is_global && !v.empty())
- {
- *pversion = v.c_str();
- // If we get the version from a version script, then we
- // are also the default version.
- is_default_version = true;
- }
+ // If we get the version from a version script, then we
+ // are also the default version.
+ is_default_version = (is_global && !v.empty());
}
}
@@ -1676,15 +1672,23 @@
if (only_if_ref)
{
+ // Look up for the externaly specified or default (NULL) versions.
oldsym = this->lookup(*pname, *pversion);
+ // Look up for the script specified default version.
if (oldsym == NULL && is_default_version)
- oldsym = this->lookup(*pname, NULL);
+ oldsym = this->lookup(*pname, v.c_str());
if (oldsym == NULL || !oldsym->is_undefined())
return NULL;
*pname = oldsym->name();
if (!is_default_version)
*pversion = oldsym->version();
+
+ if (is_default_version)
+ {
+ Stringpool::Key version_key = 0;
+ *pversion = this->namepool_.add(v.c_str(), true, &version_key);
+ }
}
else
{
@@ -1695,6 +1699,8 @@
Stringpool::Key version_key = 0;
if (*pversion != NULL)
*pversion = this->namepool_.add(*pversion, true, &version_key);
+ else if (is_default_version)
+ *pversion = this->namepool_.add(v.c_str(), true, &version_key);
Symbol* const snull = NULL;
std::pair<typename Symbol_table_type::iterator, bool> ins =