From 6047163a244dc8c2ac7aebe96a84cf7d8e98cc71 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Tue, 8 Jan 2013 22:59:27 +0000 Subject: [PATCH] [lld] Add support for -mllvm. There is no way to test this at the moment because the options are not processed until the link starts, and we can't pass an empty file. llvm-svn: 171910 --- lld/include/lld/Driver/LinkerOptions.h | 5 +++++ lld/lib/Driver/CoreOptions.td | 1 + lld/lib/Driver/Drivers.cpp | 27 ++++++++++++++++++++++++++ lld/lib/Driver/LDOptions.td | 2 ++ lld/lib/Driver/LinkerInvocation.cpp | 12 ++++++++++++ lld/tools/lld/lld.cpp | 6 ------ 6 files changed, 47 insertions(+), 6 deletions(-) diff --git a/lld/include/lld/Driver/LinkerOptions.h b/lld/include/lld/Driver/LinkerOptions.h index 1ed0241c39e7..723df9f48158 100644 --- a/lld/include/lld/Driver/LinkerOptions.h +++ b/lld/include/lld/Driver/LinkerOptions.h @@ -26,6 +26,7 @@ #include "llvm/Support/MemoryBuffer.h" #include +#include namespace lld { enum class InputKind { @@ -105,8 +106,11 @@ private: struct LinkerOptions { LinkerOptions() {} + + // This exists because MSVC doesn't support = default :( LinkerOptions(LinkerOptions &&other) : _input(std::move(other._input)) + , _llvmArgs(std::move(other._llvmArgs)) , _target(std::move(other._target)) , _outputPath(std::move(other._outputPath)) , _entrySymbol(std::move(other._entrySymbol)) @@ -115,6 +119,7 @@ struct LinkerOptions { , _outputYAML(other._outputYAML) {} std::vector _input; + std::vector _llvmArgs; std::string _target; std::string _outputPath; std::string _entrySymbol; diff --git a/lld/lib/Driver/CoreOptions.td b/lld/lib/Driver/CoreOptions.td index 938a49b7d641..65c97de3b250 100644 --- a/lld/lib/Driver/CoreOptions.td +++ b/lld/lib/Driver/CoreOptions.td @@ -2,6 +2,7 @@ include "llvm/Option/OptParser.td" def flavor : Separate<["-"], "flavor">; def target : Separate<["-"], "target">, HelpText<"Target triple to link for">; +def mllvm : Separate<["-"], "mllvm">, HelpText<"Options to pass to LLVM">; def output : Joined<["-"], "output=">; def entry : Joined<["-"], "entry=">; diff --git a/lld/lib/Driver/Drivers.cpp b/lld/lib/Driver/Drivers.cpp index 93a4087eb9ce..fcc6fa8827fe 100644 --- a/lld/lib/Driver/Drivers.cpp +++ b/lld/lib/Driver/Drivers.cpp @@ -103,6 +103,13 @@ public: return std::unique_ptr(); } + for (llvm::opt::arg_iterator it = _inputArgs->filtered_begin(ld::OPT_UNKNOWN), + ie = _inputArgs->filtered_end(); + it != ie; ++it) { + llvm::errs() << "warning: ignoring unknown argument: " + << (*it)->getAsString(*_inputArgs) << "\n"; + } + std::unique_ptr newArgs( new llvm::opt::DerivedArgList(*_inputArgs)); @@ -147,6 +154,14 @@ public: (*it)->getValue()); } + // Copy mllvm + for (llvm::opt::arg_iterator it = _inputArgs->filtered_begin(ld::OPT_mllvm), + ie = _inputArgs->filtered_end(); + it != ie; ++it) { + newArgs->AddPositionalArg(*it, _core.getOption(core::OPT_mllvm), + (*it)->getValue()); + } + return std::move(newArgs); } @@ -183,6 +198,17 @@ lld::parseCoreArgs(llvm::ArrayRef args) { return std::unique_ptr(); } + bool hasUnknown = false; + for (llvm::opt::arg_iterator it = list->filtered_begin(ld::OPT_UNKNOWN), + ie = list->filtered_end(); + it != ie; ++it) { + llvm::errs() << "error: ignoring unknown argument: " + << (*it)->getAsString(*list) << "\n"; + hasUnknown = true; + } + if (hasUnknown) + return std::unique_ptr(); + return list; } @@ -195,6 +221,7 @@ LinkerOptions lld::generateOptions(const llvm::opt::ArgList &args) { ret._input.push_back(LinkerInput((*it)->getValue(), InputKind::Object)); } + ret._llvmArgs = args.getAllArgValues(core::OPT_mllvm); ret._target = llvm::Triple::normalize(args.getLastArgValue(core::OPT_target)); ret._outputPath = args.getLastArgValue(core::OPT_output); ret._entrySymbol = args.getLastArgValue(core::OPT_entry); diff --git a/lld/lib/Driver/LDOptions.td b/lld/lib/Driver/LDOptions.td index 059e8c83f058..4231fe290198 100644 --- a/lld/lib/Driver/LDOptions.td +++ b/lld/lib/Driver/LDOptions.td @@ -2,6 +2,8 @@ include "llvm/Option/OptParser.td" def flavor : Separate<["-"], "flavor">; def target : Separate<["-"], "target">, HelpText<"Target triple to link for">; +def mllvm : Separate<["-"], "mllvm">, HelpText<"Options to pass to LLVM">; + def entry : Joined<["--"], "entry=">; def entry_e : Separate<["-"], "e">, Alias; diff --git a/lld/lib/Driver/LinkerInvocation.cpp b/lld/lib/Driver/LinkerInvocation.cpp index bf7c09c07889..36563b96d3ac 100644 --- a/lld/lib/Driver/LinkerInvocation.cpp +++ b/lld/lib/Driver/LinkerInvocation.cpp @@ -13,11 +13,23 @@ #include "lld/Core/Resolver.h" #include "lld/Driver/Target.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" using namespace lld; void LinkerInvocation::operator()() { + // Honor -mllvm + if (!_options._llvmArgs.empty()) { + unsigned NumArgs = _options._llvmArgs.size(); + const char **Args = new const char*[NumArgs + 2]; + Args[0] = "lld (LLVM option parsing)"; + for (unsigned i = 0; i != NumArgs; ++i) + Args[i + 1] = _options._llvmArgs[i].c_str(); + Args[NumArgs + 1] = 0; + llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args); + } + // Create target. std::unique_ptr target(Target::create(_options)); diff --git a/lld/tools/lld/lld.cpp b/lld/tools/lld/lld.cpp index ce7de83e8239..70c1ac8c2a51 100644 --- a/lld/tools/lld/lld.cpp +++ b/lld/tools/lld/lld.cpp @@ -132,12 +132,6 @@ int main(int argc, char **argv) { if (!coreArgs) return 1; - for (const auto &arg : *coreArgs) { - if (arg->getOption().getKind() == llvm::opt::Option::UnknownClass) { - llvm::errs() << "Unknown option: " << arg->getAsString(*coreArgs) << "\n"; - } - } - LinkerOptions lo(generateOptions(*coreArgs)); if (lo._outputCommands) {