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

i386: Do not clobber DRAP register during stack probing

Stack probing code on i386 is fixed to prevent overwriting the DRAP register.

This commit prevents the get_scratch_register_on_entry function in the i386 backend from clobbering the DRAP (Dynamic Re-Alignment Pointer) register during stack probing operations. While some safeguards were in place, not all cases were covered, leading to potential corruption of this register, particularly on 32-bit Windows targets where DRAP-based stack realignment is enabled. The fix ensures that the DRAP register, currently DI_REG, is never returned as a scratch register, preserving its integrity.

In Details

This patch addresses a register clobbering issue in the i386 get_scratch_register_on_entry function, specifically concerning the DRAP register. This register is utilized for dynamic stack realignment, a feature introduced in GCC 16 for certain targets like 32-bit Windows. Although some existing code guarded against clobbering DRAP, certain paths, particularly those involving DI_REG (which currently serves as DRAP), were not properly protected. The fix modifies the function to ensure that DI_REG is never returned as a scratch register, thus preventing its accidental overwrite during stac…

For Context
DRAP
Dynamic Re-Alignment Pointer. A register used in some architectures and calling conventions to manage dynamic stack adjustments, particularly for features like stack probing or alignment.
stack probing
A technique used by compilers to detect stack overflows at runtime. It involves checking stack usage at function entry or during execution and can involve specific instructions or register usage.
clobber
In the context of CPU registers, 'clobber' means to overwrite the value of a register, potentially destroying its previous content. Compilers must track which registers are clobbered by function calls or instructions.
scratch register
A temporary register that a function or instruction can use freely without needing to preserve its value, as it's expected to be overwritten.
i386
A 32-bit microprocessor architecture from Intel, widely used in personal computers. GCC supports generating code for this architecture.
Filed Under: i386register allocationstackbugfix