diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index f28c87ce4afb..71078cfb6dbe 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -253,7 +253,12 @@ SplitInputSection::SplitInputSection( template EHInputSection::EHInputSection(ObjectFile *F, const Elf_Shdr *Header) - : SplitInputSection(F, Header, InputSectionBase::EHFrame) {} + : SplitInputSection(F, Header, 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; +} template bool EHInputSection::classof(const InputSectionBase *S) { diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index c44220a981a9..88ec4f634d9c 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -120,10 +120,6 @@ template void lld::elf2::markLive(SymbolTable *Symtab) { continue; if (isReserved(Sec)) Enqueue(Sec); - else if (Sec->getSectionName() == ".eh_frame") - // .eh_frame is special. It should be marked live so that we don't - // drop it, but it should not keep any section alive. - Sec->Live = true; } }