[ELF] Move SyntheticSections to InputSection.h. NFC

Keep the main SectionBase hierarchy in InputSection.h.
And inline MergeInputSection::getParent.
This commit is contained in:
Fangrui Song
2022-07-30 17:42:08 -07:00
parent c559072e46
commit a465e79f19
3 changed files with 24 additions and 26 deletions

View File

@@ -1343,10 +1343,6 @@ static size_t findNull(StringRef s, size_t entSize) {
llvm_unreachable("");
}
SyntheticSection *MergeInputSection::getParent() const {
return cast_or_null<SyntheticSection>(parent);
}
// Split SHF_STRINGS section. Such section is a sequence of
// null-terminated strings.
void MergeInputSection::splitStrings(StringRef s, size_t entSize) {

View File

@@ -296,7 +296,9 @@ public:
return const_cast<MergeInputSection *>(this)->getSectionPiece(offset);
}
SyntheticSection *getParent() const;
SyntheticSection *getParent() const {
return cast_or_null<SyntheticSection>(parent);
}
private:
void splitStrings(StringRef s, size_t size);
@@ -394,6 +396,27 @@ private:
static_assert(sizeof(InputSection) <= 160, "InputSection is too big");
class SyntheticSection : public InputSection {
public:
SyntheticSection(uint64_t flags, uint32_t type, uint32_t alignment,
StringRef name)
: InputSection(nullptr, flags, type, alignment, {}, name,
InputSectionBase::Synthetic) {}
virtual ~SyntheticSection() = default;
virtual size_t getSize() const = 0;
virtual bool updateAllocSize() { return false; }
// If the section has the SHF_ALLOC flag and the size may be changed if
// thunks are added, update the section size.
virtual bool isNeeded() const { return true; }
virtual void finalizeContents() {}
virtual void writeTo(uint8_t *buf) = 0;
static bool classof(const SectionBase *sec) {
return sec->kind() == InputSectionBase::Synthetic;
}
};
inline bool isDebugSection(const InputSectionBase &sec) {
return (sec.flags & llvm::ELF::SHF_ALLOC) == 0 &&
sec.name.startswith(".debug");

View File

@@ -34,27 +34,6 @@ class Defined;
struct PhdrEntry;
class SymbolTableBaseSection;
class SyntheticSection : public InputSection {
public:
SyntheticSection(uint64_t flags, uint32_t type, uint32_t alignment,
StringRef name)
: InputSection(nullptr, flags, type, alignment, {}, name,
InputSectionBase::Synthetic) {}
virtual ~SyntheticSection() = default;
virtual void writeTo(uint8_t *buf) = 0;
virtual size_t getSize() const = 0;
virtual void finalizeContents() {}
// If the section has the SHF_ALLOC flag and the size may be changed if
// thunks are added, update the section size.
virtual bool updateAllocSize() { return false; }
virtual bool isNeeded() const { return true; }
static bool classof(const SectionBase *d) {
return d->kind() == InputSectionBase::Synthetic;
}
};
struct CieRecord {
EhSectionPiece *cie = nullptr;
SmallVector<EhSectionPiece *, 0> fdes;