Skip to content

Commit

Permalink
[Driver] Use libatomic for 32-bit SPARC atomics support on Linux
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rorth committed Jul 29, 2022
1 parent 4db7c7d commit 9b1897b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions clang/lib/Driver/ToolChains/Gnu.cpp
Expand Up @@ -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");

Expand Down
2 changes: 2 additions & 0 deletions clang/test/Driver/linux-ld.c
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down

0 comments on commit 9b1897b

Please sign in to comment.