Skip to content

ASAN alloc_dealloc_mismatch false positive on Ubuntu Linux when using libc++ package #5971

@amaiorano

Description

@amaiorano

Build and run check-all on Linux with ASAN enabled, and at least one test fails with alloc_dealloc_mismatch ASAN failure:

FAIL: Clang :: DXC/recompile.test (925 of 3612)
...
==477155==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new vs free) on 0x506000002f60
    #0 0x562b4361fd06 in free (/home/user/src/external/DirectXShaderCompiler/build-clang/bin/dxc-3.7+0x589d06) (BuildId: 85a1466c7f2cb376)
    #1 0x7f5b2a8a80d4 in std::invalid_argument::~invalid_argument() (/lib/x86_64-linux-gnu/libc++abi.so.1+0x250d4) (BuildId: 5abde9e03185be802c843f06145fa1ac038513fd)
    #2 0x7f5b2a8aa3b1 in __cxa_end_catch (/lib/x86_64-linux-gnu/libc++abi.so.1+0x273b1) (BuildId: 5abde9e03185be802c843f06145fa1ac038513fd)
    #3 0x562b4368ca23 in DxcIncludeHandlerForInjectedSources::LoadSource(wchar_t const*, IDxcBlob**) /home/user/src/external/DirectXShaderCompiler/tools/clang/tools/dxclib/dxc.cpp:709:5
    #4 0x7f5b2e2e7d95 in dxcutil::DxcArgsFileSystemImpl::TryFindOrOpen(wchar_t const*, unsigned long&) /home/user/src/external/DirectXShaderCompiler/tools/clang/tools/dxcompiler/dxcfilesystem.cpp:305:37
    #5 0x7f5b2e2e35a5 in dxcutil::DxcArgsFileSystemImpl::GetFileAttributesW(wchar_t const*) /home/user/src/external/DirectXShaderCompiler/tools/clang/tools/dxcompiler/dxcfilesystem.cpp:583:19
    #6 0x7f5b2e2e52ed in dxcutil::DxcArgsFileSystemImpl::Stat(char const*, stat*) /home/user/src/external/DirectXShaderCompiler/tools/clang/tools/dxcompiler/dxcfilesystem.cpp:811:18

...

0x506000002f60 is located 0 bytes inside of 57-byte region [0x506000002f60,0x506000002f99)
allocated by thread T0 here:
    #0 0x562b4365ca9d in operator new(unsigned long) (/home/user/src/external/DirectXShaderCompiler/build-clang/bin/dxc-3.7+0x5c6a9d) (BuildId: 85a1466c7f2cb376)
    #1 0x7f5b2a90e0af in std::logic_error::logic_error(char const*) (/lib/x86_64-linux-gnu/libc++.so.1+0x540af) (BuildId: 20da10e0f620b07021cee1c1e36a006ef4e7591a)
    #2 0x562b4368f098 in std::__1::__throw_out_of_range[abi:v170000](char const*) /usr/lib/llvm-17/bin/../include/c++/v1/stdexcept:264:11
    #3 0x562b4368e800 in std::__1::unordered_map<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t>>, CComPtr<IDxcBlob>, std::__1::hash<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t>>>, std::__1::equal_to<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t>>>, std::__1::allocator<std::__1::pair<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t>> const, CComPtr<IDxcBlob>>>>::at(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t>> const&) /usr/lib/llvm-17/bin/../include/c++/v1/unordered_map:1951:9
    #4 0x562b4368c724 in DxcIncludeHandlerForInjectedSources::LoadSource(wchar_t const*, IDxcBlob**) /home/user/src/external/DirectXShaderCompiler/tools/clang/tools/dxclib/dxc.cpp:706:39
    #5 0x7f5b2e2e7d95 in dxcutil::DxcArgsFileSystemImpl::TryFindOrOpen(wchar_t const*, unsigned long&) /home/user/src/external/DirectXShaderCompiler/tools/clang/tools/dxcompiler/dxcfilesystem.cpp:305:37
...

The issue seems to be pointing at an allocation using operator new and a deallocation using free, however looking more closely, we can see that the allocation comes from a std::logic_error::logic_error ctor call, while the deallocation comes from a std::invalid_argument dtor call. It turns out that this is a known issue with the packaged-built version of libc++ for Ubuntu, see:

Metadata

Metadata

Assignees

Labels

bugBug, regression, crash

Type

No type

Projects

Status

Triaged

Relationships

None yet

Development

No branches or pull requests

Issue actions