Can't build clang the way I need without getting errors about scudo_standalone

I am trying to build clang 16.0.5 for x86_64 Ubuntu 20.04 so that I can build ARM64 executables with Asan. I’ve tried dozens of variants of cmake options and still get complaints when compiling about scudo_standalone not existing. Cannot find much of anything from googling and using Bing chat. What am I doing wrong? Current cmake command, which I wouldn’t be surprised has things I don’t really need it this:

cmake \
    -B build \
    -G "Ninja" \
    -DCMAKE_BUILD_TYPE=Release \
    llvm/ \
    -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;lld' \
    -DLLVM_ENABLE_RUNTIMES='compiler-rt' \
    -DCOMPILER_RT_SANITIZERS_TO_BUILD='asan;dfsan;msan;tsan;cfi' \
    -DLLVM_RUNTIME_TARGETS='x86_64-pc-linux-gnu;aarch64-unknown-linux-gnu' \
    -DCOMPILER_RT_BUILD_GWP_ASAN=OFF \
    -DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF \
    -DCOMPILER_RT_BUILD_SANITIZERS=ON \
    -DCLANG_DEFAULT_LINKER=lld \
    -DCLANG_DEFAULT_RTLIB=compiler-rt \
    -DLLVM_TARGETS_TO_BUILD='X86;AArch64'

I also encountered this problem.
Finally I located these 2 pieces in build system of llvm:
compiler-rt/lib/CMakeLists.txt

function(compiler_rt_build_runtime runtime)
  string(TOUPPER ${runtime} runtime_uppercase)
  if(COMPILER_RT_HAS_${runtime_uppercase})
    if(${runtime} STREQUAL tsan)
      add_subdirectory(tsan/dd)
    endif()
    if(${runtime} STREQUAL scudo_standalone)
      add_subdirectory(scudo/standalone)
    else()
      add_subdirectory(${runtime})
    endif()
  endif()
endfunction()

compiler-rt/cmake/config-ix.cmake

if (SCUDO_STANDALONE_SUPPORTED_ARCH AND
    COMPILER_RT_BUILD_SANITIZERS AND
    "scudo_standalone" IN_LIST COMPILER_RT_SANITIZERS_TO_BUILD AND
    OS_NAME MATCHES "Linux" AND
    COMPILER_RT_HAS_AUXV)
  set(COMPILER_RT_HAS_SCUDO_STANDALONE TRUE)
else()
  set(COMPILER_RT_HAS_SCUDO_STANDALONE FALSE)
endif()

So this means that scudo_standalone target only get loaded when COMPILER_RT_HAS_SCUDO_STANDALONE is TRUE, which requires:

  • scudo_standalone supports target arch
  • sanitizers in compiler-rt are not disabled
  • “scudo_standalone” in COMPILER_RT_SANITIZERS_TO_BUILD
  • OS is linux
  • sys/auxv.h exist

Solution:
add -DCOMPILER_RT_BUILD_GWP_ASAN=FALSE so that gwp_asan is skipped and nothing depends on scudo_standalone
(According to code, this SHOULD work. If not, find the following line in CMakeLists.txt of compiler-rt and change its default to OFF)

option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)

Possible solutions if you do want gwp_asan:

  1. “scudo_standalone” not in COMPILER_RT_SANITIZERS_TO_BUILD
  • add it :wink: (it seems to be automatically added)
  1. sys/auxv.h does not exist
  • (cross) compile a newer glibc and specify CMAKE_SYSROOT

Lazy solution:
give up compile-rt or just use cross gcc in manufacturer SDK