diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/lib/Driver/ToolChains/CommonArgs.h --- a/clang/lib/Driver/ToolChains/CommonArgs.h +++ b/clang/lib/Driver/ToolChains/CommonArgs.h @@ -114,6 +114,8 @@ bool ForceStaticHostRuntime = false, bool IsOffloadingHost = false, bool GompNeedsRT = false); +const char *getAsNeededOption(const ToolChain &TC, bool as_needed); + llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args); llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args); diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -737,7 +737,7 @@ return false; } -static const char *getAsNeededOption(const ToolChain &TC, bool as_needed) { +const char *tools::getAsNeededOption(const ToolChain &TC, bool as_needed) { assert(!TC.getTriple().isOSAIX() && "AIX linker does not support any form of --as-needed option yet."); diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp --- a/clang/lib/Driver/ToolChains/Solaris.cpp +++ b/clang/lib/Driver/ToolChains/Solaris.cpp @@ -132,6 +132,13 @@ CmdArgs.push_back("-lssp_nonshared"); CmdArgs.push_back("-lssp"); } + // LLVM lacks atomics support on 32-bit SPARC, so forcibly link with + // libatomic as a workaround. + if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) { + CmdArgs.push_back(getAsNeededOption(getToolChain(), true)); + CmdArgs.push_back("-latomic"); + CmdArgs.push_back(getAsNeededOption(getToolChain(), false)); + } CmdArgs.push_back("-lgcc_s"); CmdArgs.push_back("-lc"); if (!Args.hasArg(options::OPT_shared)) {