diff -wpruN '--exclude=*.orig' a~/lib/Driver/ToolChains/Solaris.cpp a/lib/Driver/ToolChains/Solaris.cpp --- llvm-16.0.6.src~/tools/clang/lib/Driver/ToolChains/Solaris.cpp 1970-01-01 00:00:00 +++ llvm-16.0.6.src/tools/clang/lib/Driver/ToolChains/Solaris.cpp 1970-01-01 00:00:00 @@ -125,10 +125,11 @@ bool NeedsSanitizerDeps = addSanitizerRuntimes(getToolChain(), Args, CmdArgs); AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA); + if (getToolChain().ShouldLinkCXXStdlib(Args) && !Args.hasArg(options::OPT_r)) + getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs, options::OPT_r)) { - if (getToolChain().ShouldLinkCXXStdlib(Args)) - getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); // LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so // forcibly link with libatomic as a workaround. if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) { @@ -302,3 +302,16 @@ void Solaris::addLibStdCxxIncludePaths( TripleStr, Multilib.includeSuffix(), DriverArgs, CC1Args); } + +void Solaris::AddCXXStdlibLibArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { + Generic_ELF::AddCXXStdlibLibArgs(Args, CmdArgs); + + if (GetCXXStdlibType(Args) != ToolChain::CST_Libstdcxx) + return; + + StringRef LibSuffix = getSolarisLibSuffix(getTriple()); + std::string MajVer = GCCInstallation.getVersion().MajorStr; + CmdArgs.push_back(Args.MakeArgString(StringRef("-R") + + "/usr/gcc/" + MajVer + "/lib" + LibSuffix)); +} diff -wpruN '--exclude=*.orig' a~/lib/Driver/ToolChains/Solaris.h a/lib/Driver/ToolChains/Solaris.h --- llvm-16.0.6.src~/tools/clang/lib/Driver/ToolChains/Solaris.h 1970-01-01 00:00:00 +++ llvm-16.0.6.src/tools/clang/lib/Driver/ToolChains/Solaris.h 1970-01-01 00:00:00 @@ -62,6 +62,9 @@ public: addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; + void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const override; + SanitizerMask getSupportedSanitizers() const override; unsigned GetDefaultDwarfVersion() const override { return 2; } diff -wpruN '--exclude=*.orig' a~/lib/Driver/ToolChain.cpp a/lib/Driver/ToolChain.cpp --- llvm-16.0.6.src~/tools/clang/lib/Driver/ToolChain.cpp 1970-01-01 00:00:00 +++ llvm-16.0.6.src/tools/clang/lib/Driver/ToolChain.cpp 1970-01-01 00:00:00 @@ -999,9 +999,7 @@ } bool ToolChain::ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const { - return getDriver().CCCIsCXX() && - !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs, - options::OPT_nostdlibxx); + return getDriver().CCCIsCXX() && !Args.hasArg(options::OPT_nostdlibxx); } void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,