diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -292,7 +292,7 @@ set(ALL_FUZZER_SUPPORTED_ARCH ${X86_64} ${ARM64}) endif() -set(ALL_GWP_ASAN_SUPPORTED_ARCH ${X86} ${X86_64}) +set(ALL_GWP_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64} ${ARM32}) if(APPLE) set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64}) else() @@ -742,7 +742,7 @@ # TODO(hctim): Enable this on Android again. Looks like it's causing a SIGSEGV # for Scudo and GWP-ASan, further testing needed. if (COMPILER_RT_HAS_SANITIZER_COMMON AND GWP_ASAN_SUPPORTED_ARCH AND - OS_NAME MATCHES "Linux") + OS_NAME MATCHES "Android|Linux") set(COMPILER_RT_HAS_GWP_ASAN TRUE) else() set(COMPILER_RT_HAS_GWP_ASAN FALSE) diff --git a/compiler-rt/lib/gwp_asan/CMakeLists.txt b/compiler-rt/lib/gwp_asan/CMakeLists.txt --- a/compiler-rt/lib/gwp_asan/CMakeLists.txt +++ b/compiler-rt/lib/gwp_asan/CMakeLists.txt @@ -24,7 +24,7 @@ # allocators. Some supporting allocators (e.g. scudo standalone) cannot use any # parts of the C++ standard library. set(GWP_ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS} -fno-rtti -fno-exceptions - -nostdinc++ -pthread) + -nostdinc++ -pthread -fno-emulated-tls) append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC GWP_ASAN_CFLAGS) append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer GWP_ASAN_CFLAGS) @@ -89,11 +89,13 @@ CFLAGS ${GWP_ASAN_OPTIONS_PARSER_CFLAGS}) # As above, build the pre-implemented optional backtrace support libraries. - add_compiler_rt_object_libraries(RTGwpAsanBacktraceLibc - ARCHS ${GWP_ASAN_SUPPORTED_ARCH} - SOURCES optional/backtrace_linux_libc.cpp - ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} - CFLAGS ${GWP_ASAN_CFLAGS}) + if (NOT(ANDROID)) + add_compiler_rt_object_libraries(RTGwpAsanBacktraceLibc + ARCHS ${GWP_ASAN_SUPPORTED_ARCH} + SOURCES optional/backtrace_linux_libc.cpp + ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} + CFLAGS ${GWP_ASAN_CFLAGS}) + endif() add_compiler_rt_object_libraries(RTGwpAsanBacktraceSanitizerCommon ARCHS ${GWP_ASAN_SUPPORTED_ARCH} SOURCES optional/backtrace_sanitizer_common.cpp diff --git a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h --- a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h +++ b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h @@ -255,7 +255,7 @@ // Pack the thread local variables into a struct to ensure that they're in // the same cache line for performance reasons. These are the most touched // variables in GWP-ASan. - struct alignas(8) ThreadLocalPackedVariables { + struct alignas(64) ThreadLocalPackedVariables { constexpr ThreadLocalPackedVariables() {} // Thread-local decrementing counter that indicates that a given allocation // should be sampled when it reaches zero. diff --git a/compiler-rt/lib/scudo/CMakeLists.txt b/compiler-rt/lib/scudo/CMakeLists.txt --- a/compiler-rt/lib/scudo/CMakeLists.txt +++ b/compiler-rt/lib/scudo/CMakeLists.txt @@ -37,9 +37,20 @@ # Currently, Scudo uses the GwpAsan flag parser. This backs onto the flag # parsing mechanism of sanitizer_common. Once Scudo has its own flag parsing, # and parses GwpAsan options, you can remove this dependency. - list(APPEND SCUDO_MINIMAL_OBJECT_LIBS RTGwpAsan RTGwpAsanOptionsParser - RTGwpAsanBacktraceLibc) - list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS) + list(APPEND SCUDO_MINIMAL_OBJECT_LIBS RTGwpAsan RTGwpAsanOptionsParser) + + # Install GWP-ASan stubs. Also, ensure that TLS is not emulated on this + # platform (Android still compiles with emulated TLS by default). + list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS -fno-emulated-tls) + + # Android does not have the libc backtrace() support (from execinfo.h). In + # this case, we use the sanitizer common variant. + if (ANDROID) + list(APPEND SCUDO_MINIMAL_OBJECT_LIBS RTGwpAsanBacktraceSanitizerCommon + RTSanitizerCommonSymbolizer) + else() + list(APPEND SCUDO_MINIMAL_OBJECT_LIBS RTGwpAsanBacktraceLibc) + endif() endif() set(SCUDO_OBJECT_LIBS ${SCUDO_MINIMAL_OBJECT_LIBS}) diff --git a/compiler-rt/test/gwp_asan/lit.cfg.py b/compiler-rt/test/gwp_asan/lit.cfg.py --- a/compiler-rt/test/gwp_asan/lit.cfg.py +++ b/compiler-rt/test/gwp_asan/lit.cfg.py @@ -14,8 +14,11 @@ # C & CXX flags. c_flags = ([config.target_cflags]) -# Android doesn't want -lrt. -if not config.android: +if config.android: + # Ensure that libscudo/libc++ gets statically linked. + c_flags += ["-static-libsan", "-static-libstdc++"] +else: + # Android doesn't want -lrt. c_flags += ["-lrt"] cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])