[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
llvm-svn: 281946
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 @@
}
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";