Activate AddressSanitizer in Qt6

Jazzco 5 Reputation points
2025-07-03T10:44:22.05+00:00

Hi all,

I'm developing in Qt c++ under Windows and try to use AddressSanitizer within QtCreator. According to this blog from 2021 (https://devblogs.microsoft.com/cppblog/address-sanitizer-for-msvc-now-generally-available/) it should be possible.

When I add the -fsanitize=address flag and build a debug version it crashes with a null-pointer violation. Stack trace is:

.  0  Id: 302c.447c Suspend: 1 Teb: 00000047`9202c000 Unfrozen
Child-SP          RetAddr               Call Site
(Inline Function) --------`--------     clang_rt_asan_dynamic_x86_64!__asan::QuickCheckForUnpoisonedRegion(void)+0x3b [D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\asan\asan_interceptors_memintrinsics.h @ 59]
00000047`922fdfc0 00007ffb`768c5621     clang_rt_asan_dynamic_x86_64!__asan_wrap_strlen(char * s = 0x00007ffa`77f97678 "llvm-symbolizer.exe")+0x136 [D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\sanitizer_common\sanitizer_common_interceptors.inc @ 425]
00000047`922fe850 00007ffb`741ef915     ntdll!RtlInitAnsiStringEx+0x21
00000047`922fe880 00007ffa`77f2c13a     KERNELBASE!GetFileAttributesA+0x25
00000047`922fe8d0 00007ffa`77f25aee     clang_rt_asan_dynamic_x86_64!__sanitizer::FileExists(char * filename = <Value unavailable error>)+0xa [D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\sanitizer_common\sanitizer_win.cpp @ 105]
00000047`922fe900 00007ffa`77f37c56     clang_rt_asan_dynamic_x86_64!__sanitizer::FindPathToBinary(char * name = 0x00007ffa`77f97678 "llvm-symbolizer.exe")+0xe [D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\sanitizer_common\sanitizer_file.cpp @ 207]
00000047`922fe970 00007ffa`77f37ff0     clang_rt_asan_dynamic_x86_64!__sanitizer::ChooseSymbolizerTools(struct __sanitizer::IntrusiveList<__sanitizer::SymbolizerTool> * list = 0x00000047`922fe9c0, class __sanitizer::LowLevelAllocator * allocator = 0x00007ffa`789a8068)+0x146 [D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\sanitizer_common\sanitizer_symbolizer_win.cpp @ 268]
00000047`922fe9a0 00007ffa`77f35a10     clang_rt_asan_dynamic_x86_64!__sanitizer::Symbolizer::PlatformInit(void)+0x30 [D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\sanitizer_common\sanitizer_symbolizer_win.cpp @ 291]
00000047`922fea10 00007ffa`77f772b3     clang_rt_asan_dynamic_x86_64!__sanitizer::Symbolizer::GetOrInit(void)+0x30 [D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\sanitizer_common\sanitizer_symbolizer_libcdep.cpp @ 24]
00000047`922fea50 00007ffa`77f77113     clang_rt_asan_dynamic_x86_64!__asan::AsanInitInternal(void)+0x183 [D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\asan\asan_rtl.cpp @ 575]
00000047`922feab0 00007ffb`73e5e716     clang_rt_asan_dynamic_x86_64!__asan::AsanInitFromRtl(void)+0x33 [D:\a\_work\1\s\src\vctools\asan\llvm\compiler-rt\lib\asan\asan_rtl.cpp @ 588]
00000047`922feae0 00007ffa`77f8d176     ucrtbase!initterm+0x36
00000047`922feb10 00007ffa`77f8d2e7     clang_rt_asan_dynamic_x86_64!dllmain_crt_process_attach(struct HINSTANCE__ * instance = 0x00007ffa`77f20000, void * reserved = 0x00000047`922ff500)+0x9a [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\dll_dllmain.cpp @ 66]
00000047`922feb40 00007ffb`76852983     clang_rt_asan_dynamic_x86_64!dllmain_dispatch(struct HINSTANCE__ * instance = 0x00007ffa`77f20000, unsigned long reason = 1, void * reserved = 0x00000047`922ff500)+0x6f [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\dll_dllmain.cpp @ 276]
00000047`922feba0 00007ffb`7685193c     ntdll!RtlDeactivateActivationContext+0xdd3
00000047`922fee80 00007ffb`7681bc7a     ntdll!RtlDeleteElementGenericTableAvlEx+0x4fc
00000047`922fef90 00007ffb`7681bca6     ntdll!LdrGetProcedureAddressForCaller+0xb1a
00000047`922fefd0 00007ffb`768456ac     ntdll!LdrGetProcedureAddressForCaller+0xb46
00000047`922ff010 00007ffb`76843864     ntdll!EtwEventWriteNoRegistration+0x266c
00000047`922ff3e0 00007ffb`7684364e     ntdll!EtwEventWriteNoRegistration+0x824
00000047`922ff460 00007ffb`76815fce     ntdll!EtwEventWriteNoRegistration+0x60e
00000047`922ff4b0 00000000`00000000     ntdll!LdrInitializeThunk+0xe

Any ideas what I miss?

Regards

Jazzco

Developer technologies | C++
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Varsha Dundigalla(INFOSYS LIMITED) 155 Reputation points Microsoft External Staff
    2025-07-08T05:03:27.08+00:00

    Thank you for reaching out. Please find the answer below

    Fixing AddressSanitizer Crashes in Qt on Windows

    1. Use Clang-cl with MSVC Toolchain
    • Required for ASan compatibility on Windows.
    • Ensure you're using Clang-cl, not MSVC's cl.exe.
    1. Enable AddressSanitizer
    • Add the following flags:
      • -fsanitize=address to both CXXFLAGS and LDFLAGS.
    1. Symbolization Support
    • Set the path to the symbolizer:
      • Either set ASAN_SYMBOLIZER_PATH to the ___location of llvm-symbolizer.exe
      • Or ensure llvm-symbolizer.exe is in your system PATH.
    1. Rebuild Everything
    • Rebuild Qt and all its dependencies with -fsanitize=address.
    • Mixing sanitized and unsanitized binaries can cause issues.
    1. Use Release CRT
    • Link against the Release C Runtime (/MD), not Debug (/MDd).
    • Debug CRT is incompatible with ASan and may cause false positives or crashes.

    Ensures AddressSanitizer works reliably in your Qt application.

    This setup avoids null-pointer crashes and keeps AddressSanitizer working correctly.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.