[PATCH] D113235: [lld-macho] Replace LC_LINKER_OPTION parsing

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 4 19:55:25 PDT 2021


keith created this revision.
keith added a reviewer: int3.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
keith requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This removes the tablegen based parsing of LC_LINKER_OPTION since it can
only actually contain a very small number of potential arguments. In our
project with tablegen this took 5 seconds before.

This replaces https://reviews.llvm.org/D113075


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113235

Files:
  lld/MachO/Driver.cpp


Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -398,7 +398,7 @@
 // Parses LC_LINKER_OPTION contents, which can add additional command line
 // flags.
 void macho::parseLCLinkerOption(InputFile *f, unsigned argc, StringRef data) {
-  SmallVector<const char *, 4> argv;
+  SmallVector<StringRef, 4> argv;
   size_t offset = 0;
   for (unsigned i = 0; i < argc && offset < data.size(); ++i) {
     argv.push_back(data.data() + offset);
@@ -407,18 +407,10 @@
   if (argv.size() != argc || offset > data.size())
     fatal(toString(f) + ": invalid LC_LINKER_OPTION");
 
-  MachOOptTable table;
-  unsigned missingIndex, missingCount;
-  InputArgList args = table.ParseArgs(argv, missingIndex, missingCount);
-  if (missingCount)
-    fatal(Twine(args.getArgString(missingIndex)) + ": missing argument");
-  for (const Arg *arg : args.filtered(OPT_UNKNOWN))
-    error("unknown argument: " + arg->getAsString(args));
-
-  for (const Arg *arg : args) {
-    switch (arg->getOption().getID()) {
-    case OPT_l: {
-      StringRef name = arg->getValue();
+  for (unsigned i = 0; i < argv.size(); ++i) {
+    StringRef arg = argv[i];
+    if (arg.startswith("-l")) {
+      StringRef name = arg.drop_front(2);
       ForceLoad forceLoadArchive =
           config->forceLoadSwift && name.startswith("swift") ? ForceLoad::Yes
                                                              : ForceLoad::No;
@@ -426,13 +418,15 @@
                  /*isReexport=*/false, /*isExplicit=*/false, forceLoadArchive);
       break;
     }
-    case OPT_framework:
-      addFramework(arg->getValue(), /*isNeeded=*/false, /*isWeak=*/false,
+
+    if (arg == "-framework") {
+      StringRef name = argv[++i];
+      addFramework(name, /*isNeeded=*/false, /*isWeak=*/false,
                    /*isReexport=*/false, /*isExplicit=*/false, ForceLoad::No);
       break;
-    default:
-      error(arg->getSpelling() + " is not allowed in LC_LINKER_OPTION");
     }
+
+    error(arg + " is not allowed in LC_LINKER_OPTION");
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113235.384945.patch
Type: text/x-patch
Size: 2113 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211105/a99d3a2d/attachment.bin>


More information about the llvm-commits mailing list