[lld] r287260 - Allow use define symbols to override linker defined ones.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 17 13:20:16 PST 2016


Author: rafael
Date: Thu Nov 17 15:20:16 2016
New Revision: 287260

URL: http://llvm.org/viewvc/llvm-project?rev=287260&view=rev
Log:
Allow use define symbols to override linker defined ones.

I hit an internal linker script that was defining _DYNAMIC instead of
letting the linker do it. It turns out that both bfd and gold allow
that.

This is pretty easy to implement, just make the linker defined symbol
weak. This should have no impact in the case where there is no user
defined symbol: The visibility is hidden, which causes the output to
still be local.

Added:
    lld/trunk/test/ELF/linkerscript/dynamic-sym.s
Removed:
    lld/trunk/test/ELF/duplicate-internal.s
Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=287260&r1=287259&r2=287260&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Nov 17 15:20:16 2016
@@ -569,7 +569,9 @@ template <class ELFT>
 static Symbol *addRegular(StringRef Name, InputSectionBase<ELFT> *IS,
                           typename ELFT::uint Value) {
   typename ELFT::Sym LocalHidden = {};
-  LocalHidden.setBindingAndType(STB_LOCAL, STT_NOTYPE);
+  // The linker generated symbols are added as STB_WEAK to allow user defined
+  // ones to override them.
+  LocalHidden.setBindingAndType(STB_WEAK, STT_NOTYPE);
   LocalHidden.setVisibility(STV_HIDDEN);
   LocalHidden.st_value = Value;
   return Symtab<ELFT>::X->addRegular(Name, LocalHidden, IS, nullptr);

Removed: lld/trunk/test/ELF/duplicate-internal.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/duplicate-internal.s?rev=287259&view=auto
==============================================================================
--- lld/trunk/test/ELF/duplicate-internal.s (original)
+++ lld/trunk/test/ELF/duplicate-internal.s (removed)
@@ -1,11 +0,0 @@
-# Should print an expected message in case of conflict with an internally generated symbol.
-
-# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
-# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
-
-# CHECK: duplicate symbol '_gp' in {{.*}} and (internal)
-
-# REQUIRES: mips
-
-  .globl  _gp
-_gp = 0

Added: lld/trunk/test/ELF/linkerscript/dynamic-sym.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/dynamic-sym.s?rev=287260&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/dynamic-sym.s (added)
+++ lld/trunk/test/ELF/linkerscript/dynamic-sym.s Thu Nov 17 15:20:16 2016
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: echo "_DYNAMIC = 0x123;" > %t.script
+# RUN: ld.lld -T %t.script %t.o -shared -o %t.so
+# RUN: llvm-readobj -t %t.so | FileCheck %s
+
+# CHECK:      Symbol {
+# CHECK:        Name: _DYNAMIC
+# CHECK-NEXT:   Value: 0x123
+# CHECK-NEXT:   Size: 0
+# CHECK-NEXT:   Binding: Local
+# CHECK-NEXT:   Type: None
+# CHECK-NEXT:   Other [
+# CHECK-NEXT:     STV_HIDDEN
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Section: Absolute
+# CHECK-NEXT: }




More information about the llvm-commits mailing list