Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hwasan compilation failures with COMPILER_RT_HWASAN_WITH_INTERCEPTORS=OFF #64730

Closed
Gelbpunkt opened this issue Aug 16, 2023 · 3 comments
Closed
Labels
build-problem compiler-rt:hwasan Hardware-assisted address sanitizer

Comments

@Gelbpunkt
Copy link

Gelbpunkt commented Aug 16, 2023

When I compile the hwasan with -DCOMPILER_RT_HWASAN_WITH_INTERCEPTORS=OFF, I get some build errors.

Full cmake command
/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

The error is as following:

/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 if for 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.

@EugeneZelenko EugeneZelenko added build-problem compiler-rt:hwasan Hardware-assisted address sanitizer and removed new issue labels Aug 16, 2023
@thurstond
Copy link
Contributor

My bad, thanks for the report and the suggested fix! I've copied the fix into https://reviews.llvm.org/D158116

thurstond added a commit that referenced this issue Aug 16, 2023
This applies the fix as suggested by Gelbpunkt in #64730,

Thanks to Florian Mayer for pointing out that my earlier patch D151262
had caused this regression.

Differential Revision: https://reviews.llvm.org/D158116
@thurstond
Copy link
Contributor

Fix has landed

@Gelbpunkt
Copy link
Author

Thank you for the quick response and fix!

razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
This applies the fix as suggested by Gelbpunkt in llvm#64730,

Thanks to Florian Mayer for pointing out that my earlier patch D151262
had caused this regression.

Differential Revision: https://reviews.llvm.org/D158116
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
This applies the fix as suggested by Gelbpunkt in llvm#64730,

Thanks to Florian Mayer for pointing out that my earlier patch D151262
had caused this regression.

Differential Revision: https://reviews.llvm.org/D158116
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
This applies the fix as suggested by Gelbpunkt in llvm#64730,

Thanks to Florian Mayer for pointing out that my earlier patch D151262
had caused this regression.

Differential Revision: https://reviews.llvm.org/D158116
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 3, 2023
This applies the fix as suggested by Gelbpunkt in llvm#64730,

Thanks to Florian Mayer for pointing out that my earlier patch D151262
had caused this regression.

Differential Revision: https://reviews.llvm.org/D158116
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 3, 2023
This applies the fix as suggested by Gelbpunkt in llvm#64730,

Thanks to Florian Mayer for pointing out that my earlier patch D151262
had caused this regression.

Differential Revision: https://reviews.llvm.org/D158116
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 6, 2023
This applies the fix as suggested by Gelbpunkt in llvm#64730,

Thanks to Florian Mayer for pointing out that my earlier patch D151262
had caused this regression.

Differential Revision: https://reviews.llvm.org/D158116
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 11, 2023
This applies the fix as suggested by Gelbpunkt in llvm#64730,

Thanks to Florian Mayer for pointing out that my earlier patch D151262
had caused this regression.

Differential Revision: https://reviews.llvm.org/D158116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-problem compiler-rt:hwasan Hardware-assisted address sanitizer
Projects
None yet
Development

No branches or pull requests

3 participants