Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -102,7 +102,8 @@ } template void elf::reportDiscarded(InputSectionBase *IS) { - if (!Config->PrintGcSections || !IS || IS->Live) + if (!Config->PrintGcSections || !IS || IS == &InputSection::Discarded || + IS->Live) return; errs() << "removing unused section from '" << IS->Name << "' in file '" << IS->getFile()->getName() << "'\n"; Index: lld/trunk/test/ELF/lto/dynsym.ll =================================================================== --- lld/trunk/test/ELF/lto/dynsym.ll +++ lld/trunk/test/ELF/lto/dynsym.ll @@ -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"