[lld] r258102 - Prefer symbols from .o over .so.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 18 15:54:06 PST 2016


Author: rafael
Date: Mon Jan 18 17:54:05 2016
New Revision: 258102

URL: http://llvm.org/viewvc/llvm-project?rev=258102&view=rev
Log:
Prefer symbols from .o over .so.

This matches the behavior of gold and bfd ld.

Added:
    lld/trunk/test/ELF/Inputs/resolution-shared.s
    lld/trunk/test/ELF/resolution-shared.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=258102&r1=258101&r2=258102&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Mon Jan 18 17:54:05 2016
@@ -39,8 +39,9 @@ static uint8_t getMinVisibility(uint8_t
 template <class ELFT> int SymbolBody::compare(SymbolBody *Other) {
   typedef typename ELFFile<ELFT>::uintX_t uintX_t;
   assert(!isLazy() && !Other->isLazy());
-  std::pair<bool, bool> L(isDefined(), !isWeak());
-  std::pair<bool, bool> R(Other->isDefined(), !Other->isWeak());
+  std::tuple<bool, bool, bool> L(isDefined(), !isShared(), !isWeak());
+  std::tuple<bool, bool, bool> R(Other->isDefined(), !Other->isShared(),
+                                 !Other->isWeak());
 
   // Normalize
   if (L > R)
@@ -54,11 +55,7 @@ template <class ELFT> int SymbolBody::co
 
   if (L != R)
     return -1;
-  if (!L.first || !L.second)
-    return 1;
-  if (isShared())
-    return -1;
-  if (Other->isShared())
+  if (!std::get<0>(L) || !std::get<1>(L) || !std::get<2>(L))
     return 1;
   if (isCommon()) {
     if (!Other->isCommon())

Added: lld/trunk/test/ELF/Inputs/resolution-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/resolution-shared.s?rev=258102&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/resolution-shared.s (added)
+++ lld/trunk/test/ELF/Inputs/resolution-shared.s Mon Jan 18 17:54:05 2016
@@ -0,0 +1,2 @@
+        .global foo
+foo:

Added: lld/trunk/test/ELF/resolution-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/resolution-shared.s?rev=258102&view=auto
==============================================================================
--- lld/trunk/test/ELF/resolution-shared.s (added)
+++ lld/trunk/test/ELF/resolution-shared.s Mon Jan 18 17:54:05 2016
@@ -0,0 +1,15 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/resolution-shared.s -o %t2.o
+// RUN: ld.lld %t2.o -o %t2.so -shared
+// RUN: ld.lld %t.o %t2.so -o %t3 -shared
+// RUN: llvm-readobj -t %t3 | FileCheck %s
+// REQUIRES: x86
+
+        .weak foo
+foo:
+
+// CHECK:      Symbol {
+// CHECK:        Name: foo
+// CHECK-NEXT:   Value:
+// CHECK-NEXT:   Size:
+// CHECK-NEXT:   Binding: Weak




More information about the llvm-commits mailing list