[PATCH] D74687: [LLD][ELF] - Linker script: do not fail parsing when "/DISCARD/" follows the fill expression.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 18 08:08:54 PDT 2020
grimar updated this revision to Diff 251081.
grimar edited the summary of this revision.
grimar added a comment.
- Reimplemented.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74687/new/
https://reviews.llvm.org/D74687
Files:
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/sections-padding.s
Index: lld/test/ELF/linkerscript/sections-padding.s
===================================================================
--- lld/test/ELF/linkerscript/sections-padding.s
+++ lld/test/ELF/linkerscript/sections-padding.s
@@ -7,7 +7,7 @@
# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=YES %s
# YES: 66000011 22000011 22000011 22000011
-# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x1100+0x22 }" > %t.script
+# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =(0x1100+0x22) }" > %t.script
# RUN: ld.lld -o %t.out --script %t.script %t
# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=YES2 %s
# YES2: 66000011 22000011 22000011 22000011
@@ -66,6 +66,11 @@
# RUN: not ld.lld -o /dev/null %t --script %t.script 2>&1 | FileCheck --check-prefix=ERR4 %s
# ERR4: symbol not found: foo
+## Check we are able to parse scripts where "/DISCARD/" follows a section fill expression.
+# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x1122 /DISCARD/ : { *(.text) } }" > %t.script
+# RUN: ld.lld -o %t.out --script %t.script %t
+# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=YES %s
+
.section .mysec.1,"a"
.align 16
.byte 0x66
Index: lld/ELF/ScriptParser.cpp
===================================================================
--- lld/ELF/ScriptParser.cpp
+++ lld/ELF/ScriptParser.cpp
@@ -848,9 +848,9 @@
// We handle the FILL command as an alias for =fillexp section attribute,
// which is different from what GNU linkers do.
// https://sourceware.org/binutils/docs/ld/Output-Section-Data.html
- expect("(");
+ if (peek() != "(")
+ setError("( expected, but got " + peek());
cmd->filler = readFill();
- expect(")");
} else if (tok == "SORT") {
readSort();
} else if (tok == "INCLUDE") {
@@ -905,8 +905,11 @@
// When reading a hexstring, ld.bfd handles it as a blob of arbitrary
// size, while ld.gold always handles it as a 32-bit big-endian number.
// We are compatible with ld.gold because it's easier to implement.
+// Also, we require that expressions with operators must be wrapped into
+// round brackets. We did it to resolve the ambiguity when parsing scripts like:
+// SECTIONS { .foo : { ... } =120+3 /DISCARD/ : { ... } }
std::array<uint8_t, 4> ScriptParser::readFill() {
- uint64_t value = readExpr()().val;
+ uint64_t value = readPrimary()().val;
if (value > UINT32_MAX)
setError("filler expression result does not fit 32-bit: 0x" +
Twine::utohexstr(value));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74687.251081.patch
Type: text/x-patch
Size: 2505 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200318/6259d5f2/attachment.bin>
More information about the llvm-commits
mailing list