[lld] r284663 - Don't call markLiveAt for non alloc sections.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 19 16:13:41 PDT 2016


Author: rafael
Date: Wed Oct 19 18:13:40 2016
New Revision: 284663

URL: http://llvm.org/viewvc/llvm-project?rev=284663&view=rev
Log:
Don't call markLiveAt for non alloc sections.

We don't gc them anyway, so just use an early return in Enqueue.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h
    lld/trunk/ELF/MarkLive.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=284663&r1=284662&r2=284663&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Oct 19 18:13:40 2016
@@ -53,7 +53,8 @@ InputSectionBase<ELFT>::InputSectionBase
                                          const Elf_Shdr *Hdr, StringRef Name,
                                          Kind SectionKind)
     : InputSectionData(SectionKind, Name, getSectionContents(File, Hdr),
-                       isCompressed<ELFT>(Hdr, Name), !Config->GcSections),
+                       isCompressed<ELFT>(Hdr, Name),
+                       !Config->GcSections || !(Hdr->sh_flags & SHF_ALLOC)),
       Header(Hdr), File(File), Repl(this) {
   // The ELF spec states that a value of 0 means the section has
   // no alignment constraits.

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=284663&r1=284662&r2=284663&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed Oct 19 18:13:40 2016
@@ -167,7 +167,10 @@ public:
   void splitIntoPieces();
 
   // Mark the piece at a given offset live. Used by GC.
-  void markLiveAt(uintX_t Offset) { LiveOffsets.insert(Offset); }
+  void markLiveAt(uintX_t Offset) {
+    assert(this->getSectionHdr()->sh_flags & llvm::ELF::SHF_ALLOC);
+    LiveOffsets.insert(Offset);
+  }
 
   // Translate an offset in the input section to an offset
   // in the output section.

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=284663&r1=284662&r2=284663&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Wed Oct 19 18:13:40 2016
@@ -201,6 +201,10 @@ template <class ELFT> void elf::markLive
     if (!R.Sec || R.Sec == &InputSection<ELFT>::Discarded)
       return;
 
+    // We don't gc non alloc sections.
+    if (!(R.Sec->getSectionHdr()->sh_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.
@@ -210,12 +214,9 @@ template <class ELFT> void elf::markLive
     if (R.Sec->Live)
       return;
     R.Sec->Live = true;
-    // Add input section to the queue. We don't want to consider relocations
-    // from non-allocatable input sections, because we can bring those
-    // allocatable sections to living which otherwise would be dead.
+    // Add input section to the queue.
     if (InputSection<ELFT> *S = dyn_cast<InputSection<ELFT>>(R.Sec))
-      if (S->getSectionHdr()->sh_flags & SHF_ALLOC)
-        Q.push_back(S);
+      Q.push_back(S);
   };
 
   auto MarkSymbol = [&](const SymbolBody *Sym) {




More information about the llvm-commits mailing list