KhronosGroup / KhronosGroup/Vulkan-ValidationLayers
possible Android memory corruption in validation or SPIRV used by validation
- Dominant language
- C++
- Stars
- 1k
- Forks
- 504
- Avg merge
- 11h 35m
- Merged PRs (30d)
- 224
Description
**Environment:**
- OS: Android
- GPU and driver version: N/A, crash appears on all tested Android devices
- SDK or header version if building from repo: Android NDK 26.3
- Options enabled (synchronization, best practices, etc.):
**Describe the Issue**
When building and testing a `Debug` build using **Android NDK 26.3**, tests crash on all devices in the same place in `VkArmBestPracticesLayerTest.ComputeShaderBadSpatialLocalityTest`, inside an allocator within **SPIRV-Tools**:
```
#00 libVkLayer_khronos_validation.so (void std::__ndk1::allocator::construct[abi:v170000](unsigned int*, unsigned int const&)+28)
...
#04 libVkLayer_khronos_validation.so (std::__ndk1::__wrap_iter std::__ndk1::vector >::insert, 0>(std::__ndk1::__wrap_iter, std::__ndk1::__wrap_iter, std::__ndk1::__wrap_iter)+344)
#05 libVkLayer_khronos_validation.so (spvtools::val::ValidationState_t::RegisterUniqueTypeDeclaration(spvtools::val::Instruction const*)+416)
#06 libVkLayer_khronos_validation.so (spvtools::val::(anonymous namespace)::ValidateUniqueness(spvtools::val::ValidationState_t&, spvtools::val::Instruction const*)+172)
#07 libVkLayer_khronos_validation.so (spvtools::val::TypePass(spvtools::val::ValidationState_t&, spvtools::val::Instruction const*)+88)
#08 libVkLayer_khronos_validation.so (spvtools::val::(anonymous namespace)::ValidateBinaryUsingContextAndValidationState(spv_context_t const&, unsigned int const*, unsigned long, spv_diagnostic_t**, spvtools::val::ValidationState_t*)+3824)
#09 libVkLayer_khronos_validation.so (spvValidateWithOptions+164)
#10 libVkLayer_khronos_validation.so (CoreChecks::RunSpirvValidation(spv_const_binary_t&, Location const&, ValidationCache*) const+296)
#11 libVkLayer_khronos_validation.so (CoreChecks::ValidateShaderModuleCreateInfo(VkShaderModuleCreateInfo const&, Location const&) const+692)
#12 libVkLayer_khronos_validation.so (CoreChecks::PreCallValidateCreateShaderModule(VkDevice_T*, VkShaderModuleCreateInfo const*, VkAllocationCallbacks const*, VkShaderModule_T**, ErrorObject const&) const+104)
#13 libVkLayer_khronos_validation.so (vulkan_layer_chassis::CreateShaderModule(VkDevice_T*, VkShaderModuleCreateInfo const*, VkAllocationCallbacks const*, VkShaderModule_T**)+248)
#14 /system/lib64/libvulkan.so (vulkan::api::(anonymous namespace)::CreateShaderModule(VkDevice_T*, VkShaderModuleCreateInfo const*, VkAllocationCallbacks const*, VkShaderModule_T**)+160)
#15 libVulkanLayerValidationTests.so (vkt::ShaderModule::init(vkt::Device const&, VkShaderModuleCreateInfo const&)+168)
#16 libVulkanLayerValidationTests.so (VkShaderObj::InitFromGLSL(void const*)+224)
#17 libVulkanLayerValidationTests.so (VkShaderObj::VkShaderObj(VkRenderFramework*, char const*, VkShaderStageFlagBits, spv_target_env, SpvSourceType, VkSpecializationInfo const*, char const*, void const*)+268)
#18 libVulkanLayerValidationTests.so (VkArmBestPracticesLayerTest_ComputeShaderBadSpatialLocalityTest_Test::TestBody()+296)
...
```
The full `ndk-stack` output is available:
[008-ndk-stack-info.txt](https://github.com/user-attachments/files/16717326/008-ndk-stack-info.txt)
The crash appears when using a `Debug` build with **Android NDK 26.3**. It does _not_ appear when using a `Release` build with **NDK 26.3**, nor (using either a `Release` or a `Debug` build) with either **NDK 25.2** or **NDK 27.0**.
Given that the code appears to run correctly in a `Release` build, that the crash is device-independent, and that the crash occurs during memory allocation, it's fairly likely that the compiler isn't the issue, and that that something in validation or SPIRV is causing memory corruption that happens to cause a validation crash when memory is laid out "just right". If **Address Sanitizer** is supported on Android, it might be helpful in uncovering such a corruption.
It's possible, though IMHO unlikely, that this is an unknown compiler bug that appeared in NDK 26 and disappeared in NDK 27, as symptoms like this are not listed as known issues: https://github.com/android/ndk/releases
To reproduce the problem, run a **manual-Vulkan-ValidationLayers** build with: http://tcubuser.lunarg.localdomain:8080/view/Manual/job/manual-Vulkan-ValidationLayers/build
- `BUILD_MODE`: `Debug`
- `ANDROID_ARGS`: `--android-ndk 26.3`
- `NODE`: `tcubuand1`
Contributor guide
Research direction
Start by reproducing VkArmBestPracticesLayerTest.ComputeShaderBadSpatialLocalityTest with a Debug build using Android NDK 26.3, then compare the NDK 25.2 and 27.0 results and the provided ndk-stack output. Inspect the validation and SPIRV-Tools frames named in the stack, and consider Address Sanitizer if supported on Android. Done means the cause is identified and the test no longer crashes under the reported configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, cpp
- Domain
- mobile-dev, testing-qa
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100