[Driver] Use forward slashes in most linker arguments
authorMartin Storsjo <martin@martin.st>
Tue, 23 Oct 2018 06:33:26 +0000 (06:33 +0000)
committerMartin Storsjo <martin@martin.st>
Tue, 23 Oct 2018 06:33:26 +0000 (06:33 +0000)
libtool inspects the output of $CC -v to detect what object files and
libraries are linked in by default. When clang is built as a native
windows executable, all paths are formatted with backslashes, and
the backslashes cause each argument to be enclosed in quotes. The
backslashes and quotes break further processing within libtool (which
is implemented in shell script, running in e.g. msys) pretty badly.

Between unix style pathes (that only work in tools that are linked
to the msys runtime, essentially the same as cygwin) and proper windows
style paths (with backslashes, that can easily break shell scripts
and msys environments), the best compromise is to use windows style
paths (starting with e.g. c:) but with forward slashes, which both
msys based tools, shell scripts and native windows executables can
cope with. This incidentally turns out to be the form of paths that
GCC prints out when run with -v on windows as well.

This change potentially makes the output from clang -v a bit more
inconsistent, but it is isn't necessarily very consistent to begin with.

Differential Revision: https://reviews.llvm.org/D53066

llvm-svn: 345004

clang/lib/Driver/ToolChain.cpp

index 1667536..2b76dea 100644 (file)
@@ -378,7 +378,7 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
     SmallString<128> P(LibPath);
     llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix);
     if (getVFS().exists(P))
-      return P.str();
+      return llvm::sys::path::convert_to_slash(P);
   }
 
   StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
@@ -386,7 +386,7 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
   SmallString<128> Path(getCompilerRTPath());
   llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" +
                                     Arch + Env + Suffix);
-  return Path.str();
+  return llvm::sys::path::convert_to_slash(Path);
 }
 
 const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args,
@@ -425,7 +425,7 @@ Tool *ToolChain::SelectTool(const JobAction &JA) const {
 }
 
 std::string ToolChain::GetFilePath(const char *Name) const {
-  return D.GetFilePath(Name, *this);
+  return llvm::sys::path::convert_to_slash(D.GetFilePath(Name, *this));
 }
 
 std::string ToolChain::GetProgramPath(const char *Name) const {
@@ -774,12 +774,14 @@ void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
 void ToolChain::AddFilePathLibArgs(const ArgList &Args,
                                    ArgStringList &CmdArgs) const {
   for (const auto &LibPath : getLibraryPaths())
-    if(LibPath.length() > 0)
-      CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
+    if (LibPath.length() > 0)
+      CmdArgs.push_back(Args.MakeArgString(
+          StringRef("-L") + llvm::sys::path::convert_to_slash(LibPath)));
 
   for (const auto &LibPath : getFilePaths())
-    if(LibPath.length() > 0)
-      CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
+    if (LibPath.length() > 0)
+      CmdArgs.push_back(Args.MakeArgString(
+          StringRef("-L") + llvm::sys::path::convert_to_slash(LibPath)));
 }
 
 void ToolChain::AddCCKextLibArgs(const ArgList &Args,