From 1c3c3953c646bc57c4c6e2c247de912c87fa0665 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Mon, 19 Sep 2016 23:15:51 +0000 Subject: [PATCH] [GC] Don't crash when printing the special Discarded GC section. InputSection::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 llvm-svn: 281946 --- lld/ELF/Writer.cpp | 3 ++- lld/test/ELF/lto/dynsym.ll | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index f8b6323..c66126d 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -102,7 +102,8 @@ StringRef elf::getOutputSectionName(InputSectionBase *S) { } 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"; diff --git a/lld/test/ELF/lto/dynsym.ll b/lld/test/ELF/lto/dynsym.ll index 5885960..b2b4157 100644 --- a/lld/test/ELF/lto/dynsym.ll +++ b/lld/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" -- 2.7.4