[PATCH] D61298: [LLD] Emit dynamic relocations for references to script symbols in -pie links
ben via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 30 02:45:34 PDT 2019
bd1976llvm created this revision.
bd1976llvm added reviewers: grimar, peter.smith, ruiu.
Herald added subscribers: llvm-commits, MaskRay, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
https://reviews.llvm.org/D55423 caused LLD to stop emitting dynamic relocations for references to script symbols in -pie links.
This patch fixes that regression.
https://reviews.llvm.org/D61298
Files:
lld/ELF/Relocations.cpp
lld/test/ELF/linkerscript/symbol-pie.s
Index: lld/test/ELF/linkerscript/symbol-pie.s
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/symbol-pie.s
@@ -0,0 +1,14 @@
+## Position independent executables require dynamic
+## relocations for references to non-absolute script
+## symbols so that their values are correct at runtime.
+
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "foo = .;" > %t.script
+# RUN: ld.lld -pie -o %t --script %t.script %t.o
+# RUN: llvm-readelf -r %t | FileCheck %s
+
+# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 1 entries:
+
+.data
+.quad foo
Index: lld/ELF/Relocations.cpp
===================================================================
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -421,11 +421,6 @@
if (E == R_SIZE)
return true;
- // We set the final symbols values for linker script defined symbols later.
- // They always can be computed as a link time constant.
- if (Sym.ScriptDefined)
- return true;
-
// For the target and the relocation, we want to know if they are
// absolute or relative.
bool AbsVal = isAbsoluteValue(Sym);
@@ -449,6 +444,11 @@
if (Sym.isUndefWeak())
return true;
+ // We set the final symbols values for linker script defined symbols later.
+ // They always can be computed as a link time constant.
+ if (Sym.ScriptDefined)
+ return true;
+
error("relocation " + toString(Type) + " cannot refer to absolute symbol: " +
toString(Sym) + getLocation(S, Sym, RelOff));
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61298.197280.patch
Type: text/x-patch
Size: 1624 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190430/e86c36f9/attachment.bin>
More information about the llvm-commits
mailing list