[PATCH] D130569: [Driver] Use libatomic for 32-bit SPARC atomics support on Linux [clang-linux-sparc-libatomic.patch, submitted 2022-07-26]

Rainer Orth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 26 07:02:33 PDT 2022


ro created this revision.
ro added reviewers: glaubitz, jrtc27, MaskRay, efriedma.
ro added a project: clang.
Herald added subscribers: StephenFan, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

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`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130569

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -631,6 +631,14 @@
 
       AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
 
+      // LLVM support for atomics on 32-bit SPARC V8+ is incomplete, so
+      // forcibly link with libatomic as a workaround.
+      if (getToolChain().getTriple().getArch() == llvm::Triple::sparc) {
+        CmdArgs.push_back("--as-needed");
+        CmdArgs.push_back("-latomic");
+        CmdArgs.push_back("--no-as-needed");
+      }
+
       if (WantPthread && !isAndroid)
         CmdArgs.push_back("-lpthread");
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130569.447671.patch
Type: text/x-patch
Size: 692 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220726/74cd5cc8/attachment.bin>


More information about the cfe-commits mailing list