[PATCH] D22912: [ELF] - Linkerscript: implemented ASSERT() keyword.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 28 04:44:15 PDT 2016
grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, davide, evgeny777.
ASSERT(exp, message)
Ensure that exp is non-zero. If it is zero, then exit the linker with an error
code, and print message.
Looks ASSERT is useful and used by some projects. I noticed it here:
https://searchcode.com/codesearch/view/42878166/
https://reviews.llvm.org/D22912
Files:
ELF/LinkerScript.cpp
test/ELF/linkerscript/linkerscript-assert.s
Index: test/ELF/linkerscript/linkerscript-assert.s
===================================================================
--- test/ELF/linkerscript/linkerscript-assert.s
+++ test/ELF/linkerscript/linkerscript-assert.s
@@ -0,0 +1,58 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+
+# RUN: echo "SECTIONS { \
+# RUN: .aaa : { *(.aaa) } \
+# RUN: _end_aaa = .; \
+# RUN: . = ASSERT(_end_aaa == 0x128, \"Assert fail!\"); \
+# RUN: .bbb : { *(.bbb) } \
+# RUN: _end_bbb = .; \
+# RUN: . = ASSERT(_end_bbb <= 0x128 * 2, \"Assert fail!\"); \
+# RUN: }" > %t1.script
+# RUN: ld.lld -o %t1 --script %t1.script %t1.o
+# RUN: llvm-readobj -s %t1 | FileCheck %s -check-prefix=PASS
+# PASS: Section {
+# PASS: Index: 2
+# PASS-NEXT: Name: .bbb
+# PASS-NEXT: Type: SHT_PROGBITS
+# PASS-NEXT: Flags [
+# PASS-NEXT: SHF_ALLOC
+# PASS-NEXT: ]
+# PASS-NEXT: Address: 0x128
+# PASS-NEXT: Offset: 0x128
+# PASS-NEXT: Size: 8
+# PASS-NEXT: Link:
+# PASS-NEXT: Info:
+# PASS-NEXT: AddressAlignment:
+# PASS-NEXT: EntrySize:
+# PASS-NEXT: }
+
+# RUN: echo "SECTIONS { \
+# RUN: .aaa : { *(.aaa) } \
+# RUN: _end_aaa = .; \
+# RUN: . = ASSERT(_end_aaa != 0x128, \"Assert fail!\"); \
+# RUN: }" > %t2.script
+# RUN: not ld.lld -o %t2 --script %t2.script %t1.o > %t.log 2>&1
+# RUN: FileCheck %s -check-prefix=FAIL < %t.log
+# FAIL: Assert fail!
+
+# RUN: echo "SECTIONS { \
+# RUN: .aaa : { *(.aaa) } \
+# RUN: _end_aaa = .; \
+# RUN: . = ASSERT(_end_aaa == 0x128, \"Assert fail!\"); \
+# RUN: .bbb : { *(.bbb) } \
+# RUN: _end_bbb = .; \
+# RUN: . = ASSERT(_end_bbb > 0x128 * 2, \"Assert fail!\"); \
+# RUN: }" > %t3.script
+# RUN: not ld.lld -o %t3 --script %t3.script %t1.o > %t.log 2>&1
+# RUN: FileCheck %s -check-prefix=FAIL < %t.log
+
+.global _start
+_start:
+ nop
+
+.section .aaa,"a"
+ .quad 0
+
+.section .bbb,"a"
+ .quad 0
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -897,6 +897,18 @@
expect(")");
return [](uint64_t Dot) { return alignTo(Dot, Target->PageSize); };
}
+ if (Tok == "ASSERT") {
+ expect("(");
+ Expr E = readExpr();
+ expect(",");
+ StringRef Msg = next();
+ expect(")");
+ return [=](uint64_t Dot) {
+ if (!E(Dot))
+ error(Msg);
+ return Dot;
+ };
+ }
// Parse a symbol name or a number literal.
uint64_t V = 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22912.65911.patch
Type: text/x-patch
Size: 2519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160728/19393244/attachment.bin>
More information about the llvm-commits
mailing list