MINGW-packages icon indicating copy to clipboard operation
MINGW-packages copied to clipboard

WIndowed program built with asan crashes on startup

Open ThosRTanner opened this issue 2 years ago • 7 comments

Trying to discover why my windowed windows program appeared to hang when built with clang (MSYSTEM=CLANG64) (fine with gcc, with MSYSTEM=MINGW64.), I built it with -fsanitize=address -fsanitize=undefined. This built fine but crashes on startup.

This is the stack trace

(gdb) run --debug --verbose
Starting program: C:\Users\Dad\Repositories\gitlab\pan\pan\gui\pan.exe --debug --verbose
[New Thread 36524.0x6614]
[New Thread 36524.0x6c3c]
[New Thread 36524.0x71c]
[New Thread 36524.0x46e4]

Thread 1 received signal SIGSEGV, Segmentation fault.
0x00007ff902253e78 in ntdll!memset () from C:\Windows\SYSTEM32\ntdll.dll
(gdb) where
#0  0x00007ff902253e78 in ntdll!memset () from C:\Windows\SYSTEM32\ntdll.dll
#1  0x00007ff89c82489e in __sanitizer::SizeClassAllocator64<__asan::AP64<__sanitizer::LocalAddressSpaceView> >::MapWithCallbackOrDie(unsigned long long, unsigned long long, char const*) () from C:\Apps\msys64\clang64\bin\libclang_rt.asan_dynamic-x86_64.dll
#2  0x00007ff89c82479b in __sanitizer::SizeClassAllocator64<__asan::AP64<__sanitizer::LocalAddressSpaceView> >::Init(int, unsigned long long) ()
   from C:\Apps\msys64\clang64\bin\libclang_rt.asan_dynamic-x86_64.dll
#3  0x00007ff89c821b9c in __asan::InitializeAllocator(__asan::AllocatorOptions const&) () from C:\Apps\msys64\clang64\bin\libclang_rt.asan_dynamic-x86_64.dll
#4  0x00007ff89c842bc5 in __asan::AsanInitFromRtl() () from C:\Apps\msys64\clang64\bin\libclang_rt.asan_dynamic-x86_64.dll
#5  0x00007ff89c84ad03 in __main () from C:\Apps\msys64\clang64\bin\libclang_rt.asan_dynamic-x86_64.dll
#6  0x00007ff89c801233 in DllMainCRTStartup () from C:\Apps\msys64\clang64\bin\libclang_rt.asan_dynamic-x86_64.dll
#7  0x00007ff9021c9a1d in ntdll!RtlActivateActivationContextUnsafeFast () from C:\Windows\SYSTEM32\ntdll.dll
#8  0x00007ff90221c1e7 in ntdll!LdrGetProcedureAddressEx () from C:\Windows\SYSTEM32\ntdll.dll
#9  0x00007ff90221bf7a in ntdll!LdrGetProcedureAddressEx () from C:\Windows\SYSTEM32\ntdll.dll
#10 0x00007ff90221c000 in ntdll!LdrGetProcedureAddressEx () from C:\Windows\SYSTEM32\ntdll.dll
#11 0x00007ff902283c2a in ntdll!LdrInitShimEngineDynamic () from C:\Windows\SYSTEM32\ntdll.dll
#12 0x00007ff902224cdb in ntdll!LdrInitializeThunk () from C:\Windows\SYSTEM32\ntdll.dll
#13 0x00007ff902224b63 in ntdll!LdrInitializeThunk () from C:\Windows\SYSTEM32\ntdll.dll
#14 0x00007ff902224b0e in ntdll!LdrInitializeThunk () from C:\Windows\SYSTEM32\ntdll.dll
#15 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

ThosRTanner avatar Jun 12 '22 11:06 ThosRTanner

Could you try on MinGW UCRT x64?

lb90 avatar Jun 13 '22 16:06 lb90

I get:

clang++: error: unsupported option '-fsanitize=address' for target 'x86_64-pc-windows-msys'

if I use the clang supplied in /usr/bin

if I install clang from the ucrt64 pacman packages, it fails horribly at link time

Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
(repeated a lot)

C:/Apps/msys64/ucrt64/bin/ld: gui.o: in function `pan::GUI::add_widget(_GtkUIManager*, _GtkWidget*, void*)':
C:\Repositories\gitlab\pan\pan\gui/gui.cc:152: undefined reference to `__ubsan_handle_type_mismatch_v1'
C:/Apps/msys64/ucrt64/bin/ld: C:\Repositories\gitlab\pan\pan\gui/gui.cc:152: undefined reference to `__ubsan_handle_type_mismatch_v1'
C:/Apps/msys64/ucrt64/bin/ld: C:\Repositories\gitlab\pan\pan\gui/gui.cc:152: undefined reference to `__ubsan_handle_type_mismatch_v1'

26,000 lines worth

and that's just with sanitize=undefined. I hate to think what it'd get with sanitize=address

ThosRTanner avatar Jun 13 '22 19:06 ThosRTanner

if I use the clang supplied in /usr/bin

This target doesn't support sanitizers at all.

if I install clang from the ucrt64 pacman packages, it fails horribly at link time

ld.bfd doesn't support LLVM sanitizers on Windows and they aren't available there anyway.

I think lb90 wants you to try if your application works correctly when build with GCC + UCRT.

mati865 avatar Jun 13 '22 21:06 mati865

oh. i see. i can try that tomorrow.

ThosRTanner avatar Jun 13 '22 21:06 ThosRTanner

good grief. that is faster than the mingw64 code. definitely not hanging or crashing

ThosRTanner avatar Jun 14 '22 20:06 ThosRTanner

@ThosRTanner : if you fixed the problem, please close this issue. Thanks.

oscarfv avatar Jul 27 '22 15:07 oscarfv

not really. i can't build with anything useful in terms of sanitisers or profilers, my clang build in clang msys2 is still at best going extremely slowly and I have no tools to investigate it

ThosRTanner avatar Jul 27 '22 19:07 ThosRTanner

ASAN is not supported on GCC/binutils based envs.

MehdiChinoune avatar Sep 17 '22 18:09 MehdiChinoune