Hi, I am a beginner doing a project in LibFuzzer. I am trying to build the LLVM, Clang and Libfuzzer. I used the below script to do it.
#!/usr/bin/env bash
set -x
set -e
INSTALL_PREFIX=/usr/local/clang-devel
mkdir -p clang-src
cd clang-src
function brew_install() {
local pkgname=$1
echo "Ensuring $pkgname is installed"
test -f .has-$pkgname && return
brew install $pkgname || brew upgrade $pkgname
touch .has-$pkgname
}
brew_install ninja # Faster make replacement
brew_install cmake
echo "Cloning LLVM/Clang sources"
test ! -d llvm && git clone https://github.com/llvm/llvm-project.git llvm
cd llvm
test ! -d clang && git clone https://github.com/llvm/llvm-project.git clang
test ! -d llvm/projects/libcxx && \
(cd llvm/projects && git clone https://github.com/llvm/llvm-project.git libcxx)
test ! -d compiler-rt && \
(git clone https://github.com/llvm/llvm-project.git compiler-rt)
mkdir -p build
cd build
echo "Configuring LLVM/Clang for ninja"
cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DLLVM_TARGETS_TO_BUILD=AArch64 \
-DCMAKE_SYSTEM_PROCESSOR=arm64 \
-DCMAKE_SYSTEM_NAME=Darwin \
../llvm
echo "Building LLVM/Clang"
ninja
cd ../compiler-rt
echo "Configuring compiler-rt which contains fuzzer runtime."
HOST_TARGET=$(../build/bin/llvm-config --host-target)
PATH=../build/bin:$PATH cmake -G Ninja \
-DLLVM_CONFIG_PATH=../build/bin/llvm-config \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER_TARGET=${HOST_TARGET} \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_FLAGS=-I$(pwd)/../build/include \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_INSTALL_PREFIX=/usr/local/clang-devel/lib/clang/8.0.0 \
-DCOMPILER_RT_ENABLE_IOS=OFF \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
echo "Building compiler-rt"
ninja
cd ..
echo "Install clang into ${INSTALL_PREFIX}? Enter \"yes\":"
if read install && test "$install" == yes; then
(cd build && sudo ninja install)
(cd compiler-rt && sudo ninja install)
else
echo "Not installing. Execute:"
echo " (cd clang-src/build && ninja install)"
echo " (cd clang-src/compiler-rt && ninja install)"
echo "to install into ${INSTALL_PREFIX}"
fi
I referred this from https://medium.com/@levwalkin/compile-llvm-clang-libfuzzer-b61e82718430. I tried writing my own cmake command, but I ran into errors like lld not found. When I run this script, I got the error
Building compiler-rt
- ninja
ninja: error: dependency cycle: include/sanitizer/allocator_interface.h → include/sanitizer/allocator_interface.h
The build process for LLVM/Clang completed without errors. But the error occurs when building compiler-rt. There were some warnings along the way like:
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
CMake Warning at cmake/Modules/CompilerRTUtils.cmake:281 (message):
LLVM_CONFIG_PATH is deprecated, please use LLVM_CMAKE_DIR instead
Call Stack (most recent call first):
CMakeLists.txt:86 (load_llvm_config)
CMake Warning at cmake/Modules/CompilerRTUtils.cmake:326 (message):
LLVMTestingSupport not found in LLVM_AVAILABLE_LIBS
Call Stack (most recent call first):
CMakeLists.txt:86 (load_llvm_config)
Any help on how to resolve this or how to properly build libfuzzer, LLVM, and Clang would be greatly appreciated. My system is macOS 14.4.1 arm64 architecture. Thanks a lot!