GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libgcc/x86_64/cygwin

Improve x86_64 cygwin.S chkstk functions for SEH backtraces

Enhance x86_64 cygwin stack checking functions for better SEH backtraces.

This change improves the chkstk functions in libgcc/config/i386/cygwin.S for x86_64 Windows targets using Structured Exception Handling (SEH). By replacing cfi_ macro calls with .seh directives and slightly reworking __chkstk_ms to match expected MS runtime prologue/epilogue patterns, the commit facilitates more accurate backtraces when stack overflow exceptions occur. These changes are compatible with both SEH and sjlj-eh configurations.

In Details

For x86_64 Windows targets employing SEH (Structured Exception Handling), the CFI directives within cygwin.S for __alloca and __chkstk_ms were not ideal for generating reliable backtraces from stack overflow traps. This commit replaces cfi_ directives with .seh directives (.seh startproc, .seh endprologue, .seh endproc) for these functions. Additionally, __chkstk_ms is refactored to align its prologue and epilogue code sequences with the patterns documented by the Microsoft runtime, and its stack space allocation is explicitly marked, aiming to improve stack frame unwinding…

For Context
SEH
Structured Exception Handling; a mechanism for handling runtime errors and exceptions in Windows.
sjlj-eh
Setjmp/Longjmp Exception Handling; an alternative exception handling mechanism used in GCC, often paired with DWARF2 unwind information.
cfi_
Common Frame Information directives used in assembly code to describe function call frame layout, aiding debuggers and unwinding.
.seh directives
Specific assembly directives used to define exception handling frames compatible with Windows SEH.
chkstk
A function responsible for checking stack boundaries and preventing stack overflows.
prologue/epilogue
The initial (prologue) and final (epilogue) sequences of instructions in a function that set up and tear down the stack frame, respectively.
Filed Under: libgccwindowssehdebugging