buildclangllvmlldblibfuzzer

Build LLVM, Clang and Libfuzzer


I am a beginner and I want to build LLVM, clang and Libfuzzer from source. So I run the cmake command

cmake -S llvm -B build -G Ninja \
    -DLLVM_ENABLE_PROJECTS="clang;lldb" \
    -DLLVM_ENABLE_RUNTIMES="libcxx" \
    -DCMAKE_BUILD_TYPE=Debug \
    -DLLVM_TARGETS_TO_BUILD="AArch64" \
    -DLLVM_ENABLE_ASSERTIONS=ON \
    -DLLVM_USE_SANITIZER=Address \
    -DLLVM_USE_SANITIZE_COVERAGE=On \
    -DLLDB_USE_SYSTEM_DEBUGSERVER=ON \
    -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang \
    -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++  \
    -DCMAKE_OSX_ARCHITECTURES='arm64' \
    -DCMAKE_CXX_FLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"

But then when I build it, it got the error:

llvm-project/llvm/tools/vfabi-demangle-fuzzer/vfabi-demangler-fuzzer.cpp:20:16: error: variable has incomplete type ‘SMDiagnostic’
20 | SMDiagnostic Err;
llvm-project/llvm/include/llvm/AsmParser/Parser.h:29:7: note: forward declaration of ‘llvm::SMDiagnostic’
29 | class SMDiagnostic;
llvm-project/llvm/tools/vfabi-demangle-fuzzer/vfabi-demangler-fuzzer.cpp:33:44: error: member access into incomplete type ‘llvm::Module’
33 | FunctionType::get(Type::getVoidTy(M->getContext()), false);
llvm-project/llvm/include/llvm/AsmParser/Parser.h:26:7: note: forward declaration of ‘llvm::Module’
26 | class Module;
2 errors generated.
[3998/4053] Building CXX object tools/llvm-r…/CMakeFiles/llvm-readobj.dir/ELFDumper.cpp.o
ninja: build stopped: subcommand failed.

When I asked chatgpt, the answer was to include some headers in the file. I did this and still the build failed. Is this file necessary for libfuzzer? Can I change my cmake command to properly build all the necessary projects that I need to work on my project in LibFuzzer, which I believe is llvm, clang, lldb and Libfuzzer. Please give me any idea on how to resolve this and properly build. Thanks a lot for your help.


Solution

  • To build lldb these days you have to do:

    -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;compiler-rt;libunwind"
    

    And when you build it you need to build clangTooling along with lldb. If you have more problems with this, you might try filing an issue at:

    https://github.com/llvm/llvm-project/issues