From: Joerg Sonnenberger Date: Mon, 21 Mar 2011 13:51:29 +0000 (+0000) Subject: Remember sysroot in Driver. Pass it down to ld for NetBSD, FreeBSD X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ab2bdcc4f397e100c684ede8e8ca6e226e1380a;p=clang Remember sysroot in Driver. Pass it down to ld for NetBSD, FreeBSD and DragonFly. Use the --sysroot= form for Linux. Fix handling of = prefix for -B. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127994 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 2ab69c236f..5047793b64 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -77,6 +77,9 @@ public: typedef llvm::SmallVector prefix_list; prefix_list PrefixDirs; + /// sysroot, if present + std::string SysRoot; + /// Default host triple. std::string DefaultHostTriple; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index bfbf0a0be1..fac8c8c88f 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -287,6 +287,8 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) { A->claim(); PrefixDirs.push_back(A->getValue(*Args, 0)); } + if (const Arg *A = Args->getLastArg(options::OPT__sysroot_EQ)) + SysRoot = A->getValue(*Args); Host = GetHostInfo(DefaultHostTriple.c_str()); @@ -1261,7 +1263,12 @@ std::string Driver::GetFilePath(const char *Name, const ToolChain &TC) const { // attempting to use this prefix when lokup up program paths. for (Driver::prefix_list::const_iterator it = PrefixDirs.begin(), ie = PrefixDirs.end(); it != ie; ++it) { - llvm::sys::Path P(*it); + std::string Dir(*it); + if (Dir.empty()) + continue; + if (Dir[0] == '=') + Dir = SysRoot + Dir.substr(1); + llvm::sys::Path P(Dir); P.appendComponent(Name); bool Exists; if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) @@ -1271,7 +1278,12 @@ std::string Driver::GetFilePath(const char *Name, const ToolChain &TC) const { const ToolChain::path_list &List = TC.getFilePaths(); for (ToolChain::path_list::const_iterator it = List.begin(), ie = List.end(); it != ie; ++it) { - llvm::sys::Path P(*it); + std::string Dir(*it); + if (Dir.empty()) + continue; + if (Dir[0] == '=') + Dir = SysRoot + Dir.substr(1); + llvm::sys::Path P(Dir); P.appendComponent(Name); bool Exists; if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 1c3112aeca..545645b9bd 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -3259,6 +3259,9 @@ void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA, const Driver &D = getToolChain().getDriver(); ArgStringList CmdArgs; + if (!D.SysRoot.empty()) + CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); + if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-Bstatic"); } else { @@ -3437,6 +3440,9 @@ void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, const Driver &D = getToolChain().getDriver(); ArgStringList CmdArgs; + if (!D.SysRoot.empty()) + CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); + if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-Bstatic"); } else { @@ -3594,10 +3600,8 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA, // handled somewhere else. Args.ClaimAllArgs(options::OPT_w); - if (Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) { - CmdArgs.push_back("--sysroot"); - CmdArgs.push_back(A->getValue(Args)); - } + if (!D.SysRoot.empty()) + CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); if (Args.hasArg(options::OPT_pie)) CmdArgs.push_back("-pie"); @@ -3878,6 +3882,9 @@ void dragonfly::Link::ConstructJob(Compilation &C, const JobAction &JA, const Driver &D = getToolChain().getDriver(); ArgStringList CmdArgs; + if (!D.SysRoot.empty()) + CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); + if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-Bstatic"); } else {