[PATCH] D45321: [atomics] Fix runtime calls for misaligned atomics

Tim Northover via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 5 06:36:56 PDT 2018


t.p.northover created this revision.
t.p.northover added a reviewer: compnerd.
Herald added subscribers: Sanitizers, kristof.beyls, mcrosier.

The `__atomic_whatever` functions in compiler-rt were only looking at the size of their argument when deciding whether the implementation should be lock-free. This is incorrect:

- On x86 simple loads and stores are not atomic if the address is misaligned. They could use `cmpxchg` to implement loads & stores instead, but I believe this would be incompatible with GCC's ABI (and it is an ABI choice because you obviously can't mix them).
- On other platforms (ARM that I know of) misaligned atomic accesses will simply fault (as well as the above).

So this patch falls back to locks for the misaligned case. It also adds the single-byte case to the generic functions since even though Clang won't make calls to them, they should probably work properly if anyone does.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D45321

Files:
  compiler-rt/lib/builtins/atomic.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45321.141149.patch
Type: text/x-patch
Size: 4513 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180405/72475401/attachment.bin>


More information about the llvm-commits mailing list