Failed to enable AddressSanitizer with Clang for Windows platform

Hello guys, I need helps about enabling AddressSanitizer for Windows platform.

Software Environment: Windows 11 version 22621.2283, Visual Studio Community 2022 version 17.7.5, LLVM 17.0.2, Unreal Engine 5.2.1(Source Code)

Firstly, I switched compiler to Clang by following this article and build engine and project successfully.

Then I tried enable AddressSanitizer by adding the following contents to BuildConfiguration.xml:

<BuildConfiguration>
<bEnableAddressSanitizer>true</bEnableAddressSanitizer>
</BuildConfiguration>

And errors occur during linking:

undefined symbol: __asan_init
undefined symbol: __asan_version_mismatch_check_v8
undefined symbol: __asan_shadow_memory_dynamic_address

Looks like clang asan library files not found. After exploring VCToolChain.cs, I force adding linking options by modifying:

if (!bBuildImportLibraryOnly && !LinkEnvironment.bIsBuildingLibrary && Target.WindowsPlatform.bEnableAddressSanitizer &&
EnvVars.CompilerVersion < new VersionNumber(14, 28, 0))

to

if (!bBuildImportLibraryOnly && !LinkEnvironment.bIsBuildingLibrary && Target.WindowsPlatform.bEnableAddressSanitizer)

The linking errors changed to:

clang_rt.asan_dynamic-x86_64.lib(clang_rt.asan_dynamic-x86_64.dll): .idata$4 should not refer to special section 0

Seems like lib/dll files corrupted. I have done searches on internet but cannot find similar problems.

Does anyone have same issue or any trying advice for me? Thanks.

1 Like