<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64730>64730</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
hwasan compilation failures with `COMPILER_RT_HWASAN_WITH_INTERCEPTORS=OFF`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Gelbpunkt
</td>
</tr>
</table>
<pre>
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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWVlzq7gS_jXKiwqXDfH2kAfMknAHgwuTc5L7QskgbE2E5JJElnm4v_2WwAvONslk7jm3po4rwYtaH91ft7obCUlJ1gzjCzCcgaF7hmq14eLiEtPVtmZ36mzFi6eL7xvMYABzXm0JxVBtMNw8IIkYfCBqA8Gob7hOPF8EoZdkS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