[lld] a465e79 - [ELF] Move SyntheticSections to InputSection.h. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 30 17:42:18 PDT 2022


Author: Fangrui Song
Date: 2022-07-30T17:42:08-07:00
New Revision: a465e79f19569bca2201e6d71ff8cb89c87dd6fb

URL: https://github.com/llvm/llvm-project/commit/a465e79f19569bca2201e6d71ff8cb89c87dd6fb
DIFF: https://github.com/llvm/llvm-project/commit/a465e79f19569bca2201e6d71ff8cb89c87dd6fb.diff

LOG: [ELF] Move SyntheticSections to InputSection.h. NFC

Keep the main SectionBase hierarchy in InputSection.h.
And inline MergeInputSection::getParent.

Added: 
    

Modified: 
    lld/ELF/InputSection.cpp
    lld/ELF/InputSection.h
    lld/ELF/SyntheticSections.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 8fe36eca6a4b..e8fbab0666ec 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -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) {

diff  --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index d1b889750bbd..73b2bdaf58be 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -296,7 +296,9 @@ class MergeInputSection : public InputSectionBase {
     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 @@ class InputSection : public InputSectionBase {
 
 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");

diff  --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 2ac89d51e387..120532245f63 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -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;


        


More information about the llvm-commits mailing list