From 8e2fc4f3f836a082b0599a6bd74ada26e6c44b7a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 23 Jan 2018 16:59:20 +0000 Subject: [PATCH] Don't mark a shared library as needed because of a lazy symbol. Fixes PR36029. llvm-svn: 323221 --- lld/ELF/SymbolTable.cpp | 3 ++- lld/test/ELF/Inputs/as-needed-lazy.s | 3 +++ lld/test/ELF/as-needed-lazy.s | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 lld/test/ELF/Inputs/as-needed-lazy.s create mode 100644 lld/test/ELF/as-needed-lazy.s diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 9af0bbd..baf9e20 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -491,12 +491,13 @@ void SymbolTable::addShared(StringRef Name, SharedFile &File, if (WasInserted || ((S->isUndefined() || S->isLazy()) && S->Visibility == STV_DEFAULT)) { uint8_t Binding = S->Binding; + bool WasUndefined = S->isUndefined(); replaceSymbol(S, File, Name, Sym.getBinding(), Sym.st_other, Sym.getType(), Sym.st_value, Sym.st_size, Alignment, VerdefIndex); if (!WasInserted) { S->Binding = Binding; - if (!S->isWeak() && !Config->GcSections) + if (!S->isWeak() && !Config->GcSections && WasUndefined) File.IsNeeded = true; } } diff --git a/lld/test/ELF/Inputs/as-needed-lazy.s b/lld/test/ELF/Inputs/as-needed-lazy.s new file mode 100644 index 0000000..7f9c360 --- /dev/null +++ b/lld/test/ELF/Inputs/as-needed-lazy.s @@ -0,0 +1,3 @@ +.global foo +foo: + nop diff --git a/lld/test/ELF/as-needed-lazy.s b/lld/test/ELF/as-needed-lazy.s new file mode 100644 index 0000000..e892b99 --- /dev/null +++ b/lld/test/ELF/as-needed-lazy.s @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/as-needed-lazy.s -o %t2.o +# RUN: ld.lld %t2.o -o %t2.so -shared +# RUN: rm -f %t2.a +# RUN: llvm-ar rc %t2.a %t2.o +# RUN: ld.lld %t1.o %t2.a --as-needed %t2.so -o %t +# RUN: llvm-readobj -d %t | FileCheck %s + +# CHECK-NOT: NEEDED + +.global _start +_start: + nop -- 2.7.4