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; 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