#include "lld/Core/LLVM.h"
#include "llvm/ADT/Triple.h"
-#include "llvm/Support/raw_ostream.h"
#include <memory>
#include <vector>
protected:
/// Performs link using specified options.
- static bool link(const TargetInfo &targetInfo,
- raw_ostream &diagnostics = llvm::errs());
+ static bool link(const TargetInfo &targetInfo);
private:
Driver() LLVM_DELETED_FUNCTION;
};
class UniversalDriver : public Driver {
public:
/// Determine flavor and pass control to Driver for that flavor.
- static bool link(int argc, const char *argv[],
- raw_ostream &diagnostics = llvm::errs());
+ static bool link(int argc, const char *argv[]);
private:
UniversalDriver() LLVM_DELETED_FUNCTION;
public:
/// Parses command line arguments same as gnu/binutils ld and performs link.
/// Returns true iff an error occurred.
- static bool linkELF(int argc, const char *argv[],
- raw_ostream &diagnostics = llvm::errs());
+ static bool linkELF(int argc, const char *argv[]);
/// Uses gnu/binutils style ld command line options to fill in options struct.
/// Returns true iff there was an error.
static bool parse(int argc, const char *argv[],
- std::unique_ptr<ELFTargetInfo> &targetInfo,
- raw_ostream &diagnostics = llvm::errs());
+ std::unique_ptr<ELFTargetInfo> &targetInfo);
private:
static llvm::Triple getDefaultTarget(const char *progName);
public:
/// Parses command line arguments same as darwin's ld and performs link.
/// Returns true iff there was an error.
- static bool linkMachO(int argc, const char *argv[],
- raw_ostream &diagnostics = llvm::errs());
+ static bool linkMachO(int argc, const char *argv[]);
/// Uses darwin style ld command line options to update targetInfo object.
/// Returns true iff there was an error.
- static bool parse(int argc, const char *argv[], MachOTargetInfo &info,
- raw_ostream &diagnostics = llvm::errs());
+ static bool parse(int argc, const char *argv[], MachOTargetInfo &info);
private:
DarwinLdDriver() LLVM_DELETED_FUNCTION;
};
public:
/// Parses command line arguments same as Windows link.exe and performs link.
/// Returns true iff there was an error.
- static bool linkPECOFF(int argc, const char *argv[],
- raw_ostream &diagnostics = llvm::errs());
+ static bool linkPECOFF(int argc, const char *argv[]);
/// Uses Windows style link command line options to fill in options struct.
/// Returns true iff there was an error.
- static bool parse(int argc, const char *argv[], PECOFFTargetInfo &info,
- raw_ostream &diagnostics = llvm::errs());
+ static bool parse(int argc, const char *argv[], PECOFFTargetInfo &info);
private:
WinLinkDriver() LLVM_DELETED_FUNCTION;
/// Parses command line arguments same as lld-core and performs link.
/// Returns true iff there was an error.
- static bool link(int argc, const char *argv[],
- raw_ostream &diagnostics = llvm::errs());
+ static bool link(int argc, const char *argv[]);
/// Uses lld-core command line options to fill in options struct.
/// Returns true iff there was an error.
- static bool parse(int argc, const char *argv[], CoreTargetInfo &info,
- raw_ostream &diagnostics = llvm::errs());
+ static bool parse(int argc, const char *argv[], CoreTargetInfo &info);
private:
CoreDriver() LLVM_DELETED_FUNCTION;
namespace lld {
-bool CoreDriver::link(int argc, const char *argv[], raw_ostream &diagnostics) {
+bool CoreDriver::link(int argc, const char *argv[]) {
CoreTargetInfo info;
if (parse(argc, argv, info))
return true;
-
+
return Driver::link(info);
}
-
-bool CoreDriver::parse(int argc, const char *argv[],
- CoreTargetInfo &info, raw_ostream &diagnostics) {
+bool CoreDriver::parse(int argc, const char *argv[], CoreTargetInfo &info) {
// Parse command line options using CoreOptions.td
std::unique_ptr<llvm::opt::InputArgList> parsedArgs;
CoreOptTable table;
parsedArgs.reset(table.ParseArgs(&argv[1], &argv[argc],
missingIndex, missingCount));
if (missingCount) {
- diagnostics << "error: missing arg value for '"
- << parsedArgs->getArgString(missingIndex)
- << "' expected " << missingCount << " argument(s).\n";
+ llvm::errs() << "error: missing arg value for '"
+ << parsedArgs->getArgString(missingIndex) << "' expected "
+ << missingCount << " argument(s).\n";
return true;
}
for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN),
ie = parsedArgs->filtered_end(); it != ie; ++it) {
- diagnostics << "warning: ignoring unknown argument: "
+ llvm::errs() << "warning: ignoring unknown argument: "
<< (*it)->getAsString(*parsedArgs) << "\n";
}
namespace lld {
-bool DarwinLdDriver::linkMachO(int argc, const char *argv[],
- raw_ostream &diagnostics) {
+bool DarwinLdDriver::linkMachO(int argc, const char *argv[]) {
MachOTargetInfo info;
- if (parse(argc, argv, info, diagnostics))
+ if (parse(argc, argv, info))
return true;
-
- return link(info, diagnostics);
-}
-
+ return link(info);
+}
-bool DarwinLdDriver::parse(int argc, const char *argv[],
- MachOTargetInfo &info, raw_ostream &diagnostics) {
+bool DarwinLdDriver::parse(int argc, const char *argv[],
+ MachOTargetInfo &info) {
// Parse command line options using DarwinOptions.td
std::unique_ptr<llvm::opt::InputArgList> parsedArgs;
DarwinLdOptTable table;
parsedArgs.reset(table.ParseArgs(&argv[1], &argv[argc],
missingIndex, missingCount));
if (missingCount) {
- diagnostics << "error: missing arg value for '"
- << parsedArgs->getArgString(missingIndex)
- << "' expected " << missingCount << " argument(s).\n";
+ llvm::errs() << "error: missing arg value for '"
+ << parsedArgs->getArgString(missingIndex) << "' expected "
+ << missingCount << " argument(s).\n";
return true;
}
for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN),
ie = parsedArgs->filtered_end(); it != ie; ++it) {
- diagnostics << "warning: ignoring unknown argument: "
+ llvm::errs() << "warning: ignoring unknown argument: "
<< (*it)->getAsString(*parsedArgs) << "\n";
}
switch (minOS->getOption().getID()) {
case OPT_macosx_version_min:
if (info.setOS(MachOTargetInfo::OS::macOSX, minOS->getValue())) {
- diagnostics << "error: malformed macosx_version_min value\n";
+ llvm::errs() << "error: malformed macosx_version_min value\n";
return true;
}
break;
case OPT_ios_version_min:
if (info.setOS(MachOTargetInfo::OS::iOS, minOS->getValue())) {
- diagnostics << "error: malformed ios_version_min value\n";
+ llvm::errs() << "error: malformed ios_version_min value\n";
return true;
}
break;
case OPT_ios_simulator_version_min:
if (info.setOS(MachOTargetInfo::OS::iOS_simulator, minOS->getValue())) {
- diagnostics << "error: malformed ios_simulator_version_min value\n";
+ llvm::errs() << "error: malformed ios_simulator_version_min value\n";
return true;
}
break;
it != ie; ++it) {
info.appendInputFile((*it)->getValue());
}
-
+
// Validate the combination of options used.
- if (info.validate(diagnostics))
+ if (info.validate(llvm::errs()))
return true;
return false;
namespace lld {
/// This is where the link is actually performed.
-bool Driver::link(const TargetInfo &targetInfo, raw_ostream &diagnostics) {
+bool Driver::link(const TargetInfo &targetInfo) {
// Honor -mllvm
if (!targetInfo.llvmOptions().empty()) {
unsigned numArgs = targetInfo.llvmOptions().size();
if (targetInfo.logInputFiles())
llvm::outs() << input.getPath() << "\n";
- tg.spawn([&, index] {
+ tg.spawn([ &, index]{
if (error_code ec = targetInfo.readFile(input.getPath(), files[index])) {
- diagnostics << "Failed to read file: " << input.getPath()
- << ": " << ec.message() << "\n";
+ llvm::errs() << "Failed to read file: " << input.getPath() << ": "
+ << ec.message() << "\n";
fail = true;
return;
}
// Give linked atoms to Writer to generate output file.
ScopedTask writeTask(getDefaultDomain(), "Write");
if (error_code ec = targetInfo.writeFile(merged)) {
- diagnostics << "Failed to write file '" << targetInfo.outputPath()
- << "': " << ec.message() << "\n";
+ llvm::errs() << "Failed to write file '" << targetInfo.outputPath()
+ << "': " << ec.message() << "\n";
return true;
}
} // namespace
-
-
-bool GnuLdDriver::linkELF(int argc, const char *argv[],
- raw_ostream &diagnostics) {
+bool GnuLdDriver::linkELF(int argc, const char *argv[]) {
std::unique_ptr<ELFTargetInfo> options;
- bool error = parse(argc, argv, options, diagnostics);
+ bool error = parse(argc, argv, options);
if (error)
return true;
if (!options)
return false;
- return link(*options, diagnostics);
+ return link(*options);
}
bool GnuLdDriver::parse(int argc, const char *argv[],
- std::unique_ptr<ELFTargetInfo> &targetInfo,
- raw_ostream &diagnostics) {
+ std::unique_ptr<ELFTargetInfo> &targetInfo) {
// Parse command line options using LDOptions.td
std::unique_ptr<llvm::opt::InputArgList> parsedArgs;
GnuLdOptTable table;
parsedArgs.reset(
table.ParseArgs(&argv[1], &argv[argc], missingIndex, missingCount));
if (missingCount) {
- diagnostics << "error: missing arg value for '"
- << parsedArgs->getArgString(missingIndex) << "' expected "
- << missingCount << " argument(s).\n";
+ llvm::errs() << "error: missing arg value for '"
+ << parsedArgs->getArgString(missingIndex) << "' expected "
+ << missingCount << " argument(s).\n";
return true;
}
for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN),
ie = parsedArgs->filtered_end(); it != ie; ++it) {
- diagnostics << "warning: ignoring unknown argument: " << (*it)->getAsString(
- *parsedArgs)
- << "\n";
+ llvm::errs() << "warning: ignoring unknown argument: "
+ << (*it)->getAsString(*parsedArgs) << "\n";
}
// Handle --help
std::unique_ptr<ELFTargetInfo> options(ELFTargetInfo::create(triple));
if (!options) {
- diagnostics << "unknown target triple\n";
+ llvm::errs() << "unknown target triple\n";
return true;
}
break;
case OPT_l:
if (options->appendLibrary((*it)->getValue())) {
- diagnostics << "Failed to find library for " << (*it)->getValue()
- << "\n";
+ llvm::errs() << "Failed to find library for " << (*it)->getValue()
+ << "\n";
return true;
}
break;
}
// Validate the combination of options used.
- if (options->validate(diagnostics))
+ if (options->validate(llvm::errs()))
return true;
targetInfo.swap(options);
return ret;
}
-Flavor selectFlavor(std::vector<const char *> &args, raw_ostream &diag) {
+Flavor selectFlavor(std::vector<const char *> &args) {
// -core as first arg is shorthand for -flavor core.
if (args.size() > 1 && StringRef(args[1]) == "-core") {
args.erase(args.begin() + 1);
args.erase(args.begin() + 1);
args.erase(args.begin() + 1);
if (flavor == Flavor::invalid)
- diag << "error: '" << args[2] << "' invalid value for -flavor.\n";
+ llvm::errs() << "error: '" << args[2] << "' invalid value for -flavor.\n";
return flavor;
}
// If flavor still undetermined, then error out.
if (flavor == Flavor::invalid)
- diag << "error: failed to determine driver flavor from program name"
- << " '" << args[0] << "'.\n"
- << "select a flavor with -flavor [gnu|darwin|link|core].\n";
+ llvm::errs() << "error: failed to determine driver flavor from program name"
+ << " '" << args[0] << "'.\n"
+ << "select a flavor with -flavor [gnu|darwin|link|core].\n";
return flavor;
}
}
namespace lld {
-bool UniversalDriver::link(int argc, const char *argv[],
- raw_ostream &diagnostics) {
+bool UniversalDriver::link(int argc, const char *argv[]) {
// Convert argv[] C-array to vector.
std::vector<const char *> args(argv, argv + argc);
// Determine flavor of link based on command name or -flavor argument.
// Note: 'args' is modified to remove -flavor option.
- Flavor flavor = selectFlavor(args, diagnostics);
+ Flavor flavor = selectFlavor(args);
// Switch to appropriate driver.
switch (flavor) {
case Flavor::gnu_ld:
- return GnuLdDriver::linkELF(args.size(), args.data(), diagnostics);
+ return GnuLdDriver::linkELF(args.size(), args.data());
case Flavor::darwin_ld:
- return DarwinLdDriver::linkMachO(args.size(), args.data(), diagnostics);
+ return DarwinLdDriver::linkMachO(args.size(), args.data());
case Flavor::win_link:
- return WinLinkDriver::linkPECOFF(args.size(), args.data(), diagnostics);
+ return WinLinkDriver::linkPECOFF(args.size(), args.data());
case Flavor::core:
- return CoreDriver::link(args.size(), args.data(), diagnostics);
+ return CoreDriver::link(args.size(), args.data());
case Flavor::invalid:
return true;
}
} // namespace
-bool WinLinkDriver::linkPECOFF(int argc, const char *argv[],
- raw_ostream &diagnostics) {
+bool WinLinkDriver::linkPECOFF(int argc, const char *argv[]) {
PECOFFTargetInfo info;
- if (parse(argc, argv, info, diagnostics))
+ if (parse(argc, argv, info))
return true;
- return link(info, diagnostics);
+ return link(info);
}
bool WinLinkDriver::parse(int argc, const char *argv[],
- PECOFFTargetInfo &info, raw_ostream &diagnostics) {
+ PECOFFTargetInfo &info) {
// Arguments after "--" are interpreted as filenames even if they start with
// a hyphen or a slash. This is not compatible with link.exe but useful for
// us to test lld on Unix.
parsedArgs.reset(
table.ParseArgs(&argv[1], &argv[argEnd], missingIndex, missingCount));
if (missingCount) {
- diagnostics << "error: missing arg value for '"
- << parsedArgs->getArgString(missingIndex) << "' expected "
- << missingCount << " argument(s).\n";
+ llvm::errs() << "error: missing arg value for '"
+ << parsedArgs->getArgString(missingIndex) << "' expected "
+ << missingCount << " argument(s).\n";
return true;
}
// Show warning for unknown arguments
for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN),
ie = parsedArgs->filtered_end(); it != ie; ++it) {
- diagnostics << "warning: ignoring unknown argument: "
- << (*it)->getAsString(*parsedArgs) << "\n";
+ llvm::errs() << "warning: ignoring unknown argument: "
+ << (*it)->getAsString(*parsedArgs) << "\n";
}
// Copy -mllvm
// Handle -stack
if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_stack))
- if (!parseStackOption(info, arg->getValue(), diagnostics))
+ if (!parseStackOption(info, arg->getValue(), llvm::errs()))
return true;
// Handle -heap
if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_heap))
- if (!parseHeapOption(info, arg->getValue(), diagnostics))
+ if (!parseHeapOption(info, arg->getValue(), llvm::errs()))
return true;
// Handle -subsystem
if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_subsystem))
- if (!parseSubsystemOption(info, arg->getValue(), diagnostics))
+ if (!parseSubsystemOption(info, arg->getValue(), llvm::errs()))
return true;
// Handle -entry
info.setOutputPath(getDefaultOutputFileName(info, inputPaths[0]));
// Validate the combination of options used.
- return info.validate(diagnostics);
+ return info.validate(llvm::errs());
}
} // namespace lld