From 01a409520b39946bd4c7e86f83bc2d01d8c839d4 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 20 Sep 2017 18:56:08 +0000 Subject: [PATCH] Consider only A.Sec in moveAbsRight. The idea of this function is to simplify the implementation of binary operators like add. A value might be absolute because of an ABSOLUTE expression, but it still depends on the value of a section and we might not be able to evaluate it early. We should keep such values on the LHS, so that we can delay the evaluation. We can now handle both "1 + ABSOLUTE(foo)" and "ABSOLUTE(foo) + 1". llvm-svn: 313794 --- lld/ELF/ScriptParser.cpp | 2 +- lld/test/ELF/linkerscript/early-assign-symbol.s | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index 7d01bac1f39c..e91825680a5c 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -139,7 +139,7 @@ static bool isUnderSysroot(StringRef Path) { // Some operations only support one non absolute value. Move the // absolute one to the right hand side for convenience. static void moveAbsRight(ExprValue &A, ExprValue &B) { - if (A.isAbsolute()) + if (A.Sec == nullptr) std::swap(A, B); if (!B.isAbsolute()) error(A.Loc + ": at least one side of the expression must be absolute"); diff --git a/lld/test/ELF/linkerscript/early-assign-symbol.s b/lld/test/ELF/linkerscript/early-assign-symbol.s index 413724e113d5..5f6117863666 100644 --- a/lld/test/ELF/linkerscript/early-assign-symbol.s +++ b/lld/test/ELF/linkerscript/early-assign-symbol.s @@ -1,9 +1,6 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: echo "SECTIONS { aaa = ABSOLUTE(foo - 1) + 1; .text : { *(.text*) } }" > %t2.script -# RUN: not ld.lld -o %t --script %t2.script %t.o 2>&1 | FileCheck %s - # RUN: echo "SECTIONS { aaa = foo | 1; .text : { *(.text*) } }" > %t3.script # RUN: not ld.lld -o %t --script %t3.script %t.o 2>&1 | FileCheck %s @@ -11,6 +8,10 @@ # Simple cases that we can handle. +# RUN: echo "SECTIONS { aaa = ABSOLUTE(foo - 1) + 1; .text : { *(.text*) } }" > %t.script +# RUN: ld.lld -o %t --script %t.script %t.o +# RUN: llvm-objdump -t %t | FileCheck --check-prefix=VAL %s + # RUN: echo "SECTIONS { aaa = 1 + ABSOLUTE(foo - 1); .text : { *(.text*) } }" > %t.script # RUN: ld.lld -o %t --script %t.script %t.o # RUN: llvm-objdump -t %t | FileCheck --check-prefix=VAL %s