[PATCH] D36451: [ELF, LinkerScript] Support ! operator in linker script.

Hafiz Abid Qadeer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 02:29:11 PDT 2017


abidh updated this revision to Diff 110337.
abidh added a comment.

Handle review comments.


https://reviews.llvm.org/D36451

Files:
  ELF/ScriptParser.cpp
  test/ELF/linkerscript/assert.s
  test/ELF/linkerscript/symbol-assignexpr.s


Index: test/ELF/linkerscript/symbol-assignexpr.s
===================================================================
--- test/ELF/linkerscript/symbol-assignexpr.s
+++ test/ELF/linkerscript/symbol-assignexpr.s
@@ -15,6 +15,7 @@
 # RUN:         symbol11 = ((0x28000 + 0x1fff) & ~(0x1000 + -1)); \
 # RUN:         symbol12 = 0x1234; \
 # RUN:         symbol12 += 1; \
+# RUN:         symbol13 = ! symbol; \
 # RUN:         bar = 0x5678; \
 # RUN:         baz = 0x9abc; \
 # RUN:       }" > %t.script
@@ -39,6 +40,7 @@
 # CHECK-NEXT: fedcba9876543210 *ABS* 00000000 symbol10
 # CHECK-NEXT: 0000000000029000 *ABS* 00000000 symbol11
 # CHECK-NEXT: 0000000000001235 *ABS* 00000000 symbol12
+# CHECK-NEXT: 0000000000000000 *ABS* 00000000 symbol13
 
 # RUN: echo "SECTIONS { symbol2 = symbol; }" > %t2.script
 # RUN: not ld.lld -o %t2 --script %t2.script %t 2>&1 \
Index: test/ELF/linkerscript/assert.s
===================================================================
--- test/ELF/linkerscript/assert.s
+++ test/ELF/linkerscript/assert.s
@@ -35,5 +35,20 @@
 # RUN: FileCheck %s -check-prefix=CHECK-SEMI < %t.log
 # CHECK-SEMI: error: {{.*}}.script:1: ; expected, but got }
 
+## Test assert with ! operator
+# RUN: echo "SECTIONS { ASSERT(!(0), fail) }" > %t8.script
+# RUN: ld.lld -shared -o %t8 --script %t8.script %t1.o
+# RUN: llvm-readobj %t8 > /dev/null
+
+# RUN: echo "SECTIONS { ASSERT(!(1), fail) }" > %t9.script
+# RUN: not ld.lld -shared -o %t9 --script %t9.script %t1.o > %t.log 2>&1
+# RUN: FileCheck %s -check-prefix=FAIL1 < %t.log
+# FAIL1: fail
+
+# RUN: echo "SECTIONS { .foo : { *(.foo) } }" > %t10.script
+# RUN: echo "ASSERT(!(SIZEOF(.foo) == 0), fail);" >> %t10.script
+# RUN: ld.lld -shared -o %t10 --script %t10.script %t1.o
+# RUN: llvm-readobj %t10 > /dev/null
+
 .section .foo, "a"
  .quad 0
Index: ELF/ScriptParser.cpp
===================================================================
--- ELF/ScriptParser.cpp
+++ ELF/ScriptParser.cpp
@@ -884,6 +884,10 @@
     Expr E = readPrimary();
     return [=] { return ~E().getValue(); };
   }
+  if (consume("!")) {
+    Expr E = readPrimary();
+    return [=] { return !E().getValue(); };
+  }
   if (consume("-")) {
     Expr E = readPrimary();
     return [=] { return -E().getValue(); };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36451.110337.patch
Type: text/x-patch
Size: 2257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170809/08b33282/attachment.bin>


More information about the llvm-commits mailing list