[lld] r302065 - Handle mixed strong and weak undefined symbols.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed May 3 11:40:27 PDT 2017


Author: rafael
Date: Wed May  3 13:40:27 2017
New Revision: 302065

URL: http://llvm.org/viewvc/llvm-project?rev=302065&view=rev
Log:
Handle mixed strong and weak undefined symbols.

We were ignoring strong undefined symbols if they followed weak ones.

Fixes pr32899.

Added:
    lld/trunk/test/ELF/Inputs/weak-and-strong-undef.s
    lld/trunk/test/ELF/weak-and-strong-undef.s
Modified:
    lld/trunk/ELF/SymbolTable.cpp

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=302065&r1=302064&r2=302065&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed May  3 13:40:27 2017
@@ -279,9 +279,10 @@ Symbol *SymbolTable<ELFT>::addUndefined(
     return S;
   }
   if (Binding != STB_WEAK) {
-    if (S->body()->isShared() || S->body()->isLazy())
+    SymbolBody *B = S->body();
+    if (B->isShared() || B->isLazy() || B->isUndefined())
       S->Binding = Binding;
-    if (auto *SS = dyn_cast<SharedSymbol>(S->body()))
+    if (auto *SS = dyn_cast<SharedSymbol>(B))
       cast<SharedFile<ELFT>>(SS->File)->IsUsed = true;
   }
   if (auto *L = dyn_cast<Lazy>(S->body())) {

Added: lld/trunk/test/ELF/Inputs/weak-and-strong-undef.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/weak-and-strong-undef.s?rev=302065&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/weak-and-strong-undef.s (added)
+++ lld/trunk/test/ELF/Inputs/weak-and-strong-undef.s Wed May  3 13:40:27 2017
@@ -0,0 +1 @@
+        .weak foo

Added: lld/trunk/test/ELF/weak-and-strong-undef.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/weak-and-strong-undef.s?rev=302065&view=auto
==============================================================================
--- lld/trunk/test/ELF/weak-and-strong-undef.s (added)
+++ lld/trunk/test/ELF/weak-and-strong-undef.s Wed May  3 13:40:27 2017
@@ -0,0 +1,12 @@
+# 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/weak-and-strong-undef.s -o %t2.o
+# RUN: not ld.lld %t1.o %t2.o -o %t 2>&1 | FileCheck %s
+# RUN: not ld.lld %t2.o %t1.o -o %t 2>&1 | FileCheck %s
+
+# CHECK: error: undefined symbol: foo
+
+.long foo
+.globl _start
+_start:
+ret




More information about the llvm-commits mailing list