diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index f80000079139..dc653d9697ab 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -94,7 +94,9 @@ static void forEachSuccessor(InputSection *Sec, run(Obj, Sec, RelSec, Fn); } -template static void scanEhFrameSection(EHInputSection &EH) { +template +static void scanEhFrameSection(EHInputSection &EH, + std::function)> Fn) { if (!EH.RelocSection) return; ELFFile &EObj = EH.getFile()->getObj(); @@ -103,7 +105,7 @@ template static void scanEhFrameSection(EHInputSection &EH) { return; if (R.Sec->getSectionHdr()->sh_flags & SHF_EXECINSTR) return; - R.Sec->Live = true; + Fn({R.Sec, 0}); }); } @@ -181,7 +183,7 @@ template void elf::markLive() { // sections that contain personality. We preserve all non-text sections // referred by .eh_frame here. if (auto *EH = dyn_cast_or_null>(Sec)) - scanEhFrameSection(*EH); + scanEhFrameSection(*EH, Enqueue); if (isReserved(Sec) || Script::X->shouldKeep(Sec)) Enqueue({Sec, 0}); } diff --git a/lld/test/ELF/gc-sections-lsda.s b/lld/test/ELF/gc-sections-lsda.s new file mode 100644 index 000000000000..b5bed8f0c816 --- /dev/null +++ b/lld/test/ELF/gc-sections-lsda.s @@ -0,0 +1,21 @@ +// REQUIRES: x86 + +// RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux +// RUN: ld.lld -shared --gc-sections %t.o -o %t + +// Test that we handle .eh_frame keeping sections alive. We could be more +// precise and gc the entire contents of this file, but test that at least +// we are consistent: if we keep .abc, we have to keep .foo + +// RUN: llvm-readobj -s %t | FileCheck %s +// CHECK: Name: .abc +// CHECK: Name: .foo (38) + + .cfi_startproc + .cfi_lsda 0x1b,zed + .cfi_endproc + .section .abc,"a" +zed: + .long bar-. + .section .foo,"ax" +bar: