[PATCH] D35942: [ELF] - Do not crash when ALIGN/DATA_SEGMENT_ALIGN expression used with zero value.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 28 02:29:25 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL309372: [ELF] - Do not crash when ALIGN/DATA_SEGMENT_ALIGN expression used with zero… (authored by grimar).
Changed prior to commit:
https://reviews.llvm.org/D35942?vs=108457&id=108610#toc
Repository:
rL LLVM
https://reviews.llvm.org/D35942
Files:
lld/trunk/ELF/ScriptParser.cpp
lld/trunk/test/ELF/linkerscript/align.s
lld/trunk/test/ELF/linkerscript/operators.s
Index: lld/trunk/test/ELF/linkerscript/align.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/align.s
+++ lld/trunk/test/ELF/linkerscript/align.s
@@ -66,6 +66,21 @@
# SYMBOLS-NEXT: 0000000000011000 .bbb 00000000 __start_bbb
# SYMBOLS-NEXT: 0000000000012000 .bbb 00000000 __end_bbb
+## Check that ALIGN zero do nothing and does not crash #1.
+# RUN: echo "SECTIONS { . = ALIGN(0x123, 0); .aaa : { *(.aaa) } }" > %t.script
+# RUN: ld.lld -o %t4 --script %t.script %t
+# RUN: llvm-objdump -section-headers %t4 | FileCheck %s -check-prefix=ZERO
+
+# ZERO: Sections:
+# ZERO-NEXT: Idx Name Size Address Type
+# ZERO-NEXT: 0 00000000 0000000000000000
+# ZERO-NEXT: 1 .aaa 00000008 0000000000000123 DATA
+
+## Check that ALIGN zero do nothing and does not crash #2.
+# RUN: echo "SECTIONS { . = 0x123; . = ALIGN(0); .aaa : { *(.aaa) } }" > %t.script
+# RUN: ld.lld -o %t5 --script %t.script %t
+# RUN: llvm-objdump -section-headers %t5 | FileCheck %s -check-prefix=ZERO
+
.global _start
_start:
nop
Index: lld/trunk/test/ELF/linkerscript/operators.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/operators.s
+++ lld/trunk/test/ELF/linkerscript/operators.s
@@ -25,6 +25,7 @@
# RUN: commonpagesize = CONSTANT (COMMONPAGESIZE); \
# RUN: . = 0xfff0; \
# RUN: datasegmentalign = DATA_SEGMENT_ALIGN (0xffff, 0); \
+# RUN: datasegmentalign2 = DATA_SEGMENT_ALIGN (0, 0); \
# RUN: }" > %t.script
# RUN: ld.lld %t --script %t.script -o %t2
# RUN: llvm-objdump -t %t2 | FileCheck %s
@@ -51,6 +52,7 @@
# CHECK: 00000000001000 *ABS* 00000000 maxpagesize
# CHECK: 00000000001000 *ABS* 00000000 commonpagesize
# CHECK: 0000000000ffff *ABS* 00000000 datasegmentalign
+# CHECK: 0000000000fff0 *ABS* 00000000 datasegmentalign2
## Mailformed number error.
# RUN: echo "SECTIONS { . = 0x12Q41; }" > %t.script
Index: lld/trunk/ELF/ScriptParser.cpp
===================================================================
--- lld/trunk/ELF/ScriptParser.cpp
+++ lld/trunk/ELF/ScriptParser.cpp
@@ -900,13 +900,15 @@
expect("(");
Expr E = readExpr();
if (consume(")"))
- return [=] { return alignTo(Script->getDot(), E().getValue()); };
+ return [=] {
+ return alignTo(Script->getDot(), std::max((uint64_t)1, E().getValue()));
+ };
expect(",");
Expr E2 = readExpr();
expect(")");
return [=] {
ExprValue V = E();
- V.Alignment = E2().getValue();
+ V.Alignment = std::max((uint64_t)1, E2().getValue());
return V;
};
}
@@ -927,7 +929,9 @@
expect(",");
readExpr();
expect(")");
- return [=] { return alignTo(Script->getDot(), E().getValue()); };
+ return [=] {
+ return alignTo(Script->getDot(), std::max((uint64_t)1, E().getValue()));
+ };
}
if (Tok == "DATA_SEGMENT_END") {
expect("(");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35942.108610.patch
Type: text/x-patch
Size: 3009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170728/d4da05c7/attachment.bin>
More information about the llvm-commits
mailing list