Skip to content

Commit 3747cde

Browse files
authored
[Fuzzer] Enable custom libc++ for Android (#70407)
The Android LLVM build system builds the arm64 fuzzer lib without HWASan, but then applications that enable HWASan can generated an object file with a HWASan-ified version of some libc++ symbols (e.g. `std::__1::piecewise_construct`). The linker can choose the HWASan-ified definition, but then it cannot resolve the relocation from libclang_rt.fuzzer-aarch64-android.a to this symbol because the high bits of the address are unexpectedly set. This produces an error: ``` relocation R_AARCH64_ADR_PREL_PG_HI21 out of range ``` Fix this problem by linking a custom isolated libc++ into Android's fuzzer library. We need to pass through ANDROID_NATIVE_API_LEVEL so that the libc++ for 32-bit Android (API < 24) uses LLVM_FORCE_SMALLFILE_FOR_ANDROID.
1 parent 839f1e4 commit 3747cde

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ macro(add_custom_libcxx name prefix)
625625
set_target_properties(${name}-clobber PROPERTIES FOLDER "Compiler-RT Misc")
626626

627627
set(PASSTHROUGH_VARIABLES
628+
ANDROID
629+
ANDROID_NATIVE_API_LEVEL
628630
CMAKE_C_COMPILER_TARGET
629631
CMAKE_CXX_COMPILER_TARGET
630632
CMAKE_SHARED_LINKER_FLAGS

compiler-rt/lib/fuzzer/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ CHECK_CXX_SOURCE_COMPILES("
5959

6060
set(LIBFUZZER_CFLAGS ${COMPILER_RT_COMMON_CFLAGS})
6161

62-
if(OS_NAME MATCHES "Linux|Fuchsia" AND
62+
if(OS_NAME MATCHES "Android|Linux|Fuchsia" AND
6363
COMPILER_RT_LIBCXX_PATH AND
6464
COMPILER_RT_LIBCXXABI_PATH)
6565
list(APPEND LIBFUZZER_CFLAGS -D_LIBCPP_ABI_VERSION=Fuzzer)
@@ -135,7 +135,7 @@ add_compiler_rt_runtime(clang_rt.fuzzer_interceptors
135135
CFLAGS ${LIBFUZZER_CFLAGS}
136136
PARENT_TARGET fuzzer)
137137

138-
if(OS_NAME MATCHES "Linux|Fuchsia" AND
138+
if(OS_NAME MATCHES "Android|Linux|Fuchsia" AND
139139
COMPILER_RT_LIBCXX_PATH AND
140140
COMPILER_RT_LIBCXXABI_PATH)
141141
macro(partially_link_libcxx name dir arch)

0 commit comments

Comments
 (0)