From 2e610cd4706ac71f95dffe7beb577aed2fcb1243 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Thu, 30 Nov 2017 14:01:06 +0000 Subject: [PATCH] [ELF] - Handle EhInputSection Live bit in MarkLive.cpp Since MarkLive.cpp is the place where we set Live flags for other sections, it looks correct to do that there. Benefit is that we stop spreading GC logic outsize of MarkLive.cpp. Differential revision: https://reviews.llvm.org/D40454 llvm-svn: 319435 --- lld/ELF/InputSection.cpp | 7 +------ lld/ELF/MarkLive.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index dc55f6320b94..5daff1259ca1 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -808,12 +808,7 @@ template EhInputSection::EhInputSection(ObjFile *F, const typename ELFT::Shdr *Header, StringRef Name) - : InputSectionBase(F, Header, Name, InputSectionBase::EHFrame) { - // Mark .eh_frame sections as live by default because there are - // usually no relocations that point to .eh_frames. Otherwise, - // the garbage collector would drop all .eh_frame sections. - this->Live = true; -} + : InputSectionBase(F, Header, Name, InputSectionBase::EHFrame) {} SyntheticSection *EhInputSection::getParent() const { return cast_or_null(Parent); diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index e27d35c9a89b..e2d2ee9c6cf5 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -241,11 +241,15 @@ template static void doGcSections() { // Preserve special sections and those which are specified in linker // script KEEP command. for (InputSectionBase *Sec : InputSections) { - // .eh_frame is always marked as live now, but also it can reference to - // sections that contain personality. We preserve all non-text sections - // referred by .eh_frame here. - if (auto *EH = dyn_cast_or_null(Sec)) + // Mark .eh_frame sections as live because there are usually no relocations + // that point to .eh_frames. Otherwise, the garbage collector would drop + // all of them. We also want to preserve personality routines and LSDA + // referenced by .eh_frame sections, so we scan them for that here. + if (auto *EH = dyn_cast_or_null(Sec)) { + EH->Live = true; scanEhFrameSection(*EH, Enqueue); + } + if (Sec->Flags & SHF_LINK_ORDER) continue; if (isReserved(Sec) || Script->shouldKeep(Sec))