[PATCH] D26801: Allow use define symbols to override linker defined ones
Rafael Ávila de Espíndola via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 17 07:46:54 PST 2016
rafael created this revision.
rafael added a reviewer: ruiu.
rafael added a subscriber: llvm-commits.
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.
https://reviews.llvm.org/D26801
Files:
ELF/Writer.cpp
test/ELF/duplicate-internal.s
test/ELF/linkerscript/dynamic-sym.s
Index: test/ELF/linkerscript/dynamic-sym.s
===================================================================
--- /dev/null
+++ test/ELF/linkerscript/dynamic-sym.s
@@ -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: }
Index: test/ELF/duplicate-internal.s
===================================================================
--- test/ELF/duplicate-internal.s
+++ /dev/null
@@ -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
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -569,7 +569,7 @@
static Symbol *addRegular(StringRef Name, InputSectionBase<ELFT> *IS,
typename ELFT::uint Value) {
typename ELFT::Sym LocalHidden = {};
- LocalHidden.setBindingAndType(STB_LOCAL, STT_NOTYPE);
+ LocalHidden.setBindingAndType(STB_WEAK, STT_NOTYPE);
LocalHidden.setVisibility(STV_HIDDEN);
LocalHidden.st_value = Value;
return Symtab<ELFT>::X->addRegular(Name, LocalHidden, IS, nullptr);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26801.78367.patch
Type: text/x-patch
Size: 1777 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161117/241b9ef4/attachment.bin>
More information about the llvm-commits
mailing list