Index: lld/trunk/ELF/LinkerScript.cpp =================================================================== --- lld/trunk/ELF/LinkerScript.cpp +++ lld/trunk/ELF/LinkerScript.cpp @@ -1072,30 +1072,24 @@ // * Include .foo.2 from every file but a.o // * Include .foo.3 from every file but b.o void ScriptParser::readSectionExcludes(InputSectionDescription *Cmd) { - Regex ExcludeFileRe; - std::vector V; - - while (!Error) { - if (skip(")")) { - Cmd->SectionPatterns.push_back( - {std::move(ExcludeFileRe), compileGlobPatterns(V)}); - return; - } - + while (!Error && peek() != ")") { + Regex ExcludeFileRe; if (skip("EXCLUDE_FILE")) { - if (!V.empty()) { - Cmd->SectionPatterns.push_back( - {std::move(ExcludeFileRe), compileGlobPatterns(V)}); - V.clear(); - } - expect("("); ExcludeFileRe = readFilePatterns(); - continue; } - V.push_back(next()); + std::vector V; + while (!Error && peek() != ")" && peek() != "EXCLUDE_FILE") + V.push_back(next()); + + if (!V.empty()) + Cmd->SectionPatterns.push_back( + {std::move(ExcludeFileRe), compileGlobPatterns(V)}); + else + setError("section pattern is expected"); } + expect(")"); } InputSectionDescription * Index: lld/trunk/test/ELF/linkerscript/exclude-multiple.s =================================================================== --- lld/trunk/test/ELF/linkerscript/exclude-multiple.s +++ lld/trunk/test/ELF/linkerscript/exclude-multiple.s @@ -18,6 +18,15 @@ # CHECK-NEXT: Contents of section .foo.3: # CHECK-NEXT: 06000000 00000000 +# RUN: echo "SECTIONS { .foo : { *(EXCLUDE_FILE (*file1.o) EXCLUDE_FILE (*file2.o) .foo.3) } }" > %t2.script +# RUN: not ld.lld -script %t2.script %tfile1.o %tfile2.o %tfile3.o -o %t2.o 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ERR +# ERR: section pattern is expected + +# RUN: echo "SECTIONS { .foo : { *(EXCLUDE_FILE (*file1.o)) } }" > %t3.script +# RUN: not ld.lld -script %t3.script %tfile1.o %tfile2.o %tfile3.o -o %t2.o 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ERR + .section .foo.1,"a" .quad 1