This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Use libatomic for 32-bit SPARC atomics support on Linux
ClosedPublic

Authored by ro on Jul 26 2022, 7:02 AM.

Details

Summary

This is the Linux/sparc64 equivalent to 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.

Diff Detail

Event Timeline

ro created this revision.Jul 26 2022, 7:02 AM
ro requested review of this revision.Jul 26 2022, 7:02 AM
glaubitz accepted this revision.Jul 26 2022, 7:54 AM

This should address the current CI issues on sparc64 together with D130571.

This revision is now accepted and ready to land.Jul 26 2022, 7:54 AM
ro retitled this revision from [Driver] Use libatomic for 32-bit SPARC atomics support on Linux [clang-linux-sparc-libatomic.patch, submitted 2022-07-26] to [Driver] Use libatomic for 32-bit SPARC atomics support on Linux.Jul 26 2022, 12:20 PM
MaskRay added inline comments.Jul 26 2022, 12:51 PM
clang/lib/Driver/ToolChains/Gnu.cpp
634

// TODO ... and attach a bug link

637

Such --as-needed usage is a bit fragile if clang driver in the future passes --as-needed in the beginning. Better to use --push-state if you have a not-too-old ld.

This needs a test. For now you can use linux-ld.c which has some sparc tests.

ro marked 2 inline comments as done.Jul 28 2022, 12:54 AM
ro added inline comments.
clang/lib/Driver/ToolChains/Gnu.cpp
634

It's split between the original bug report and a patch review: I only noticed later (when compiler-rt started to make use of 64-bit atomics) that those aren't implemented by clang -m32 -mcpu=v9.

637

Good point: I initially fell into that trap in D130571 when I added --as-needed -latomic --no-as-needed to SANITIZER_COMMON_LINK_FLAGS: it got added early to the link line, before the objects using atomics, and had no effect. Only then did Iearn that target_link_libraries accepts not only library names, but also linker flags.

As for --push-state, it was introduced in GNU ld 2.25 back in 2014, to it's save to assume it's present.

ro updated this revision to Diff 448253.Jul 28 2022, 12:56 AM
ro marked 2 inline comments as done.
  • Switch to --push-state/--pop-state.
  • Add testcase.
This revision was landed with ongoing or failed builds.Jul 29 2022, 12:20 AM
This revision was automatically updated to reflect the committed changes.