return llvm::libDriverMain(ArgsArr.slice(1)) == 0;
// Parse command line options.
- auto ArgsOrErr = Parser.parse(ArgsArr);
+ auto ArgsOrErr = Parser.parseLINK(ArgsArr);
if (auto EC = ArgsOrErr.getError()) {
llvm::errs() << EC.message() << "\n";
return false;
// Parses command line options.
ErrorOr<llvm::opt::InputArgList> parse(llvm::ArrayRef<const char *> Args);
+ // Concatenate LINK environment varirable and given arguments and parse them.
+ ErrorOr<llvm::opt::InputArgList> parseLINK(llvm::ArrayRef<const char *> Args);
+
// Tokenizes a given string and then parses as command line options.
ErrorOr<llvm::opt::InputArgList> parse(StringRef S) {
return parse(tokenize(S));
return parse(V);
}
+ErrorOr<llvm::opt::InputArgList>
+ArgParser::parseLINK(ArrayRef<const char *> Args) {
+ // Concatenate LINK env and given arguments and parse them.
+ Optional<std::string> Env = Process::GetEnv("LINK");
+ if (!Env)
+ return parse(Args);
+ std::vector<const char *> V = tokenize(*Env);
+ V.insert(V.end(), Args.begin() + 1, Args.end());
+ return parse(V);
+}
+
std::vector<const char *> ArgParser::tokenize(StringRef S) {
SmallVector<const char *, 16> Tokens;
BumpPtrStringSaver Saver(AllocAux);
--- /dev/null
+# RUN: env LINK="-help -foo" lld -flavor link2 >& %t.log
+# RUN: FileCheck %s < %t.log
+
+CHECK: unknown argument: -foo
+CHECK: OVERVIEW: LLVM Linker