Crashes in memory allocator

I am on the release branch, currently tagged as 4.10.0-preview-2. I have built Unreal Engine all right and am trying to run UE4Editor. I’m on Ubuntu 15.10, and I compiled the Unreal Engine with clang 3.6.2.

The issues arise at 35% loading.

First of all, I get an assertion failure in HLSLCC:

ShaderCompileWorker: ../../src/hlslcc_lib/symbol_table.cpp:167: void check_symbol_table(struct _mesa_symbol_table *): Assertion `sym2->hdr == hdr' failed.

But the ShaderCompileWorker remains in memory as a separate thread regardless of the assertion failure and seems to continue working. I’m not sure if this is related.

There is a crash in FreeInternal(). The relevant part of the code is here:

Runtime/Core/Public/HAL/MallocBinned.h

    /**
    * Releases memory back to the system. This is not protected from multi-threaded access and it's
    * the callers responsibility to Lock AccessGuard before calling this.
    */
    void FreeInternal( void* Ptr )
    {
        MEM_TIME(MemTime -= FPlatformTime::Seconds());
        BINNED_DECREMENT_STATCOUNTER(CurrentAllocs);

        UPTRINT BasePtr;
        FPoolInfo* Pool = FindPoolInfo((UPTRINT)Ptr, BasePtr);
#if PLATFORM_IOS
        if (Pool == NULL)
        {
            UE_LOG(LogMemory, Warning, TEXT("Attempting to free a pointer we didn't allocate!"));
            return;
        }
#endif
        checkSlow(Pool);
        checkSlow(Pool->GetBytes() != 0);
        if( Pool->TableIndex < BinnedOSTableIndex )

In particular, Pool is NULL. Incidentally, there is a check for Pool being NULL, but it’s only checked if building for IOS.

This is the backtrace at the point of crash:

#0  FMallocBinned::FreeInternal (this=0x7ffff7f21010, Ptr=0x7fffac129b40) at Runtime/Core/Public/HAL/MallocBinned.h:636
#1  0x00007fffb5b5adb6 in operator delete (Ptr=0x7fffac119) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Developer/ShaderFormatOpenGL/Private/ShaderFormatOpenGL.cpp:223
#2  0x00007fffb5b91f7b in SCBuffer::AddMember(glsl_type const*, ir_variable*) () from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#3  0x00007fffb5b8cf7f in ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) () from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#4  0x00007fffb5b837b1 in _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) () from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#5  0x00007fffb5b82b4f in FHlslCrossCompilerContext::RunFrontend(char const**) () from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#6  0x00007fffb5b83005 in FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) ()
   from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#7  0x00007fffb5b5497d in CompileShader_Windows_OGL (Input=..., Output=..., WorkingDirectory=..., Version=GLSL_150)
    at /home/sciabaz/programs/UnrealEngine/Engine/Source/Developer/ShaderFormatOpenGL/Private/OpenGLShaderCompiler.cpp:1370
#8  0x00007ffff479de83 in FShaderCompileThreadRunnable::CompileDirectlyThroughDll (this=0x125d820)
    at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:716
#9  0x00007ffff479e011 in FShaderCompileThreadRunnable::CompilingLoop (this=0x125d820) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:769
#10 0x00007ffff4797119 in FShaderCompileThreadRunnableBase::Run (this=0x125d820) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:385
#11 0x00007ffff6ffbf14 in FRunnableThreadPThread::Run (this=0x12368a0) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Core/Private/HAL/PThreadRunnableThread.cpp:26
#12 0x00007ffff7039fe0 in FRunnableThreadPThread::_ThreadProc (pThis=0x12368a0) at Runtime/Core/Private/HAL/PThreadRunnableThread.h:167
#13 0x00007ffff7bc26aa in start_thread (arg=0x7fffbcbab700) at pthread_create.c:333
#14 0x00007fffeb9ceeed in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Having the above check for IOS to be always active, I now get another error, again with the binned memory allocator:

This time, in here:

FORCEINLINE FFreeMem* AllocateBlockFromPool(FPoolTable* Table, FPoolInfo* Pool, uint32 Alignment)
{
        // Pick first available block and unlink it.
        Pool->Taken++;
        checkSlow(Pool->TableIndex < BinnedOSTableIndex); // if this is false, FirstMem is actually a size not a pointer
        checkSlow(Pool->FirstMem);
        checkSlow(Pool->FirstMem->NumFreeBlocks > 0);
        checkSlow(Pool->FirstMem->NumFreeBlocks < PAGE_SIZE_LIMIT);
        FFreeMem* Free = (FFreeMem*)((uint8*)Pool->FirstMem + --Pool->FirstMem->NumFreeBlocks * Table->BlockSize);

The value of Pool->FirstMem is 0x10000 which is not a pointer and hence another crash. The line in the beginning of the function hints at this:

checkSlow(Pool->TableIndex < BinnedOSTableIndex); // if this is false, FirstMem is actually a size not a pointer

which seems to be the case. Pool->TableIndex is 32770, and BinnedOSTableIndex is optimized out, so I can’t see this.

Stack trace at this point is:

#0  0x00007ffff700c21c in FMallocBinned::AllocateBlockFromPool (this=<optimized out>, Table=0x7ffff7f216b8, Pool=0x7fffac00e200, Alignment=<optimized out>) at Runtime/Core/Public/HAL/MallocBinned.h:601
#1  FMallocBinned::Malloc (this=0x7ffff7f21010, Size=<optimized out>, Alignment=16) at Runtime/Core/Public/HAL/MallocBinned.h:1021
#2  0x00007ffff709553e in FMemory::Realloc (Count=65536, Alignment=0, Original=<optimized out>) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Core/Private/HAL/UnrealMemory.cpp:61
#3  FHeapAllocator::ForAnyElementType::ResizeAllocation (NumElements=90, NumBytesPerElement=4, this=<optimized out>, PreviousNumElements=<optimized out>)
    at Runtime/Core/Public/Containers/ContainerAllocationPolicies.h:344
#4  TArray<wchar_t, FDefaultAllocator>::AddUninitialized (this=<optimized out>, Count=<optimized out>) at Runtime/Core/Public/Containers/Array.h:1311
#5  FString::AppendChars (this=<optimized out>, Array=<optimized out>, Count=53) at Runtime/Core/Public/Containers/UnrealString.h:373
#6  FString::operator+= (this=<optimized out>, Str=<optimized out>) at Runtime/Core/Public/Containers/UnrealString.h:395
#7  DescribeSignal (Signal=<optimized out>, Info=0x7fffbcba90b0) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformCrashContext.cpp:24
#8  0x00007ffff7095aee in CreateExceptionInfoString (Signal=11, Info=0x7fffbcba90b0) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformCrashContext.cpp:105
#9  0x00007ffff7098e01 in ReportCrash (Context=...) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformCrashContext.cpp:319
#10 0x0000000000435b3b in EngineCrashHandler (GenericContext=...) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Launch/Private/Linux/LaunchLinux.cpp:30
#11 0x00007ffff709d291 in PlatformCrashHandler (Signal=<optimized out>, Info=<optimized out>, Context=<optimized out>)
    at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformCrashContext.cpp:439
#12 <signal handler called>
#13 __strcmp_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:29
#14 0x00007fffb5b926c4 in hash_table_find(hash_table*, void const*) () from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#15 0x00007fffb5ba081e in _mesa_symbol_table_find_symbol(_mesa_symbol_table*, int, char const*) () from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#16 0x00007fffb5b7e655 in glsl_symbol_table::get_variable(char const*) () from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#17 0x00007fffb5b8ce7c in ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) () from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#18 0x00007fffb5b837b1 in _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) () from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#19 0x00007fffb5b82b4f in FHlslCrossCompilerContext::RunFrontend(char const**) () from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#20 0x00007fffb5b83005 in FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) ()
   from /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so
#21 0x00007fffb5b5497d in CompileShader_Windows_OGL (Input=..., Output=..., WorkingDirectory=..., Version=GLSL_150)
    at /home/sciabaz/programs/UnrealEngine/Engine/Source/Developer/ShaderFormatOpenGL/Private/OpenGLShaderCompiler.cpp:1370
#22 0x00007ffff479de83 in FShaderCompileThreadRunnable::CompileDirectlyThroughDll (this=0x125d780)
    at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:716
#23 0x00007ffff479e011 in FShaderCompileThreadRunnable::CompilingLoop (this=0x125d780) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:769
#24 0x00007ffff4797119 in FShaderCompileThreadRunnableBase::Run (this=0x125d780) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:385
#25 0x00007ffff6ffbf14 in FRunnableThreadPThread::Run (this=0x12368a0) at /home/sciabaz/programs/UnrealEngine/Engine/Source/Runtime/Core/Private/HAL/PThreadRunnableThread.cpp:26
#26 0x00007ffff703a080 in FRunnableThreadPThread::_ThreadProc (pThis=0x12368a0) at Runtime/Core/Private/HAL/PThreadRunnableThread.h:167
#27 0x00007ffff7bc26aa in start_thread (arg=0x7fffbcbab700) at pthread_create.c:333
#28 0x00007fffeb9ceeed in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

It seems that the crash happens after the shader compiler crashes (hash_table_find()) and then the crash handler crashes! So perhaps the assertion I mentioned at the top is not irrelevant.


Running the editor through valgrind, these errors are reported just before the crash:

==11981== Thread 9 ShaderCompiling:
==11981== Invalid write of size 4
==11981==    at 0x53F3515: FMallocBinned::FreeInternal(void*) (MallocBinned.h:663)
==11981==    by 0x46AB0DB5: operator delete(void*) (ShaderFormatOpenGL.cpp:223)
==11981==    by 0x46AE7F7A: SCBuffer::AddMember(glsl_type const*, ir_variable*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AE2F7E: ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD97B0: _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD8B4E: FHlslCrossCompilerContext::RunFrontend(char const**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD9004: FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AAA97C: CompileShader_Windows_OGL(FShaderCompilerInput const&, FShaderCompilerOutput&, FString const&, GLSLVersion) (OpenGLShaderCompiler.cpp:1370)
==11981==    by 0x7FECE82: FShaderCompileThreadRunnable::CompileDirectlyThroughDll() (ShaderCompiler.cpp:716)
==11981==    by 0x7FED010: FShaderCompileThreadRunnable::CompilingLoop() (ShaderCompiler.cpp:769)
==11981==    by 0x7FE6118: FShaderCompileThreadRunnableBase::Run() (ShaderCompiler.cpp:385)
==11981==    by 0x53C4F13: FRunnableThreadPThread::Run() (PThreadRunnableThread.cpp:26)
==11981==  Address 0x42741d88 is 8 bytes after a block of size 32 alloc'd
==11981==    at 0x4C2DB95: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11981==    by 0x46AE870F: hash_table_insert(hash_table*, void*, void const*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AF6998: _mesa_symbol_table_add_symbol(_mesa_symbol_table*, int, char const*, void*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD4414: glsl_symbol_table::add_variable(ir_variable*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AE2F12: ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD97B0: _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD8B4E: FHlslCrossCompilerContext::RunFrontend(char const**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD9004: FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AAA97C: CompileShader_Windows_OGL(FShaderCompilerInput const&, FShaderCompilerOutput&, FString const&, GLSLVersion) (OpenGLShaderCompiler.cpp:1370)
==11981==    by 0x7FECE82: FShaderCompileThreadRunnable::CompileDirectlyThroughDll() (ShaderCompiler.cpp:716)
==11981==    by 0x7FED010: FShaderCompileThreadRunnable::CompilingLoop() (ShaderCompiler.cpp:769)
==11981==    by 0x7FE6118: FShaderCompileThreadRunnableBase::Run() (ShaderCompiler.cpp:385)
==11981== 
==11981== Invalid write of size 8
==11981==    at 0x53F351F: FMallocBinned::FreeInternal(void*) (MallocBinned.h:664)
==11981==    by 0x46AB0DB5: operator delete(void*) (ShaderFormatOpenGL.cpp:223)
==11981==    by 0x46AE7F7A: SCBuffer::AddMember(glsl_type const*, ir_variable*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AE2F7E: ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD97B0: _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD8B4E: FHlslCrossCompilerContext::RunFrontend(char const**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD9004: FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AAA97C: CompileShader_Windows_OGL(FShaderCompilerInput const&, FShaderCompilerOutput&, FString const&, GLSLVersion) (OpenGLShaderCompiler.cpp:1370)
==11981==    by 0x7FECE82: FShaderCompileThreadRunnable::CompileDirectlyThroughDll() (ShaderCompiler.cpp:716)
==11981==    by 0x7FED010: FShaderCompileThreadRunnable::CompilingLoop() (ShaderCompiler.cpp:769)
==11981==    by 0x7FE6118: FShaderCompileThreadRunnableBase::Run() (ShaderCompiler.cpp:385)
==11981==    by 0x53C4F13: FRunnableThreadPThread::Run() (PThreadRunnableThread.cpp:26)
==11981==  Address 0x42741d80 is 0 bytes after a block of size 32 alloc'd
==11981==    at 0x4C2DB95: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11981==    by 0x46AE870F: hash_table_insert(hash_table*, void*, void const*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AF6998: _mesa_symbol_table_add_symbol(_mesa_symbol_table*, int, char const*, void*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD4414: glsl_symbol_table::add_variable(ir_variable*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AE2F12: ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD97B0: _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD8B4E: FHlslCrossCompilerContext::RunFrontend(char const**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AD9004: FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==11981==    by 0x46AAA97C: CompileShader_Windows_OGL(FShaderCompilerInput const&, FShaderCompilerOutput&, FString const&, GLSLVersion) (OpenGLShaderCompiler.cpp:1370)
==11981==    by 0x7FECE82: FShaderCompileThreadRunnable::CompileDirectlyThroughDll() (ShaderCompiler.cpp:716)
==11981==    by 0x7FED010: FShaderCompileThreadRunnable::CompilingLoop() (ShaderCompiler.cpp:769)
==11981==    by 0x7FE6118: FShaderCompileThreadRunnableBase::Run() (ShaderCompiler.cpp:385)
==11981== 

valgrind: m_mallocfree.c:303 (get_bszB_as_is): Assertion 'bszB_lo == bszB_hi' failed.
valgrind: Heap block lo/hi size mismatch: lo = 68928, hi = 1.
This is probably caused by your program erroneously writing past the
end of a heap block and corrupting heap metadata.  If you fix any
invalid writes reported by Memcheck, this assertion failure will
probably go away.  Please try that before reporting this as a bug.

I ran the editor through valgrind with -ansimalloc as well with similar results:

==12536== Thread 9 ShaderCompiling:
==12536== Invalid read of size 8
==12536==    at 0x540596F: FMallocAnsi::Free(void*) (MallocAnsi.h:118)
==12536==    by 0x54B0F15: FMallocThreadSafeProxy::Free(void*) (MallocThreadSafeProxy.h:62)
==12536==    by 0x4B89EDB5: operator delete(void*) (ShaderFormatOpenGL.cpp:223)
==12536==    by 0x4B8D5F7A: SCBuffer::AddMember(glsl_type const*, ir_variable*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8D0F7E: ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C77B0: _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C6B4E: FHlslCrossCompilerContext::RunFrontend(char const**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C7004: FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B89897C: CompileShader_Windows_OGL(FShaderCompilerInput const&, FShaderCompilerOutput&, FString const&, GLSLVersion) (OpenGLShaderCompiler.cpp:1370)
==12536==    by 0x7FECE82: FShaderCompileThreadRunnable::CompileDirectlyThroughDll() (ShaderCompiler.cpp:716)
==12536==    by 0x7FED010: FShaderCompileThreadRunnable::CompilingLoop() (ShaderCompiler.cpp:769)
==12536==    by 0x7FE6118: FShaderCompileThreadRunnableBase::Run() (ShaderCompiler.cpp:385)
==12536==  Address 0x40eaf7f8 is 8 bytes before a block of size 31 alloc'd
==12536==    at 0x4C2C12F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==12536==    by 0x10B05988: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate(unsigned long, unsigned long, char const*, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==12536==    by 0x10B064FA: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==12536==    by 0x4B8D5F0D: SCBuffer::AddMember(glsl_type const*, ir_variable*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8D0F7E: ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C77B0: _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C6B4E: FHlslCrossCompilerContext::RunFrontend(char const**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C7004: FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B89897C: CompileShader_Windows_OGL(FShaderCompilerInput const&, FShaderCompilerOutput&, FString const&, GLSLVersion) (OpenGLShaderCompiler.cpp:1370)
==12536==    by 0x7FECE82: FShaderCompileThreadRunnable::CompileDirectlyThroughDll() (ShaderCompiler.cpp:716)
==12536==    by 0x7FED010: FShaderCompileThreadRunnable::CompilingLoop() (ShaderCompiler.cpp:769)
==12536==    by 0x7FE6118: FShaderCompileThreadRunnableBase::Run() (ShaderCompiler.cpp:385)
==12536== 
==12536== Invalid free() / delete / delete[] / realloc()
==12536==    at 0x4C2CE2B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==12536==    by 0x54B0F15: FMallocThreadSafeProxy::Free(void*) (MallocThreadSafeProxy.h:62)
==12536==    by 0x4B89EDB5: operator delete(void*) (ShaderFormatOpenGL.cpp:223)
==12536==    by 0x4B8D5F7A: SCBuffer::AddMember(glsl_type const*, ir_variable*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8D0F7E: ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C77B0: _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C6B4E: FHlslCrossCompilerContext::RunFrontend(char const**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C7004: FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B89897C: CompileShader_Windows_OGL(FShaderCompilerInput const&, FShaderCompilerOutput&, FString const&, GLSLVersion) (OpenGLShaderCompiler.cpp:1370)
==12536==    by 0x7FECE82: FShaderCompileThreadRunnable::CompileDirectlyThroughDll() (ShaderCompiler.cpp:716)
==12536==    by 0x7FED010: FShaderCompileThreadRunnable::CompilingLoop() (ShaderCompiler.cpp:769)
==12536==    by 0x7FE6118: FShaderCompileThreadRunnableBase::Run() (ShaderCompiler.cpp:385)
==12536==  Address 0x630000006f is not stack'd, malloc'd or (recently) free'd
==12536== 
==12536== Invalid read of size 8
==12536==    at 0x540596F: FMallocAnsi::Free(void*) (MallocAnsi.h:118)
==12536==    by 0x54B0F15: FMallocThreadSafeProxy::Free(void*) (MallocThreadSafeProxy.h:62)
==12536==    by 0x4B89EDB5: operator delete(void*) (ShaderFormatOpenGL.cpp:223)
==12536==    by 0x4B8D1054: ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C77B0: _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C6B4E: FHlslCrossCompilerContext::RunFrontend(char const**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C7004: FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B89897C: CompileShader_Windows_OGL(FShaderCompilerInput const&, FShaderCompilerOutput&, FString const&, GLSLVersion) (OpenGLShaderCompiler.cpp:1370)
==12536==    by 0x7FECE82: FShaderCompileThreadRunnable::CompileDirectlyThroughDll() (ShaderCompiler.cpp:716)
==12536==    by 0x7FED010: FShaderCompileThreadRunnable::CompilingLoop() (ShaderCompiler.cpp:769)
==12536==    by 0x7FE6118: FShaderCompileThreadRunnableBase::Run() (ShaderCompiler.cpp:385)
==12536==    by 0x53C4F13: FRunnableThreadPThread::Run() (PThreadRunnableThread.cpp:26)
==12536==  Address 0x40eb3768 is 8 bytes before a block of size 27 alloc'd
==12536==    at 0x4C2C12F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==12536==    by 0x4B8B9DB5: std::_List_node<SCBufferMember>* std::__cxx11::list<SCBufferMember, std::allocator<SCBufferMember> >::_M_create_node<SCBufferMember const&>(SCBufferMember const&) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8D5F57: SCBuffer::AddMember(glsl_type const*, ir_variable*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8D0F7E: ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C77B0: _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C6B4E: FHlslCrossCompilerContext::RunFrontend(char const**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C7004: FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B89897C: CompileShader_Windows_OGL(FShaderCompilerInput const&, FShaderCompilerOutput&, FString const&, GLSLVersion) (OpenGLShaderCompiler.cpp:1370)
==12536==    by 0x7FECE82: FShaderCompileThreadRunnable::CompileDirectlyThroughDll() (ShaderCompiler.cpp:716)
==12536==    by 0x7FED010: FShaderCompileThreadRunnable::CompilingLoop() (ShaderCompiler.cpp:769)
==12536==    by 0x7FE6118: FShaderCompileThreadRunnableBase::Run() (ShaderCompiler.cpp:385)
==12536==    by 0x53C4F13: FRunnableThreadPThread::Run() (PThreadRunnableThread.cpp:26)
==12536== 
==12536== Invalid free() / delete / delete[] / realloc()
==12536==    at 0x4C2CE2B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==12536==    by 0x54B0F15: FMallocThreadSafeProxy::Free(void*) (MallocThreadSafeProxy.h:62)
==12536==    by 0x4B89EDB5: operator delete(void*) (ShaderFormatOpenGL.cpp:223)
==12536==    by 0x4B8D1054: ast_cbuffer_declaration::hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C77B0: _mesa_ast_to_hir(exec_list*, _mesa_glsl_parse_state*) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C6B4E: FHlslCrossCompilerContext::RunFrontend(char const**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B8C7004: FHlslCrossCompilerContext::Run(char const*, char const*, FCodeBackend*, char**, char**) (in /home/sciabaz/programs/UnrealEngine/Engine/Binaries/Linux/libUE4Editor-ShaderFormatOpenGL.so)
==12536==    by 0x4B89897C: CompileShader_Windows_OGL(FShaderCompilerInput const&, FShaderCompilerOutput&, FString const&, GLSLVersion) (OpenGLShaderCompiler.cpp:1370)
==12536==    by 0x7FECE82: FShaderCompileThreadRunnable::CompileDirectlyThroughDll() (ShaderCompiler.cpp:716)
==12536==    by 0x7FED010: FShaderCompileThreadRunnable::CompilingLoop() (ShaderCompiler.cpp:769)
==12536==    by 0x7FE6118: FShaderCompileThreadRunnableBase::Run() (ShaderCompiler.cpp:385)
==12536==    by 0x53C4F13: FRunnableThreadPThread::Run() (PThreadRunnableThread.cpp:26)
==12536==  Address 0x630000006f is not stack'd, malloc'd or (recently) free'd
==12536== 
.... AND MORE ....

Has anybody experienced issues with the memory allocator? Are there any workarounds? Is this a known issue?

The errors from valgrind seem to be related to this bug since it seems that FMalloc::Free is being called for something that used valgrind’s new.

I have the same issue. I originally had the bad hlsl header error. I used the patch from this thread, which worked with 4.9, and now I get the same error you have.

The bug report filed was closed, as being irrelevant, seems it’s an upstream bug in binutils. Other than the original bug report opened for binutils, last year, there doesn’t seem to be any effort to fix it. The binutils bug report can be found here.

Yeah, I had the hlsl error as well which I fixed by recompiling hlslcc (instructions in some other thread). I also saw the binutils error as well. So, do you have any workarounds? I’m trying to debug, but it’s a slow process compiling and it takes time.

Unfortunately, no. For now I’m just going to stick with 4.9 using the patch from the other thread. I can compile in a VM and use that, but it causes issues for me trying to compile c++ projects, so 4.9 it is… for now.

I’ll keep checking for updates and trying any new fixes I may run across, but my time’s limited, and perhaps more importantly, my skill level isn’t high enough to really dig into it myself.

I see, it’s actually good to know that 4.9 works. Of course I can always try that branch if I can’t fix this.

Huh, so I tried 4.9.2-release and I get the same behavior. What distribution did you successfully run UE4Editor on? Perhaps it has something to do with me being on Ubuntu 15.10.

The patch I referred to was based off of Dmitry Rekman’s 4.9-rcl Linux branch ( https://github.com/RCL/UnrealEngine ) I was following ExpiredPopsicle’s post, fom the link I posted earlier. It’s actually 4.9.0

The issue seems to have been related to clang. I was using clang 3.6, which is the current default version on Ubuntu 15.10. Playing around with clang-3.7, ld.gold and combinations of different tags, all ended with different problems.

On the 4.9 branch (currently tagged 4.9.2-release), I finally built with the default ld.bfd and clang-3.5 (having fixed this bug as well by cherry-picking this and this) and the particular problem above is no more.