[lld] r307110 - Fix PR33635.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 4 17:43:18 PDT 2017


Author: rafael
Date: Tue Jul  4 17:43:18 2017
New Revision: 307110

URL: http://llvm.org/viewvc/llvm-project?rev=307110&view=rev
Log:
Fix PR33635.

This is a semantic revert of r306036.

We have to change the names, otherwise dynamic relocations will point
to the wrong name.

Added:
    lld/trunk/test/ELF/Inputs/wrap-dynamic-undef.s
    lld/trunk/test/ELF/wrap-dynamic-undef.s
Modified:
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/test/ELF/defsym.s
    lld/trunk/test/ELF/lto/wrap-2.ll
    lld/trunk/test/ELF/wrap.s

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=307110&r1=307109&r2=307110&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Tue Jul  4 17:43:18 2017
@@ -159,19 +159,12 @@ bool SymbolBody::isPreemptible() const {
   return true;
 }
 
-// Overwrites all attributes except symbol name with Other's so that
-// this symbol becomes an alias to Other. This is useful for handling
-// some options such as --wrap.
-//
-// The reason why we want to keep the symbol name is because, if we
-// copy symbol names, we'll end up having symbol tables in resulting
-// executables or DSOs containing two or more identical symbols, which
-// is just inconvenient.
+// Overwrites all attributes with Other's so that this symbol becomes
+// an alias to Other. This is useful for handling some options such as
+// --wrap.
 void SymbolBody::copy(SymbolBody *Other) {
-  StringRef S = Name;
   memcpy(symbol()->Body.buffer, Other->symbol()->Body.buffer,
          sizeof(Symbol::Body));
-  Name = S;
 }
 
 uint64_t SymbolBody::getVA(int64_t Addend) const {

Added: lld/trunk/test/ELF/Inputs/wrap-dynamic-undef.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/wrap-dynamic-undef.s?rev=307110&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/wrap-dynamic-undef.s (added)
+++ lld/trunk/test/ELF/Inputs/wrap-dynamic-undef.s Tue Jul  4 17:43:18 2017
@@ -0,0 +1,2 @@
+.global foo
+foo:

Modified: lld/trunk/test/ELF/defsym.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/defsym.s?rev=307110&r1=307109&r2=307110&view=diff
==============================================================================
--- lld/trunk/test/ELF/defsym.s (original)
+++ lld/trunk/test/ELF/defsym.s Tue Jul  4 17:43:18 2017
@@ -19,7 +19,7 @@
 # CHECK-NEXT:   Section: Absolute
 # CHECK-NEXT: }
 # CHECK-NEXT: Symbol {
-# CHECK-NEXT:   Name: foo2
+# CHECK-NEXT:   Name: foo1
 # CHECK-NEXT:   Value: 0x123
 # CHECK-NEXT:   Size:
 # CHECK-NEXT:   Binding: Global

Modified: lld/trunk/test/ELF/lto/wrap-2.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/wrap-2.ll?rev=307110&r1=307109&r2=307110&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/wrap-2.ll (original)
+++ lld/trunk/test/ELF/lto/wrap-2.ll Tue Jul  4 17:43:18 2017
@@ -10,8 +10,8 @@
 
 ; CHECK:      foo:
 ; CHECK-NEXT: pushq	%rax
+; CHECK-NEXT: callq{{.*}}<__wrap_bar>
 ; CHECK-NEXT: callq{{.*}}<bar>
-; CHECK-NEXT: callq{{.*}}<__real_bar>
 
 ; Check that bar and __wrap_bar retain their original binding.
 ; BIND:      Name: bar

Added: lld/trunk/test/ELF/wrap-dynamic-undef.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/wrap-dynamic-undef.s?rev=307110&view=auto
==============================================================================
--- lld/trunk/test/ELF/wrap-dynamic-undef.s (added)
+++ lld/trunk/test/ELF/wrap-dynamic-undef.s Tue Jul  4 17:43:18 2017
@@ -0,0 +1,15 @@
+# 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/wrap-dynamic-undef.s -o %t2.o
+# RUN: ld.lld %t2.o -o %t2.so -shared
+# RUN: ld.lld %t1.o %t2.so -o %t --wrap foo
+# RUN: llvm-readobj -dyn-symbols --elf-output-style=GNU %t | FileCheck %s
+
+# Test that the dynamic relocation uses foo. We used to produce a
+# relocation with __real_foo.
+
+# CHECK: NOTYPE  GLOBAL DEFAULT UND foo
+
+.global _start
+_start:
+	callq	__real_foo at plt

Modified: lld/trunk/test/ELF/wrap.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/wrap.s?rev=307110&r1=307109&r2=307110&view=diff
==============================================================================
--- lld/trunk/test/ELF/wrap.s (original)
+++ lld/trunk/test/ELF/wrap.s Tue Jul  4 17:43:18 2017
@@ -12,12 +12,16 @@
 // CHECK-NEXT: movl $0x11010, %edx
 // CHECK-NEXT: movl $0x11000, %edx
 
+// This shows an oddity of our implementation. The symbol foo gets
+// mapped to __wrap_foo, but stays in the symbol table. This results
+// in it showing up twice in the output.
+
 // RUN: llvm-readobj -t -s %t3 | FileCheck -check-prefix=SYM %s
-// SYM:      Name: __real_foo
+// SYM:      Name: foo
 // SYM-NEXT: Value: 0x11000
 // SYM:      Name: __wrap_foo
 // SYM-NEXT: Value: 0x11010
-// SYM:      Name: foo
+// SYM:      Name: __wrap_foo
 // SYM-NEXT: Value: 0x11010
 
 .global _start




More information about the llvm-commits mailing list