Author: Jason Molenda Date: 2024-03-25T15:00:36-07:00 New Revision: 765d4c402fe2ff614a15a762bb7cefe7289663b4
URL: https://github.com/llvm/llvm-project/commit/765d4c402fe2ff614a15a762bb7cefe7289663b4 DIFF: https://github.com/llvm/llvm-project/commit/765d4c402fe2ff614a15a762bb7cefe7289663b4.diff LOG: [lldb] [ObjectFileMachO] LLVM_COV is not mapped into firmware memory (#86359) It is possible to gather code coverage in a firmware environment, where the __LLVM_COV segment will not be mapped in memory but does exist in the binary, see https://llvm.org/devmtg/2020-09/slides/PhippsAlan_EmbeddedCodeCoverage_LLVM_Conf_Talk_final.pdf The __LLVM_COV segment in the binary happens to be at the same address as the __DATA segment, so if lldb treats this segment as loaded, it shadows the __DATA segment and address->symbol resolution can fail. For these non-userland code cases, we need to mark __LLVM_COV as not a loadable segment. rdar://124475661 Added: Modified: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h Removed: ################################################################################ diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index bcf3a3274cf3a0..1caf93659956b4 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -905,6 +905,11 @@ ConstString ObjectFileMachO::GetSegmentNameDWARF() { return g_section_name; } +ConstString ObjectFileMachO::GetSegmentNameLLVM_COV() { + static ConstString g_section_name("__LLVM_COV"); + return g_section_name; +} + ConstString ObjectFileMachO::GetSectionNameEHFrame() { static ConstString g_section_name_eh_frame("__eh_frame"); return g_section_name_eh_frame; @@ -6145,6 +6150,13 @@ bool ObjectFileMachO::SectionIsLoadable(const Section *section) { return false; if (GetModule().get() != section->GetModule().get()) return false; + // firmware style binaries with llvm gcov segment do + // not have that segment mapped into memory. + if (section->GetName() == GetSegmentNameLLVM_COV()) { + const Strata strata = GetStrata(); + if (strata == eStrataKernel || strata == eStrataRawImage) + return false; + } // Be careful with __LINKEDIT and __DWARF segments if (section->GetName() == GetSegmentNameLINKEDIT() || section->GetName() == GetSegmentNameDWARF()) { diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h index 0a47f3a7dd1861..55bc688126eb36 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h @@ -271,6 +271,7 @@ class ObjectFileMachO : public lldb_private::ObjectFile { static lldb_private::ConstString GetSegmentNameOBJC(); static lldb_private::ConstString GetSegmentNameLINKEDIT(); static lldb_private::ConstString GetSegmentNameDWARF(); + static lldb_private::ConstString GetSegmentNameLLVM_COV(); static lldb_private::ConstString GetSectionNameEHFrame(); llvm::MachO::dysymtab_command m_dysymtab; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits