Handle _LINK_ env string as command line parameters.
authorRui Ueyama <ruiu@google.com>
Mon, 24 Apr 2017 22:20:03 +0000 (22:20 +0000)
committerRui Ueyama <ruiu@google.com>
Mon, 24 Apr 2017 22:20:03 +0000 (22:20 +0000)
"_LINK_" environment varaible should be appended to the command line.
https://msdn.microsoft.com/en-us/library/6y6t9esh.aspx

Fixes https://bugs.llvm.org/show_bug.cgi?id=32756

llvm-svn: 301264

lld/COFF/Driver.h
lld/COFF/DriverUtils.cpp
lld/test/COFF/linkenv.test

index 4566f73..ad72562 100644 (file)
@@ -48,7 +48,7 @@ public:
   llvm::opt::InputArgList parse(llvm::ArrayRef<const char *> Args);
 
   // Concatenate LINK environment varirable and given arguments and parse them.
-  llvm::opt::InputArgList parseLINK(llvm::ArrayRef<const char *> Args);
+  llvm::opt::InputArgList parseLINK(std::vector<const char *> Args);
 
   // Tokenizes a given string and then parses as command line options.
   llvm::opt::InputArgList parse(StringRef S) { return parse(tokenize(S)); }
index 736e846..252590c 100644 (file)
@@ -699,17 +699,20 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> ArgsArr) {
   return Args;
 }
 
-// link.exe has an interesting feature. If LINK environment exists,
-// its contents are handled as a command line string. So you can pass
-// extra arguments using the environment variable.
-opt::InputArgList ArgParser::parseLINK(ArrayRef<const char *> Args) {
+// link.exe has an interesting feature. If LINK or _LINK_ environment
+// variables exist, their contents are handled as command line strings.
+// So you can pass extra arguments using them.
+opt::InputArgList ArgParser::parseLINK(std::vector<const char *> Args) {
   // Concatenate LINK env and command line arguments, and then 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(), Args.end());
-  return parse(V);
+  if (Optional<std::string> S = Process::GetEnv("LINK")) {
+    std::vector<const char *> V = tokenize(*S);
+    Args.insert(Args.begin(), V.begin(), V.end());
+  }
+  if (Optional<std::string> S = Process::GetEnv("_LINK_")) {
+    std::vector<const char *> V = tokenize(*S);
+    Args.insert(Args.begin(), V.begin(), V.end());
+  }
+  return parse(Args);
 }
 
 std::vector<const char *> ArgParser::tokenize(StringRef S) {
index 5dfb875..6033094 100644 (file)
@@ -1,4 +1,4 @@
-# RUN: env LINK=-help lld-link > %t.log
-# RUN: FileCheck %s < %t.log
+# RUN: env LINK=-help lld-link | FileCheck %s
+# RUN: env _LINK_=-help lld-link | FileCheck %s
 
 CHECK: OVERVIEW: LLVM Linker