diff options
author | Greg Clayton <gclayton@apple.com> | 2014-01-16 01:38:29 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2014-01-16 01:38:29 +0000 |
commit | d81088c540036f4ad9a2189eb75bf5ba7b404740 (patch) | |
tree | 9352aba76e6191ef17fe2d0aab9f5db58b608864 /lldb/source/Plugins/ObjectFile | |
parent | 43788a20c6a9a6328e7ecac864d5160ec8be29d6 (diff) | |
download | bcm5719-llvm-d81088c540036f4ad9a2189eb75bf5ba7b404740.tar.gz bcm5719-llvm-d81088c540036f4ad9a2189eb75bf5ba7b404740.zip |
Make sure we correctly merge all N_FUN symbols with non-stab entries even if there are multiple symbols with the same name.
<rdar://problem/15831292>
llvm-svn: 199344
Diffstat (limited to 'lldb/source/Plugins/ObjectFile')
-rw-r--r-- | lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 132 |
1 files changed, 82 insertions, 50 deletions
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 7a34515c02f..e1972a2f09e 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -1987,7 +1987,7 @@ ObjectFileMachO::ParseSymtab () std::vector<uint32_t> N_INCL_indexes; std::vector<uint32_t> N_BRAC_indexes; std::vector<uint32_t> N_COMM_indexes; - typedef std::map <uint64_t, uint32_t> ValueToSymbolIndexMap; + typedef std::multimap <uint64_t, uint32_t> ValueToSymbolIndexMap; typedef std::map <uint32_t, uint32_t> NListIndexToSymbolIndexMap; typedef std::map <const char *, uint32_t> ConstNameToSymbolIndexMap; ValueToSymbolIndexMap N_FUN_addr_to_sym_idx; @@ -2322,7 +2322,7 @@ ObjectFileMachO::ParseSymtab () type = eSymbolTypeCode; symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value); - N_FUN_addr_to_sym_idx[nlist.n_value] = sym_idx; + N_FUN_addr_to_sym_idx.insert(std::make_pair(nlist.n_value, sym_idx)); // We use the current number of symbols in the symbol table in lieu of // using nlist_idx in case we ever start trimming entries out N_FUN_indexes.push_back(sym_idx); @@ -2347,7 +2347,7 @@ ObjectFileMachO::ParseSymtab () case N_STSYM: // static symbol: name,,n_sect,type,address - N_STSYM_addr_to_sym_idx[nlist.n_value] = sym_idx; + N_STSYM_addr_to_sym_idx.insert(std::make_pair(nlist.n_value, sym_idx)); symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value); type = eSymbolTypeData; break; @@ -2855,25 +2855,33 @@ ObjectFileMachO::ParseSymtab () // If we do find a match, and the name matches, then we // can merge the two into just the function symbol to avoid // duplicate entries in the symbol table - ValueToSymbolIndexMap::const_iterator pos = N_FUN_addr_to_sym_idx.find (nlist.n_value); - if (pos != N_FUN_addr_to_sym_idx.end()) + std::pair<ValueToSymbolIndexMap::const_iterator, ValueToSymbolIndexMap::const_iterator> range; + range = N_FUN_addr_to_sym_idx.equal_range(nlist.n_value); + if (range.first != range.second) { - if (sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(Mangled::ePreferMangled)) + bool found_it = false; + for (ValueToSymbolIndexMap::const_iterator pos = range.first; pos != range.second; ++pos) { - m_nlist_idx_to_sym_idx[nlist_idx] = pos->second; - // We just need the flags from the linker symbol, so put these flags - // into the N_FUN flags to avoid duplicate symbols in the symbol table - sym[pos->second].SetExternal(sym[sym_idx].IsExternal()); - sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc); - if (resolver_addresses.find(nlist.n_value) != resolver_adresses.end()) - sym[pos->second].SetType (eSymbolTypeResolver); - sym[sym_idx].Clear(); - continue; + if (sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(Mangled::ePreferMangled)) + { + m_nlist_idx_to_sym_idx[nlist_idx] = pos->second; + // We just need the flags from the linker symbol, so put these flags + // into the N_FUN flags to avoid duplicate symbols in the symbol table + sym[pos->second].SetExternal(sym[sym_idx].IsExternal()); + sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc); + if (resolver_addresses.find(nlist.n_value) != resolver_addresses.end()) + sym[pos->second].SetType (eSymbolTypeResolver); + sym[sym_idx].Clear(); + found_it = true; + break; + } } + if (found_it) + continue; } else { - if (resolver_addresses.find(nlist.n_value) != resolver_adresses.end()) + if (resolver_addresses.find(nlist.n_value) != resolver_addresses.end()) sym[sym_idx].SetType (eSymbolTypeResolver); } } @@ -2883,19 +2891,27 @@ ObjectFileMachO::ParseSymtab () // If we do find a match, and the name matches, then we // can merge the two into just the Static symbol to avoid // duplicate entries in the symbol table - ValueToSymbolIndexMap::const_iterator pos = N_STSYM_addr_to_sym_idx.find (nlist.n_value); - if (pos != N_STSYM_addr_to_sym_idx.end()) + std::pair<ValueToSymbolIndexMap::const_iterator, ValueToSymbolIndexMap::const_iterator> range; + range = N_STSYM_addr_to_sym_idx.equal_range(nlist.n_value); + if (range.first != range.second) { - if (sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(Mangled::ePreferMangled)) + bool found_it = false; + for (ValueToSymbolIndexMap::const_iterator pos = range.first; pos != range.second; ++pos) { - m_nlist_idx_to_sym_idx[nlist_idx] = pos->second; - // We just need the flags from the linker symbol, so put these flags - // into the N_STSYM flags to avoid duplicate symbols in the symbol table - sym[pos->second].SetExternal(sym[sym_idx].IsExternal()); - sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc); - sym[sym_idx].Clear(); - continue; + if (sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(Mangled::ePreferMangled)) + { + m_nlist_idx_to_sym_idx[nlist_idx] = pos->second; + // We just need the flags from the linker symbol, so put these flags + // into the N_STSYM flags to avoid duplicate symbols in the symbol table + sym[pos->second].SetExternal(sym[sym_idx].IsExternal()); + sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc); + sym[sym_idx].Clear(); + found_it = true; + break; + } } + if (found_it) + continue; } else { @@ -3071,7 +3087,7 @@ ObjectFileMachO::ParseSymtab () type = eSymbolTypeCode; symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value); - N_FUN_addr_to_sym_idx[nlist.n_value] = sym_idx; + N_FUN_addr_to_sym_idx.insert(std::make_pair(nlist.n_value, sym_idx)); // We use the current number of symbols in the symbol table in lieu of // using nlist_idx in case we ever start trimming entries out N_FUN_indexes.push_back(sym_idx); @@ -3096,7 +3112,7 @@ ObjectFileMachO::ParseSymtab () case N_STSYM: // static symbol: name,,n_sect,type,address - N_STSYM_addr_to_sym_idx[nlist.n_value] = sym_idx; + N_STSYM_addr_to_sym_idx.insert(std::make_pair(nlist.n_value, sym_idx)); symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value); type = eSymbolTypeData; break; @@ -3607,21 +3623,29 @@ ObjectFileMachO::ParseSymtab () // If we do find a match, and the name matches, then we // can merge the two into just the function symbol to avoid // duplicate entries in the symbol table - ValueToSymbolIndexMap::const_iterator pos = N_FUN_addr_to_sym_idx.find (nlist.n_value); - if (pos != N_FUN_addr_to_sym_idx.end()) + std::pair<ValueToSymbolIndexMap::const_iterator, ValueToSymbolIndexMap::const_iterator> range; + range = N_FUN_addr_to_sym_idx.equal_range(nlist.n_value); + if (range.first != range.second) { - if (sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(Mangled::ePreferMangled)) + bool found_it = false; + for (ValueToSymbolIndexMap::const_iterator pos = range.first; pos != range.second; ++pos) { - m_nlist_idx_to_sym_idx[nlist_idx] = pos->second; - // We just need the flags from the linker symbol, so put these flags - // into the N_FUN flags to avoid duplicate symbols in the symbol table - sym[pos->second].SetExternal(sym[sym_idx].IsExternal()); - sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc); - if (resolver_addresses.find(nlist.n_value) != resolver_addresses.end()) - sym[pos->second].SetType (eSymbolTypeResolver); - sym[sym_idx].Clear(); - continue; + if (sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(Mangled::ePreferMangled)) + { + m_nlist_idx_to_sym_idx[nlist_idx] = pos->second; + // We just need the flags from the linker symbol, so put these flags + // into the N_FUN flags to avoid duplicate symbols in the symbol table + sym[pos->second].SetExternal(sym[sym_idx].IsExternal()); + sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc); + if (resolver_addresses.find(nlist.n_value) != resolver_addresses.end()) + sym[pos->second].SetType (eSymbolTypeResolver); + sym[sym_idx].Clear(); + found_it = true; + break; + } } + if (found_it) + continue; } else { @@ -3635,19 +3659,27 @@ ObjectFileMachO::ParseSymtab () // If we do find a match, and the name matches, then we // can merge the two into just the Static symbol to avoid // duplicate entries in the symbol table - ValueToSymbolIndexMap::const_iterator pos = N_STSYM_addr_to_sym_idx.find (nlist.n_value); - if (pos != N_STSYM_addr_to_sym_idx.end()) + std::pair<ValueToSymbolIndexMap::const_iterator, ValueToSymbolIndexMap::const_iterator> range; + range = N_STSYM_addr_to_sym_idx.equal_range(nlist.n_value); + if (range.first != range.second) { - if (sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(Mangled::ePreferMangled)) + bool found_it = false; + for (ValueToSymbolIndexMap::const_iterator pos = range.first; pos != range.second; ++pos) { - m_nlist_idx_to_sym_idx[nlist_idx] = pos->second; - // We just need the flags from the linker symbol, so put these flags - // into the N_STSYM flags to avoid duplicate symbols in the symbol table - sym[pos->second].SetExternal(sym[sym_idx].IsExternal()); - sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc); - sym[sym_idx].Clear(); - continue; + if (sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled) == sym[pos->second].GetMangled().GetName(Mangled::ePreferMangled)) + { + m_nlist_idx_to_sym_idx[nlist_idx] = pos->second; + // We just need the flags from the linker symbol, so put these flags + // into the N_STSYM flags to avoid duplicate symbols in the symbol table + sym[pos->second].SetExternal(sym[sym_idx].IsExternal()); + sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc); + sym[sym_idx].Clear(); + found_it = true; + break; + } } + if (found_it) + continue; } else { |