On Sun, 17 Jan 2021, Martin Storsjö wrote:

> On Thu, 14 Jan 2021, Martin Storsjö wrote:
>
> > On Wed, 13 Jan 2021, Jeremy Drake wrote:
> >
> > > On Wed, 13 Jan 2021, Martin Storsjö wrote:
> > >
> > > > The pragmatic path forward in that case, I think, would to add a
> > > > configure
> > > > option to mingw-w64-crt for optionally enabling the __cxa_thread_atexit
> > > > function. So if that's omitted from mingw-w64-crt, a new build of
> > > > libstdc++
> > > > would include their version of it instead, and it should work as it used
> > > > to,
> > > > for better and worse.
> > > >
>
> What about patching upstream gcc/libstdc++ to add an option for preferring to
> provide its own __cxa_thread_atexit even if the platform seems to have one?
> Ideally it'd default to enabled for mingw platforms.

MSYS2 just tried doing a build of GCC configured to use its implementation
of __cxa_thread_atexit, but a quick test revealed it also had
use-after-free issues, except its variant applied to thread_local objects
from DLLs, whereas the mingw-w64 provided implementation only seemed to
have that issue with thread_local objects from the EXE.  :(

https://github.com/msys2/MINGW-packages/pull/8052#issuecomment-789364255
Starting program: tlstest-main.exe
[New Thread 7216.0x2058]
[New Thread 7216.0x2530]
[New Thread 7216.0x1728]
main global ctor on thread 8576
main
main, starting thread1
[New Thread 7216.0x2494]
threadfunc thread 9364
main local tls ctor on thread 9364
main, thread1 started
LoadLibrary tlstest-lib.dll
lib global ctor on thread 8576
LoadLibrary tlstest-lib.dll ret 5bb50000
main, got func address, calling it
func
lib local tls ctor on thread 8576
lib global tls ctor on thread 8576
func end, thread 8576
main, starting thread2
[New Thread 7216.0x13b0]
threadfunc thread 5040
main local tls ctor on thread 5040
main, thread2 started
thread 9364 calling func
func
lib local tls ctor on thread 9364
lib global tls ctor on thread 9364
func end, thread 9364
main, thread1 work done
thread 5040 calling func
func
lib local tls ctor on thread 5040
lib global tls ctor on thread 5040
func end, thread 5040
main, thread2 work done
thread 9364 finishing

Thread 5 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 7216.0x2494]
0x762d97fc in strlen () from C:\WINDOWS\System32\msvcrt.dll
=> 0x762d97fc <strlen+12>:      8a 01   mov    al,BYTE PTR [ecx]
(gdb) bt
#0  0x762d97fc in strlen () from C:\WINDOWS\System32\msvcrt.dll
#1  0x5bb52828 in __pformat_puts (
    s=0xfeeefeee <error: Cannot access memory at address 0xfeeefeee>,
    stream=stream@entry=0x1def880)
    at 
C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/mingw_pformat.c:558
#2  0x5bb544fe in __mingw_pformat (flags=<optimized out>,
    dest=<optimized out>, max=<optimized out>,
    fmt=0x5bb5a05e " dtor from thread %d, now on %d\n", argv=<optimized out>)
    at 
C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/mingw_pformat.c:2482
#3  0x5bb523c9 in __mingw_vfprintf (stream=0x76304640 <msvcrt!_iob+64>,
    fmt=0x5bb5a05c "%s dtor from thread %d, now on %d\n",
    argv=0x1def934 "î_î_î_î_"$")
    at 
C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/mingw_vfprintf.c:54
#4  0x5bb57f05 in fprintf(_iobuf*, char const*, ...) ()
   from ...\tlstest-lib.dll
#5  0x5bb57fba in Hello::~Hello() ()
   from ...\tlstest-lib.dll
#6  0x7a69a2b7 in ?? () from ...\mingw32\bin\libstdc++-6.dll
#7  0x6c054e42 in ?? () from ...\mingw32\bin\libwinpthread-1.dll
#8  0x6c0550d3 in ?? () from ...\mingw32\bin\libwinpthread-1.dll
#9  0x770ed656 in ntdll!RtlFreeOemString () from C:\WINDOWS\SYSTEM32\ntdll.dll
#10 0x770922bd in ntdll!RtlActivateActivationContextUnsafeFast ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
#11 0x770949ba in ntdll!RtlInitUnicodeStringEx ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
#12 0x77090f43 in ntdll!LdrShutdownThread ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
Starting program: ...\tlstest-main.exe
[New Thread 556.0x12ec]
[New Thread 556.0x1c14]
[New Thread 556.0x17c]
main global ctor on thread 6780
main
main, starting thread1
[New Thread 556.0x27a8]
threadfunc thread 10152
main local tls ctor on thread 10152
main, thread1 started
LoadLibrary tlstest-lib.dll
lib global ctor on thread 6780
LoadLibrary tlstest-lib.dll ret 5bb50000
main, got func address, calling it
func
lib local tls ctor on thread 6780
lib global tls ctor on thread 6780
func end, thread 6780
main, starting thread2
[New Thread 556.0xedc]
threadfunc thread 3804
main local tls ctor on thread 3804
main, thread2 started
thread 10152 calling func
func
lib local tls ctor on thread 10152
lib global tls ctor on thread 10152
func end, thread 10152
main, thread1 work done
thread 3804 calling func
func
lib local tls ctor on thread 3804
lib global tls ctor on thread 3804
func end, thread 3804
main, thread2 work done
thread 10152 finishing
lib global tls dtor from thread 10152, now on 10152
lib local tls dtor from thread 10152, now on 10152

Thread 5 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 556.0x27a8]
0x762d97fc in strlen () from C:\WINDOWS\System32\msvcrt.dll
=> 0x762d97fc <strlen+12>:      8a 01   mov    al,BYTE PTR [ecx]
(gdb) bt
#0  0x762d97fc in strlen () from C:\WINDOWS\System32\msvcrt.dll
#1  0x00633458 in __pformat_puts (
    s=0xfeeefeee <error: Cannot access memory at address 0xfeeefeee>,
    stream=stream@entry=0x1d1f9d8)
    at 
C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/mingw_pformat.c:558
#2  0x0063512e in __mingw_pformat (flags=<optimized out>, flags@entry=24576,
    dest=<optimized out>, dest@entry=0x76304640 <msvcrt!_iob+64>,
    max=<optimized out>, max@entry=0,
    fmt=0x63a05e " dtor from thread %d, now on %d\n",
    fmt@entry=0x63a05c "%s dtor from thread %d, now on %d\n",
    argv=<optimized out>, argv@entry=0x1d1fa8c "î_î_î_î_"'")
    at 
C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/mingw_pformat.c:2482
#3  0x00632ff9 in __mingw_vfprintf (stream=0x76304640 <msvcrt!_iob+64>,
    fmt=0x63a05c "%s dtor from thread %d, now on %d\n",
    argv=0x1d1fa8c "î_î_î_î_"'")
    at 
C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/mingw_vfprintf.c:54
#4  0x00638abd in fprintf(_iobuf*, char const*, ...) ()
#5  0x00638b72 in Hello::~Hello() ()
#6  0x00632915 in run_dtor_list (ptr=<synthetic pointer>)
    at C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:59
#7  tls_callback (hDllHandle=0x630000, dwReason=3, lpReserved=0x0)
    at C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:155
#8  0x770ed656 in ntdll!RtlFreeOemString () from C:\WINDOWS\SYSTEM32\ntdll.dll
#9  0x770922bd in ntdll!RtlActivateActivationContextUnsafeFast ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
#10 0x770949ba in ntdll!RtlInitUnicodeStringEx ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
#11 0x77091014 in ntdll!LdrShutdownThread ()
   from C:\WINDOWS\SYSTEM32\ntdll.dll
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to