/// Performs link using specified options
static bool link(LinkingContext &context,
- raw_ostream &diagnostics = llvm::errs());
+ raw_ostream &diag = llvm::errs());
private:
Driver() LLVM_DELETED_FUNCTION;
public:
/// Determine flavor and pass control to Driver for that flavor.
static bool link(int argc, const char *argv[],
- raw_ostream &diagnostics = llvm::errs());
+ raw_ostream &diag = llvm::errs());
private:
UniversalDriver() LLVM_DELETED_FUNCTION;
/// 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());
+ raw_ostream &diag = llvm::errs());
/// 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<ELFLinkingContext> &context,
- raw_ostream &diagnostics = llvm::errs());
+ raw_ostream &diag = llvm::errs());
/// Parses a given memory buffer as a linker script and evaluate that.
/// Public function for testing.
static llvm::Triple getDefaultTarget(const char *progName);
static bool applyEmulation(llvm::Triple &triple,
llvm::opt::InputArgList &args,
- raw_ostream &diagnostics);
+ raw_ostream &diag);
static void addPlatformSearchDirs(ELFLinkingContext &ctx,
llvm::Triple &triple,
llvm::Triple &baseTriple);
/// 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());
+ raw_ostream &diag = llvm::errs());
/// Uses darwin style ld command line options to update LinkingContext object.
/// Returns true iff there was an error.
static bool parse(int argc, const char *argv[], MachOLinkingContext &info,
- raw_ostream &diagnostics = llvm::errs());
+ raw_ostream &diag = llvm::errs());
private:
DarwinLdDriver() LLVM_DELETED_FUNCTION;
/// 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());
+ raw_ostream &diag = llvm::errs());
/// 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[], PECOFFLinkingContext &info,
- raw_ostream &diagnostics = llvm::errs(),
+ raw_ostream &diag = llvm::errs(),
bool isDirective = false,
std::set<StringRef> *undefinedSymbols = nullptr);
// Same as parse(), but restricted to the context of directives.
static bool parseDirectives(int argc, const char *argv[],
PECOFFLinkingContext &info,
- raw_ostream &diagnostics = llvm::errs(),
+ raw_ostream &diag = llvm::errs(),
std::set<StringRef> *undefinedSymbols = nullptr) {
- return parse(argc, argv, info, diagnostics, true, undefinedSymbols);
+ return parse(argc, argv, info, diag, true, undefinedSymbols);
}
private:
/// 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());
+ raw_ostream &diag = llvm::errs());
/// 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[], CoreLinkingContext &info,
- raw_ostream &diagnostics = llvm::errs());
+ raw_ostream &diag = llvm::errs());
private:
CoreDriver() LLVM_DELETED_FUNCTION;
return true;
}
-bool GnuLdDriver::linkELF(int argc, const char *argv[],
- raw_ostream &diagnostics) {
+bool GnuLdDriver::linkELF(int argc, const char *argv[], raw_ostream &diag) {
BumpPtrAllocator alloc;
std::tie(argc, argv) = maybeExpandResponseFiles(argc, argv, alloc);
std::unique_ptr<ELFLinkingContext> options;
- if (!parse(argc, argv, options, diagnostics))
+ if (!parse(argc, argv, options, diag))
return false;
if (!options)
return true;
- return link(*options, diagnostics);
+ return link(*options, diag);
}
static llvm::Optional<llvm::Triple::ArchType>
bool GnuLdDriver::applyEmulation(llvm::Triple &triple,
llvm::opt::InputArgList &args,
- raw_ostream &diagnostics) {
+ raw_ostream &diag) {
llvm::opt::Arg *arg = args.getLastArg(OPT_m);
if (!arg)
return true;
llvm::Optional<llvm::Triple::ArchType> arch =
getArchType(triple, arg->getValue());
if (!arch) {
- diagnostics << "error: unsupported emulation '" << arg->getValue()
- << "'.\n";
+ diag << "error: unsupported emulation '" << arg->getValue() << "'.\n";
return false;
}
triple.setArch(*arch);
bool GnuLdDriver::parse(int argc, const char *argv[],
std::unique_ptr<ELFLinkingContext> &context,
- raw_ostream &diagnostics) {
+ raw_ostream &diag) {
// Parse command line options using GnuLdOptions.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";
+ diag << "error: missing arg value for '"
+ << parsedArgs->getArgString(missingIndex) << "' expected "
+ << missingCount << " argument(s).\n";
return false;
}
baseTriple = getDefaultTarget(argv[0]);
llvm::Triple triple(baseTriple);
- if (!applyEmulation(triple, *parsedArgs, diagnostics))
+ if (!applyEmulation(triple, *parsedArgs, diag))
return false;
std::unique_ptr<ELFLinkingContext> ctx(createELFLinkingContext(triple));
if (!ctx) {
- diagnostics << "unknown target triple\n";
+ diag << "unknown target triple\n";
return false;
}
// Ignore unknown arguments.
for (auto unknownArg : parsedArgs->filtered(OPT_UNKNOWN))
- diagnostics << "warning: ignoring unknown argument: "
- << unknownArg->getValue() << "\n";
+ diag << "warning: ignoring unknown argument: "
+ << unknownArg->getValue() << "\n";
// Set sys root path.
if (llvm::opt::Arg *sysRootPath = parsedArgs->getLastArg(OPT_sysroot))
} else if (parseDefsymAsAlias(inputArg->getValue(), sym, target)) {
ctx->addAlias(sym, target);
} else {
- diagnostics << "invalid --defsym: " << inputArg->getValue() << "\n";
+ diag << "invalid --defsym: " << inputArg->getValue() << "\n";
return false;
}
break;
case OPT_end_group: {
if (groupStack.empty()) {
- diagnostics << "stray --end-group\n";
+ diag << "stray --end-group\n";
return false;
}
int startGroupPos = groupStack.top();
if ((!parseZOption(extOpt, maxPageSize)) ||
(maxPageSize < ctx->getPageSize()) ||
(maxPageSize % ctx->getPageSize())) {
- diagnostics << "invalid option: " << extOpt << "\n";
+ diag << "invalid option: " << extOpt << "\n";
return false;
}
ctx->setMaxPageSize(maxPageSize);
} else
- diagnostics << "warning: ignoring unknown argument for -z: " << extOpt
- << "\n";
+ diag << "warning: ignoring unknown argument for -z: " << extOpt << "\n";
break;
}
StringRef realpath = pathOrErr.get();
bool isScript =
- (!path.endswith(".objtxt") && isLinkerScript(realpath, diagnostics));
+ (!path.endswith(".objtxt") && isLinkerScript(realpath, diag));
if (isScript) {
if (ctx->logInputFiles())
- diagnostics << path << "\n";
+ diag << path << "\n";
ErrorOr<std::unique_ptr<MemoryBuffer>> mb =
MemoryBuffer::getFileOrSTDIN(path);
if (std::error_code ec = mb.getError()) {
- diagnostics << "Cannot open " << path << ": "
- << ec.message() << "\n";
+ diag << "Cannot open " << path << ": " << ec.message() << "\n";
return false;
}
- std::error_code ec = evalLinkerScript(*ctx, std::move(mb.get()),
- diagnostics);
+ std::error_code ec = evalLinkerScript(*ctx, std::move(mb.get()), diag);
if (ec) {
- diagnostics << path << ": Error parsing linker script: "
- << ec.message() << "\n";
+ diag << path << ": Error parsing linker script: "
+ << ec.message() << "\n";
return false;
}
break;
= loadFile(*ctx, realpath, wholeArchive);
for (std::unique_ptr<File> &file : files) {
if (ctx->logInputFiles())
- diagnostics << file->path() << "\n";
+ diag << file->path() << "\n";
auto node = llvm::make_unique<FileNode>(std::move(file));
node->setAsNeeded(asNeeded);
ctx->getNodes().push_back(std::move(node));
uint64_t baseAddress = 0;
StringRef inputValue = inputArg->getValue();
if ((inputValue.getAsInteger(0, baseAddress)) || !baseAddress) {
- diagnostics << "invalid value for image base " << inputValue
- << "\n";
+ diag << "invalid value for image base " << inputValue << "\n";
return false;
}
ctx->setBaseAddress(baseAddress);
} // end for
if (ctx->getNodes().empty()) {
- diagnostics << "No input files\n";
+ diag << "No input files\n";
return false;
}
}
// Validate the combination of options used.
- if (!ctx->validate(diagnostics))
+ if (!ctx->validate(diag))
return false;
context.swap(ctx);