Re: [PATCH] Cygwin: gendef: add _sigfe_maybe for TLS initialization

Jon Turney <[email protected]> Sat, 20 Jun 2026 13:46:13 +0100
Newsgroups gmane.os.cygwin.patches
Message-ID <[email protected]>
On 19/12/2025 17:30, Thirumalai Nagalingam wrote:
> Hi all,
> 
> Please find the attached patch which adds an ARM64 stub for the _sigfe_maybe routine
> in the gendef script.
> 
> Any feedback or nits are very welcome. The changes are documented with inline
> comments intended to be self-explanatory. please let me know if any part
> of this patch should be adjusted.
> 
> Thanks for your time and review.
> 
> Thanks & regards
> Thirumalai Nagalingam <[email protected]>
> 
> In-lined patch:
> 
> diff --git a/winsup/cygwin/scripts/gendef b/winsup/cygwin/scripts/gendef
> index 1419704b8..52a5b77ca 100755
> --- a/winsup/cygwin/scripts/gendef
> +++ b/winsup/cygwin/scripts/gendef
> @@ -367,8 +367,24 @@ EOF
>          .include "tlsoffsets"
>          .text
> 
> -_sigfe_maybe:
> -       .global _sigbe
> +       .seh_proc _sigfe_maybe
> +_sigfe_maybe:                                  # stack is aligned on entry!
> +       .seh_endprologue
> +       ldr     x10, [x18, #0x8]                // Load TEB pointer in x10
> +       ldr     x11, =_cygtls.initialized       // Load relative offset of _cygtls.initialized
> +       add     x11, x10, x11                   // compute absolute address and store in x11
> +       cmp     sp, x11                         // Compare current stack pointer with TLS location
> +       b.hs    0f                              // if sp >= tls, skip TLS logic
> +       ldr     w12, [x11]                      // Load the value at _cygtls.initialized (32-bit)
> +       movz    w13, #0xc763                    // Prepare magic value(0xc763173f) lower 16 bits
> +       movk    w13, #0x173f, lsl #16           // Add upper 16 bits, full value now in w13
> +       cmp     w12, w13                        // Compare loaded value with magic
> +       b.ne    0f                              // If not equal, not initialized, skip TLS logic

Hmmm... while staring at this code, trying to refresh my memory of how 
this it all works... this seems wrong.

Comparing this to the x86_64 version of sigfe_maybe, shouldn't the 
branch here be to forward to label 1? Otherwise this function 
effectively does nothing.

(Of course, this isn't very important since sigfe_maybe is only used by 
cygwin_detach_dll())

> +       ret
> +0:
> +       ret
> +       .seh_endproc
> +
>   _sigfe:
>   _sigbe:
>          .global sigdelayed
> --