Index: ELF/ScriptLexer.h =================================================================== --- ELF/ScriptLexer.h +++ ELF/ScriptLexer.h @@ -39,6 +39,7 @@ std::vector Tokens; bool InExpr = false; size_t Pos = 0; + std::string ErrorPrefix; private: void maybeSplitExpr(); Index: ELF/ScriptLexer.cpp =================================================================== --- ELF/ScriptLexer.cpp +++ ELF/ScriptLexer.cpp @@ -78,7 +78,7 @@ if (ErrorCount) return; - std::string S = (getCurrentLocation() + ": " + Msg).str(); + std::string S = getCurrentLocation() + ": " + ErrorPrefix + Msg.str(); if (Pos) S += "\n>>> " + getLine().str() + "\n>>> " + std::string(getColumnNumber(), ' ') + "^"; Index: ELF/ScriptParser.cpp =================================================================== --- ELF/ScriptParser.cpp +++ ELF/ScriptParser.cpp @@ -604,6 +604,8 @@ } OutputSection *ScriptParser::readOutputSectionDescription(StringRef OutSec) { + ErrorPrefix = "unable to parse description for output section '" + + OutSec.str() + "':\n>>> "; OutputSection *Cmd = Script->createOutputSection(OutSec, getCurrentLocation()); @@ -666,6 +668,7 @@ // Consume optional comma following output section command. consume(","); + ErrorPrefix = ""; return Cmd; } Index: test/ELF/linkerscript/assert.s =================================================================== --- test/ELF/linkerscript/assert.s +++ test/ELF/linkerscript/assert.s @@ -33,7 +33,8 @@ # RUN: echo "SECTIONS { .foo : { ASSERT(1, \"true\") } }" > %t7.script # RUN: not ld.lld -shared -o %t7 --script %t7.script %t1.o > %t.log 2>&1 # RUN: FileCheck %s -check-prefix=CHECK-SEMI < %t.log -# CHECK-SEMI: error: {{.*}}.script:1: ; expected, but got } +# CHECK-SEMI: error: {{.*}}.script:1: unable to parse description for output section '.foo': +# CHECK-SEMI-NEXT: >>> ; expected, but got } .section .foo, "a" .quad 0 Index: test/ELF/linkerscript/diagnostic.s =================================================================== --- test/ELF/linkerscript/diagnostic.s +++ test/ELF/linkerscript/diagnostic.s @@ -61,7 +61,8 @@ # RUN: echo "boom .temp : { *(.temp) } }" >> %t.script # RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | \ # RUN: FileCheck -check-prefix=ERR7 -strict-whitespace %s -# ERR7: error: {{.*}}.script:4: malformed number: .temp +# ERR7: error: {{.*}}.script:4: unable to parse description for output section 'boom': +# ERR7-NEXT: >>> malformed number: .temp # ERR7-NEXT: >>> boom .temp : { *(.temp) } } # ERR7-NEXT: >>> ^ @@ -88,7 +89,8 @@ # RUN: echo "INCLUDE \"%t.script.inc\"" > %t.script # RUN: not ld.lld -shared %t -o %t1 --script %t.script 2>&1 | \ # RUN: FileCheck -check-prefix=ERR10 -strict-whitespace %s -# ERR10: error: {{.*}}.script.inc:4: malformed number: .temp +# ERR10: error: {{.*}}.script.inc:4: unable to parse description for output section 'boom': +# ERR10-NEXT: >>> malformed number: .temp # ERR10-NEXT: >>> boom .temp : { *(.temp) } } # ERR10-NEXT: >>> ^