[PATCH] D22781: [LinkerScript] Refactor KEEP handling in a separate function

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


davide created this revision.
davide added a reviewer: ruiu.
davide added a subscriber: llvm-commits.

This will grow because I have a patch to support:
`    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))`
Let's make this a separate function.

https://reviews.llvm.org/D22781

Files:
  ELF/LinkerScript.cpp

Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -409,6 +409,7 @@
   void readEntry();
   void readExtern();
   void readGroup();
+  void readKeep(OutputSectionCommand *Cmd);
   void readInclude();
   void readNothing() {}
   void readOutput();
@@ -648,6 +649,19 @@
       .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);
@@ -675,16 +689,7 @@
       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") {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22781.65426.patch
Type: text/x-patch
Size: 1466 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160725/8e12da2e/attachment.bin>


More information about the llvm-commits mailing list