diff --git a/lld/MachO/CMakeLists.txt b/lld/MachO/CMakeLists.txt --- a/lld/MachO/CMakeLists.txt +++ b/lld/MachO/CMakeLists.txt @@ -2,6 +2,10 @@ tablegen(LLVM Options.inc -gen-opt-parser-defs) add_public_tablegen_target(MachOOptionsTableGen) +set(LLVM_TARGET_DEFINITIONS LCLinkerOptions.td) +tablegen(LLVM LCLinkerOptions.inc -gen-opt-parser-defs) +add_public_tablegen_target(MachOLCLinkerOptionsTableGen) + include_directories(${LLVM_MAIN_SRC_DIR}/../libunwind/include) add_lld_library(lldMachO @@ -54,6 +58,7 @@ DEPENDS MachOOptionsTableGen + MachOLCLinkerOptionsTableGen ${tablegen_deps} ) diff --git a/lld/MachO/Driver.h b/lld/MachO/Driver.h --- a/lld/MachO/Driver.h +++ b/lld/MachO/Driver.h @@ -47,6 +47,20 @@ #undef OPTION }; +class MachOLCLinkerOptTable : public llvm::opt::OptTable { +public: + MachOLCLinkerOptTable(); + // llvm::opt::InputArgList parse(ArrayRef argv); +}; + +// Create enum with OPT_xxx values for each option in Options.td +enum { + OPT_LC_INVALID = 0, +#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_lc_##ID, +#include "LCLinkerOptions.inc" +#undef OPTION +}; + void parseLCLinkerOption(InputFile *, unsigned argc, StringRef data); std::string createResponseFile(const llvm::opt::InputArgList &args); diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -409,7 +409,7 @@ if (argv.size() != argc || offset > data.size()) fatal(toString(f) + ": invalid LC_LINKER_OPTION"); - MachOOptTable table; + MachOLCLinkerOptTable table; unsigned missingIndex, missingCount; InputArgList args = table.ParseArgs(argv, missingIndex, missingCount); if (missingCount) @@ -419,7 +419,7 @@ for (const Arg *arg : args) { switch (arg->getOption().getID()) { - case OPT_l: { + case OPT_lc_l: { StringRef name = arg->getValue(); ForceLoad forceLoadArchive = config->forceLoadSwift && name.startswith("swift") ? ForceLoad::Yes @@ -428,7 +428,7 @@ /*isReexport=*/false, /*isExplicit=*/false, forceLoadArchive); break; } - case OPT_framework: + case OPT_lc_framework: addFramework(arg->getValue(), /*isNeeded=*/false, /*isWeak=*/false, /*isReexport=*/false, /*isExplicit=*/false, ForceLoad::No); break; diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp --- a/lld/MachO/DriverUtils.cpp +++ b/lld/MachO/DriverUtils.cpp @@ -51,6 +51,34 @@ MachOOptTable::MachOOptTable() : OptTable(optInfo) {} +namespace LCLinkerOptInfo { +// Create prefix string literals used in LCLinkerOptions.td +#define PREFIX(NAME, VALUE) const char *NAME[] = VALUE; +#include "LCLinkerOptions.inc" +#undef PREFIX + +// Create table mapping all options defined in Options.td +static const OptTable::Info lcLinkerOptInfo[] = { +#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \ + {X1, \ + X2, \ + X10, \ + X11, \ + OPT_lc_##ID, \ + Option::KIND##Class, \ + X9, \ + X8, \ + OPT_LC_##GROUP, \ + OPT_LC_##ALIAS, \ + X7, \ + X12}, +#include "LCLinkerOptions.inc" +#undef OPTION +}; +} // namespace LCLinkerOptInfo +MachOLCLinkerOptTable::MachOLCLinkerOptTable() + : OptTable(LCLinkerOptInfo::lcLinkerOptInfo) {} + // Set color diagnostics according to --color-diagnostics={auto,always,never} // or --no-color-diagnostics flags. static void handleColorDiagnostics(InputArgList &args) { diff --git a/lld/MachO/LCLinkerOptions.td b/lld/MachO/LCLinkerOptions.td new file mode 100644 --- /dev/null +++ b/lld/MachO/LCLinkerOptions.td @@ -0,0 +1,10 @@ +include "llvm/Option/OptParser.td" + +// Flags that can be used in the LC_LINKER_OPTION load command + +def l : Joined<["-"], "l">, + MetaVarName<"">, + HelpText<"Search for lib.dylib or lib.a on the library search path">; +def framework : Separate<["-"], "framework">, + MetaVarName<"">, + HelpText<"Search for .framework/ on the framework search path">;