[lld] a7a2959 - [lld-macho] Replace LC_LINKER_OPTION parsing
Keith Smiley via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 4 22:05:33 PDT 2021
Author: Keith Smiley
Date: 2021-11-04T22:03:40-07:00
New Revision: a7a29599014b038a282ccceff796ecefdc03ad41
URL: https://github.com/llvm/llvm-project/commit/a7a29599014b038a282ccceff796ecefdc03ad41
DIFF: https://github.com/llvm/llvm-project/commit/a7a29599014b038a282ccceff796ecefdc03ad41.diff
LOG: [lld-macho] Replace LC_LINKER_OPTION parsing
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
Differential Revision: https://reviews.llvm.org/D113235
Added:
Modified:
lld/MachO/Driver.cpp
Removed:
################################################################################
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 5aa19a7cfbda..861ba9706675 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -396,9 +396,10 @@ static void addFramework(StringRef name, bool isNeeded, bool isWeak,
}
// 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,20 @@ void macho::parseLCLinkerOption(InputFile *f, unsigned argc, StringRef data) {
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();
- ForceLoad forceLoadArchive =
- config->forceLoadSwift && name.startswith("swift") ? ForceLoad::Yes
- : ForceLoad::No;
- addLibrary(name, /*isNeeded=*/false, /*isWeak=*/false,
- /*isReexport=*/false, /*isExplicit=*/false, forceLoadArchive);
- break;
- }
- case OPT_framework:
- addFramework(arg->getValue(), /*isNeeded=*/false, /*isWeak=*/false,
- /*isReexport=*/false, /*isExplicit=*/false, ForceLoad::No);
- break;
- default:
- error(arg->getSpelling() + " is not allowed in LC_LINKER_OPTION");
- }
+ unsigned i = 0;
+ StringRef arg = argv[i];
+ if (arg.consume_front("-l")) {
+ ForceLoad forceLoadArchive =
+ config->forceLoadSwift && arg.startswith("swift") ? ForceLoad::Yes
+ : ForceLoad::No;
+ addLibrary(arg, /*isNeeded=*/false, /*isWeak=*/false,
+ /*isReexport=*/false, /*isExplicit=*/false, forceLoadArchive);
+ } else if (arg == "-framework") {
+ StringRef name = argv[++i];
+ addFramework(name, /*isNeeded=*/false, /*isWeak=*/false,
+ /*isReexport=*/false, /*isExplicit=*/false, ForceLoad::No);
+ } else {
+ error(arg + " is not allowed in LC_LINKER_OPTION");
}
}
More information about the llvm-commits
mailing list