aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorRainer Orth <ro@gcc.gnu.org>2022-07-29 09:19:38 +0200
committerTom Stellard <tstellar@redhat.com>2022-08-02 01:53:12 -0700
commit0b96bce063b1cb0c118c94704b7ca778b687b239 (patch)
tree9f6ef057b4125109d086f532490623c89718c6f0 /clang/lib
parent12e4e9777975858ea7f5f2a80157b0543c1f0c72 (diff)
downloadllvm-0b96bce063b1cb0c118c94704b7ca778b687b239.zip
llvm-0b96bce063b1cb0c118c94704b7ca778b687b239.tar.gz
llvm-0b96bce063b1cb0c118c94704b7ca778b687b239.tar.bz2
[Driver] Use libatomic for 32-bit SPARC atomics support on Linux
This is the Linux/sparc64 equivalent to D118021 <https://reviews.llvm.org/D118021>, necessary to provide an external implementation of atomics on 32-bit SPARC which LLVM cannot inline even with `-mcpu=v9` or an equivalent default. Tested on `sparc64-unknown-linux-gnu`. Differential Revision: https://reviews.llvm.org/D130569 (cherry picked from commit 9b1897bbd0e3a6e9ef099e74c3d3ed35428c0460)
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Driver/ToolChains/Gnu.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 34396b0..f203cae 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -631,6 +631,16 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
+ // LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+ // forcibly link with libatomic as a workaround.
+ // TODO: Issue #41880 and D118021.
+ if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+ CmdArgs.push_back("--push-state");
+ CmdArgs.push_back("--as-needed");
+ CmdArgs.push_back("-latomic");
+ CmdArgs.push_back("--pop-state");
+ }
+
if (WantPthread && !isAndroid)
CmdArgs.push_back("-lpthread");