Skip to content

Commit

Permalink
[lldb] Don't persist the LINKEDIT slide in the indirect symbol offset
Browse files Browse the repository at this point in the history
The current code increment the indirect symbol offset with the LINKEDIT
slide every time ObjectFileMachO::ParseSymtab is called.

This resulted in a crash when calling add-dsym which causes us to
potentially re-parse the original binary's symbol table. There's a
separate question about whether we should re-parse the symbol table at
all which was fixed by D114288. Regardless, copying the load command is
cheap enough that this is still the right thing to do.

rdar://72337717

Differential revision: https://reviews.llvm.org/D122349
  • Loading branch information
JDevlieghere committed Mar 23, 2022
1 parent 316f9fd commit b0dc2fa
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
llvm::MachO::linkedit_data_command function_starts_load_command = {0, 0, 0, 0};
llvm::MachO::linkedit_data_command exports_trie_load_command = {0, 0, 0, 0};
llvm::MachO::dyld_info_command dyld_info = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
llvm::MachO::dysymtab_command dysymtab = m_dysymtab;
// The data element of type bool indicates that this entry is thumb
// code.
typedef AddressDataArray<lldb::addr_t, bool, 100> FunctionStarts;
Expand Down Expand Up @@ -2394,12 +2395,12 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
ReadMemory(process_sp, symoff_addr, nlist_data_byte_size));
if (nlist_data_sp)
nlist_data.SetData(nlist_data_sp, 0, nlist_data_sp->GetByteSize());
if (m_dysymtab.nindirectsyms != 0) {
if (dysymtab.nindirectsyms != 0) {
const addr_t indirect_syms_addr = linkedit_load_addr +
m_dysymtab.indirectsymoff -
dysymtab.indirectsymoff -
linkedit_file_offset;
DataBufferSP indirect_syms_data_sp(ReadMemory(
process_sp, indirect_syms_addr, m_dysymtab.nindirectsyms * 4));
process_sp, indirect_syms_addr, dysymtab.nindirectsyms * 4));
if (indirect_syms_data_sp)
indirect_symbol_index_data.SetData(
indirect_syms_data_sp, 0,
Expand Down Expand Up @@ -2452,7 +2453,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
symtab_load_command.symoff += linkedit_slide;
symtab_load_command.stroff += linkedit_slide;
dyld_info.export_off += linkedit_slide;
m_dysymtab.indirectsymoff += linkedit_slide;
dysymtab.indirectsymoff += linkedit_slide;
function_starts_load_command.dataoff += linkedit_slide;
exports_trie_load_command.dataoff += linkedit_slide;
}
Expand All @@ -2474,9 +2475,9 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
exports_trie_load_command.datasize);
}

if (m_dysymtab.nindirectsyms != 0) {
indirect_symbol_index_data.SetData(m_data, m_dysymtab.indirectsymoff,
m_dysymtab.nindirectsyms * 4);
if (dysymtab.nindirectsyms != 0) {
indirect_symbol_index_data.SetData(m_data, dysymtab.indirectsymoff,
dysymtab.nindirectsyms * 4);
}
if (function_starts_load_command.cmd) {
function_starts_data.SetData(m_data, function_starts_load_command.dataoff,
Expand Down

0 comments on commit b0dc2fa

Please sign in to comment.