summaryrefslogtreecommitdiffstats
path: root/src/build/linker/linker.C
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2012-02-29 17:00:28 -0600
committerA. Patrick Williams III <iawillia@us.ibm.com>2012-03-03 08:46:48 -0600
commitb623fb5b9feba1e5eb1808b456f6dd67bcd79cea (patch)
treed5c3030cbae1b541d27dabf9f49358c48fb05502 /src/build/linker/linker.C
parent2e6867c1170ada1c07d38e4facbf10c619d03e48 (diff)
downloadtalos-hostboot-b623fb5b9feba1e5eb1808b456f6dd67bcd79cea.tar.gz
talos-hostboot-b623fb5b9feba1e5eb1808b456f6dd67bcd79cea.zip
Linker fixes for multiple weak symbols.
We have issues with weak symbols containing member variables if they exist in multiple modules because each module's code ends up with their own copy. For objects like Singleton's this is bad because the objects are no longer singleton. The original solution for this was to prohibit multiple definition of the same weak symbol. This causes extra errors when using templated code such as using a vector<foo> in two different modules. The solution here is to search for member values inside of a weak symbol instead of just duplicate weak symbols. This allows multiple weak symbol definitions as long as those weak symbols do not have a contained member value (like a singleton instance would). Change-Id: I173dde9be71f169a457b20db8b960c2b89e7a900 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/709 Tested-by: Jenkins Server Reviewed-by: Van H. Lee <vanlee@us.ibm.com> Reviewed-by: MIKE J. JONES <mjjones@us.ibm.com> Reviewed-by: Douglas R. Gilbert <dgilbert@us.ibm.com> Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/build/linker/linker.C')
-rw-r--r--src/build/linker/linker.C45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/build/linker/linker.C b/src/build/linker/linker.C
index 2da9e881e..209745af6 100644
--- a/src/build/linker/linker.C
+++ b/src/build/linker/linker.C
@@ -36,6 +36,7 @@
#include <string>
#include <vector>
#include <map>
+#include <set>
#include <stdio.h>
#include <errno.h>
#include <string.h>
@@ -56,6 +57,7 @@ using std::setw;
using std::string;
using std::vector;
using std::map;
+using std::set;
using std::for_each;
using std::mem_fun_ref;
using std::bind1st;
@@ -213,7 +215,7 @@ class ModuleTable
ModuleTable(FILE * i_binfile,
const string & i_path,
const string & i_mod_table_name)
- :
+ :
iv_output(i_binfile),
iv_path(i_path),
iv_vfs_mod_table_name(i_mod_table_name) {}
@@ -264,6 +266,8 @@ ofstream modinfo;
vector<uint64_t> all_relocations;
vector<ModuleTable> module_tables;
map<string,size_t> weak_symbols;
+set<string> all_symbols;
+set<string> weak_symbols_to_check;
//-----------------------------------------------------------------------------
// MAIN
@@ -346,6 +350,39 @@ int main(int argc, char** argv)
}
}
+ // Check weak-symbol collisions for contained values (typically
+ // static member variables).
+ for(set<string>::iterator i = weak_symbols_to_check.begin();
+ i != weak_symbols_to_check.end();
+ ++i)
+ {
+
+ // Need to ignore the first character of the weak symbol.
+ // In mangled C++ names a symbol is something like _Z3foo.
+ // A contained member value might be something like
+ // _ZZ3fooE3bar.
+ string sym_name = string((i->c_str())+1);
+
+ cout << "Checking weak symbol: " << *i << endl;
+
+ for(set<string>::iterator j = all_symbols.begin();
+ j != all_symbols.end();
+ ++j)
+ {
+ if ((string::npos != j->find(sym_name)) &&
+ (*i != *j))
+ {
+ cout << "\tDuplicate member found: " << *j << endl;
+ throw std::runtime_error(
+ string("Duplicate weak symbol with contained "
+ "value member detected: ") +
+ *i +
+ string(" with member: ") +
+ *j);
+ }
+ }
+ }
+
// Write objects to their output file
for_each(objects.begin(), objects.end(),
mem_fun_ref(&Object::write_object));
@@ -590,6 +627,8 @@ bool Object::read_relocation()
s.base = syms[i]->section->vma;
s.type = 0;
+ all_symbols.insert(s.name);
+
cout << "\tSymbol: " << syms[i]->name << endl;
cout << "\t\tAddress: " << std::hex << syms[i]->value << endl;
@@ -606,9 +645,7 @@ bool Object::read_relocation()
{
if (weak_symbols[syms[i]->name]++)
{
- throw std::runtime_error(
- string("Duplicate weak symbol detected: ") +
- s.name);
+ weak_symbols_to_check.insert(syms[i]->name);
}
}
OpenPOWER on IntegriCloud