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
llvm-svn: 359683
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);
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;
--- /dev/null
+# REQUIRES: x86\r
+\r
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o\r
+# RUN: echo "SECTIONS { .data 0x2000 : { foo = .; *(.data) } }" > %t.script\r
+# RUN: ld.lld -pie -o %t --script %t.script %t.o\r
+# RUN: llvm-readobj -r %t | FileCheck %s\r
+\r
+## Position independent executables require dynamic\r
+## relocations for references to non-absolute script\r
+## symbols.\r
+\r
+# CHECK: Relocations [\r
+# CHECK-NEXT: Section ({{.*}}) .rela.dyn {\r
+# CHECK-NEXT: 0x2000 R_X86_64_RELATIVE - 0x2000\r
+# CHECK-NEXT: }\r
+# CHECK-NEXT: ]\r
+\r
+.data\r
+.quad foo\r