1 add_compiler_rt_component(scudo_standalone)
3 include_directories(../.. include)
7 list(APPEND SCUDO_CFLAGS
15 # Remove -stdlib= which is unused when passing -nostdinc++.
16 string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
18 append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SCUDO_CFLAGS)
20 append_list_if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions SCUDO_CFLAGS)
22 append_list_if(COMPILER_RT_HAS_WNO_PEDANTIC -Wno-pedantic SCUDO_CFLAGS)
24 # FIXME: find cleaner way to agree with GWPAsan flags
25 append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SCUDO_CFLAGS)
28 list(APPEND SCUDO_CFLAGS -O0 -DSCUDO_DEBUG=1 -DSCUDO_ENABLE_HOOKS=1)
30 list(APPEND SCUDO_CFLAGS -O3)
33 append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_FLAG -Werror=thread-safety
38 list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro)
40 list(APPEND SCUDO_LINK_FLAGS -ffunction-sections -fdata-sections -Wl,--gc-sections)
42 # We don't use the C++ standard library, so avoid including it by mistake.
43 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS)
44 append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SCUDO_LINK_FLAGS)
46 if(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)
47 list(APPEND SCUDO_CFLAGS "--sysroot=${COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH}")
51 list(APPEND SCUDO_CFLAGS -fno-emulated-tls)
53 # Put the shared library in the global group. For more details, see
54 # android-changes-for-ndk-developers.md#changes-to-library-search-order
55 append_list_if(COMPILER_RT_HAS_Z_GLOBAL -Wl,-z,global SCUDO_LINK_FLAGS)
66 condition_variable_base.h
67 condition_variable_linux.h
104 include/scudo/interface.h
110 condition_variable_linux.cpp
126 # Temporary hack until LLVM libc supports inttypes.h print format macros
127 # See: https://github.com/llvm/llvm-project/issues/63317#issuecomment-1591906241
128 if(LLVM_LIBC_INCLUDE_SCUDO)
129 list(REMOVE_ITEM SCUDO_HEADERS timing.h)
130 list(REMOVE_ITEM SCUDO_SOURCES timing.cpp)
133 # Enable the necessary instruction set for scudo_crc32.cpp, if available.
134 # Newer compiler versions use -mcrc32 rather than -msse4.2.
135 if (COMPILER_RT_HAS_MCRC32_FLAG)
136 set_source_files_properties(crc32_hw.cpp PROPERTIES COMPILE_FLAGS -mcrc32)
137 elseif (COMPILER_RT_HAS_MSSE4_2_FLAG)
138 set_source_files_properties(crc32_hw.cpp PROPERTIES COMPILE_FLAGS -msse4.2)
141 # Enable the AArch64 CRC32 feature for crc32_hw.cpp, if available.
142 # Note that it is enabled by default starting with armv8.1-a.
143 if (COMPILER_RT_HAS_MCRC_FLAG)
144 set_source_files_properties(crc32_hw.cpp PROPERTIES COMPILE_FLAGS -mcrc)
147 set(SCUDO_SOURCES_C_WRAPPERS
151 set(SCUDO_SOURCES_CXX_WRAPPERS
155 set(SCUDO_OBJECT_LIBS)
158 if (COMPILER_RT_HAS_GWP_ASAN)
159 if(COMPILER_RT_USE_LLVM_UNWINDER)
160 list(APPEND SCUDO_LINK_LIBS ${COMPILER_RT_UNWINDER_LINK_LIBS} dl)
161 elseif (COMPILER_RT_HAS_GCC_S_LIB)
162 list(APPEND SCUDO_LINK_LIBS gcc_s)
163 elseif (COMPILER_RT_HAS_GCC_LIB)
164 list(APPEND SCUDO_LINK_LIBS gcc)
165 elseif (NOT COMPILER_RT_USE_BUILTINS_LIBRARY)
166 message(FATAL_ERROR "No suitable unwinder library")
169 add_dependencies(scudo_standalone gwp_asan)
170 list(APPEND SCUDO_OBJECT_LIBS
171 RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler
172 RTGwpAsanOptionsParser)
174 append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer
175 -mno-omit-leaf-frame-pointer
177 list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS)
181 if(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)
182 include_directories(${COMPILER_RT_BINARY_DIR}/../libc/include/)
184 set(SCUDO_DEPS libc-headers)
186 list(APPEND SCUDO_CFLAGS "-ffreestanding")
189 append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread SCUDO_LINK_FLAGS)
191 append_list_if(FUCHSIA zircon SCUDO_LINK_LIBS)
193 if(COMPILER_RT_DEFAULT_TARGET_ARCH MATCHES "mips|mips64|mipsel|mips64el")
194 list(APPEND SCUDO_LINK_LIBS atomic)
197 if(COMPILER_RT_HAS_SCUDO_STANDALONE)
198 add_compiler_rt_object_libraries(RTScudoStandalone
199 ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
200 SOURCES ${SCUDO_SOURCES}
201 ADDITIONAL_HEADERS ${SCUDO_HEADERS}
202 CFLAGS ${SCUDO_CFLAGS}
204 add_compiler_rt_object_libraries(RTScudoStandaloneCWrappers
205 ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
206 SOURCES ${SCUDO_SOURCES_C_WRAPPERS}
207 ADDITIONAL_HEADERS ${SCUDO_HEADERS}
208 CFLAGS ${SCUDO_CFLAGS}
210 add_compiler_rt_object_libraries(RTScudoStandaloneCxxWrappers
211 ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
212 SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS}
213 ADDITIONAL_HEADERS ${SCUDO_HEADERS}
214 CFLAGS ${SCUDO_CFLAGS}
217 add_compiler_rt_runtime(clang_rt.scudo_standalone
219 ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
220 SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS}
221 ADDITIONAL_HEADERS ${SCUDO_HEADERS}
222 CFLAGS ${SCUDO_CFLAGS}
224 OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
225 PARENT_TARGET scudo_standalone)
226 add_compiler_rt_runtime(clang_rt.scudo_standalone_cxx
228 ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
229 SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS}
230 ADDITIONAL_HEADERS ${SCUDO_HEADERS}
231 CFLAGS ${SCUDO_CFLAGS}
233 PARENT_TARGET scudo_standalone)
235 if(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
236 add_compiler_rt_runtime(clang_rt.scudo_standalone
238 ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
239 SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS} ${SCUDO_SOURCES_CXX_WRAPPERS}
240 ADDITIONAL_HEADERS ${SCUDO_HEADERS}
241 CFLAGS ${SCUDO_CFLAGS}
243 OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
244 LINK_FLAGS ${SCUDO_LINK_FLAGS}
245 LINK_LIBS ${SCUDO_LINK_LIBS}
246 PARENT_TARGET scudo_standalone)
249 add_subdirectory(benchmarks)
250 if(COMPILER_RT_INCLUDE_TESTS)
251 add_subdirectory(tests)