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
This commit is contained in:
Rafael Espindola 2017-09-20 18:56:08 +00:00
parent be46b4e6d7
commit 01a409520b
2 changed files with 5 additions and 4 deletions

View File

@ -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");

View File

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