summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Relocations.cpp10
-rw-r--r--lld/test/ELF/linkerscript/symbol-pie.s19
2 files changed, 24 insertions, 5 deletions
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 7408506ccf7..fc352508ce8 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -421,11 +421,6 @@ static bool isStaticLinkTimeConstant(RelExpr E, RelType Type, const Symbol &Sym,
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 @@ static bool isStaticLinkTimeConstant(RelExpr E, RelType Type, const Symbol &Sym,
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;
diff --git a/lld/test/ELF/linkerscript/symbol-pie.s b/lld/test/ELF/linkerscript/symbol-pie.s
new file mode 100644
index 00000000000..1e4bc541225
--- /dev/null
+++ b/lld/test/ELF/linkerscript/symbol-pie.s
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { .data 0x2000 : { foo = .; *(.data) } }" > %t.script
+# RUN: ld.lld -pie -o %t --script %t.script %t.o
+# RUN: llvm-readobj -r %t | FileCheck %s
+
+## Position independent executables require dynamic
+## relocations for references to non-absolute script
+## symbols.
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section ({{.*}}) .rela.dyn {
+# CHECK-NEXT: 0x2000 R_X86_64_RELATIVE - 0x2000
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+.data
+.quad foo
OpenPOWER on IntegriCloud