[LinkerScript] Refactor KEEP handling in a separate function

This will grow because I have a patch to support more complex
constructs, e.g.:

KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))

Let's make this a separate function.

llvm-svn: 276695
This commit is contained in:
Davide Italiano 2016-07-25 21:47:13 +00:00
parent bef810ff95
commit 0ed42b0ca0
1 changed files with 15 additions and 10 deletions

View File

@ -426,6 +426,7 @@ private:
void readEntry(); void readEntry();
void readExtern(); void readExtern();
void readGroup(); void readGroup();
void readKeep(OutputSectionCommand *Cmd);
void readInclude(); void readInclude();
void readNothing() {} void readNothing() {}
void readOutput(); void readOutput();
@ -665,6 +666,19 @@ static int precedence(StringRef Op) {
.Default(-1); .Default(-1);
} }
void ScriptParser::readKeep(OutputSectionCommand *Cmd) {
expect("(");
expect("*");
expect("(");
auto *InCmd = new InputSectionDescription();
Cmd->Commands.emplace_back(InCmd);
while (!Error && !skip(")")) {
Opt.KeptSections.push_back(peek());
InCmd->Patterns.push_back(next());
}
expect(")");
}
void ScriptParser::readOutputSectionDescription(StringRef OutSec) { void ScriptParser::readOutputSectionDescription(StringRef OutSec) {
OutputSectionCommand *Cmd = new OutputSectionCommand(OutSec); OutputSectionCommand *Cmd = new OutputSectionCommand(OutSec);
Opt.Commands.emplace_back(Cmd); Opt.Commands.emplace_back(Cmd);
@ -692,16 +706,7 @@ void ScriptParser::readOutputSectionDescription(StringRef OutSec) {
while (!Error && !skip(")")) while (!Error && !skip(")"))
InCmd->Patterns.push_back(next()); InCmd->Patterns.push_back(next());
} else if (Tok == "KEEP") { } else if (Tok == "KEEP") {
expect("("); readKeep(Cmd);
expect("*");
expect("(");
auto *InCmd = new InputSectionDescription();
Cmd->Commands.emplace_back(InCmd);
while (!Error && !skip(")")) {
Opt.KeptSections.push_back(peek());
InCmd->Patterns.push_back(next());
}
expect(")");
} else if (Tok == "PROVIDE") { } else if (Tok == "PROVIDE") {
readProvide(false); readProvide(false);
} else if (Tok == "PROVIDE_HIDDEN") { } else if (Tok == "PROVIDE_HIDDEN") {