[lld] r267323 - ELF: Simplify preemption logic. Do not include weak undefined symbols in non-DSOs.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 23 21:29:59 PDT 2016


Author: pcc
Date: Sat Apr 23 23:29:59 2016
New Revision: 267323

URL: http://llvm.org/viewvc/llvm-project?rev=267323&view=rev
Log:
ELF: Simplify preemption logic. Do not include weak undefined symbols in non-DSOs.
Add a test for -Bsymbolic + undefined symbols.

Added:
    lld/trunk/test/ELF/bsymbolic-undef.s
    lld/trunk/test/ELF/weak-undef.s
Modified:
    lld/trunk/ELF/Symbols.cpp

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=267323&r1=267322&r2=267323&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Sat Apr 23 23:29:59 2016
@@ -123,14 +123,15 @@ bool SymbolBody::isPreemptible() const {
   if (!Config->Shared)
     return false;
 
-  // -Bsymbolic means that not even default visibility symbols can be preempted.
-  if ((Config->Bsymbolic || (Config->BsymbolicFunctions && isFunc())) &&
-      isDefined())
+  // Only symbols that appear in dynsym can be preempted.
+  if (!Backref->includeInDynsym())
     return false;
 
-  // Only default visibility symbols that appear in the dynamic symbol table can
-  // be preempted.
-  return Backref->Visibility == STV_DEFAULT && Backref->includeInDynsym();
+  // Normally only default visibility symbols can be preempted, but -Bsymbolic
+  // means that not even they can be preempted.
+  if (Config->Bsymbolic || (Config->BsymbolicFunctions && isFunc()))
+    return !isDefined();
+  return Backref->Visibility == STV_DEFAULT;
 }
 
 template <class ELFT>
@@ -320,7 +321,7 @@ bool Symbol::includeInDynsym() const {
   if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
     return false;
   return (ExportDynamic && VersionScriptGlobal) || Body->isShared() ||
-         Body->isUndefined();
+         (Body->isUndefined() && Config->Shared);
 }
 
 template uint32_t SymbolBody::template getVA<ELF32LE>(uint32_t) const;

Added: lld/trunk/test/ELF/bsymbolic-undef.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/bsymbolic-undef.s?rev=267323&view=auto
==============================================================================
--- lld/trunk/test/ELF/bsymbolic-undef.s (added)
+++ lld/trunk/test/ELF/bsymbolic-undef.s Sat Apr 23 23:29:59 2016
@@ -0,0 +1,26 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld -shared -Bsymbolic %t.o -o %t.so
+# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck %s
+
+# CHECK:      DynamicSymbols [
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: @ (0)
+# CHECK-NEXT:     Value: 0x0
+# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Binding: Local (0x0)
+# CHECK-NEXT:     Type: None (0x0)
+# CHECK-NEXT:     Other: 0
+# CHECK-NEXT:     Section: Undefined (0x0)
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: undef@ (1)
+# CHECK-NEXT:     Value: 0x0
+# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Binding: Global (0x1)
+# CHECK-NEXT:     Type: None (0x0)
+# CHECK-NEXT:     Other: 0
+# CHECK-NEXT:     Section: Undefined (0x0)
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+
+call undef at PLT

Added: lld/trunk/test/ELF/weak-undef.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/weak-undef.s?rev=267323&view=auto
==============================================================================
--- lld/trunk/test/ELF/weak-undef.s (added)
+++ lld/trunk/test/ELF/weak-undef.s Sat Apr 23 23:29:59 2016
@@ -0,0 +1,21 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t -pie
+# RUN: llvm-readobj -dyn-symbols %t | FileCheck %s
+
+# CHECK:      DynamicSymbols [
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: @ (0)
+# CHECK-NEXT:     Value: 0x0
+# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Binding: Local (0x0)
+# CHECK-NEXT:     Type: None (0x0)
+# CHECK-NEXT:     Other: 0
+# CHECK-NEXT:     Section: Undefined (0x0)
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+
+.weak foo
+
+.globl _start
+_start:




More information about the llvm-commits mailing list