Author: Alex Langford Date: 2023-02-22T13:22:15-08:00 New Revision: cee05eed2f478630b5435070bdefe06156dc5035
URL: https://github.com/llvm/llvm-project/commit/cee05eed2f478630b5435070bdefe06156dc5035 DIFF: https://github.com/llvm/llvm-project/commit/cee05eed2f478630b5435070bdefe06156dc5035.diff LOG: [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 Added: Modified: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 84856590fe8ad..eaa47359ac882 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -6182,6 +6182,10 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value, size_t num_loaded_sections = 0; const size_t num_sections = section_list->GetSize(); + // Warn if some top-level segments map to the same address. The binary may be + // malformed. + const bool warn_multiple = true; + if (value_is_offset) { // "value" is an offset to apply to each top level segment for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) { @@ -6190,7 +6194,8 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value, SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx)); if (SectionIsLoadable(section_sp.get())) if (target.GetSectionLoadList().SetSectionLoadAddress( - section_sp, section_sp->GetFileAddress() + value)) + section_sp, section_sp->GetFileAddress() + value, + warn_multiple)) ++num_loaded_sections; } } else { @@ -6207,7 +6212,7 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value, value, mach_header_section, section_sp.get()); if (section_load_addr != LLDB_INVALID_ADDRESS) { if (target.GetSectionLoadList().SetSectionLoadAddress( - section_sp, section_load_addr)) + section_sp, section_load_addr, warn_multiple)) ++num_loaded_sections; } } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits