Index: include/clang/Driver/Driver.h =================================================================== --- include/clang/Driver/Driver.h +++ include/clang/Driver/Driver.h @@ -145,6 +145,9 @@ /// sysroot, if present std::string SysRoot; + /// Include sysroot, if present + std::string IncludeSysRoot; + /// Dynamic loader prefix, if present std::string DyldPrefix; Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -88,7 +88,8 @@ : Opts(createDriverOptTable()), Diags(Diags), VFS(std::move(VFS)), Mode(GCCMode), SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone), LTOMode(LTOK_None), ClangExecutable(ClangExecutable), - SysRoot(DEFAULT_SYSROOT), UseStdLib(true), + SysRoot(DEFAULT_SYSROOT), IncludeSysRoot(DEFAULT_SYSROOT), + UseStdLib(true), DriverTitle("clang LLVM compiler"), CCPrintOptionsFilename(nullptr), CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr), CCCPrintBindings(false), CCPrintHeaders(false), CCLogDiagnostics(false), @@ -677,6 +678,10 @@ } if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) SysRoot = A->getValue(); + if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) + IncludeSysRoot = A->getValue(); + if (IncludeSysRoot.empty() && !SysRoot.empty()) + IncludeSysRoot = SysRoot; if (const Arg *A = Args.getLastArg(options::OPT__dyld_prefix_EQ)) DyldPrefix = A->getValue(); if (Args.hasArg(options::OPT_nostdlib)) Index: lib/Driver/ToolChains/Linux.h =================================================================== --- lib/Driver/ToolChains/Linux.h +++ lib/Driver/ToolChains/Linux.h @@ -40,6 +40,7 @@ void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; virtual std::string computeSysRoot() const; + virtual std::string computeIncludeSysRoot() const; virtual std::string getDynamicLinker(const llvm::opt::ArgList &Args) const; @@ -48,6 +49,7 @@ protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; + std::string defaultSysRoot() const; }; } // end namespace toolchains Index: lib/Driver/ToolChains/Linux.cpp =================================================================== --- lib/Driver/ToolChains/Linux.cpp +++ lib/Driver/ToolChains/Linux.cpp @@ -380,10 +380,7 @@ return new tools::gnutools::Assembler(*this); } -std::string Linux::computeSysRoot() const { - if (!getDriver().SysRoot.empty()) - return getDriver().SysRoot; - +std::string Linux::defaultSysRoot() const { if (!GCCInstallation.isValid() || !tools::isMipsArch(getTriple().getArch())) return std::string(); @@ -410,6 +407,20 @@ return std::string(); } +std::string Linux::computeSysRoot() const { + if (!getDriver().SysRoot.empty()) + return getDriver().SysRoot; + + return defaultSysRoot(); +} + +std::string Linux::computeIncludeSysRoot() const { + if (!getDriver().IncludeSysRoot.empty()) + return getDriver().IncludeSysRoot; + + return defaultSysRoot(); +} + std::string Linux::getDynamicLinker(const ArgList &Args) const { const llvm::Triple::ArchType Arch = getArch(); const llvm::Triple &Triple = getTriple(); @@ -541,7 +552,7 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { const Driver &D = getDriver(); - std::string SysRoot = computeSysRoot(); + std::string SysRoot = computeIncludeSysRoot(); if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc)) return; @@ -732,8 +743,8 @@ // If this is a development, non-installed, clang, libcxx will // not be found at ../include/c++ but it likely to be found at // one of the following two locations: - DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/local/include/c++"), - DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++") }; + DetectLibcxxIncludePath(getDriver().IncludeSysRoot + "/usr/local/include/c++"), + DetectLibcxxIncludePath(getDriver().IncludeSysRoot + "/usr/include/c++") }; for (const auto &IncludePath : LibCXXIncludePathCandidates) { if (IncludePath.empty() || !getVFS().exists(IncludePath)) continue;