[PATCH] D30171: [ELF] - Make ASSERT() return Dot instead of evaluated value.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 20 08:37:41 PST 2017


grimar created this revision.

Currently we fail with "unable to move location counter backward" in scripts that
assign ASSERT to Dot.

Previously ASSERT we implemented earlier returned expression value.
Ex:

  . = ASSERT(0x100); 

would set Dot to 0x100

Documentation does not say anything about this behavior:
"ASSERT(exp, message) Ensure that exp is non-zero. If it is zero, then exit the linker with an error code, and print message."

As far I know form of assert when it is assigned to Dot was used for compatibility with very old GNU ld whick required it.
Some scripts in the wild, including linux kernel scripts use ASSERTs at the end for checks, like:

  <many script code here>
  /*
   * Build-time check on the image size:
   */
  . = ASSERT((_end - _text <= (512 * 1024 * 1024)), "kernel image bigger than KERNEL_IMAGE_SIZE");

Since we error out moving backward now, I thing it is reasonable just to change behavior to return Dot. That way ASSERT will be unable
to move it backward. Anyways since that form was implemented just for compatibility, we probably should not really care what does
it return.

That fixes issue I am observing now when trying to use reproduce for vmlinux,


https://reviews.llvm.org/D30171

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript/assert.s
  test/ELF/linkerscript/locationcountererr2.s


Index: test/ELF/linkerscript/locationcountererr2.s
===================================================================
--- test/ELF/linkerscript/locationcountererr2.s
+++ test/ELF/linkerscript/locationcountererr2.s
@@ -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(0x10 > 0x1, "foo"); }" > %t2.script
+# RUN: ld.lld %t.o --script %t2.script -o %t -shared
Index: test/ELF/linkerscript/assert.s
===================================================================
--- test/ELF/linkerscript/assert.s
+++ test/ELF/linkerscript/assert.s
@@ -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
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -1468,10 +1468,9 @@
   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;
   };
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30171.89127.patch
Type: text/x-patch
Size: 1568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170220/52ed7262/attachment.bin>


More information about the llvm-commits mailing list