Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc5d34f4

Browse files
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: 13
1 parent7742f99 commitc5d34f4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

‎src/include/port/atomics/generic-gcc.h‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@
4444

4545
#if !defined(pg_read_barrier_impl)&& defined(HAVE_GCC__ATOMIC_INT32_CAS)
4646
/* acquire semantics include read barrier semantics */
47-
#definepg_read_barrier_impl()__atomic_thread_fence(__ATOMIC_ACQUIRE)
47+
#definepg_read_barrier_impl() do \
48+
{ \
49+
pg_compiler_barrier_impl(); \
50+
__atomic_thread_fence(__ATOMIC_ACQUIRE); \
51+
} while (0)
4852
#endif
4953

5054
#if !defined(pg_write_barrier_impl)&& defined(HAVE_GCC__ATOMIC_INT32_CAS)
5155
/* release semantics include write barrier semantics */
52-
#definepg_write_barrier_impl()__atomic_thread_fence(__ATOMIC_RELEASE)
56+
#definepg_write_barrier_impl() do \
57+
{ \
58+
pg_compiler_barrier_impl(); \
59+
__atomic_thread_fence(__ATOMIC_RELEASE); \
60+
} while (0)
5361
#endif
5462

5563

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp