[PATCH] D26935: [ELF] Allow `ASSERT` in output section descriptions
Meador Inge via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 22 08:49:39 PST 2016
meadori updated this revision to Diff 78883.
meadori added a comment.
Address review feedback.
https://reviews.llvm.org/D26935
Files:
ELF/LinkerScript.cpp
test/ELF/linkerscript/assert.s
Index: test/ELF/linkerscript/assert.s
===================================================================
--- test/ELF/linkerscript/assert.s
+++ test/ELF/linkerscript/assert.s
@@ -29,5 +29,20 @@
# RUN: ld.lld -shared -o %t5 --script %t5.script %t1.o
# RUN: llvm-readobj %t5 > /dev/null
+## Test assertions inside of output section decriptions.
+# RUN: echo "SECTIONS { \
+# RUN: .foo : { \
+# RUN: *(.foo) \
+# RUN: ASSERT(SIZEOF(.foo) == 8, \"true\"); \
+# RUN: } \
+# RUN: }" > %t6.script
+# RUN: ld.lld -shared -o %t6 --script %t6.script %t1.o
+# RUN: llvm-readobj %t6 > /dev/null
+
+# RUN: echo "SECTIONS { .foo : { ASSERT(1, \"true\") } }" > %t7.script
+# RUN: not ld.lld -shared -o %t7 --script %t7.script %t1.o > %t.log 2>&1
+# RUN: FileCheck %s -check-prefix=CHECK-SEMI < %t.log
+# CHECK-SEMI: error: {{.*}}.script:1: ; expected, but got }
+
.section .foo, "a"
.quad 0
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -470,6 +470,11 @@
return;
}
+ if (auto *AssertCmd = dyn_cast<AssertCommand>(&Base)) {
+ AssertCmd->Expression(Dot);
+ return;
+ }
+
// It handles single input section description command,
// calculates and assigns the offsets for each section and also
// updates the output section size.
@@ -1413,18 +1418,22 @@
while (!Error && !consume("}")) {
StringRef Tok = next();
- if (SymbolAssignment *Assignment = readProvideOrAssignment(Tok))
+ if (SymbolAssignment *Assignment = readProvideOrAssignment(Tok)) {
Cmd->Commands.emplace_back(Assignment);
- else if (BytesDataCommand *Data = readBytesDataCommand(Tok))
+ } else if (BytesDataCommand *Data = readBytesDataCommand(Tok)) {
Cmd->Commands.emplace_back(Data);
- else if (Tok == "FILL")
+ } else if (Tok == "ASSERT") {
+ Cmd->Commands.emplace_back(new AssertCommand(readAssert()));
+ expect(";");
+ } else if (Tok == "FILL") {
Cmd->Filler = readFill();
- else if (Tok == "SORT")
+ } else if (Tok == "SORT") {
readSort();
- else if (peek() == "(")
+ } else if (peek() == "(") {
Cmd->Commands.emplace_back(readInputSectionDescription(Tok));
- else
+ } else {
setError("unknown command " + Tok);
+ }
}
Cmd->Phdrs = readOutputSectionPhdrs();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26935.78883.patch
Type: text/x-patch
Size: 2491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161122/c7e96338/attachment.bin>
More information about the llvm-commits
mailing list