On Wednesday 30 September 2026 13:56:43 LIU Hao wrote:
> 在 2026-9-29 05:19, Pali Rohár 写道:
> > Callbacks defined via PIMAGE_TLS_CALLBACK are not called on Win9x systems,
> > and also they are not called on all pre-Vista systems when DLL library is
> > loaded at runtime by LoadLibrary() call.
> > ---
> > mingw-w64-libraries/winpthreads/src/thread.c | 21 ++++++++++++++++++++
> > 1 file changed, 21 insertions(+)
> >
> > diff --git a/mingw-w64-libraries/winpthreads/src/thread.c
> > b/mingw-w64-libraries/winpthreads/src/thread.c
> > index ceac61d864ef..6075b8aef348 100644
> > --- a/mingw-w64-libraries/winpthreads/src/thread.c
> > +++ b/mingw-w64-libraries/winpthreads/src/thread.c
> > @@ -526,6 +526,25 @@ __dyn_tls_pthread (HANDLE hDllHandle, DWORD dwReason,
> > LPVOID lpreserved)
> > }
> > }
> > +#ifdef DLL_EXPORT
> > +
> > +/* For DLL builds register TLS hook via DllMain(). Entrypoint DllMain()
> > + * works on all Windows versions (Win32s, Win9x, WinNT) for all cases.
> > + *
> > + * Callbacks defined via PIMAGE_TLS_CALLBACK are not called on Win9x
> > + * systems, and also they are not called on pre-Vista systems when
> > + * DLL library is loaded at runtime by LoadLibrary() call.
> > + */
> > +
> > +BOOL WINAPI
> > +DllMain (HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved)
> > +{
> > + __dyn_tls_pthread (hDllHandle, dwReason, lpReserved);
> > + return TRUE;
> > +}
> > +
> > +#else
> > +
> > /* TLS-runtime section variable. */
> > /* Force a reference to _tls_used to make the linker create the TLS
> > @@ -565,6 +584,8 @@ static __attribute__((used))
> > WINPTHREADS_ATTRIBUTE((WINPTHREADS_SECTION(".CRT$XLF")))
> > const PIMAGE_TLS_CALLBACK __xl_f = __dyn_tls_pthread;
> > +#endif
> > +
> > /* Internal collect-once structure. */
> > typedef struct collect_once_t {
> > pthread_once_t *o;
>
> This change is fine, but `__xl_f` is used later in this file. I have pushed
> this patch with this fixup:
>
> diff --git a/mingw-w64-libraries/winpthreads/src/thread.c
> b/mingw-w64-libraries/winpthreads/src/thread.c
> index ddf35c3a3..09d6a732a 100644
> --- a/mingw-w64-libraries/winpthreads/src/thread.c
> +++ b/mingw-w64-libraries/winpthreads/src/thread.c
> @@ -1039,7 +1060,7 @@ __pthread_self_lite (void)
> t = (struct _pthread_v *) pop_pthread_mem ();
>
> /* If cannot initialize main thread, then the only thing we can do is
> return null pthread_t */
> - if (!__xl_f || !t)
> + if (!t)
> return 0;
>
> t->p_state = PTHREAD_DEFAULT_ATTR /*| PTHREAD_CREATE_DETACHED*/;
I had exactly this change in my local git repo and I planned to send it
as a followup. I forgot that the removal of __xl_f needs to be done
together with DllMain.
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public