[PATCH] D55902: [ELF] SymbolTable::addShared: don't set IsNeeded unless IsUsedInRegularObj

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 20 12:27:15 PST 2018


MaskRay updated this revision to Diff 179124.
MaskRay removed a subscriber: grimar.
MaskRay added a comment.

Elaborate a comment


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55902/new/

https://reviews.llvm.org/D55902

Files:
  ELF/SymbolTable.cpp
  test/ELF/as-needed-not-in-regular.s


Index: test/ELF/as-needed-not-in-regular.s
===================================================================
--- /dev/null
+++ test/ELF/as-needed-not-in-regular.s
@@ -0,0 +1,24 @@
+# REQUIRES: x86
+
+# RUN: echo '.globl a; .type a, @function; a: ret' | \
+# RUN:   llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %ta.o
+# RUN: ld.lld %ta.o --shared --soname=a.so -o %ta.so
+
+# RUN: echo '.globl b; .type b, @function; b: jmp a at PLT' | \
+# RUN:   llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %tb.o
+# RUN: ld.lld %tb.o %ta.so --shared --soname=b.so -o %tb.so
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o %tb.so --as-needed %ta.so -o %t
+# RUN: llvm-readelf -d %t | FileCheck %s
+
+# RUN: ld.lld %t.o %tb.so --as-needed %ta.so --gc-sections -o %t
+# RUN: llvm-readelf -d %t | FileCheck %s
+
+# The symbol a (defined in a.so) is not referenced by a regular object,
+# don't add a DT_NEEDED entry for it.
+# CHECK-NOT: a.so
+
+.global _start
+_start:
+  jmp b at PLT
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -509,7 +509,8 @@
                                 Alignment, VerdefIndex);
 
     S->Binding = Binding;
-    if (!S->isWeak() && !Config->GcSections && WasUndefined)
+    if (!S->isWeak() && S->IsUsedInRegularObj && !Config->GcSections &&
+        WasUndefined)
       File.IsNeeded = true;
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55902.179124.patch
Type: text/x-patch
Size: 1474 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181220/d79d915d/attachment.bin>


More information about the llvm-commits mailing list