Page MenuHomePhabricator

Linux support for mimalloc as a custom allocator
Needs ReviewPublic

Authored by michaeljclark on Apr 28 2021, 12:34 AM.

Details

Summary

Adds support for mimalloc with static linking on Linux, for testing purposes, the following combination works:

- -DLLVM_INTEGRATED_CRT_ALLOC=mimalloc and -DLLVM_LINK_LLVM_DYLIB=OFF

I have been working on testing rpmalloc and mimalloc as custom allocators with clang on Linux. Neither of them works out of the box with dynamic linking due to a hang bug in glibc 2.31 (Ubuntu 20.04LTS) elf/rtld.c:_dl_start_final which I have not yet debugged fully. As a result this patch just adds support for mimalloc with static linking (LLVM_LINK_LLVM_DYLIB=OFF) which was the only configuration I could get working.

Most of the patch is implementing CMake constraints conditions similar to the Windows support so that CMake will report errors for combinations that do not work, so it checks LLVM_LINK_LLVM_DYLIB and only allows mimalloc on Linux. The patch expects mimalloc to be checked out next to the LLVM directory same as the Windows support. Unlike the windows patch, mimalloc is added as a CMake subdirectory and mimalloc-static is properly exported into LLVM's CMake.

It adds the following error messages:

  • LLVM_INTEGRATED_CRT_ALLOC is only supported on Windows and Linux.
  • LLVM_INTEGRATED_CRT_ALLOC currently only supports mimalloc on Linux!"
  • LLVM_INTEGRATED_CRT_ALLOC cannot be used with LLVM_LINK_LLVM_DYLIB on Linux!"

Diff Detail

Event Timeline

michaeljclark created this revision.Apr 28 2021, 12:34 AM
michaeljclark requested review of this revision.Apr 28 2021, 12:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2021, 12:34 AM
mjp41 added a subscriber: mjp41.Apr 29 2021, 12:14 AM

I have been working on testing rpmalloc and mimalloc as custom allocators with clang on Linux. Neither of them works out of the box with dynamic linking due to a hang bug in glibc 2.31 (Ubuntu 20.04LTS) elf/rtld.c:_dl_start_final which I have not yet debugged fully.

+@maniccoder

Which version of rpmalloc did you use?

I tried building with integrated rpmalloc (using the latest develop branch) and while the compiled toolchain seemed to work fine (clang, lld) I ran into issues in the llvm test suite where it passed what seemed to be a global data segment pointer to delete operator. I will keep digging into this.