From 60fb5e79f358b7d0784e4cfae4df9ec196e47f19 Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Mon, 20 Jun 2016 14:39:48 +0100 Subject: base: Fix multiple names to one address bug in SymbolTable The SymbolTable class currently assumes that at most one symbol can point to a given address. If multiple symbols point to the same address, only the first one gets added to the internal symbol table since there is already a match in the address table. This changeset converts the address table from a map into a multimap to be able to handle cases where an address maps to multiple symbols. Additionally, the insert method is changed to not fail if there is a match in the address table. Change-Id: I6b4f1d5560c21e49a4af33220efb2a8302961768 Signed-off-by: Andreas Sandberg Reviewed-by: Nikos Nikoleris Reviewed-by: Andreas Hansson Reviewed-by: Gabor Dozsa --- src/base/loader/symtab.cc | 7 ++++--- src/base/loader/symtab.hh | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/base/loader/symtab.cc b/src/base/loader/symtab.cc index 439394852..853d98cc4 100644 --- a/src/base/loader/symtab.cc +++ b/src/base/loader/symtab.cc @@ -56,12 +56,13 @@ SymbolTable::insert(Addr address, string symbol) if (symbol.empty()) return false; - if (!addrTable.insert(make_pair(address, symbol)).second) - return false; - if (!symbolTable.insert(make_pair(symbol, address)).second) return false; + // There can be multiple symbols for the same address, so always + // update the addrTable multimap when we see a new symbol name. + addrTable.insert(make_pair(address, symbol)); + return true; } diff --git a/src/base/loader/symtab.hh b/src/base/loader/symtab.hh index 403cb13ac..bd0406b74 100644 --- a/src/base/loader/symtab.hh +++ b/src/base/loader/symtab.hh @@ -42,7 +42,7 @@ class SymbolTable { public: - typedef std::map ATable; + typedef std::multimap ATable; typedef std::map STable; private: @@ -87,6 +87,8 @@ class SymbolTable if (i == addrTable.end()) return false; + // There are potentially multiple symbols that map to the same + // address. For simplicity, just return the first one. symbol = (*i).second; return true; } -- cgit v1.2.3