[ELF] make KEEP command recognize file patterns
Differential revision: https://reviews.llvm.org/D25242
llvm-svn: 283305
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 5cdee70..b0a83d8 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -108,9 +108,15 @@
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 @@
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 47b7b68..ac73d4e 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -184,7 +184,7 @@
// 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;