diff options
author | Rainer Orth <ro@gcc.gnu.org> | 2022-07-29 09:19:38 +0200 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2022-08-02 01:53:12 -0700 |
commit | 0b96bce063b1cb0c118c94704b7ca778b687b239 (patch) | |
tree | 9f6ef057b4125109d086f532490623c89718c6f0 | |
parent | 12e4e9777975858ea7f5f2a80157b0543c1f0c72 (diff) |
[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)
-rw-r--r-- | clang/lib/Driver/ToolChains/Gnu.cpp | 10 | ||||
-rw-r--r-- | clang/test/Driver/linux-ld.c | 2 |
2 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 34396b0b59c2..f203cae1d329 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"); diff --git a/clang/test/Driver/linux-ld.c b/clang/test/Driver/linux-ld.c index d7c58431fa76..e76b35d6137c 100644 --- a/clang/test/Driver/linux-ld.c +++ b/clang/test/Driver/linux-ld.c @@ -1007,6 +1007,7 @@ // CHECK-SPARCV8: "{{.*}}ld{{(.exe)?}}" // CHECK-SPARCV8: "-m" "elf32_sparc" // CHECK-SPARCV8: "-dynamic-linker" "{{(/usr/sparc-unknown-linux-gnu)?}}/lib/ld-linux.so.2" +// CHECK-SPARCV8: "--push-state" "--as-needed" "-latomic" "--pop-state" // // RUN: %clang -### %s -no-pie 2>&1 \ // RUN: --target=sparcel-unknown-linux-gnu \ @@ -1021,6 +1022,7 @@ // CHECK-SPARCV9: "{{.*}}ld{{(.exe)?}}" // CHECK-SPARCV9: "-m" "elf64_sparc" // CHECK-SPARCV9: "-dynamic-linker" "{{(/usr/sparcv9-unknown-linux-gnu)?}}/lib{{(64)?}}/ld-linux.so.2" +// CHECK-SPARCV9-NOT: "-latomic" // Test linker invocation on Android. // RUN: %clang -### %s -no-pie 2>&1 \ |