Skip to content

Change VOLATILE_MEMORY_BARRIER for x64 Unix - #131807

Merged
janvorli merged 1 commit into
dotnet:mainfrom
janvorli:modify-volatile-memory-barrier
Aug 4, 2026
Merged

Change VOLATILE_MEMORY_BARRIER for x64 Unix#131807
janvorli merged 1 commit into
dotnet:mainfrom
janvorli:modify-volatile-memory-barrier

Conversation

@janvorli

@janvorli janvorli commented Aug 4, 2026

Copy link
Copy Markdown
Member

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

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 dotnet#130698
@janvorli janvorli added this to the 11.0.0 milestone Aug 4, 2026
@janvorli
janvorli requested a review from jkotas August 4, 2026 14:03
@janvorli janvorli self-assigned this Aug 4, 2026
Copilot AI review requested due to automatic review settings August 4, 2026 14:03
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates CoreCLR’s VOLATILE_MEMORY_BARRIER() macro for GCC/Clang builds by replacing an empty asm volatile ("" : : : "memory") compiler barrier with __atomic_signal_fence(__ATOMIC_SEQ_CST) in both the main CoreCLR header and the GC environment copy, with the intent of avoiding undesirable codegen side-effects on Linux/x64 (per #130698).

Changes:

  • Replace the GCC/Clang fallback VOLATILE_MEMORY_BARRIER() implementation with __atomic_signal_fence(__ATOMIC_SEQ_CST) in CoreCLR’s inc/volatile.h.
  • Apply the same change to the GC’s corresponding gc/env/volatile.h to keep the duplicated implementations aligned.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/coreclr/inc/volatile.h Switches the GCC/Clang fallback compiler barrier macro to __atomic_signal_fence in the shared CoreCLR volatile helper header.
src/coreclr/gc/env/volatile.h Mirrors the same barrier macro change in the GC environment’s copy of the volatile helper.

Comment thread src/coreclr/inc/volatile.h
Comment thread src/coreclr/gc/env/volatile.h
@janvorli

janvorli commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

/ba-g the NativeAOT legs are timing out on all PRs

@janvorli
janvorli merged commit 18f89a4 into dotnet:main Aug 4, 2026
114 of 120 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Perf] Linux/x64: 2 Regressions on 7/5/2026 4:58:39 PM +00:00

3 participants