- 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.
- 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
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?