[lld] r313800 - Consider ForceAbsolute again in moveAbsRight.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 12:24:57 PDT 2017


Author: rafael
Date: Wed Sep 20 12:24:57 2017
New Revision: 313800

URL: http://llvm.org/viewvc/llvm-project?rev=313800&view=rev
Log:
Consider ForceAbsolute again in moveAbsRight.

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".

Added:
    lld/trunk/test/ELF/linkerscript/absolute2.s
Modified:
    lld/trunk/ELF/ScriptParser.cpp

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=313800&r1=313799&r2=313800&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Wed Sep 20 12:24:57 2017
@@ -139,7 +139,7 @@ static bool isUnderSysroot(StringRef Pat
 // 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");

Added: lld/trunk/test/ELF/linkerscript/absolute2.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/absolute2.s?rev=313800&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/absolute2.s (added)
+++ lld/trunk/test/ELF/linkerscript/absolute2.s Wed Sep 20 12:24:57 2017
@@ -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:




More information about the llvm-commits mailing list