Skip to content

Commit

Permalink
[Driver] Use forward slashes in most linker arguments
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mstorsjo committed Oct 23, 2018
1 parent bf6f82a commit 965a361
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions clang/lib/Driver/ToolChain.cpp
Expand Up @@ -378,15 +378,15 @@ 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);
const char *Env = TT.isAndroid() ? "-android" : "";
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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 965a361

Please sign in to comment.