Consider ForceAbsolute again in moveAbsRight.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 20 Sep 2017 19:24:57 +0000 (19:24 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 20 Sep 2017 19:24:57 +0000 (19:24 +0000)
This patch goes back to considering ForceAbsolute in moveAbsRight, but
only if the second argument is not already absolute.

With this we can handle "foo + ABSOLUTE(foo)" and "ABSOLUTE(foo) + foo".

llvm-svn: 313800

lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/absolute2.s [new file with mode: 0644]

index e918256..c1daa9a 100644 (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.Sec == nullptr)
+  if (A.Sec == nullptr || (A.ForceAbsolute && !B.isAbsolute()))
     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/absolute2.s b/lld/test/ELF/linkerscript/absolute2.s
new file mode 100644 (file)
index 0000000..513468d
--- /dev/null
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+
+# RUN: echo "SECTIONS { .text : { *(.text) } foo = ABSOLUTE(_start) + _start; };" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-objdump -t %t | FileCheck %s
+
+# RUN: echo "SECTIONS { .text : { *(.text) } foo = _start + ABSOLUTE(_start); };" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
+# RUN: llvm-objdump -t %t | FileCheck %s
+
+# CHECK: 0000000000000001         .text           00000000 _start
+# CHECK: 0000000000000002         .text           00000000 foo
+
+        .global _start
+        nop
+_start: