Index: include/llvm/Object/MachO.h =================================================================== --- include/llvm/Object/MachO.h +++ include/llvm/Object/MachO.h @@ -310,6 +310,7 @@ bool isSectionBSS(DataRefImpl Sec) const override; bool isSectionVirtual(DataRefImpl Sec) const override; bool isSectionBitcode(DataRefImpl Sec) const override; + bool isSectionStripped(DataRefImpl Sec) const override; relocation_iterator section_rel_begin(DataRefImpl Sec) const override; relocation_iterator section_rel_end(DataRefImpl Sec) const override; Index: include/llvm/Object/ObjectFile.h =================================================================== --- include/llvm/Object/ObjectFile.h +++ include/llvm/Object/ObjectFile.h @@ -109,6 +109,7 @@ bool isBSS() const; bool isVirtual() const; bool isBitcode() const; + bool isStripped() const; bool containsSymbol(SymbolRef S) const; @@ -236,6 +237,7 @@ // A section is 'virtual' if its contents aren't present in the object image. virtual bool isSectionVirtual(DataRefImpl Sec) const = 0; virtual bool isSectionBitcode(DataRefImpl Sec) const; + virtual bool isSectionStripped(DataRefImpl Sec) const; virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0; virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0; virtual section_iterator getRelocatedSection(DataRefImpl Sec) const; @@ -442,6 +444,10 @@ return OwningObject->isSectionBitcode(SectionPimpl); } +inline bool SectionRef::isStripped() const { + return OwningObject->isSectionStripped(SectionPimpl); +} + inline relocation_iterator SectionRef::relocation_begin() const { return OwningObject->section_rel_begin(SectionPimpl); } Index: lib/DebugInfo/DWARF/DWARFContext.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFContext.cpp +++ lib/DebugInfo/DWARF/DWARFContext.cpp @@ -1131,6 +1131,10 @@ if (Section.isBSS() || Section.isVirtual()) continue; + // Skip sections stripped by dsymutil. + if (Section.isStripped()) + continue; + StringRef Data; section_iterator RelocatedSection = Section.getRelocatedSection(); // Try to obtain an already relocated version of this section. Index: lib/Object/MachOObjectFile.cpp =================================================================== --- lib/Object/MachOObjectFile.cpp +++ lib/Object/MachOObjectFile.cpp @@ -1928,6 +1928,12 @@ return false; } +bool MachOObjectFile::isSectionStripped(DataRefImpl Sec) const { + if (is64Bit()) + return getSection64(Sec).offset == 0; + return getSection(Sec).offset == 0; +} + relocation_iterator MachOObjectFile::section_rel_begin(DataRefImpl Sec) const { DataRefImpl Ret; Ret.d.a = Sec.d.a; Index: lib/Object/ObjectFile.cpp =================================================================== --- lib/Object/ObjectFile.cpp +++ lib/Object/ObjectFile.cpp @@ -75,6 +75,8 @@ return false; } +bool ObjectFile::isSectionStripped(DataRefImpl Sec) const { return false; } + section_iterator ObjectFile::getRelocatedSection(DataRefImpl Sec) const { return section_iterator(SectionRef(Sec, this)); } Index: test/tools/llvm-dwarfdump/X86/Inputs/foo.c =================================================================== --- /dev/null +++ test/tools/llvm-dwarfdump/X86/Inputs/foo.c @@ -0,0 +1 @@ +int foo(int i) { return i; } Index: test/tools/llvm-dwarfdump/X86/stripped.test =================================================================== --- /dev/null +++ test/tools/llvm-dwarfdump/X86/stripped.test @@ -0,0 +1,12 @@ +RUN: clang -g -O0 -fexceptions %S/Inputs/foo.c -c -o %t.o +RUN: dsymutil %t.o -flat -o %t.dsym +RUN: llvm-dwarfdump -debug-frame %t.dsym | FileCheck %s + +This generates an empty dSYM companion file with a stripped .eh_frame section. + +CHECK: .debug_frame contents: +CHECK-NOT: CIE +CHECK-NOT: FDE +CHECK: .eh_frame contents: +CHECK-NOT: CIE +CHECK-NOT: FDE