[lld] r268628 - Fix --gc-sections when .eh_frame has a lsda.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 06:51:14 PDT 2016


Author: rafael
Date: Thu May  5 08:51:14 2016
New Revision: 268628

URL: http://llvm.org/viewvc/llvm-project?rev=268628&view=rev
Log:
Fix --gc-sections when .eh_frame has a lsda.

We have to add sections to the work list, not just mark them live.

Added:
    lld/trunk/test/ELF/gc-sections-lsda.s
Modified:
    lld/trunk/ELF/MarkLive.cpp

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=268628&r1=268627&r2=268628&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Thu May  5 08:51:14 2016
@@ -94,7 +94,9 @@ static void forEachSuccessor(InputSectio
     run(Obj, Sec, RelSec, Fn);
 }
 
-template <class ELFT> static void scanEhFrameSection(EHInputSection<ELFT> &EH) {
+template <class ELFT>
+static void scanEhFrameSection(EHInputSection<ELFT> &EH,
+                               std::function<void(ResolvedReloc<ELFT>)> Fn) {
   if (!EH.RelocSection)
     return;
   ELFFile<ELFT> &EObj = EH.getFile()->getObj();
@@ -103,7 +105,7 @@ template <class ELFT> static void scanEh
       return;
     if (R.Sec->getSectionHdr()->sh_flags & SHF_EXECINSTR)
       return;
-    R.Sec->Live = true;
+    Fn({R.Sec, 0});
   });
 }
 
@@ -181,7 +183,7 @@ template <class ELFT> void elf::markLive
         // sections that contain personality. We preserve all non-text sections
         // referred by .eh_frame here.
         if (auto *EH = dyn_cast_or_null<EHInputSection<ELFT>>(Sec))
-          scanEhFrameSection<ELFT>(*EH);
+          scanEhFrameSection<ELFT>(*EH, Enqueue);
         if (isReserved(Sec) || Script<ELFT>::X->shouldKeep(Sec))
           Enqueue({Sec, 0});
       }

Added: lld/trunk/test/ELF/gc-sections-lsda.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gc-sections-lsda.s?rev=268628&view=auto
==============================================================================
--- lld/trunk/test/ELF/gc-sections-lsda.s (added)
+++ lld/trunk/test/ELF/gc-sections-lsda.s Thu May  5 08:51:14 2016
@@ -0,0 +1,21 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
+// RUN: ld.lld -shared --gc-sections %t.o -o %t
+
+// Test that we handle .eh_frame keeping sections alive. We could be more
+// precise and gc the entire contents of this file, but test that at least
+// we are consistent: if we keep .abc, we have to keep .foo
+
+// RUN: llvm-readobj -s %t | FileCheck %s
+// CHECK:  Name: .abc
+// CHECK: Name: .foo (38)
+
+        .cfi_startproc
+        .cfi_lsda 0x1b,zed
+        .cfi_endproc
+        .section        .abc,"a"
+zed:
+        .long   bar-.
+        .section        .foo,"ax"
+bar:




More information about the llvm-commits mailing list