diff --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h --- a/llvm/include/llvm/Object/COFF.h +++ b/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; diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h --- a/llvm/include/llvm/Object/ELFObjectFile.h +++ b/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; @@ -814,6 +815,12 @@ } 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 { DataRefImpl RelData; diff --git a/llvm/include/llvm/Object/MachO.h b/llvm/include/llvm/Object/MachO.h --- a/llvm/include/llvm/Object/MachO.h +++ b/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 diff --git a/llvm/include/llvm/Object/ObjectFile.h b/llvm/include/llvm/Object/ObjectFile.h --- a/llvm/include/llvm/Object/ObjectFile.h +++ b/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); } diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -328,6 +328,12 @@ return (Sec->Characteristics & BssFlags) == BssFlags; } +// The .debug sections are the only debug sections for COFF +// (\see MCObjectFileInfo.cpp). +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); diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/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; } diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp --- a/llvm/lib/Object/ObjectFile.cpp +++ b/llvm/lib/Object/ObjectFile.cpp @@ -91,6 +91,10 @@ return isSectionData(Sec); } +bool ObjectFile::isDebugSection(StringRef SectionName) const { + return false; +} + Expected ObjectFile::getRelocatedSection(DataRefImpl Sec) const { return section_iterator(SectionRef(Sec, this));