diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -2963,7 +2963,8 @@ } bool VersionTableSection::isNeeded() const { - return getPartition().verDef || getPartition().verNeed->isNeeded(); + return isLive() && + (getPartition().verDef || getPartition().verNeed->isNeeded()); } void addVerneed(Symbol *ss) { diff --git a/lld/test/ELF/linkerscript/discard-gnu-version.s b/lld/test/ELF/linkerscript/discard-gnu-version.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/linkerscript/discard-gnu-version.s @@ -0,0 +1,21 @@ +# REQUIRES: x86 +# RUN: echo '.globl f; f:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o +# RUN: echo 'v1 { f; };' > %t1.ver +# RUN: ld.lld -shared --version-script %t1.ver %t1.o -o %t1.so + +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o +# RUN: echo 'v1 { foo; };' > %t.ver +# RUN: ld.lld -shared --version-script %t.ver %t.o %t1.so -o %t.so +# RUN: llvm-readelf -S %t.so | FileCheck %s + +# CHECK: .gnu.version +# CHECK: .gnu.version_d +# CHECK: .gnu.version_r + +# RUN: echo 'SECTIONS { /DISCARD/ : { *(.gnu.version*) } }' > %t.script +# RUN: ld.lld -shared --version-script %t.ver -T %t.script %t.o %t1.so -o %t.so +# RUN: llvm-readelf -S %t.so | FileCheck /dev/null --implicit-check-not=.gnu.version + +.globl foo +foo: + call f@plt