GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
aarch64

Add memory clobber to GCS stack switch patterns

Corrects AArch64 GCS stack switch patterns to include memory clobbers.

This commit adds memory clobbers to the AArch64 aarch64_gcsss1 and aarch64_gcsss2 patterns, which handle GCS stack switches. These instructions validate and consume a cap token while writing a return token, implicitly affecting memory. Without explicit memory clobbers, RTL optimizers incorrectly assumed memory was unchanged, leading to incorrect code generation, such as Common Subexpression Elimination reusing stale loads. The addition ensures that memory is treated as potentially changed across these instructions.

In Details

This patch addresses PR target/128284 by adding (clobber (mem:BLK (scratch))) to the AArch64 aarch64_gcsss1 and aarch64_gcsss2 patterns defined in aarch64.md. These patterns correspond to the GCSSS1 and GCSSS2 instructions, which manipulate capability registers for secure execution environments. The GCSSS1/2 instructions validate and consume a cap token at a new GCS address and write a return token to the old GCS address, implying memory effects. Previously, these were implemented as unspec_volatile without memory clobbers. RTL optimizers, like CSE1, treated memory as unchanged acro…

For Context
GCS
Generic Capability System. A security mechanism that provides fine-grained access control for memory and other resources.
Capability Token
A security token used by the GCS to represent and enforce access rights to resources.
RTL
Register Transfer Language. An intermediate representation used by GCC internally to describe machine code operations before they are translated into final machine instructions.
Memory Clobber
A directive in RTL that informs the compiler that a certain memory location or region may have been modified by an operation, preventing optimizations that assume the memory remains unchanged.
CSE
Common Subexpression Elimination. An optimization that identifies and eliminates redundant computations of the same expression.
Filed Under: aarch64gccsecurityoptimization