[lld] r252493 - Start treating .eh_frame specially.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 9 09:44:11 PST 2015


Author: rafael
Date: Mon Nov  9 11:44:10 2015
New Revision: 252493

URL: http://llvm.org/viewvc/llvm-project?rev=252493&view=rev
Log:
Start treating .eh_frame specially.

For now, just don't follow edges leaving from it to mark other sections
live.

Added:
    lld/trunk/test/elf2/gc-sections-eh.s
Modified:
    lld/trunk/ELF/MarkLive.cpp
    lld/trunk/ELF/OutputSections.cpp

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=252493&r1=252492&r2=252493&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Mon Nov  9 11:44:10 2015
@@ -71,7 +71,7 @@ template <class ELFT> static bool isRese
   default:
     StringRef S = Sec->getSectionName();
     return S.startswith(".init") || S.startswith(".fini") ||
-           S.startswith(".jcr") || S == ".eh_frame";
+           S.startswith(".jcr");
   }
 }
 
@@ -109,11 +109,18 @@ template <class ELFT> void lld::elf2::ma
   }
 
   // Preserve special sections.
-  for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab->getObjectFiles())
-    for (InputSectionBase<ELFT> *Sec : F->getSections())
-      if (Sec && Sec != &InputSection<ELFT>::Discarded)
+  for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab->getObjectFiles()) {
+    for (InputSectionBase<ELFT> *Sec : F->getSections()) {
+      if (Sec && Sec != &InputSection<ELFT>::Discarded) {
         if (isReserved(Sec))
           Enqueue(Sec);
+        else if (Sec->getSectionName() == ".eh_frame")
+          // .eh_frame is special. It should be marked live so that we don't
+          // drop it, but it should not keep any section alive.
+          Sec->Live = true;
+      }
+    }
+  }
 
   // Mark all reachable sections.
   while (!Q.empty())

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=252493&r1=252492&r2=252493&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Mon Nov  9 11:44:10 2015
@@ -707,7 +707,7 @@ lld::elf2::getLocalRelTarget(const Objec
   // and must be treated specially. For now we just replace the symbol with
   // 0.
   InputSectionBase<ELFT> *Section = File.getSection(*Sym);
-  if (Section == &InputSection<ELFT>::Discarded)
+  if (Section == &InputSection<ELFT>::Discarded || !Section->isLive())
     return Addend;
 
   uintX_t VA = Section->OutSec->getVA();

Added: lld/trunk/test/elf2/gc-sections-eh.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/gc-sections-eh.s?rev=252493&view=auto
==============================================================================
--- lld/trunk/test/elf2/gc-sections-eh.s (added)
+++ lld/trunk/test/elf2/gc-sections-eh.s Mon Nov  9 11:44:10 2015
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld2 %t -o %t2 --gc-sections
+# RUN: llvm-readobj -t %t2 | FileCheck %s
+
+# CHECK-NOT: foo
+
+	.section	.text,"ax", at progbits,unique,0
+	.globl	foo
+foo:
+	.cfi_startproc
+	.cfi_endproc
+
+	.section	.text,"ax", at progbits,unique,1
+	.globl	_start
+_start:
+	.cfi_startproc
+	.cfi_endproc




More information about the llvm-commits mailing list