[PATCH] D29170: [ELF] - Remove unnessesary checks.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 26 01:34:17 PST 2017


grimar created this revision.

We set Live bit in constructor of InputSectionBase currently.
If it is set, then section should not be collected.

Previously GC code contained few excessive checks for that, thrown around in code.
And when I was need in https://reviews.llvm.org/D28612 to prevent GC for .rel[a] sections,
I had to modify that places. Though it is cleaner to remove them at all, because
we already have a Live bit set, what looks to be enough.

That should help to reduce amoount of changes for https://reviews.llvm.org/D28612.


https://reviews.llvm.org/D29170

Files:
  ELF/InputSection.h
  ELF/MarkLive.cpp


Index: ELF/MarkLive.cpp
===================================================================
--- ELF/MarkLive.cpp
+++ ELF/MarkLive.cpp
@@ -156,20 +156,16 @@
     scanEhFrameSection(EH, EH.rels(), Enqueue);
 }
 
-// We do not garbage-collect two types of sections:
-// 1) Sections used by the loader (.init, .fini, .ctors, .dtors or .jcr)
-// 2) Non-allocatable sections which typically contain debugging information
+// We do not garbage-collect sections used by the loader (.init, .fini, .ctors,
+// .dtors or .jcr)
 template <class ELFT> static bool isReserved(InputSectionBase<ELFT> *Sec) {
   switch (Sec->Type) {
   case SHT_FINI_ARRAY:
   case SHT_INIT_ARRAY:
   case SHT_NOTE:
   case SHT_PREINIT_ARRAY:
     return true;
   default:
-    if (!(Sec->Flags & SHF_ALLOC))
-      return true;
-
     // We do not want to reclaim sections if they can be referred
     // by __start_* and __stop_* symbols.
     StringRef S = Sec->Name;
@@ -196,10 +192,6 @@
     if (!R.Sec || R.Sec == &InputSection<ELFT>::Discarded)
       return;
 
-    // We don't gc non alloc sections.
-    if (!(R.Sec->Flags & SHF_ALLOC))
-      return;
-
     // Usually, a whole section is marked as live or dead, but in mergeable
     // (splittable) sections, each piece of data has independent liveness bit.
     // So we explicitly tell it which offset is in use.
@@ -240,7 +232,7 @@
     // referred by .eh_frame here.
     if (auto *EH = dyn_cast_or_null<EhInputSection<ELFT>>(Sec))
       scanEhFrameSection<ELFT>(*EH, Enqueue);
-    if (isReserved(Sec) || Script<ELFT>::X->shouldKeep(Sec))
+    if (Sec->Live || isReserved(Sec) || Script<ELFT>::X->shouldKeep(Sec))
       Enqueue({Sec, 0});
   }
 
Index: ELF/InputSection.h
===================================================================
--- ELF/InputSection.h
+++ ELF/InputSection.h
@@ -175,7 +175,6 @@
 
   // Mark the piece at a given offset live. Used by GC.
   void markLiveAt(uintX_t Offset) {
-    assert(this->Flags & llvm::ELF::SHF_ALLOC);
     LiveOffsets.insert(Offset);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29170.85870.patch
Type: text/x-patch
Size: 2028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170126/2f3050ab/attachment.bin>


More information about the llvm-commits mailing list