Skip to content

Commit d92122e

Browse files
authored
Merge pull request #6861 from jasonmolenda/r109128418-prioritize-text-segment-addr-as-mach-header-59
Prioritize using a segment with the name TEXT instead off fileoff 0
2 parents c8d099f + dbd139b commit d92122e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6141,21 +6141,23 @@ Section *ObjectFileMachO::GetMachHeaderSection() {
61416141
SectionList *section_list = GetSectionList();
61426142
if (!section_list)
61436143
return nullptr;
6144+
6145+
// Some binaries can have a TEXT segment with a non-zero file offset.
6146+
// Binaries in the shared cache are one example. Some hand-generated
6147+
// binaries may not be laid out in the normal TEXT,DATA,LC_SYMTAB order
6148+
// in the file, even though they're laid out correctly in vmaddr terms.
6149+
SectionSP text_segment_sp =
6150+
section_list->FindSectionByName(GetSegmentNameTEXT());
6151+
if (text_segment_sp.get() && SectionIsLoadable(text_segment_sp.get()))
6152+
return text_segment_sp.get();
6153+
61446154
const size_t num_sections = section_list->GetSize();
61456155
for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
61466156
Section *section = section_list->GetSectionAtIndex(sect_idx).get();
61476157
if (section->GetFileOffset() == 0 && SectionIsLoadable(section))
61486158
return section;
61496159
}
61506160

6151-
// We may have a binary in the shared cache that has a non-zero
6152-
// file address for its first segment, traditionally the __TEXT segment.
6153-
// Search for it by name and return it as our next best guess.
6154-
SectionSP text_segment_sp =
6155-
GetSectionList()->FindSectionByName(GetSegmentNameTEXT());
6156-
if (text_segment_sp.get() && SectionIsLoadable(text_segment_sp.get()))
6157-
return text_segment_sp.get();
6158-
61596161
return nullptr;
61606162
}
61616163

0 commit comments

Comments
 (0)