cmake 如何使用ASAN构建LLVM?

sdnqo3pr  于 2023-04-30  发布在  其他
关注(0)|答案(1)|浏览(230)

我想用ASAN构建LLVM。文档说明使用LLVM_USE_SANITIZERS。那没用我试过不同的组合旗,浪费了很多时间搜索,但一无所获。我尝试的最后一个是:

cmake -G Ninja ../llvm \
-DCMAKE_INSTALL_PREFIX=/home/mikadore/local/llvm15-debug \
-DCMAKE_BUILD_TYPE=Debug \
-DLLVM_ENABLE_PROJECTS='lld;clang;clang-tools-extra;compiler-rt' \
-DLLVM_USE_RUNTIMES='compiler-rt' \
-DLLVM_ENABLE_LIBXML2=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_LIBEDIT=OFF \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_USE_SANITIZER='Address;Undefined' \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang

我还将compiler-rtllvm-project复制到llvm子文件夹中。但它们都失败了,都犯了同样的错误:

CMake Error at projects/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt:61 (add_library):
  Error evaluating generator expression:

    $<TARGET_OBJECTS:RTSanitizerCommon.x86_64>

  Objects of target "RTSanitizerCommon.x86_64" referenced but no such target
  exists.

CMake Error at projects/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt:61 (add_library):
  Error evaluating generator expression:

    $<TARGET_OBJECTS:RTSanitizerCommon.x86_64>

  Objects of target "RTSanitizerCommon.x86_64" referenced but no such target
  exists.

CMake Error at projects/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt:61 (add_library):
  Error evaluating generator expression:

    $<TARGET_OBJECTS:RTSanitizerCommon.x86_64>

  Objects of target "RTSanitizerCommon.x86_64" referenced but no such target
  exists.

CMake Error at projects/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt:61 (add_library):
  No SOURCES given to target: RTGwpAsanTest.x86_64

在启用ASAN的情况下构建LLVM的正确方法是什么?

kdfy810k

kdfy810k1#

消毒器,包括ASAN,实际上是compiler-rt项目的一部分,该项目包含消毒器库,包括在启用消毒器时在编译时插入到代码中的消毒器函数(在使用ASAN的情况下为__asan_函数)。
我能够使用CMake构建启用ASAN的LLVM 16:

dir$ git clone https://github.com/llvm/llvm-project.git
dir$ cd llvm-project
dir/llvm-project$ mkdir build && cd build
dir/llvm-project/build$ cmake -DLLVM_ENABLE_PROJECTS="clang;compiler-rt" ...
dir/llvm-project/build$ make -j ...

相关问题