diff options
Diffstat (limited to 'lld/ELF')
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 15 | ||||
-rw-r--r-- | lld/ELF/LinkerScript.h | 2 |
2 files changed, 11 insertions, 6 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 5cdee7082e1..b0a83d8d5cf 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -108,9 +108,15 @@ template <class ELFT> LinkerScript<ELFT>::~LinkerScript() {} template <class ELFT> bool LinkerScript<ELFT>::shouldKeep(InputSectionBase<ELFT> *S) { - for (Regex *Re : Opt.KeptSections) - if (Re->match(S->Name)) - return true; + for (InputSectionDescription *ID : Opt.KeptSections) { + StringRef Filename = S->getFile()->getName(); + if (!ID->FileRe.match(sys::path::filename(Filename))) + continue; + + for (SectionPattern &P : ID->SectionPatterns) + if (P.SectionRe.match(S->Name)) + return true; + } return false; } @@ -1247,8 +1253,7 @@ ScriptParser::readInputSectionDescription(StringRef Tok) { StringRef FilePattern = next(); InputSectionDescription *Cmd = readInputSectionRules(FilePattern); expect(")"); - for (SectionPattern &Pat : Cmd->SectionPatterns) - Opt.KeptSections.push_back(&Pat.SectionRe); + Opt.KeptSections.push_back(Cmd); return Cmd; } return readInputSectionRules(Tok); diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index 47b7b683a34..ac73d4ea7b2 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -184,7 +184,7 @@ struct ScriptConfiguration { // List of section patterns specified with KEEP commands. They will // be kept even if they are unused and --gc-sections is specified. - std::vector<llvm::Regex *> KeptSections; + std::vector<InputSectionDescription *> KeptSections; }; extern ScriptConfiguration *ScriptConfig; |