Skip to content

Commit

Permalink
Alt mechanism to find the first loadable seg in a Mach-O binary
Browse files Browse the repository at this point in the history
ObjectFileMachO, for a couple of special binaries at the initial
launch, needs to find segment load addresses before the Target's
SectionLoadList has been initialized. The calculation to find
the first segment, which is at the same address as the mach header,
was not correct if the binary was in the Darwin shared cache.
Update the logic to handle that case.

Differential Revision: https://reviews.llvm.org/D119602
rdar://88802629
  • Loading branch information
jasonmolenda committed Feb 14, 2022
1 parent b85cfe2 commit 4a39436
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Expand Up @@ -6102,6 +6102,15 @@ Section *ObjectFileMachO::GetMachHeaderSection() {
if (section->GetFileOffset() == 0 && SectionIsLoadable(section))
return section;
}

// We may have a binary in the shared cache that has a non-zero
// file address for its first segment, traditionally the __TEXT segment.
// Search for it by name and return it as our next best guess.
SectionSP text_segment_sp =
GetSectionList()->FindSectionByName(GetSegmentNameTEXT());
if (text_segment_sp.get() && SectionIsLoadable(text_segment_sp.get()))
return text_segment_sp.get();

return nullptr;
}

Expand Down

0 comments on commit 4a39436

Please sign in to comment.