Index: llvm/include/llvm/Object/COFF.h =================================================================== --- llvm/include/llvm/Object/COFF.h +++ llvm/include/llvm/Object/COFF.h @@ -912,6 +912,7 @@ bool isSectionData(DataRefImpl Sec) const override; bool isSectionBSS(DataRefImpl Sec) const override; bool isSectionVirtual(DataRefImpl Sec) const override; + bool isDebugSection(StringRef SectionName) const override; relocation_iterator section_rel_begin(DataRefImpl Sec) const override; relocation_iterator section_rel_end(DataRefImpl Sec) const override; Index: llvm/include/llvm/Object/ELFObjectFile.h =================================================================== --- llvm/include/llvm/Object/ELFObjectFile.h +++ llvm/include/llvm/Object/ELFObjectFile.h @@ -285,6 +285,7 @@ bool isSectionVirtual(DataRefImpl Sec) const override; bool isBerkeleyText(DataRefImpl Sec) const override; bool isBerkeleyData(DataRefImpl Sec) const override; + bool isDebugSection(StringRef SectionName) const override; relocation_iterator section_rel_begin(DataRefImpl Sec) const override; relocation_iterator section_rel_end(DataRefImpl Sec) const override; std::vector dynamic_relocation_sections() const override; @@ -812,6 +813,12 @@ EShdr->sh_flags & ELF::SHF_ALLOC; } +template +bool ELFObjectFile::isDebugSection(StringRef SectionName) const { + return SectionName.startswith(".debug") || + SectionName.startswith(".zdebug") || SectionName == ".gdb_index"; +} + template relocation_iterator ELFObjectFile::section_rel_begin(DataRefImpl Sec) const { Index: llvm/include/llvm/Object/MachO.h =================================================================== --- llvm/include/llvm/Object/MachO.h +++ llvm/include/llvm/Object/MachO.h @@ -309,6 +309,7 @@ bool isSectionBSS(DataRefImpl Sec) const override; bool isSectionVirtual(DataRefImpl Sec) const override; bool isSectionBitcode(DataRefImpl Sec) const override; + bool isDebugSection(StringRef SectionName) const override; /// When dsymutil generates the companion file, it strips all unnecessary /// sections (e.g. everything in the _TEXT segment) by omitting their body Index: llvm/include/llvm/Object/ObjectFile.h =================================================================== --- llvm/include/llvm/Object/ObjectFile.h +++ llvm/include/llvm/Object/ObjectFile.h @@ -123,6 +123,9 @@ /// contains data (e.g. PROGBITS), but is not text. bool isBerkeleyData() const; + /// Whether this section is a debug section. + bool isDebugSection(StringRef SectionName) const; + bool containsSymbol(SymbolRef S) const; relocation_iterator relocation_begin() const; @@ -272,6 +275,7 @@ virtual bool isSectionStripped(DataRefImpl Sec) const; virtual bool isBerkeleyText(DataRefImpl Sec) const; virtual bool isBerkeleyData(DataRefImpl Sec) const; + virtual bool isDebugSection(StringRef SectionName) const; virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0; virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0; virtual Expected getRelocatedSection(DataRefImpl Sec) const; @@ -495,6 +499,10 @@ return OwningObject->isBerkeleyData(SectionPimpl); } +inline bool SectionRef::isDebugSection(StringRef SectionName) const { + return OwningObject->isDebugSection(SectionName); +} + inline relocation_iterator SectionRef::relocation_begin() const { return OwningObject->section_rel_begin(SectionPimpl); } Index: llvm/lib/Object/COFFObjectFile.cpp =================================================================== --- llvm/lib/Object/COFFObjectFile.cpp +++ llvm/lib/Object/COFFObjectFile.cpp @@ -328,6 +328,10 @@ return (Sec->Characteristics & BssFlags) == BssFlags; } +bool COFFObjectFile::isDebugSection(StringRef SectionName) const { + return SectionName.startswith(".debug"); +} + unsigned COFFObjectFile::getSectionID(SectionRef Sec) const { uintptr_t Offset = uintptr_t(Sec.getRawDataRefImpl().p) - uintptr_t(SectionTable); Index: llvm/lib/Object/MachOObjectFile.cpp =================================================================== --- llvm/lib/Object/MachOObjectFile.cpp +++ llvm/lib/Object/MachOObjectFile.cpp @@ -2030,6 +2030,11 @@ SectionType == MachO::S_GB_ZEROFILL); } +bool MachOObjectFile::isDebugSection(StringRef SectionName) const { + return SectionName.startswith("__debug") || + SectionName.startswith("__zdebug") || SectionName == "__gdb_index"; +} + unsigned MachOObjectFile::getSectionID(SectionRef Sec) const { return Sec.getRawDataRefImpl().d.a; } Index: llvm/lib/Object/ObjectFile.cpp =================================================================== --- llvm/lib/Object/ObjectFile.cpp +++ llvm/lib/Object/ObjectFile.cpp @@ -91,6 +91,10 @@ return isSectionData(Sec); } +bool ObjectFile::isDebugSection(StringRef SectionName) const { + return isDebugSection(SectionName); +} + Expected ObjectFile::getRelocatedSection(DataRefImpl Sec) const { return section_iterator(SectionRef(Sec, this));