diff options
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 3872d30d248..6085b19b678 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -92,44 +92,35 @@ template <class ELFT> LinkerScript<ELFT>::~LinkerScript() {} template <class ELFT> bool LinkerScript<ELFT>::shouldKeep(InputSectionBase<ELFT> *S) { - for (StringRef Pat : Opt.KeptSections) - if (globMatch(Pat, S->getSectionName())) - return true; - return false; -} - -static bool match(ArrayRef<StringRef> Patterns, StringRef S) { - for (StringRef Pat : Patterns) - if (globMatch(Pat, S)) + for (Regex *Re : Opt.KeptSections) + if (Re->match(S->getSectionName())) return true; return false; } static bool fileMatches(const InputSectionDescription *Desc, StringRef Filename) { - if (!globMatch(Desc->FilePattern, Filename)) - return false; - return Desc->ExcludedFiles.empty() || !match(Desc->ExcludedFiles, Filename); + return const_cast<Regex &>(Desc->FileRe).match(Filename) && + !const_cast<Regex &>(Desc->ExcludedFileRe).match(Filename); } // Returns input sections filtered by given glob patterns. template <class ELFT> std::vector<InputSectionBase<ELFT> *> LinkerScript<ELFT>::getInputSections(const InputSectionDescription *I) { - ArrayRef<StringRef> Patterns = I->SectionPatterns; + const Regex &Re = I->SectionRe; std::vector<InputSectionBase<ELFT> *> Ret; for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab<ELFT>::X->getObjectFiles()) { if (fileMatches(I, sys::path::filename(F->getName()))) for (InputSectionBase<ELFT> *S : F->getSections()) if (!isDiscarded(S) && !S->OutSec && - match(Patterns, S->getSectionName())) + const_cast<Regex &>(Re).match(S->getSectionName())) Ret.push_back(S); } - if (llvm::find(Patterns, "COMMON") != Patterns.end()) + if (const_cast<Regex &>(Re).match("COMMON")) Ret.push_back(CommonInputSection<ELFT>::X); - return Ret; } @@ -634,7 +625,7 @@ private: std::vector<uint8_t> readOutputSectionFiller(); std::vector<StringRef> readOutputSectionPhdrs(); InputSectionDescription *readInputSectionDescription(StringRef Tok); - std::vector<StringRef> readInputFilePatterns(); + Regex readFilePatterns(); InputSectionDescription *readInputSectionRules(StringRef FilePattern); unsigned readPhdrType(); SortKind readSortKind(); @@ -908,11 +899,11 @@ static int precedence(StringRef Op) { .Default(-1); } -std::vector<StringRef> ScriptParser::readInputFilePatterns() { +Regex ScriptParser::readFilePatterns() { std::vector<StringRef> V; while (!Error && !skip(")")) V.push_back(next()); - return V; + return compileGlobPatterns(V); } SortKind ScriptParser::readSortKind() { @@ -925,15 +916,13 @@ SortKind ScriptParser::readSortKind() { InputSectionDescription * ScriptParser::readInputSectionRules(StringRef FilePattern) { - auto *Cmd = new InputSectionDescription; - Cmd->FilePattern = FilePattern; + auto *Cmd = new InputSectionDescription(FilePattern); expect("("); // Read EXCLUDE_FILE(). if (skip("EXCLUDE_FILE")) { expect("("); - while (!Error && !skip(")")) - Cmd->ExcludedFiles.push_back(next()); + Cmd->ExcludedFileRe = readFilePatterns(); } // Read SORT(). @@ -943,16 +932,16 @@ ScriptParser::readInputSectionRules(StringRef FilePattern) { if (SortKind K2 = readSortKind()) { Cmd->SortInner = K2; expect("("); - Cmd->SectionPatterns = readInputFilePatterns(); + Cmd->SectionRe = readFilePatterns(); expect(")"); } else { - Cmd->SectionPatterns = readInputFilePatterns(); + Cmd->SectionRe = readFilePatterns(); } expect(")"); return Cmd; } - Cmd->SectionPatterns = readInputFilePatterns(); + Cmd->SectionRe = readFilePatterns(); return Cmd; } @@ -965,9 +954,7 @@ ScriptParser::readInputSectionDescription(StringRef Tok) { StringRef FilePattern = next(); InputSectionDescription *Cmd = readInputSectionRules(FilePattern); expect(")"); - Opt.KeptSections.insert(Opt.KeptSections.end(), - Cmd->SectionPatterns.begin(), - Cmd->SectionPatterns.end()); + Opt.KeptSections.push_back(&Cmd->SectionRe); return Cmd; } return readInputSectionRules(Tok); |