From a7e3132d0324ca13a592668410f91c202525aa42 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 13 Oct 2017 18:32:16 +0000 Subject: [PATCH] Handle shared symbols in --gc-sections. We don't want to gc a section if it is used via __start_*, but we were doing that if the same symbol was visible in a shared library. llvm-svn: 315727 --- lld/ELF/MarkLive.cpp | 2 +- lld/test/ELF/startstop-gccollect.s | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index b91be1297725..62a0039ef015 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -74,7 +74,7 @@ static void resolveReloc(InputSectionBase &Sec, RelT &Rel, return; } - if (B.isUndefined()) + if (!B.isInCurrentDSO()) for (InputSectionBase *Sec : CNamedSections.lookup(B.getName())) Fn(Sec, 0); } diff --git a/lld/test/ELF/startstop-gccollect.s b/lld/test/ELF/startstop-gccollect.s index fea4657ba8c9..cb0009c54bec 100644 --- a/lld/test/ELF/startstop-gccollect.s +++ b/lld/test/ELF/startstop-gccollect.s @@ -11,6 +11,12 @@ # RUN: ld.lld %t --gc-sections -o %tout # RUN: llvm-objdump -d %tout | FileCheck -check-prefix=DISASM %s +# RUN: echo ".global __start_foo; __start_foo:" > %t2.s +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t2.s -o %t2.o +# RUN: ld.lld -shared %t2.o -o %t2.so +# RUN: ld.lld %t --gc-sections -o %tout %t2.so +# RUN: llvm-objdump -d %tout | FileCheck -check-prefix=DISASM %s + # DISASM: _start: # DISASM-NEXT: 201000: e8 05 00 00 00 callq 5 <__start_foo> # DISASM-NEXT: 201005: e8 02 00 00 00 callq 2 <__stop_bar> -- 2.34.1