diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -47,6 +47,8 @@ mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT) option(COMPILER_RT_BUILD_ORC "Build ORC runtime" ON) mark_as_advanced(COMPILER_RT_BUILD_ORC) +option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON) +mark_as_advanced(COMPILER_RT_BUILD_GWP_ASAN) set(COMPILER_RT_ASAN_SHADOW_SCALE "" CACHE STRING "Override the shadow scale to be used in ASan runtime") 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 @@ -812,7 +812,7 @@ # calling malloc on first use. # 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 +if (COMPILER_RT_HAS_SANITIZER_COMMON AND GWP_ASAN_SUPPORTED_ARCH AND COMPILER_RT_BUILD_GWP_ASAN AND OS_NAME MATCHES "Linux") set(COMPILER_RT_HAS_GWP_ASAN TRUE) else() diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt --- a/libc/lib/CMakeLists.txt +++ b/libc/lib/CMakeLists.txt @@ -4,6 +4,10 @@ list(APPEND SCUDO_DEPS RTScudoStandalone.${LIBC_TARGET_ARCHITECTURE} RTScudoStandaloneCWrappers.${LIBC_TARGET_ARCHITECTURE}) endif() +if(COMPILER_RT_BUILD_GWP_ASAN) + list(APPEND SCUDO_DEPS RTGwpAsan.${LIBC_TARGET_ARCHITECTURE} RTGwpAsanBacktraceLibc.${LIBC_TARGET_ARCHITECTURE} RTGwpAsanSegvHandler.${LIBC_TARGET_ARCHITECTURE}) +endif() + add_entrypoint_library( llvmlibc DEPENDS diff --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt --- a/libc/test/CMakeLists.txt +++ b/libc/test/CMakeLists.txt @@ -18,4 +18,5 @@ endif() add_subdirectory(config) +add_subdirectory(integration) add_subdirectory(loader) diff --git a/libc/test/integration/CMakeLists.txt b/libc/test/integration/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/libc/test/integration/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(scudo) \ No newline at end of file diff --git a/libc/test/integration/scudo/CMakeLists.txt b/libc/test/integration/scudo/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/libc/test/integration/scudo/CMakeLists.txt @@ -0,0 +1,25 @@ +if(NOT LLVM_LIBC_INCLUDE_SCUDO) + return() +endif() + +add_executable( + libc-scudo-integration-test + integration_test.cpp +) + +add_dependencies(libc-scudo-integration-test + llvmlibc +) + +target_link_options( + libc-scudo-integration-test + PRIVATE + # TODO: Uncomment "-nolibc" once llvm-libc is complete enough to run scudo. + # "-nolibc" + -pthreads +) + +target_link_libraries(libc-scudo-integration-test + PRIVATE + llvmlibc +) \ No newline at end of file diff --git a/libc/test/integration/scudo/integration_test.cpp b/libc/test/integration/scudo/integration_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/integration/scudo/integration_test.cpp @@ -0,0 +1,17 @@ +//===-- Integration Test for Scudo ----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +int main() { + void *P = malloc(100); + if (P == nullptr) { + return 1; + } + return 0; +}