Don't try to compute a value that is known to fail.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 20 Sep 2017 16:42:56 +0000 (16:42 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 20 Sep 2017 16:42:56 +0000 (16:42 +0000)
We try to evaluate expressions early when possible, but it is not
possible to evaluate them early if they are based on a section.

Before we would get this wrong on ABSOLUTE expressions.

llvm-svn: 313764

lld/ELF/LinkerScript.cpp
lld/test/ELF/linkerscript/early-assign-symbol.s

index 908ebe5..b717067 100644 (file)
@@ -87,7 +87,7 @@ static SymbolBody *addRegular(SymbolAssignment *Cmd) {
   // We want to set symbol values early if we can. This allows us to use symbols
   // as variables in linker scripts. Doing so allows us to write expressions
   // like this: `alignment = 16; . = ALIGN(., alignment)`
-  uint64_t SymValue = Value.isAbsolute() ? Value.getValue() : 0;
+  uint64_t SymValue = Value.Sec ? 0 : Value.getValue();
   replaceBody<DefinedRegular>(Sym, nullptr, Cmd->Name, /*IsLocal=*/false,
                               Visibility, STT_NOTYPE, SymValue, 0, Sec);
   return Sym->body();
index cc8394b..e2e9175 100644 (file)
 
 # CHECK: error: {{.*}}.script:1: unable to evaluate expression: input section .text has no output section assigned
 
+# Simple case that we can handle.
+# RUN: echo "SECTIONS { aaa = ABSOLUTE(foo); .text  : { *(.text*) } }" > %t4.script
+# RUN: ld.lld -o %t --script %t4.script %t.o
+
 .section .text
 .globl foo
 foo: