[ELF] - Linkerscript: reimplement readSectionExcludes()
It is not only a bit more straightforward now, but also next 2 issues are solved:
* It just crashed on ".foo : { *(EXCLUDE_FILE (*file1.o)) }" before.
* It accepted multiple EXCLUDE_FILEs in a row.
Differential revision: https://reviews.llvm.org/D24726
llvm-svn: 282060
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 7101c7f..a0bffce 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/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<StringRef> 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<StringRef> 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 *