[lld] r276695 - [LinkerScript] Refactor KEEP handling in a separate function

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 14:47:14 PDT 2016


Author: davide
Date: Mon Jul 25 16:47:13 2016
New Revision: 276695

URL: http://llvm.org/viewvc/llvm-project?rev=276695&view=rev
Log:
[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.

Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=276695&r1=276694&r2=276695&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Jul 25 16:47:13 2016
@@ -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::readOutputSectionDesc
       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") {




More information about the llvm-commits mailing list