1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[Object] Add the method for checking if a section is a debug section

Different file formats have different naming style for the debug
sections. The method is implemented for ELF, COFF and Mach-O formats.

Differential Revision: https://reviews.llvm.org/D76276
This commit is contained in:
Djordje Todorovic 2020-04-02 10:00:18 +02:00
parent d97943eb3e
commit df20828951
7 changed files with 32 additions and 0 deletions

View File

@ -912,6 +912,7 @@ protected:
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;

View File

@ -285,6 +285,7 @@ protected:
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<SectionRef> dynamic_relocation_sections() const override;
@ -813,6 +814,12 @@ bool ELFObjectFile<ELFT>::isBerkeleyData(DataRefImpl Sec) const {
EShdr->sh_flags & ELF::SHF_ALLOC;
}
template <class ELFT>
bool ELFObjectFile<ELFT>::isDebugSection(StringRef SectionName) const {
return SectionName.startswith(".debug") ||
SectionName.startswith(".zdebug") || SectionName == ".gdb_index";
}
template <class ELFT>
relocation_iterator
ELFObjectFile<ELFT>::section_rel_begin(DataRefImpl Sec) const {

View File

@ -309,6 +309,7 @@ public:
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

View File

@ -123,6 +123,9 @@ public:
/// 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 @@ protected:
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<section_iterator> getRelocatedSection(DataRefImpl Sec) const;
@ -495,6 +499,10 @@ inline bool SectionRef::isBerkeleyData() const {
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);
}

View File

@ -328,6 +328,12 @@ bool COFFObjectFile::isSectionBSS(DataRefImpl Ref) const {
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);

View File

@ -2030,6 +2030,11 @@ bool MachOObjectFile::isSectionBSS(DataRefImpl Sec) const {
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;
}

View File

@ -91,6 +91,10 @@ bool ObjectFile::isBerkeleyData(DataRefImpl Sec) const {
return isSectionData(Sec);
}
bool ObjectFile::isDebugSection(StringRef SectionName) const {
return false;
}
Expected<section_iterator>
ObjectFile::getRelocatedSection(DataRefImpl Sec) const {
return section_iterator(SectionRef(Sec, this));