Skip to content

Commit 765d4c4

Browse files
authored
[lldb] [ObjectFileMachO] LLVM_COV is not mapped into firmware memory (llvm#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
1 parent cb994d4 commit 765d4c4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,11 @@ ConstString ObjectFileMachO::GetSegmentNameDWARF() {
905905
return g_section_name;
906906
}
907907

908+
ConstString ObjectFileMachO::GetSegmentNameLLVM_COV() {
909+
static ConstString g_section_name("__LLVM_COV");
910+
return g_section_name;
911+
}
912+
908913
ConstString ObjectFileMachO::GetSectionNameEHFrame() {
909914
static ConstString g_section_name_eh_frame("__eh_frame");
910915
return g_section_name_eh_frame;
@@ -6145,6 +6150,13 @@ bool ObjectFileMachO::SectionIsLoadable(const Section *section) {
61456150
return false;
61466151
if (GetModule().get() != section->GetModule().get())
61476152
return false;
6153+
// firmware style binaries with llvm gcov segment do
6154+
// not have that segment mapped into memory.
6155+
if (section->GetName() == GetSegmentNameLLVM_COV()) {
6156+
const Strata strata = GetStrata();
6157+
if (strata == eStrataKernel || strata == eStrataRawImage)
6158+
return false;
6159+
}
61486160
// Be careful with __LINKEDIT and __DWARF segments
61496161
if (section->GetName() == GetSegmentNameLINKEDIT() ||
61506162
section->GetName() == GetSegmentNameDWARF()) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
271271
static lldb_private::ConstString GetSegmentNameOBJC();
272272
static lldb_private::ConstString GetSegmentNameLINKEDIT();
273273
static lldb_private::ConstString GetSegmentNameDWARF();
274+
static lldb_private::ConstString GetSegmentNameLLVM_COV();
274275
static lldb_private::ConstString GetSectionNameEHFrame();
275276

276277
llvm::MachO::dysymtab_command m_dysymtab;

0 commit comments

Comments
 (0)