Not Possible to Use HWAsan to Track Down Memory Issues on Android?

GuyEP-Modulate
Sat, 21 Jun 2025 01:35:30 +0000
Feedback & Requests

I’m trying to track down a crash-at-free issue with a statically linked library in our Unreal 5.6 project:

Fatal error: [File:Runtime/Core/Public/HAL/MallocBinnedCommon.h] [Line: 894]
FMallocBinned Attempt to GetAllocationSizeExternal an unrecognized pointer 0xb4000074a2b9e1d0

According to Using Clang Sanitizers in Unreal Engine Projects, it should be possible to pass -EnableHWAsan to UBT in order to debug memory allocations with the hardware-accelerated ASAN built into Android 14 on NDK 26.1.10909125+, but I’m finding that this does not work. If I pass -EnableHWAsan, the crash actually stops happening in the project and I am not getting any HWAsan output in logcat. In addition, with HWAsan on, I find that the project is no longer debuggable when launching it through Visual Studio and the AGDE. My hunch is that the issue lies in the wrapper script being used for HWAsan, which isn’t waiting for the debugger.

Meanwhile, setting HWAsan aside, if I pass -EnableAsan instead, the application crashes at launch with an invalid instruction error. This is possibly related to the fact that Android documentation indicates ASan is deprecated and no longer supported.

According to the Android Developer Documentation on HWAsan, HWAsan requires a dynamically linked version of the C++ standard library (STL) but it looks like Unreal uses a statically linked version instead. In addition, if I switch the library we’re using from being statically linked to being dynamically linked with a dynamically linked STL, I get this error during the build:

Lib libMyDependency depends on libc++_shared.so. Unreal Engine is designed to be linked with libs that are built against static libc++ only. Please rebuild your dependencies with static libc++!

I also have found that adding this snippet to the .Target.cs file for the project seems to avoid the crash on free, but this feels like a bandaid solution:

    if(Target.Platform == UnrealTargetPlatform.Android)
    {
        bOverrideBuildEnvironment = true;
        StaticAllocator = StaticAllocatorType.Ansi;
    }

Here are my requests:

1. Could I get a clarification to the docs on ASan and HWAsan use in Unreal Engine 5.6?

2. Could I get some guidance on why one would want the ANSI static allocator and what the pros and cons of it are?

3. Could someone indicate if it’s expected that enabling HWAsan would cause the AGDE to no longer be able to attach at launch?

1 post - 1 participant