Skip to content

Commit 94f51a3

Browse files
committed
[lldb] Warn when Mach-O files have overlapping segments
I recently came across a binary that for some reason had overlapping sections. When debugging it, LLDB was able to get information about one of the sections but not the other because SectionLoadList assumes that each address maps to exactly one section. We have the capability to warn about this, but it was not turned on. rdar://105751700 Differential Revision: https://reviews.llvm.org/D144528 (cherry picked from commit cee05ee)
1 parent 34096e4 commit 94f51a3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6207,6 +6207,10 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value,
62076207
size_t num_loaded_sections = 0;
62086208
const size_t num_sections = section_list->GetSize();
62096209

6210+
// Warn if some top-level segments map to the same address. The binary may be
6211+
// malformed.
6212+
const bool warn_multiple = true;
6213+
62106214
if (value_is_offset) {
62116215
// "value" is an offset to apply to each top level segment
62126216
for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
@@ -6215,7 +6219,8 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value,
62156219
SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
62166220
if (SectionIsLoadable(section_sp.get()))
62176221
if (target.GetSectionLoadList().SetSectionLoadAddress(
6218-
section_sp, section_sp->GetFileAddress() + value))
6222+
section_sp, section_sp->GetFileAddress() + value,
6223+
warn_multiple))
62196224
++num_loaded_sections;
62206225
}
62216226
} else {
@@ -6232,7 +6237,7 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value,
62326237
value, mach_header_section, section_sp.get());
62336238
if (section_load_addr != LLDB_INVALID_ADDRESS) {
62346239
if (target.GetSectionLoadList().SetSectionLoadAddress(
6235-
section_sp, section_load_addr))
6240+
section_sp, section_load_addr, warn_multiple))
62366241
++num_loaded_sections;
62376242
}
62386243
}

0 commit comments

Comments
 (0)