- Notifications
You must be signed in to change notification settings - Fork5.2k
Commitc5d34f4
committed
Fix generic read and write barriers for Clang.
generic-gcc.h maps our read and write barriers to C11 acquire andrelease fences using compiler builtins, for platforms where we don'thave our own hand-rolled assembler. This is apparently enough for GCC,but the C11 memory model is only defined in terms of atomic accesses,and our barriers for non-atomic, non-volatile accesses were not alwaysrespected under Clang's stricter interpretation of the standard.This explains the occasional breakage observed on new RISC-V + Clanganimal greenfly in lock-free PgAioHandle manipulation code containing arepeating pattern of loads and read barriers. The problem can also beobserved in code generated for MIPS and LoongAarch, though we aren'tcurrently testing those with Clang, and on x86, though we use our ownassembler there. The scariest aspect is that we use the generic versionon very common ARM systems, but it doesn't seem to reorder the relevantcode there (or we'd have debugged this long ago).Fix by inserting an explicit compiler barrier. It expands to an emptyassembler block declared to have memory side-effects, so registers areflushed and reordering is prevented. In those respects this is like thearchitecture-specific assembler versions, but the compiler is still incharge of generating the appropriate fence instruction. Done for writebarriers on principle, though concrete problems have only been observedwith read barriers.Reported-by: Alexander Lakhin <exclusion@gmail.com>Tested-by: Alexander Lakhin <exclusion@gmail.com>Discussion:https://postgr.es/m/d79691be-22bd-457d-9d90-18033b78c40a%40gmail.comBackpatch-through: 131 parent7742f99 commitc5d34f4
1 file changed
+10
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
52 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
53 | 61 | | |
54 | 62 | | |
55 | 63 | | |
| |||
0 commit comments
Comments
(0)