[PATCH] D24750: [GC] Don't crash while processing Discarded sections

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 22 14:17:35 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL282197: [ELF/GC] Don't crash while processing Discarded sections. (authored by davide).

Changed prior to commit:
  https://reviews.llvm.org/D24750?vs=71894&id=72212#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24750

Files:
  lld/trunk/ELF/MarkLive.cpp
  lld/trunk/test/ELF/comdat.s

Index: lld/trunk/test/ELF/comdat.s
===================================================================
--- lld/trunk/test/ELF/comdat.s
+++ lld/trunk/test/ELF/comdat.s
@@ -5,6 +5,15 @@
 // RUN: llvm-readobj -s -t %t | FileCheck --check-prefix=READ %s
 // REQUIRES: x86
 
+// Check that we don't crash with --gc-section and that we print a list of
+// reclaimed sections on stderr.
+// RUN: ld.lld --gc-sections --print-gc-sections -shared %t.o %t.o %t2.o -o %t \
+// RUN:   2>&1 | FileCheck --check-prefix=GC %s
+// GC: removing unused section from '.text' in file
+// GC: removing unused section from '.text3' in file
+// GC: removing unused section from '.text' in file
+// GC: removing unused section from '.text' in file
+
         .section	.text2,"axG", at progbits,foo,comdat,unique,0
 foo:
         nop
Index: lld/trunk/ELF/MarkLive.cpp
===================================================================
--- lld/trunk/ELF/MarkLive.cpp
+++ lld/trunk/ELF/MarkLive.cpp
@@ -81,6 +81,13 @@
 template <class ELFT>
 static void forEachSuccessor(InputSection<ELFT> &Sec,
                              std::function<void(ResolvedReloc<ELFT>)> Fn) {
+  // Skip over discarded sections. This in theory shouldn't happen, because
+  // the ELF spec doesn't allow a relocation to point to a deduplicated
+  // COMDAT section directly. Unfortunately this happens in practice (e.g.
+  // .eh_frame) so we need to add a check.
+  if (&Sec == &InputSection<ELFT>::Discarded)
+    return;
+
   ELFFile<ELFT> &Obj = Sec.getFile()->getObj();
   for (const typename ELFT::Shdr *RelSec : Sec.RelocSections) {
     if (RelSec->sh_type == SHT_RELA) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24750.72212.patch
Type: text/x-patch
Size: 1630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160922/18262289/attachment.bin>


More information about the llvm-commits mailing list