[lld] r309372 - [ELF] - Do not crash when ALIGN/DATA_SEGMENT_ALIGN expression used with zero value.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 28 02:27:49 PDT 2017
Author: grimar
Date: Fri Jul 28 02:27:49 2017
New Revision: 309372
URL: http://llvm.org/viewvc/llvm-project?rev=309372&view=rev
Log:
[ELF] - Do not crash when ALIGN/DATA_SEGMENT_ALIGN expression used with zero value.
Previously we would crash when tried to ALIGN(0).
Patch uses value 1 instead in this case, that
looks to be consistent with GNU linkers
and reasonable and simple behavior itself.
Differential revision: https://reviews.llvm.org/D35942
Modified:
lld/trunk/ELF/ScriptParser.cpp
lld/trunk/test/ELF/linkerscript/align.s
lld/trunk/test/ELF/linkerscript/operators.s
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=309372&r1=309371&r2=309372&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Fri Jul 28 02:27:49 2017
@@ -900,13 +900,15 @@ Expr ScriptParser::readPrimary() {
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 @@ Expr ScriptParser::readPrimary() {
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("(");
Modified: lld/trunk/test/ELF/linkerscript/align.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/align.s?rev=309372&r1=309371&r2=309372&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/align.s (original)
+++ lld/trunk/test/ELF/linkerscript/align.s Fri Jul 28 02:27:49 2017
@@ -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
Modified: lld/trunk/test/ELF/linkerscript/operators.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/operators.s?rev=309372&r1=309371&r2=309372&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/operators.s (original)
+++ lld/trunk/test/ELF/linkerscript/operators.s Fri Jul 28 02:27:49 2017
@@ -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
More information about the llvm-commits
mailing list