From 4a394367c124172dff26ef5042ecd6fa666a6e07 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Mon, 14 Feb 2022 11:09:34 -0800 Subject: [PATCH] Alt mechanism to find the first loadable seg in a Mach-O binary 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 --- .../source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 131d1932fe14..ff4d0a1cc41c 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -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; }