[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 21:40:34 PDT 2021


keith updated this revision to Diff 384960.
keith marked 2 inline comments as done.
keith added a comment.

Update for feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113235/new/

https://reviews.llvm.org/D113235

Files:
  lld/MachO/Driver.cpp


Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -396,9 +396,10 @@
 }
 
 // Parses LC_LINKER_OPTION contents, which can add additional command line
-// flags.
+// flags. This directly parses the flags instead of using the standard argument
+// parser to improve performance.
 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,32 +408,25 @@
   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.consume_front("-l")) {
       ForceLoad forceLoadArchive =
-          config->forceLoadSwift && name.startswith("swift") ? ForceLoad::Yes
-                                                             : ForceLoad::No;
-      addLibrary(name, /*isNeeded=*/false, /*isWeak=*/false,
+          config->forceLoadSwift && arg.startswith("swift") ? ForceLoad::Yes
+                                                            : ForceLoad::No;
+      addLibrary(arg, /*isNeeded=*/false, /*isWeak=*/false,
                  /*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.384960.patch
Type: text/x-patch
Size: 2452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211105/d754f1f0/attachment.bin>


More information about the llvm-commits mailing list