This is an archive of the discontinued LLVM Phabricator instance.

Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.
ClosedPublic

Authored by dim on Sep 22 2015, 4:22 AM.

Details

Summary

In rL241532, atomic_support.h was added, which provides handling of
atomic operations for libc++. When atomic builtins are not available,
it emits a warning about being unsupported, but it still provides a
number of stubs for the required functions.

However, it misses a stub for __libcpp_relaxed_store(). Add it, by
using the same implementation as for __libcpp_atomic_store().

(Note that I encountered this on arm-freebsd, which still defaults to
armv4, and does not have the runtime libcalls to support atomic
builtins. For now, I have simply disabled using them.)

Diff Detail

Event Timeline

dim updated this revision to Diff 35358.Sep 22 2015, 4:22 AM
dim retitled this revision from to Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available..
dim updated this object.
dim added reviewers: EricWF, mclow.lists.
dim added subscribers: majnemer, jroelofs, cfe-commits.
dim added a subscriber: theraven.Sep 22 2015, 4:22 AM
dim updated this object.Sep 22 2015, 4:25 AM

Looks fine (though this probably won't actually work correctly on ARMv4).

It's a shame that libc++ decided to reinvent the wheel here and not use the C11 atomics support...

EricWF edited edge metadata.Sep 22 2015, 10:44 AM

Does anything actually need this? This interface was never really meant to be complete, just want was needed.

It's a shame that libc++ decided to reinvent the wheel here and not use the C11 atomics support

GCC doesn't provide "_Atomic" and <atomic> isn't always fully available. This is a minimal subset of atomic functionality needed to support std::shared_ptr and std::call_once among other things. All new code should use std::atomic IMO. It's not meant to reinvent the wheel, It's meant to be a portable option for when there is no "wheel" already.

Does armv4 need lib calls for atomic operations on "unsigned long"?

Does armv4 need lib calls for atomic operations on "unsigned long"?

IIRC, yes.

dim added a comment.Sep 22 2015, 11:26 AM

Does anything actually need this? This interface was never really meant to be complete, just want was needed.

I need it at least for FreeBSD/arm, since it defaults to armv4, and it does not yet have a full set of atomic ops as libcalls. In any case, if stub functions are provided, they should at least compile. :-)

EricWF accepted this revision.Sep 22 2015, 11:35 AM
EricWF edited edge metadata.

Ah sorry I hadn't had coffee yet. Sorry for the breakage. I'll make sure this make sure this patch gets backported appropriately.

LGTM thanks for the fix.

This revision is now accepted and ready to land.Sep 22 2015, 11:35 AM
dim closed this revision.Sep 22 2015, 11:57 AM

@jroelofs @dim, could we fallback to the __sync_* builtins on arm?

@jroelofs @dim, could we fallback to the __sync_* builtins on arm?

@dim would need armv4-flavored implementations of them in compiler-rt (if that's what he's using)... the existing ones use instructions that v4 doesn't have. Implementation-wise, they'd have to use __kuser_cmpxchg. See: https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt

dim added a comment.Sep 22 2015, 2:22 PM

@jroelofs @dim, could we fallback to the __sync_* builtins on arm?

The actual implementations of these __sync builtins should still come from somewhere, as they will also be libcalls, right?

@dim would need armv4-flavored implementations of them in compiler-rt (if that's what he's using)... the existing ones use instructions that v4 doesn't have.

Andrew Turner, a fellow FreeBSD developer, has added them pretty quickly, in https://svnweb.freebsd.org/base?view=revision&revision=288125. So I have now reverted the ugly workaround in FreeBSD that disabled _LIBCPP_HAS_ATOMIC_BUILTINS for arm < v6.