[llvm-branch-commits] [clang] 0b96bce - [Driver] Use libatomic for 32-bit SPARC atomics support on Linux
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Aug 2 01:56:40 PDT 2022
Author: Rainer Orth
Date: 2022-08-02T01:53:12-07:00
New Revision: 0b96bce063b1cb0c118c94704b7ca778b687b239
URL: https://github.com/llvm/llvm-project/commit/0b96bce063b1cb0c118c94704b7ca778b687b239
DIFF: https://github.com/llvm/llvm-project/commit/0b96bce063b1cb0c118c94704b7ca778b687b239.diff
LOG: [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)
Added:
Modified:
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/linux-ld.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 34396b0b59c2b..f203cae1d329f 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 d7c58431fa76f..e76b35d6137c7 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 \
More information about the llvm-branch-commits
mailing list