From 0ed42b0ca029a046311227672fc6491f6b5a63d9 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Mon, 25 Jul 2016 21:47:13 +0000 Subject: [PATCH] [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 --- lld/ELF/LinkerScript.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 9ccc27ddcdcf..b1779b2ddd45 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -426,6 +426,7 @@ private: void readEntry(); void readExtern(); void readGroup(); + void readKeep(OutputSectionCommand *Cmd); void readInclude(); void readNothing() {} void readOutput(); @@ -665,6 +666,19 @@ static int precedence(StringRef Op) { .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) { OutputSectionCommand *Cmd = new OutputSectionCommand(OutSec); Opt.Commands.emplace_back(Cmd); @@ -692,16 +706,7 @@ void ScriptParser::readOutputSectionDescription(StringRef OutSec) { while (!Error && !skip(")")) InCmd->Patterns.push_back(next()); } else if (Tok == "KEEP") { - 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(")"); + readKeep(Cmd); } else if (Tok == "PROVIDE") { readProvide(false); } else if (Tok == "PROVIDE_HIDDEN") {