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 @@ -959,7 +959,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; + bool isDebugSection(DataRefImpl Sec) 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 @@ -289,7 +289,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; + bool isDebugSection(DataRefImpl Sec) 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; @@ -928,9 +928,13 @@ } template -bool ELFObjectFile::isDebugSection(StringRef SectionName) const { - return SectionName.startswith(".debug") || - SectionName.startswith(".zdebug") || SectionName == ".gdb_index"; +bool ELFObjectFile::isDebugSection(DataRefImpl Sec) const { + if (Expected SectionNameOrErr = getSectionName(Sec)) { + StringRef SectionName = SectionNameOrErr.get(); + return SectionName.startswith(".debug") || + SectionName.startswith(".zdebug") || SectionName == ".gdb_index"; + } + return false; } template 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,7 +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; + bool isDebugSection(DataRefImpl Sec) 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,7 +123,7 @@ bool isBerkeleyData() const; /// Whether this section is a debug section. - bool isDebugSection(StringRef SectionName) const; + bool isDebugSection() const; bool containsSymbol(SymbolRef S) const; @@ -274,7 +274,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 bool isDebugSection(DataRefImpl Sec) 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; @@ -504,8 +504,8 @@ return OwningObject->isBerkeleyData(SectionPimpl); } -inline bool SectionRef::isDebugSection(StringRef SectionName) const { - return OwningObject->isDebugSection(SectionName); +inline bool SectionRef::isDebugSection() const { + return OwningObject->isDebugSection(SectionPimpl); } inline relocation_iterator SectionRef::relocation_begin() const { diff --git a/llvm/include/llvm/Object/XCOFFObjectFile.h b/llvm/include/llvm/Object/XCOFFObjectFile.h --- a/llvm/include/llvm/Object/XCOFFObjectFile.h +++ b/llvm/include/llvm/Object/XCOFFObjectFile.h @@ -338,6 +338,7 @@ bool isSectionText(DataRefImpl Sec) const override; bool isSectionData(DataRefImpl Sec) const override; bool isSectionBSS(DataRefImpl Sec) const override; + bool isDebugSection(DataRefImpl Sec) const override; bool isSectionVirtual(DataRefImpl Sec) const override; relocation_iterator section_rel_begin(DataRefImpl Sec) const override; 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,8 +328,12 @@ // The .debug sections are the only debug sections for COFF // (\see MCObjectFileInfo.cpp). -bool COFFObjectFile::isDebugSection(StringRef SectionName) const { - return SectionName.startswith(".debug"); +bool COFFObjectFile::isDebugSection(DataRefImpl Ref) const { + if (Expected SectionNameOrErr = getSectionName(Ref)) { + StringRef SectionName = SectionNameOrErr.get(); + return SectionName.startswith(".debug"); + } + return false; } unsigned COFFObjectFile::getSectionID(SectionRef Sec) const { 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 @@ -2035,11 +2035,15 @@ SectionType == MachO::S_GB_ZEROFILL); } -bool MachOObjectFile::isDebugSection(StringRef SectionName) const { - return SectionName.startswith("__debug") || - SectionName.startswith("__zdebug") || - SectionName.startswith("__apple") || SectionName == "__gdb_index" || - SectionName == "__swift_ast"; +bool MachOObjectFile::isDebugSection(DataRefImpl Sec) const { + if (Expected SectionNameOrErr = getSectionName(Sec)) { + StringRef SectionName = SectionNameOrErr.get(); + return SectionName.startswith("__debug") || + SectionName.startswith("__zdebug") || + SectionName.startswith("__apple") || SectionName == "__gdb_index" || + SectionName == "__swift_ast"; + } + return false; } unsigned MachOObjectFile::getSectionID(SectionRef Sec) const { 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 @@ -94,7 +94,7 @@ return isSectionData(Sec); } -bool ObjectFile::isDebugSection(StringRef SectionName) const { +bool ObjectFile::isDebugSection(DataRefImpl Sec) const { return false; } diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp --- a/llvm/lib/Object/XCOFFObjectFile.cpp +++ b/llvm/lib/Object/XCOFFObjectFile.cpp @@ -304,6 +304,11 @@ return Flags & (XCOFF::STYP_BSS | XCOFF::STYP_TBSS); } +bool XCOFFObjectFile::isDebugSection(DataRefImpl Sec) const { + uint32_t Flags = getSectionFlags(Sec); + return Flags & (XCOFF::STYP_DEBUG | XCOFF::STYP_DWARF); +} + bool XCOFFObjectFile::isSectionVirtual(DataRefImpl Sec) const { return is64Bit() ? toSection64(Sec)->FileOffsetToRawData == 0 : toSection32(Sec)->FileOffsetToRawData == 0; diff --git a/llvm/tools/llvm-dwarfdump/SectionSizes.cpp b/llvm/tools/llvm-dwarfdump/SectionSizes.cpp --- a/llvm/tools/llvm-dwarfdump/SectionSizes.cpp +++ b/llvm/tools/llvm-dwarfdump/SectionSizes.cpp @@ -93,7 +93,7 @@ LLVM_DEBUG(dbgs() << SectionName.str() << ": " << Section.getSize() << '\n'); - if (!Section.isDebugSection(SectionName)) + if (!Section.isDebugSection()) continue; Sizes.TotalDebugSectionsSize += Section.getSize();