[lld] r295298 - [ELF] - Allow section to have multiple dependent sections.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 16 00:41:20 PST 2017


Author: grimar
Date: Thu Feb 16 02:41:19 2017
New Revision: 295298

URL: http://llvm.org/viewvc/llvm-project?rev=295298&view=rev
Log:
[ELF] - Allow section to have multiple dependent sections.

That fixes a case when section has more than one metadata 
section. Previously GC would collect one of such sections 
because we had implementation that stored only last one as
dependent.

Differential revision: https://reviews.llvm.org/D29981

Added:
    lld/trunk/test/ELF/gc-sections-metadata2.s
Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputSection.h
    lld/trunk/ELF/MarkLive.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=295298&r1=295297&r2=295298&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Feb 16 02:41:19 2017
@@ -323,7 +323,7 @@ void elf::ObjectFile<ELFT>::initializeSe
         fatal(toString(this) + ": invalid sh_link index: " +
               Twine(Sec.sh_link));
       auto *IS = cast<InputSection<ELFT>>(Sections[Sec.sh_link]);
-      IS->DependentSection = Sections[I];
+      IS->DependentSections.push_back(Sections[I]);
     }
   }
 }

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=295298&r1=295297&r2=295298&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Thu Feb 16 02:41:19 2017
@@ -281,8 +281,8 @@ public:
   // to. The writer sets a value.
   uint64_t OutSecOff = 0;
 
-  // InputSection that is dependent on us (reverse dependency for GC)
-  InputSectionBase<ELFT> *DependentSection = nullptr;
+  // InputSections that are dependent on us (reverse dependency for GC)
+  llvm::TinyPtrVector<InputSectionBase<ELFT> *> DependentSections;
 
   static bool classof(const InputSectionData *S);
 

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=295298&r1=295297&r2=295298&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Thu Feb 16 02:41:19 2017
@@ -87,8 +87,8 @@ static void forEachSuccessor(InputSectio
     for (const typename ELFT::Rel &Rel : Sec.rels())
       Fn(resolveReloc(Sec, Rel));
   }
-  if (Sec.DependentSection)
-    Fn({Sec.DependentSection, 0});
+  for (InputSectionBase<ELFT> *IS : Sec.DependentSections)
+    Fn({IS, 0});
 }
 
 // The .eh_frame section is an unfortunate special case.

Added: lld/trunk/test/ELF/gc-sections-metadata2.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gc-sections-metadata2.s?rev=295298&view=auto
==============================================================================
--- lld/trunk/test/ELF/gc-sections-metadata2.s (added)
+++ lld/trunk/test/ELF/gc-sections-metadata2.s Thu Feb 16 02:41:19 2017
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld --gc-sections %t.o -o %t
+# RUN: llvm-objdump -section-headers %t | FileCheck %s
+
+# CHECK: .foo
+# CHECK: .bar
+# CHECK: .zed
+
+.globl _start
+_start:
+.quad .foo
+
+.section .foo,"a"
+.quad 0
+.section .bar,"am", at progbits,.foo
+.quad 0
+.section .zed,"am", at progbits,.foo
+.quad 0




More information about the llvm-commits mailing list