Check to make sure we have a valid N_GSYM symbol name before we use it for anything.

llvm-svn: 241210
This commit is contained in:
Greg Clayton 2015-07-01 23:29:06 +00:00
parent e521457db3
commit 14cd13c513
1 changed files with 45 additions and 29 deletions

View File

@ -3386,7 +3386,11 @@ ObjectFileMachO::ParseSymtab ()
ConstString const_symbol_name(symbol_name); ConstString const_symbol_name(symbol_name);
sym[sym_idx].GetMangled().SetValue(const_symbol_name, symbol_name_is_mangled); sym[sym_idx].GetMangled().SetValue(const_symbol_name, symbol_name_is_mangled);
if (is_gsym && is_debug) if (is_gsym && is_debug)
N_GSYM_name_to_sym_idx[sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString()] = sym_idx; {
const char *gsym_name = sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString();
if (gsym_name)
N_GSYM_name_to_sym_idx[gsym_name] = sym_idx;
}
} }
} }
if (symbol_section) if (symbol_section)
@ -3513,21 +3517,25 @@ ObjectFileMachO::ParseSymtab ()
} }
else else
{ {
// Combine N_GSYM stab entries with the non stab symbol const char *gsym_name = sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString();
ConstNameToSymbolIndexMap::const_iterator pos = N_GSYM_name_to_sym_idx.find(sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString()); if (gsym_name)
if (pos != N_GSYM_name_to_sym_idx.end())
{ {
const uint32_t GSYM_sym_idx = pos->second; // Combine N_GSYM stab entries with the non stab symbol
m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx; ConstNameToSymbolIndexMap::const_iterator pos = N_GSYM_name_to_sym_idx.find(gsym_name);
// Copy the address, because often the N_GSYM address has an invalid address of zero if (pos != N_GSYM_name_to_sym_idx.end())
// when the global is a common symbol {
sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section); const uint32_t GSYM_sym_idx = pos->second;
sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value); m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx;
// We just need the flags from the linker symbol, so put these flags // Copy the address, because often the N_GSYM address has an invalid address of zero
// into the N_GSYM flags to avoid duplicate symbols in the symbol table // when the global is a common symbol
sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc); sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section);
sym[sym_idx].Clear(); sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value);
continue; // We just need the flags from the linker symbol, so put these flags
// into the N_GSYM flags to avoid duplicate symbols in the symbol table
sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
sym[sym_idx].Clear();
continue;
}
} }
} }
} }
@ -4235,7 +4243,11 @@ ObjectFileMachO::ParseSymtab ()
} }
if (is_gsym) if (is_gsym)
N_GSYM_name_to_sym_idx[sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString()] = sym_idx; {
const char *gsym_name = sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString();
if (gsym_name)
N_GSYM_name_to_sym_idx[gsym_name] = sym_idx;
}
if (symbol_section) if (symbol_section)
{ {
@ -4357,20 +4369,24 @@ ObjectFileMachO::ParseSymtab ()
else else
{ {
// Combine N_GSYM stab entries with the non stab symbol // Combine N_GSYM stab entries with the non stab symbol
ConstNameToSymbolIndexMap::const_iterator pos = N_GSYM_name_to_sym_idx.find(sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString()); const char *gsym_name = sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString();
if (pos != N_GSYM_name_to_sym_idx.end()) if (gsym_name)
{ {
const uint32_t GSYM_sym_idx = pos->second; ConstNameToSymbolIndexMap::const_iterator pos = N_GSYM_name_to_sym_idx.find(gsym_name);
m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx; if (pos != N_GSYM_name_to_sym_idx.end())
// Copy the address, because often the N_GSYM address has an invalid address of zero {
// when the global is a common symbol const uint32_t GSYM_sym_idx = pos->second;
sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section); m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx;
sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value); // Copy the address, because often the N_GSYM address has an invalid address of zero
// We just need the flags from the linker symbol, so put these flags // when the global is a common symbol
// into the N_GSYM flags to avoid duplicate symbols in the symbol table sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section);
sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc); sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value);
sym[sym_idx].Clear(); // We just need the flags from the linker symbol, so put these flags
continue; // into the N_GSYM flags to avoid duplicate symbols in the symbol table
sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
sym[sym_idx].Clear();
continue;
}
} }
} }
} }