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,7 +928,14 @@ } template -bool ELFObjectFile::isDebugSection(StringRef SectionName) const { +bool ELFObjectFile::isDebugSection(DataRefImpl Sec) const { + Expected SectionNameOrErr = getSectionName(Sec); + if (!SectionNameOrErr) { + // TODO: Report the error message properly. + consumeError(SectionNameOrErr.takeError()); + return false; + } + StringRef SectionName = SectionNameOrErr.get(); return SectionName.startswith(".debug") || SectionName.startswith(".zdebug") || SectionName == ".gdb_index"; } 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/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -328,7 +328,14 @@ // The .debug sections are the only debug sections for COFF // (\see MCObjectFileInfo.cpp). -bool COFFObjectFile::isDebugSection(StringRef SectionName) const { +bool COFFObjectFile::isDebugSection(DataRefImpl Ref) const { + Expected SectionNameOrErr = getSectionName(Ref); + if (!SectionNameOrErr) { + // TODO: Report the error message properly. + consumeError(SectionNameOrErr.takeError()); + return false; + } + StringRef SectionName = SectionNameOrErr.get(); return SectionName.startswith(".debug"); } 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,7 +2035,14 @@ SectionType == MachO::S_GB_ZEROFILL); } -bool MachOObjectFile::isDebugSection(StringRef SectionName) const { +bool MachOObjectFile::isDebugSection(DataRefImpl Sec) const { + Expected SectionNameOrErr = getSectionName(Sec); + if (!SectionNameOrErr) { + // TODO: Report the error message properly. + consumeError(SectionNameOrErr.takeError()); + return false; + } + StringRef SectionName = SectionNameOrErr.get(); return SectionName.startswith("__debug") || SectionName.startswith("__zdebug") || SectionName.startswith("__apple") || SectionName == "__gdb_index" || 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,9 +94,7 @@ return isSectionData(Sec); } -bool ObjectFile::isDebugSection(StringRef SectionName) const { - return false; -} +bool ObjectFile::isDebugSection(DataRefImpl Sec) const { return false; } Expected ObjectFile::getRelocatedSection(DataRefImpl Sec) const { 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();