[lld] r295703 - [ELF] - Make ASSERT() return Dot instead of evaluated value.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 20 23:33:39 PST 2017


Author: grimar
Date: Tue Feb 21 01:33:38 2017
New Revision: 295703

URL: http://llvm.org/viewvc/llvm-project?rev=295703&view=rev
Log:
[ELF] - Make ASSERT() return Dot instead of evaluated value.

Previously ASSERT we implemented returned expression value.
Ex:
. = ASSERT(0x100);
would set Dot value to 0x100

Form of assert when it is assigned to Dot was implemented for 
compatibility with very old GNU ld which required it.
Some scripts in the wild, including linux kernel scripts 
use such ASSERTs at the end for doing different checks.

Currently we fail with "unable to move location counter backward"
for such scripts. Patch changes ASSERT to return location counter 
value to fix that.

Differential revision: https://reviews.llvm.org/D30171

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/test/ELF/linkerscript/assert.s
    lld/trunk/test/ELF/linkerscript/locationcountererr2.s

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=295703&r1=295702&r2=295703&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Feb 21 01:33:38 2017
@@ -1468,10 +1468,9 @@ Expr ScriptParser::readAssert() {
   StringRef Msg = unquote(next());
   expect(")");
   return [=](uint64_t Dot) {
-    uint64_t V = E(Dot);
-    if (!V)
+    if (!E(Dot))
       error(Msg);
-    return V;
+    return Dot;
   };
 }
 

Modified: lld/trunk/test/ELF/linkerscript/assert.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/assert.s?rev=295703&r1=295702&r2=295703&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/assert.s (original)
+++ lld/trunk/test/ELF/linkerscript/assert.s Tue Feb 21 01:33:38 2017
@@ -5,10 +5,6 @@
 # RUN: ld.lld -shared -o %t1 --script %t1.script %t1.o
 # RUN: llvm-readobj %t1 > /dev/null
 
-# RUN: echo "SECTIONS { ASSERT(ASSERT(42, fail) == 42, fail) }" > %t2.script
-# RUN: ld.lld -shared -o %t2 --script %t2.script %t1.o
-# RUN: llvm-readobj %t2 > /dev/null
-
 # RUN: echo "SECTIONS { ASSERT(0, fail) }" > %t3.script
 # RUN: not ld.lld -shared -o %t3 --script %t3.script %t1.o > %t.log 2>&1
 # RUN: FileCheck %s -check-prefix=FAIL < %t.log

Modified: lld/trunk/test/ELF/linkerscript/locationcountererr2.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/locationcountererr2.s?rev=295703&r1=295702&r2=295703&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/locationcountererr2.s (original)
+++ lld/trunk/test/ELF/linkerscript/locationcountererr2.s Tue Feb 21 01:33:38 2017
@@ -3,3 +3,6 @@
 # RUN: echo "SECTIONS { . = 0x20; . = 0x10; }" > %t.script
 # RUN: not ld.lld %t.o --script %t.script -o %t -shared 2>&1 | FileCheck %s
 # CHECK: unable to move location counter backward
+
+# RUN: echo "SECTIONS { . = 0x20; . = ASSERT(0x1, "foo"); }" > %t2.script
+# RUN: ld.lld %t.o --script %t2.script -o %t -shared




More information about the llvm-commits mailing list