Index: ELF/ScriptParser.cpp =================================================================== --- ELF/ScriptParser.cpp +++ ELF/ScriptParser.cpp @@ -282,8 +282,13 @@ expect("("); bool Orig = Config->AsNeeded; Config->AsNeeded = true; - while (!Error && !consume(")")) - addFile(unquote(next())); + while (!Error && !consume(")") && !ErrorCount) { + StringRef File = unquote(next()); + addFile(File); + if (ErrorCount) + setError("unable to find " + File); + } + Config->AsNeeded = Orig; } @@ -304,11 +309,16 @@ void ScriptParser::readGroup() { expect("("); - while (!Error && !consume(")")) { - if (consume("AS_NEEDED")) + while (!Error && !consume(")") && !ErrorCount) { + if (consume("AS_NEEDED")) { readAsNeeded(); - else - addFile(unquote(next())); + continue; + } + + StringRef File = unquote(next()); + addFile(File); + if (ErrorCount) + setError("unable to find " + File); } } Index: test/ELF/linkerscript/group.s =================================================================== --- test/ELF/linkerscript/group.s +++ test/ELF/linkerscript/group.s @@ -51,6 +51,20 @@ # RUN: ld.lld -o %t2 %t.script # RUN: llvm-readobj %t2 > /dev/null +# RUN: echo "INPUT(/no_such_file)" > %t.script +# RUN: not ld.lld -o %t2 %t.script 2>&1 | FileCheck -check-prefix=ERR %s +# ERR: cannot open {{.*}}no_such_file: {{[Nn]}}o such file or directory +# ERR: {{.*}}.script:1: unable to find /no_such_file + +# RUN: echo "INPUT(AS_NEEDED(/no_such_file))" > %t.script +# RUN: not ld.lld -o %t2 %t.script 2>&1 | FileCheck -check-prefix=ERR %s + +# RUN: echo "GROUP(/no_such_file)" > %t.script +# RUN: not ld.lld -o %t2 %t.script 2>&1 | FileCheck -check-prefix=ERR %s + +# RUN: echo "GROUP(AS_NEEDED(/no_such_file))" > %t.script +# RUN: not ld.lld -o %t2 %t.script 2>&1 | FileCheck -check-prefix=ERR %s + .globl _start _start: ret