[PATCH] D21171: ELF: Compute used bit for --as-needed during symbol resolution.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 9 11:08:24 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL272282: ELF: Compute used bit for --as-needed during symbol resolution. (authored by pcc).

Changed prior to commit:
  http://reviews.llvm.org/D21171?vs=60139&id=60209#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D21171

Files:
  lld/trunk/ELF/SymbolTable.cpp
  lld/trunk/ELF/Writer.cpp
  lld/trunk/test/ELF/verneed-as-needed-weak.s

Index: lld/trunk/test/ELF/verneed-as-needed-weak.s
===================================================================
--- lld/trunk/test/ELF/verneed-as-needed-weak.s
+++ lld/trunk/test/ELF/verneed-as-needed-weak.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o --as-needed %S/Inputs/verneed1.so -o %t
+# RUN: llvm-readobj -V %t | FileCheck %s
+
+# CHECK:       SHT_GNU_verneed {
+# CHECK-NEXT:  }
+
+.weak f1
+
+.globl _start
+_start:
+.data
+.long f1
Index: lld/trunk/ELF/SymbolTable.cpp
===================================================================
--- lld/trunk/ELF/SymbolTable.cpp
+++ lld/trunk/ELF/SymbolTable.cpp
@@ -238,9 +238,12 @@
     cast<Undefined>(S->body())->File = File;
     return S;
   }
-  if (Binding != STB_WEAK &&
-      (S->body()->isShared() || S->body()->isLazy()))
-    S->Binding = Binding;
+  if (Binding != STB_WEAK) {
+    if (S->body()->isShared() || S->body()->isLazy())
+      S->Binding = Binding;
+    if (auto *SS = dyn_cast<SharedSymbol<ELFT>>(S->body()))
+      SS->File->IsUsed = true;
+  }
   if (auto *L = dyn_cast<Lazy>(S->body())) {
     // An undefined weak will not fetch archive members, but we have to remember
     // its type. See also comment in addLazyArchive.
@@ -393,8 +396,11 @@
   // Make sure we preempt DSO symbols with default visibility.
   if (Sym.getVisibility() == STV_DEFAULT)
     S->ExportDynamic = true;
-  if (WasInserted || isa<Undefined>(S->body()))
+  if (WasInserted || isa<Undefined>(S->body())) {
     replaceBody<SharedSymbol<ELFT>>(S, F, Name, Sym, Verdef);
+    if (!S->isWeak())
+      F->IsUsed = true;
+  }
 }
 
 template <class ELFT>
Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -813,11 +813,6 @@
   for (Symbol *S : Symtab.getSymbols()) {
     SymbolBody *Body = S->body();
 
-    // Set "used" bit for --as-needed.
-    if (S->IsUsedInRegularObj && !S->isWeak())
-      if (auto *SS = dyn_cast<SharedSymbol<ELFT>>(Body))
-        SS->File->IsUsed = true;
-
     // We only report undefined symbols in regular objects. This means that we
     // will accept an undefined reference in bitcode if it can be optimized out.
     if (S->IsUsedInRegularObj && Body->isUndefined() && !S->isWeak())
@@ -834,7 +829,8 @@
     if (isOutputDynamic() && S->includeInDynsym()) {
       Out<ELFT>::DynSymTab->addSymbol(Body);
       if (auto *SS = dyn_cast<SharedSymbol<ELFT>>(Body))
-        Out<ELFT>::VerNeed->addSymbol(SS);
+        if (SS->File->isNeeded())
+          Out<ELFT>::VerNeed->addSymbol(SS);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21171.60209.patch
Type: text/x-patch
Size: 2684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160609/9f1a4279/attachment.bin>


More information about the llvm-commits mailing list