[lld] r339412 - [LLD][ELF] - Fix crash when using empty --defsym.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 9 23:32:39 PDT 2018
Author: grimar
Date: Thu Aug 9 23:32:39 2018
New Revision: 339412
URL: http://llvm.org/viewvc/llvm-project?rev=339412&view=rev
Log:
[LLD][ELF] - Fix crash when using empty --defsym.
We have a crash issue when handling the empty -defsym.
For parsing this option we are using ScriptParser class which is used
generally for reading the linker script. For empty defsym case, we
pass the empty memory buffer and crash in the place removed in https://reviews.llvm.org/rL336436.
But reverting of the above patch would not help here (we would still crash but a bit later). And
even after fixing the crash we would report something like
"lld.exe: error: -defsym:1: unexpected EOF"
It is probably not the appropriate message because mentions EOF.
I think the issue should be handled on a higher level like this patch does.
So we do not want to pass the empty memory buffer first of all I believe.
Differential revision: https://reviews.llvm.org/D50498
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/test/ELF/defsym.s
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=339412&r1=339411&r2=339412&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Aug 9 23:32:39 2018
@@ -1029,7 +1029,10 @@ void LinkerDriver::createFiles(opt::Inpu
StringRef From;
StringRef To;
std::tie(From, To) = StringRef(Arg->getValue()).split('=');
- readDefsym(From, MemoryBufferRef(To, "-defsym"));
+ if (From.empty() || To.empty())
+ error("-defsym: syntax error: " + StringRef(Arg->getValue()));
+ else
+ readDefsym(From, MemoryBufferRef(To, "-defsym"));
break;
}
case OPT_script:
Modified: lld/trunk/test/ELF/defsym.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/defsym.s?rev=339412&r1=339411&r2=339412&view=diff
==============================================================================
--- lld/trunk/test/ELF/defsym.s (original)
+++ lld/trunk/test/ELF/defsym.s Thu Aug 9 23:32:39 2018
@@ -74,6 +74,12 @@
# RUN: not ld.lld -o %t %t.o --defsym=xxx=yyy,zzz 2>&1 | FileCheck %s -check-prefix=ERR2
# ERR2: -defsym:1: EOF expected, but got ,
+# RUN: not ld.lld -o %t %t.o --defsym=foo 2>&1 | FileCheck %s -check-prefix=ERR3
+# ERR3: error: -defsym: syntax error: foo
+
+# RUN: not ld.lld -o %t %t.o --defsym= 2>&1 | FileCheck %s -check-prefix=ERR4
+# ERR4: error: -defsym: syntax error:
+
.globl foo1
foo1 = 0x123
More information about the llvm-commits
mailing list