[Patch] Make atomics work on FreeBSD+arm

Ed Schouten ed at 80386.nl
Sun May 26 14:47:21 PDT 2013


2013/5/26 Rafael EspĂ­ndola <rafael.espindola at gmail.com>:
> Note that this patch (like r181728), makes clang *not* use the
> function calls and instead use atomic instructions. This is safe given
> * How these functions are implemented on linux (call a vdso in the kernel)
> * The assumption that the kernel is as new as cpu.

Ah, I see. Yes. Well, I looked into it a bit further and I guess I'm
hitting a different problem than I was expecting. The point is that I
was doing addition/subtraction on atomic integers. CGAtomic.cpp has
this piece of code:

#if 0
    // These are only defined for 1-16 byte integers.  It is not clear what
    // their semantics would be on anything else...
    case AtomicExpr::Add:   LibCallName = "__atomic_fetch_add_generic"; break;
    case AtomicExpr::Sub:   LibCallName = "__atomic_fetch_sub_generic"; break;
    case AtomicExpr::And:   LibCallName = "__atomic_fetch_and_generic"; break;
    case AtomicExpr::Or:    LibCallName = "__atomic_fetch_or_generic"; break;
    case AtomicExpr::Xor:   LibCallName = "__atomic_fetch_xor_generic"; break;
#endif

So we don't support libcalls for atomic_fetch*(). I have to confess I
don't entirely agree with the comment. I think and, or and xor only
apply to integer types. Independent of the size of these, the
semantics would be pretty clear. If retricted to integer types, add
and sub would also have pretty clear semantics on both little and big
endian systems. Just walk over the buffer and perform the
addition/subtraction byte by byte.

Unfortunately, it seems we have little choice here, as we're
essentially implementing something that conforms to this API:

http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary

As an experiment, I wrote the following patch, which seems to make
Clang call into __atomic_fetch_* properly:

http://80386.nl/pub/clang-atomic-hax.txt

Unfortunately compiler-rt lacks these functions, so I'll have to add
these first before I can do some proper tests.

To be continued...

--
Ed Schouten <ed at 80386.nl>




More information about the cfe-commits mailing list