[ELF] make KEEP command recognize file patterns

Differential revision: https://reviews.llvm.org/D25242

llvm-svn: 283305
This commit is contained in:
Eugene Leviant
2016-10-05 09:36:59 +00:00
parent 014181e7f4
commit cf43f179b1
4 changed files with 24 additions and 6 deletions

View File

@@ -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);