[PATCH] D30084: [ELF] - Move DependentSections vector from InputSection to InputSectionBase

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 17 02:13:19 PST 2017


grimar created this revision.

I splitted it from https://reviews.llvm.org/D29273.
Since we plan to make relocatable sections as dependent for target ones for
--emit-relocs implementation, this change is required to support .eh_frame case.

EhInputSection inherets from InputSectionBase and not from InputSection.
So for case when it has relocation section, it should be able to access DependentSections
vector.

This case is real for Linux kernel.


https://reviews.llvm.org/D30084

Files:
  ELF/InputFiles.cpp
  ELF/InputSection.h
  ELF/LinkerScript.cpp


Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -277,11 +277,7 @@
   for (InputSectionBase<ELFT> *S : V) {
     S->Live = false;
     reportDiscarded(S);
-
-    InputSection<ELFT> *IS = dyn_cast<InputSection<ELFT>>(S);
-    if (!IS || IS->DependentSections.empty())
-      continue;
-    discard(IS->DependentSections);
+    discard(S->DependentSections);
   }
 }
 
Index: ELF/InputSection.h
===================================================================
--- ELF/InputSection.h
+++ ELF/InputSection.h
@@ -128,6 +128,9 @@
   // this but instead this->Repl.
   InputSectionBase<ELFT> *Repl;
 
+  // InputSections that are dependent on us (reverse dependency for GC)
+  llvm::TinyPtrVector<InputSectionBase<ELFT> *> DependentSections;
+
   // Returns the size of this section (even if this is a common or BSS.)
   size_t getSize() const;
 
@@ -281,9 +284,6 @@
   // to. The writer sets a value.
   uint64_t OutSecOff = 0;
 
-  // InputSections that are dependent on us (reverse dependency for GC)
-  llvm::TinyPtrVector<InputSectionBase<ELFT> *> DependentSections;
-
   static bool classof(const InputSectionData *S);
 
   InputSectionBase<ELFT> *getRelocatedSection();
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -322,8 +322,7 @@
       if (Sec.sh_link >= Sections.size())
         fatal(toString(this) + ": invalid sh_link index: " +
               Twine(Sec.sh_link));
-      auto *IS = cast<InputSection<ELFT>>(Sections[Sec.sh_link]);
-      IS->DependentSections.push_back(Sections[I]);
+      Sections[Sec.sh_link]->DependentSections.push_back(Sections[I]);
     }
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30084.88867.patch
Type: text/x-patch
Size: 1781 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170217/40c003cc/attachment.bin>


More information about the llvm-commits mailing list