[lld] r281946 - [GC] Don't crash when printing the special Discarded GC section.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 19 16:15:51 PDT 2016
Author: davide
Date: Mon Sep 19 18:15:51 2016
New Revision: 281946
URL: http://llvm.org/viewvc/llvm-project?rev=281946&view=rev
Log:
[GC] Don't crash when printing the special Discarded GC section.
InputSection<ELFT>::Discarded has no name and it's not backed by
a file. Trying to report it as discared will cause a nullptr
dereference, therefore a crash. Skip it.
Differential Revision: https://reviews.llvm.org/D24731
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/lto/dynsym.ll
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=281946&r1=281945&r2=281946&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Sep 19 18:15:51 2016
@@ -102,7 +102,8 @@ StringRef elf::getOutputSectionName(Inpu
}
template <class ELFT> void elf::reportDiscarded(InputSectionBase<ELFT> *IS) {
- if (!Config->PrintGcSections || !IS || IS->Live)
+ if (!Config->PrintGcSections || !IS || IS == &InputSection<ELFT>::Discarded ||
+ IS->Live)
return;
errs() << "removing unused section from '" << IS->Name << "' in file '"
<< IS->getFile()->getName() << "'\n";
Modified: lld/trunk/test/ELF/lto/dynsym.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/dynsym.ll?rev=281946&r1=281945&r2=281946&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/dynsym.ll (original)
+++ lld/trunk/test/ELF/lto/dynsym.ll Mon Sep 19 18:15:51 2016
@@ -5,6 +5,11 @@
; RUN: ld.lld -m elf_x86_64 %t2.o %t.so -o %t
; RUN: llvm-readobj -dyn-symbols %t | FileCheck %s
+; Check that we don't crash when gc'ing sections and printing the result.
+; RUN: ld.lld -m elf_x86_64 %t2.o %t.so --gc-sections --print-gc-sections \
+; RUN: -o %t
+; RUN: llvm-readobj -dyn-symbols %t | FileCheck %s
+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
More information about the llvm-commits
mailing list