[PATCH] D43866: [ELF] - Don't crash on broken MEMORY declaration.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 28 10:22:09 PST 2018
LGTM
George Rimar via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:
> grimar updated this revision to Diff 136281.
> grimar added a comment.
>
> - Added one more broken case.
>
>
> https://reviews.llvm.org/D43866
>
> Files:
> ELF/ScriptParser.cpp
> test/ELF/linkerscript/broken-memory-declaration.s
>
>
> Index: test/ELF/linkerscript/broken-memory-declaration.s
> ===================================================================
> --- test/ELF/linkerscript/broken-memory-declaration.s
> +++ 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
> Index: ELF/ScriptParser.cpp
> ===================================================================
> --- ELF/ScriptParser.cpp
> +++ ELF/ScriptParser.cpp
> @@ -880,7 +880,7 @@
> 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
> @@ -1043,8 +1043,10 @@
> }
> 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") {
> @@ -1057,8 +1059,10 @@
> }
> 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") {
>
>
> Index: test/ELF/linkerscript/broken-memory-declaration.s
> ===================================================================
> --- test/ELF/linkerscript/broken-memory-declaration.s
> +++ 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
> Index: ELF/ScriptParser.cpp
> ===================================================================
> --- ELF/ScriptParser.cpp
> +++ ELF/ScriptParser.cpp
> @@ -880,7 +880,7 @@
> 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
> @@ -1043,8 +1043,10 @@
> }
> 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") {
> @@ -1057,8 +1059,10 @@
> }
> 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") {
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list