[lld] r347549 - [LLD][ELF] - Do not crash when parsing the -defsym option from a error state.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 26 04:29:57 PST 2018
Author: grimar
Date: Mon Nov 26 04:29:56 2018
New Revision: 347549
URL: http://llvm.org/viewvc/llvm-project?rev=347549&view=rev
Log:
[LLD][ELF] - Do not crash when parsing the -defsym option from a error state.
When we are in a error state, script parser will not parse the -defsym
expression and hence will not tokenize it. Then ScriptLexer::Pos will be 0
and LLD will assert and crash here:
MemoryBufferRef ScriptLexer::getCurrentMB() {
assert(!MBs.empty() && Pos > 0); // Bang !
Solution - stop parsing the defsym in a error state. That is consistent
with the regular case (when we parse the linker script).
Modified:
lld/trunk/ELF/ScriptParser.cpp
lld/trunk/test/ELF/defsym.s
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=347549&r1=347548&r2=347549&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Mon Nov 26 04:29:56 2018
@@ -271,6 +271,8 @@ void ScriptParser::readLinkerScript() {
}
void ScriptParser::readDefsym(StringRef Name) {
+ if (errorCount())
+ return;
Expr E = readExpr();
if (!atEOF())
setError("EOF expected, but got " + next());
Modified: lld/trunk/test/ELF/defsym.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/defsym.s?rev=347549&r1=347548&r2=347549&view=diff
==============================================================================
--- lld/trunk/test/ELF/defsym.s (original)
+++ lld/trunk/test/ELF/defsym.s Mon Nov 26 04:29:56 2018
@@ -9,6 +9,12 @@
# RUN: llvm-readobj -t -s %t2 | FileCheck %s
# RUN: llvm-objdump -d -print-imm-hex %t2 | FileCheck %s --check-prefix=USE
+## Check we are reporting the error correctly and don't crash
+## when handling the second --defsym.
+# RUN: not ld.lld -o %t2 %t.o --defsym ERR+ \
+# --defsym foo2=foo1 2>&1 | FileCheck %s --check-prefix=ERR
+# ERR: error: -defsym: syntax error: ERR+
+
# CHECK: Symbol {
# CHECK: Name: foo1
# CHECK-NEXT: Value: 0x123
More information about the llvm-commits
mailing list