1add_compiler_rt_component(scudo_standalone) 2if (COMPILER_RT_HAS_GWP_ASAN) 3 add_dependencies(scudo_standalone gwp_asan) 4endif() 5 6include_directories(../.. include) 7 8set(SCUDO_CFLAGS) 9 10list(APPEND SCUDO_CFLAGS 11 -Werror=conversion 12 -Wall 13 -nostdinc++) 14 15# Remove -stdlib= which is unused when passing -nostdinc++. 16string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) 17 18append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding SCUDO_CFLAGS) 19 20append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SCUDO_CFLAGS) 21 22# FIXME: find cleaner way to agree with GWPAsan flags 23append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SCUDO_CFLAGS) 24 25if (COMPILER_RT_HAS_GWP_ASAN) 26 append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer 27 SCUDO_CFLAGS) 28 append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG 29 -mno-omit-leaf-frame-pointer SCUDO_CFLAGS) 30endif() # COMPILER_RT_HAS_GWP_ASAN 31 32if(COMPILER_RT_DEBUG) 33 list(APPEND SCUDO_CFLAGS -O0) 34else() 35 list(APPEND SCUDO_CFLAGS -O3) 36endif() 37 38set(SCUDO_LINK_FLAGS) 39 40list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro) 41 42append_list_if(COMPILER_RT_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs SCUDO_LINK_FLAGS) 43 44if(ANDROID) 45 list(APPEND SCUDO_CFLAGS -fno-emulated-tls) 46 47# Put the shared library in the global group. For more details, see 48# android-changes-for-ndk-developers.md#changes-to-library-search-order 49 append_list_if(COMPILER_RT_HAS_Z_GLOBAL -Wl,-z,global SCUDO_LINK_FLAGS) 50endif() 51 52set(SCUDO_HEADERS 53 allocator_config.h 54 atomic_helpers.h 55 bytemap.h 56 checksum.h 57 chunk.h 58 combined.h 59 flags.h 60 flags_parser.h 61 fuchsia.h 62 internal_defs.h 63 linux.h 64 list.h 65 local_cache.h 66 mutex.h 67 platform.h 68 primary32.h 69 primary64.h 70 quarantine.h 71 release.h 72 report.h 73 secondary.h 74 size_class_map.h 75 stats.h 76 string_utils.h 77 tsd.h 78 tsd_exclusive.h 79 tsd_shared.h 80 vector.h 81 wrappers_c_checks.h 82 wrappers_c.h 83 84 include/scudo/interface.h 85 ) 86 87set(SCUDO_SOURCES 88 checksum.cpp 89 crc32_hw.cpp 90 common.cpp 91 flags.cpp 92 flags_parser.cpp 93 fuchsia.cpp 94 linux.cpp 95 release.cpp 96 report.cpp 97 string_utils.cpp 98 ) 99 100# Enable the SSE 4.2 instruction set for crc32_hw.cpp, if available. 101if (COMPILER_RT_HAS_MSSE4_2_FLAG) 102 set_source_files_properties(crc32_hw.cpp PROPERTIES COMPILE_FLAGS -msse4.2) 103endif() 104 105# Enable the AArch64 CRC32 feature for crc32_hw.cpp, if available. 106# Note that it is enabled by default starting with armv8.1-a. 107if (COMPILER_RT_HAS_MCRC_FLAG) 108 set_source_files_properties(crc32_hw.cpp PROPERTIES COMPILE_FLAGS -mcrc) 109endif() 110 111set(SCUDO_SOURCES_C_WRAPPERS 112 wrappers_c.cpp 113 ) 114 115set(SCUDO_SOURCES_CXX_WRAPPERS 116 wrappers_cpp.cpp 117 ) 118 119set(SCUDO_OBJECT_LIBS) 120 121if (COMPILER_RT_HAS_GWP_ASAN) 122 list(APPEND SCUDO_OBJECT_LIBS 123 RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler) 124 list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS) 125endif() 126 127if(COMPILER_RT_HAS_SCUDO_STANDALONE) 128 add_compiler_rt_object_libraries(RTScudoStandalone 129 ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} 130 SOURCES ${SCUDO_SOURCES} 131 ADDITIONAL_HEADERS ${SCUDO_HEADERS} 132 CFLAGS ${SCUDO_CFLAGS}) 133 add_compiler_rt_object_libraries(RTScudoStandaloneCWrappers 134 ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} 135 SOURCES ${SCUDO_SOURCES_C_WRAPPERS} 136 ADDITIONAL_HEADERS ${SCUDO_HEADERS} 137 CFLAGS ${SCUDO_CFLAGS}) 138 add_compiler_rt_object_libraries(RTScudoStandaloneCxxWrappers 139 ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} 140 SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS} 141 ADDITIONAL_HEADERS ${SCUDO_HEADERS} 142 CFLAGS ${SCUDO_CFLAGS}) 143 144 add_compiler_rt_runtime(clang_rt.scudo_standalone 145 STATIC 146 ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} 147 SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS} 148 ADDITIONAL_HEADERS ${SCUDO_HEADERS} 149 CFLAGS ${SCUDO_CFLAGS} 150 OBJECT_LIBS ${SCUDO_OBJECT_LIBS} 151 PARENT_TARGET scudo_standalone) 152 add_compiler_rt_runtime(clang_rt.scudo_standalone_cxx 153 STATIC 154 ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} 155 SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS} 156 ADDITIONAL_HEADERS ${SCUDO_HEADERS} 157 CFLAGS ${SCUDO_CFLAGS} 158 OBJECT_LIBS ${SCUDO_OBJECT_LIBS} 159 PARENT_TARGET scudo_standalone) 160 161 add_subdirectory(benchmarks) 162 if(COMPILER_RT_INCLUDE_TESTS) 163 add_subdirectory(tests) 164 endif() 165endif() 166