From 1b97dc1d620847ab45bf0bc30632d3f121604b43 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Tue, 4 Aug 2026 13:54:25 +0000 Subject: [PATCH] Change VOLATILE_MEMORY_BARRIER for x64 Unix Currently the macro is defined as asm volatile ("" : : : "memory"). That caused a recent regression in HndWriteBarrier due to an added VolatileStore where clang adds an extra dummy jmp instruction to the very next location after a call to HndWriteBarrierWorker. This happens due to LLVM internal handling of the asm volatile ("" : : : "memory"). This change fixes it by replacing the barrier definition for x64 Unix by __atomic_signal_fence(__ATOMIC_SEQ_CST) This is a pure compiler only barrier and it doesn't introduce the side effect like the asm volatile ("" : : : "memory"). Close #130698 --- src/coreclr/gc/env/volatile.h | 2 +- src/coreclr/inc/volatile.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/gc/env/volatile.h b/src/coreclr/gc/env/volatile.h index e42c78e983b77a..0b320ebec510f6 100644 --- a/src/coreclr/gc/env/volatile.h +++ b/src/coreclr/gc/env/volatile.h @@ -90,7 +90,7 @@ // Please do not use this macro outside of this file. It is subject to change or removal without // notice. // -#define VOLATILE_MEMORY_BARRIER() asm volatile ("" : : : "memory") +#define VOLATILE_MEMORY_BARRIER() __atomic_signal_fence(__ATOMIC_SEQ_CST) #endif // HOST_ARM || HOST_ARM64 #elif (defined(HOST_ARM) || defined(HOST_ARM64)) && _ISO_VOLATILE // ARM & ARM64 have a very weak memory model and very few tools to control that model. We're forced to perform a full diff --git a/src/coreclr/inc/volatile.h b/src/coreclr/inc/volatile.h index 1c97750496d74d..7cfd30c4d1ca65 100644 --- a/src/coreclr/inc/volatile.h +++ b/src/coreclr/inc/volatile.h @@ -100,7 +100,7 @@ // Please do not use this macro outside of this file. It is subject to change or removal without // notice. // -#define VOLATILE_MEMORY_BARRIER() asm volatile ("" : : : "memory") +#define VOLATILE_MEMORY_BARRIER() __atomic_signal_fence(__ATOMIC_SEQ_CST) #endif // HOST_ARM || HOST_ARM64 #elif (defined(HOST_ARM) || defined(HOST_ARM64)) && _ISO_VOLATILE