forked from OSchip/llvm-project
[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
This commit is contained in:
parent
79fafccb5e
commit
6047163a24
|
@ -26,6 +26,7 @@
|
|||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
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<LinkerInput> _input;
|
||||
std::vector<std::string> _llvmArgs;
|
||||
std::string _target;
|
||||
std::string _outputPath;
|
||||
std::string _entrySymbol;
|
||||
|
|
|
@ -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=">;
|
||||
|
|
|
@ -103,6 +103,13 @@ public:
|
|||
return std::unique_ptr<llvm::opt::DerivedArgList>();
|
||||
}
|
||||
|
||||
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<llvm::opt::DerivedArgList> 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<const char *> args) {
|
|||
return std::unique_ptr<llvm::opt::ArgList>();
|
||||
}
|
||||
|
||||
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<llvm::opt::ArgList>();
|
||||
|
||||
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);
|
||||
|
|
|
@ -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<entry>;
|
||||
|
|
|
@ -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(Target::create(_options));
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue