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# append_list_if(COMPILER_RT_HAS_SANITIZER_COMMON ${SANITIZER_COMMON_CFLAGS} GWP_ASAN_CFLAGS) 40 41# Remove -stdlib= which is unused when passing -nostdinc++. 42string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 43 44# Options parsing support is optional. This is an optional library that can be 45# used by an allocator to automatically parse GwpAsan options from the 46# environment variable GWP_ASAN_FLAGS, but the allocator can choose to implement 47# its own options parsing and populate the Options struct itself. 48set(GWP_ASAN_OPTIONS_PARSER_SOURCES 49 optional/options_parser.cpp 50) 51set(GWP_ASAN_OPTIONS_PARSER_HEADERS 52 optional/options_parser.h 53 options.h 54 options.inc 55) 56set(GWP_ASAN_BACKTRACE_HEADERS 57 optional/backtrace.h 58 options.h 59 options.inc 60) 61set(GWP_ASAN_SEGV_HANDLER_HEADERS 62 optional/segv_handler.h 63 options.h) 64 65set(GWP_ASAN_OPTIONS_PARSER_CFLAGS 66 ${GWP_ASAN_CFLAGS}) 67 68if (COMPILER_RT_HAS_GWP_ASAN) 69 foreach(arch ${GWP_ASAN_SUPPORTED_ARCH}) 70 add_compiler_rt_runtime( 71 clang_rt.gwp_asan 72 STATIC 73 ARCHS ${arch} 74 SOURCES ${GWP_ASAN_SOURCES} 75 ADDITIONAL_HEADERS ${GWP_ASAN_HEADERS} 76 CFLAGS ${GWP_ASAN_CFLAGS} 77 PARENT_TARGET gwp_asan 78 ) 79 endforeach() 80 81 add_compiler_rt_object_libraries(RTGwpAsan 82 ARCHS ${GWP_ASAN_SUPPORTED_ARCH} 83 SOURCES ${GWP_ASAN_SOURCES} 84 ADDITIONAL_HEADERS ${GWP_ASAN_HEADERS} 85 CFLAGS ${GWP_ASAN_CFLAGS}) 86 87 add_compiler_rt_object_libraries(RTGwpAsanOptionsParser 88 ARCHS ${GWP_ASAN_SUPPORTED_ARCH} 89 SOURCES ${GWP_ASAN_OPTIONS_PARSER_SOURCES} 90 ADDITIONAL_HEADERS ${GWP_ASAN_OPTIONS_PARSER_HEADERS} 91 CFLAGS ${GWP_ASAN_OPTIONS_PARSER_CFLAGS}) 92 93 # As above, build the pre-implemented optional backtrace support libraries. 94 add_compiler_rt_object_libraries(RTGwpAsanBacktraceLibc 95 ARCHS ${GWP_ASAN_SUPPORTED_ARCH} 96 SOURCES optional/backtrace_linux_libc.cpp 97 ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} 98 CFLAGS ${GWP_ASAN_CFLAGS}) 99 add_compiler_rt_object_libraries(RTGwpAsanSegvHandler 100 ARCHS ${GWP_ASAN_SUPPORTED_ARCH} 101 SOURCES optional/segv_handler_posix.cpp 102 ADDITIONAL_HEADERS ${GWP_ASAN_SEGV_HANDLER_HEADERS} 103 CFLAGS ${GWP_ASAN_CFLAGS}) 104 add_compiler_rt_object_libraries(RTGwpAsanBacktraceSanitizerCommon 105 ARCHS ${GWP_ASAN_SUPPORTED_ARCH} 106 SOURCES optional/backtrace_sanitizer_common.cpp 107 ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} 108 CFLAGS ${GWP_ASAN_CFLAGS} ${SANITIZER_COMMON_CFLAGS}) 109endif() 110 111if(COMPILER_RT_INCLUDE_TESTS) 112 add_subdirectory(tests) 113endif() 114