summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/ScriptParser.cpp10
-rw-r--r--lld/test/ELF/linkerscript/broken-memory-declaration.s13
2 files changed, 20 insertions, 3 deletions
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index d2f12a10cfa..b89dfea4246 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -889,7 +889,7 @@ Expr ScriptParser::readConstant() {
if (S == "MAXPAGESIZE")
return [] { return Config->MaxPageSize; };
setError("unknown constant: " + S);
- return {};
+ return [] { return 0; };
}
// Parses Tok as an integer. It recognizes hexadecimal (prefixed with
@@ -1052,8 +1052,10 @@ Expr ScriptParser::readPrimary() {
}
if (Tok == "LENGTH") {
StringRef Name = readParenLiteral();
- if (Script->MemoryRegions.count(Name) == 0)
+ if (Script->MemoryRegions.count(Name) == 0) {
setError("memory region not defined: " + Name);
+ return [] { return 0; };
+ }
return [=] { return Script->MemoryRegions[Name]->Length; };
}
if (Tok == "LOADADDR") {
@@ -1066,8 +1068,10 @@ Expr ScriptParser::readPrimary() {
}
if (Tok == "ORIGIN") {
StringRef Name = readParenLiteral();
- if (Script->MemoryRegions.count(Name) == 0)
+ if (Script->MemoryRegions.count(Name) == 0) {
setError("memory region not defined: " + Name);
+ return [] { return 0; };
+ }
return [=] { return Script->MemoryRegions[Name]->Origin; };
}
if (Tok == "SEGMENT_START") {
diff --git a/lld/test/ELF/linkerscript/broken-memory-declaration.s b/lld/test/ELF/linkerscript/broken-memory-declaration.s
new file mode 100644
index 00000000000..197c9cd22b6
--- /dev/null
+++ b/lld/test/ELF/linkerscript/broken-memory-declaration.s
@@ -0,0 +1,13 @@
+# REQUIRES: x86
+
+## Check we do not crash.
+
+# RUN: echo "MEMORY { FLASH (rx) : ORIGIN = 0x1000< LENGTH" > %t.script
+# RUN: not ld.lld -o %t --script %t.script 2>&1 | FileCheck %s
+# CHECK: unexpected EOF
+
+# RUN: echo "MEMORY { FLASH (rx) : ORIGIN = 0x1000< ORIGIN" > %t.script
+# RUN: not ld.lld -o %t --script %t.script 2>&1 | FileCheck %s
+
+# RUN: echo "MEMORY { FLASH (rx) : ORIGIN = 0x1000, LENGTH = CONSTANT" > %t.script
+# RUN: not ld.lld -o %t --script %t.script 2>&1 | FileCheck %s
OpenPOWER on IntegriCloud