Issue 64730
Summary hwasan compilation failures with `COMPILER_RT_HWASAN_WITH_INTERCEPTORS=OFF`
Labels
Assignees
Reporter Gelbpunkt
    When I compile the hwasan with `-DCOMPILER_RT_HWASAN_WITH_INTERCEPTORS=OFF`, I get some build errors.

<details>
    <summary>Full cmake command</summary>

 /build/llvm-toolchain/prebuilts/cmake/linux-x86/bin/cmake -G Ninja -DCMAKE_C_COMPILER=/build/llvm-toolchain/out/stage1-install/bin/clang -DCMAKE_CXX_COMPILER=/build/llvm-toolchain/out/stage1-install/bin/clang++ -DCMAKE_ADDR2LINE=/build/llvm-toolchain/out/stage1-install/bin/llvm-addr2line -DCMAKE_AR=/build/llvm-toolchain/out/stage1-install/bin/llvm-ar -DCMAKE_NM=/build/llvm-toolchain/out/stage1-install/bin/llvm-nm -DCMAKE_OBJCOPY=/build/llvm-toolchain/out/stage1-install/bin/llvm-objcopy -DCMAKE_OBJDUMP=/build/llvm-toolchain/out/stage1-install/bin/llvm-objdump -DCMAKE_RANLIB=/build/llvm-toolchain/out/stage1-install/bin/llvm-ranlib -DCMAKE_READELF=/build/llvm-toolchain/out/stage1-install/bin/llvm-readelf -DCMAKE_STRIP=/build/llvm-toolchain/out/stage1-install/bin/llvm-strip -DCMAKE_MT=/build/llvm-toolchain/out/stage1-install/bin/llvm-mt '-DCMAKE_ASM_FLAGS=-ffile-prefix-map=/build/llvm-toolchain/= --target=aarch64-linux-android30 -B/build/llvm-toolchain/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin -ffunction-sections -fdata-sections -mbranch-protection=standard -funwind-tables --sysroot=/build/llvm-toolchain/out/sysroots/platform/arm64' '-DCMAKE_C_FLAGS=-ffile-prefix-map=/build/llvm-toolchain/= --target=aarch64-linux-android30 -B/build/llvm-toolchain/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin -ffunction-sections -fdata-sections -mbranch-protection=standard -funwind-tables --sysroot=/build/llvm-toolchain/out/sysroots/platform/arm64' '-DCMAKE_CXX_FLAGS=-ffile-prefix-map=/build/llvm-toolchain/= --target=aarch64-linux-android30 -B/build/llvm-toolchain/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin -ffunction-sections -fdata-sections -mbranch-protection=standard -nostdinc++ -isystem /build/llvm-toolchain/prebuilts/clang/host/linux-x86/clang-r498229/include/c++/v1 -isystem /build/llvm-toolchain/bionic/libc/include -isystem /build/llvm-toolchain/bionic/libc/kernel/uapi -funwind-tables --sysroot=/build/llvm-toolchain/out/sysroots/platform/arm64' '-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -rtlib=compiler-rt -Wl,-z,defs -Wl,--gc-sections -Wl,--build-id=sha1 -pie --sysroot=/build/llvm-toolchain/out/sysroots/platform/arm64' '-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld -rtlib=compiler-rt -Wl,-z,defs -Wl,--gc-sections -Wl,--build-id=sha1 -pie --sysroot=/build/llvm-toolchain/out/sysroots/platform/arm64' '-DCMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld -rtlib=compiler-rt -Wl,-z,defs -Wl,--gc-sections -Wl,--build-id=sha1 -pie --sysroot=/build/llvm-toolchain/out/sysroots/platform/arm64' -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/build/llvm-toolchain/out/stage2-install/lib/clang/18 -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_MAKE_PROGRAM=/build/llvm-toolchain/prebuilts/build-tools/linux_musl-x86/bin/ninja -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_LINKER=/build/llvm-toolchain/out/stage1-install/bin/ld.lld -DCMAKE_SYSROOT=/build/llvm-toolchain/out/sysroots/platform/arm64 -DANDROID=1 -DCMAKE_SYSTEM_VERSION=1 -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_THREADS=ON -DLLVM_ENABLE_PLUGINS=OFF -DLLVM_VERSION_PATCH=0 -DLLVM_VERSION_SUFFIX= -DCLANG_REPOSITORY_STRING=https://android.googlesource.com/toolchain/llvm-project -DBUG_REPORT_URL=https://github.com/android-ndk/ndk/issues -DLLVM_ENABLE_LIBCXX=ON -DLLVM_USE_LINKER=lld -DPython3_EXECUTABLE=/build/llvm-toolchain/prebuilts/python/linux-x86/bin/python3.10 -DLLVM_CMAKE_DIR=/build/llvm-toolchain/out/stage1-install -DANDROID_PLATFORM_LEVEL=30 -DCOMPILER_RT_BUILD_BUILTINS=OFF -DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON '-DCOMPILER_RT_TEST_COMPILER_CFLAGS=-ffile-prefix-map=/build/llvm-toolchain/= --target=aarch64-linux-android30 -B/build/llvm-toolchain/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin -ffunction-sections -fdata-sections -mbranch-protection=standard -funwind-tables --sysroot=/build/llvm-toolchain/out/sysroots/platform/arm64' -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE=aarch64-linux-android30 -DCOMPILER_RT_INCLUDE_TESTS=OFF -DSANITIZER_CXX_ABI=libcxxabi -DSANITIZER_COMMON_LINK_LIBS=-lunwind -DSANITIZER_COMMON_LINK_FLAGS=-Wl,-z,defs -DCOMPILER_RT_HWASAN_WITH_INTERCEPTORS=OFF /build/llvm-toolchain/out/llvm-project/compiler-rt
</details>

The error is as following:

```c
/build/llvm-toolchain/out/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp:523:3: error: use of undeclared identifier 'InitializeCommonInterceptors'; did you mean 'InitializeInterceptors'?
  523 | InitializeCommonInterceptors();
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | InitializeInterceptors
/build/llvm-toolchain/out/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp:519:6: note: 'InitializeInterceptors' declared here
  519 | void InitializeInterceptors() {
      | ^
/build/llvm-toolchain/out/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp:525:10: error: use of undeclared identifier 'read_iovec'
  525 | (void)(read_iovec);
      | ^
/build/llvm-toolchain/out/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp:526:10: error: use of undeclared identifier 'write_iovec'
  526 | (void)(write_iovec);
      |          ^
3 errors generated.
```

I took a look at the offending file and all the includes for the headers that define these functions (https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/hwasan/hwasan_interceptors.cpp#L247) are in a conditionally compiled section (`HWASAN_WITH_INTERCEPTORS`, https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/hwasan/hwasan_interceptors.cpp#L59-L502). That means if `HWASAN_WITH_INTERCEPTORS` is not enabled, the methods won't exist. I believe the fix for this (that also works for me) is moving the conditional intercepts (https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/hwasan/hwasan_interceptors.cpp#L528) up right before the `InitializeCommonInterceptors` call.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to