[PATCH] D64136: [ELF] resolveUndefined: ignore undefined symbols in SharedFile for Undefined and SharedSymbol

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 4 03:38:54 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL365129: [ELF] resolveUndefined: ignore undefined symbols in SharedFile for Undefined… (authored by MaskRay, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D64136?vs=207990&id=208011#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64136

Files:
  lld/trunk/ELF/Symbols.cpp
  lld/trunk/test/ELF/archive-fetch.s
  lld/trunk/test/ELF/weak-undef-shared.s


Index: lld/trunk/ELF/Symbols.cpp
===================================================================
--- lld/trunk/ELF/Symbols.cpp
+++ lld/trunk/ELF/Symbols.cpp
@@ -410,18 +410,7 @@
   if (Traced)
     printTraceSymbol(&Other);
 
-  if (isUndefined()) {
-    // The binding may "upgrade" from weak to non-weak.
-    if (Other.Binding != STB_WEAK)
-      Binding = Other.Binding;
-  } else if (auto *S = dyn_cast<SharedSymbol>(this)) {
-    // The binding of a SharedSymbol will be weak if there is at least one
-    // reference and all are weak. The binding has one opportunity to change to
-    // weak: if the first reference is weak.
-    if (Other.Binding != STB_WEAK || !S->Referenced)
-      Binding = Other.Binding;
-    S->Referenced = true;
-  } else if (isLazy()) {
+  if (isLazy()) {
     // An undefined weak will not fetch archive members. See comment on Lazy in
     // Symbols.h for the details.
     if (Other.Binding == STB_WEAK) {
@@ -489,6 +478,24 @@
     if (Backref && !isWeak())
       warn("backward reference detected: " + Other.getName() + " in " +
            toString(Other.File) + " refers to " + toString(File));
+    return;
+  }
+
+  // Undefined symbols in a SharedFile do not change the binding.
+  if (dyn_cast_or_null<SharedFile>(Other.File))
+    return;
+
+  if (isUndefined()) {
+    // The binding may "upgrade" from weak to non-weak.
+    if (Other.Binding != STB_WEAK)
+      Binding = Other.Binding;
+  } else if (auto *S = dyn_cast<SharedSymbol>(this)) {
+    // The binding of a SharedSymbol will be weak if there is at least one
+    // reference and all are weak. The binding has one opportunity to change to
+    // weak: if the first reference is weak.
+    if (Other.Binding != STB_WEAK || !S->Referenced)
+      Binding = Other.Binding;
+    S->Referenced = true;
   }
 }
 
Index: lld/trunk/test/ELF/archive-fetch.s
===================================================================
--- lld/trunk/test/ELF/archive-fetch.s
+++ lld/trunk/test/ELF/archive-fetch.s
@@ -9,7 +9,14 @@
 # RUN: llvm-ar rcs %t.a %tfoo.o %tbar.o
 
 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: ld.lld %t.a %t.o -o /dev/null
+# RUN: ld.lld %t.a %t.o -o %t
+# RUN: llvm-nm %t | FileCheck %s
+
+# RUN: ld.lld -shared %t.o -o %t.so
+# RUN: ld.lld %t.a %t.so -o %t
+# RUN: llvm-nm %t | FileCheck %s
+
+# CHECK: T foo
 
 _start:
 callq foo
Index: lld/trunk/test/ELF/weak-undef-shared.s
===================================================================
--- lld/trunk/test/ELF/weak-undef-shared.s
+++ lld/trunk/test/ELF/weak-undef-shared.s
@@ -24,6 +24,11 @@
 # RUN: ld.lld %t2.o %t.so %t1.o -o %t
 # RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=GLOBAL %s
 
+## Check the binding (weak) is not affected by the STB_GLOBAL undefined
+## reference in %t2.so
+# RUN: ld.lld %t1.o %t2.so -o %t
+# RUN: llvm-readelf --dyn-syms %t | FileCheck --check-prefix=WEAK %s
+
 # WEAK:   NOTYPE WEAK   DEFAULT UND foo
 # GLOBAL: NOTYPE GLOBAL DEFAULT UND foo
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64136.208011.patch
Type: text/x-patch
Size: 3005 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190704/d165a2e5/attachment.bin>


More information about the llvm-commits mailing list