1add_compiler_rt_component(gwp_asan) 2 3include_directories(..) 4 5set(GWP_ASAN_SOURCES 6 common.cpp 7 crash_handler.cpp 8 platform_specific/common_posix.cpp 9 platform_specific/guarded_pool_allocator_posix.cpp 10 platform_specific/mutex_posix.cpp 11 platform_specific/utilities_posix.cpp 12 guarded_pool_allocator.cpp 13 stack_trace_compressor.cpp 14) 15 16set(GWP_ASAN_HEADERS 17 common.h 18 crash_handler.h 19 definitions.h 20 guarded_pool_allocator.h 21 mutex.h 22 options.h 23 options.inc 24 platform_specific/guarded_pool_allocator_fuchsia.h 25 platform_specific/guarded_pool_allocator_posix.h 26 platform_specific/guarded_pool_allocator_tls.h 27 platform_specific/mutex_fuchsia.h 28 platform_specific/mutex_posix.h 29 stack_trace_compressor.h 30 utilities.h 31) 32 33# Ensure that GWP-ASan meets the delegated requirements of some supporting 34# allocators. Some supporting allocators (e.g. scudo standalone) cannot use any 35# parts of the C++ standard library. 36set(GWP_ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS} -fno-rtti -fno-exceptions 37 -nostdinc++ -pthread -fno-omit-frame-pointer) 38append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC GWP_ASAN_CFLAGS) 39 40# Remove -stdlib= which is unused when passing -nostdinc++. 41string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) 42 43# Options parsing support is optional. This is an optional library that can be 44# used by an allocator to automatically parse GwpAsan options from the 45# environment variable GWP_ASAN_FLAGS, but the allocator can choose to implement 46# its own options parsing and populate the Options struct itself. 47set(GWP_ASAN_OPTIONS_PARSER_SOURCES 48 optional/options_parser.cpp 49) 50set(GWP_ASAN_OPTIONS_PARSER_HEADERS 51 optional/options_parser.h 52 options.h 53 options.inc 54) 55set(GWP_ASAN_BACKTRACE_HEADERS 56 optional/backtrace.h 57 options.h 58 options.inc 59) 60set(GWP_ASAN_SEGV_HANDLER_HEADERS 61 optional/segv_handler.h 62 options.h) 63 64set(GWP_ASAN_OPTIONS_PARSER_CFLAGS 65 ${GWP_ASAN_CFLAGS}) 66 67if (COMPILER_RT_HAS_GWP_ASAN) 68 foreach(arch ${GWP_ASAN_SUPPORTED_ARCH}) 69 add_compiler_rt_runtime( 70 clang_rt.gwp_asan 71 STATIC 72 ARCHS ${arch} 73 SOURCES ${GWP_ASAN_SOURCES} 74 ADDITIONAL_HEADERS ${GWP_ASAN_HEADERS} 75 CFLAGS ${GWP_ASAN_CFLAGS} 76 PARENT_TARGET gwp_asan 77 ) 78 endforeach() 79 80 add_compiler_rt_object_libraries(RTGwpAsan 81 ARCHS ${GWP_ASAN_SUPPORTED_ARCH} 82 SOURCES ${GWP_ASAN_SOURCES} 83 ADDITIONAL_HEADERS ${GWP_ASAN_HEADERS} 84 CFLAGS ${GWP_ASAN_CFLAGS}) 85 86 add_compiler_rt_object_libraries(RTGwpAsanOptionsParser 87 ARCHS ${GWP_ASAN_SUPPORTED_ARCH} 88 SOURCES ${GWP_ASAN_OPTIONS_PARSER_SOURCES} 89 ADDITIONAL_HEADERS ${GWP_ASAN_OPTIONS_PARSER_HEADERS} 90 CFLAGS ${GWP_ASAN_OPTIONS_PARSER_CFLAGS}) 91 92 # As above, build the pre-implemented optional backtrace support libraries. 93 add_compiler_rt_object_libraries(RTGwpAsanBacktraceLibc 94 ARCHS ${GWP_ASAN_SUPPORTED_ARCH} 95 SOURCES optional/backtrace_linux_libc.cpp 96 ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} 97 CFLAGS ${GWP_ASAN_CFLAGS}) 98 add_compiler_rt_object_libraries(RTGwpAsanSegvHandler 99 ARCHS ${GWP_ASAN_SUPPORTED_ARCH} 100 SOURCES optional/segv_handler_posix.cpp 101 ADDITIONAL_HEADERS ${GWP_ASAN_SEGV_HANDLER_HEADERS} 102 CFLAGS ${GWP_ASAN_CFLAGS}) 103 add_compiler_rt_object_libraries(RTGwpAsanBacktraceSanitizerCommon 104 ARCHS ${GWP_ASAN_SUPPORTED_ARCH} 105 SOURCES optional/backtrace_sanitizer_common.cpp 106 ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} 107 CFLAGS ${GWP_ASAN_CFLAGS} ${SANITIZER_COMMON_CFLAGS}) 108endif() 109 110if(COMPILER_RT_INCLUDE_TESTS) 111 add_subdirectory(tests) 112endif() 113