[lld] r313764 - Don't try to compute a value that is known to fail.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 09:42:56 PDT 2017


Author: rafael
Date: Wed Sep 20 09:42:56 2017
New Revision: 313764

URL: http://llvm.org/viewvc/llvm-project?rev=313764&view=rev
Log:
Don't try to compute a value that is known to fail.

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.

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

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=313764&r1=313763&r2=313764&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Sep 20 09:42:56 2017
@@ -87,7 +87,7 @@ static SymbolBody *addRegular(SymbolAssi
   // 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();

Modified: lld/trunk/test/ELF/linkerscript/early-assign-symbol.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/early-assign-symbol.s?rev=313764&r1=313763&r2=313764&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/early-assign-symbol.s (original)
+++ lld/trunk/test/ELF/linkerscript/early-assign-symbol.s Wed Sep 20 09:42:56 2017
@@ -12,6 +12,10 @@
 
 # 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:




More information about the llvm-commits mailing list