Index: lld/trunk/ELF/LinkerScript.cpp =================================================================== --- lld/trunk/ELF/LinkerScript.cpp +++ lld/trunk/ELF/LinkerScript.cpp @@ -48,8 +48,12 @@ LinkerScript *elf::Script; uint64_t ExprValue::getValue() const { - if (Sec) - return Sec->getOffset(Val) + Sec->getOutputSection()->Addr; + if (Sec) { + if (Sec->getOutputSection()) + return Sec->getOffset(Val) + Sec->getOutputSection()->Addr; + error("unable to evaluate expression: input section " + Sec->Name + + " has no output section assigned"); + } return Val; } Index: lld/trunk/test/ELF/linkerscript/early-assign-symbol.s =================================================================== --- lld/trunk/test/ELF/linkerscript/early-assign-symbol.s +++ lld/trunk/test/ELF/linkerscript/early-assign-symbol.s @@ -0,0 +1,14 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o + +# RUN: echo "SECTIONS { aaa = 1 + ABSOLUTE(foo - 1); }" > %t1.script +# RUN: not ld.lld -o %t --script %t1.script %t.o 2>&1 | FileCheck %s + +# RUN: echo "SECTIONS { aaa = ABSOLUTE(foo - 1) + 1; }" > %t2.script +# RUN: not ld.lld -o %t --script %t2.script %t.o 2>&1 | FileCheck %s + +# CHECK: error: unable to evaluate expression: input section .text has no output section assigned + +.section .text +.globl foo +foo: