This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add redirected malloc using system-libc.
AbandonedPublic

Authored by cheng.w on Jan 26 2021, 9:16 PM.

Details

Reviewers
sivachandra
Summary
  1. Add a redirected malloc referred to [1].

It is a temporary scheme to make memory management functions work.
[2] is a recent report published by mimalloc, in which leading memory
allocators were evaluated.

  1. Add an optional argument REDIRECTED to add_libc_unittest.

Unit tests do not depend on libllvmlibc.a static library which
links libllvmlibc_redirectors.so shared library. [3]

[1] https://reviews.llvm.org/D69020
[2] https://www.microsoft.com/en-us/research/uploads/prod/2019/06/mimalloc-tr-v1.pdf
[3] https://github.com/llvm/llvm-project/blob/main/libc/docs/redirectors_schematic.svg

Diff Detail

Event Timeline

cheng.w created this revision.Jan 26 2021, 9:16 PM
cheng.w requested review of this revision.Jan 26 2021, 9:16 PM
cheng.w added inline comments.Jan 27 2021, 3:39 AM
libc/cmake/modules/LLVMLibCTestRules.cmake
148–163

Also tried here:

if(LIBC_UNITTEST_REDIRECTED)
#   find_library(
#     libc_redirectors
#     llvmlibc_redirectors
#     PATHS ${LIBC_BUILD_DIR}/lib
#   )
    target_link_libraries(
      ${fq_target_name}
      PRIVATE
#     ${libc_redirectors}
+     llvmlibc_redirectors
    )
    add_dependencies(
      ${fq_target_name}
      llvmlibc_redirectors
    )
endif()

But malloc unit test failed for passing -nostdlib below to linker.

libc/cmake/modules/LLVMLibCLibraryRules.cmake, line: 142
target_link_libraries(
  ${target_name}
  -nostdlib -lc -lm
)

Would it work fine after the TODO(libc/cmake/modules/LLVMLibCLibraryRules.cmake, line: 133) fixed?

Hi,

Sorry for the delay here. The reason for the delay is that, for LLVM-libc's malloc, the plan to is to use Scudo's standalone malloc from here: https://github.com/llvm/llvm-project/tree/main/compiler-rt/lib/scudo/standalone

The high level plan is to keep the the standalone Scudo sources in the compiler-rt area but pull them via some kind of CMake machinery to package them for LLVM libc. This way, we don't add target dependency on compiler-rt, but if they break LLVM libc in some manner, the LLVM libc bots will catch the failures.

I had planned to pick this up in the second half of February. But, if this is something which interests you, go for it.

Thanks,
Siva Chandra

cheng.w abandoned this revision.Feb 2 2021, 5:23 PM

Good to hear this plan. 🤗