llvm-project/compiler-rt/lib/scudo/CMakeLists.txt

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

159 lines
4.8 KiB
CMake
Raw Normal View History

[CMake] Connect Compiler-RT targets to LLVM Runtimes directory This patch builds on LLVM r279776. In this patch I've done some cleanup and abstracted three common steps runtime components have in their CMakeLists files, and added a fourth. The three steps I abstract are: (1) Add a top-level target (i.e asan, msan, ...) (2) Set the target properties for sorting files in IDE generators (3) Make the compiler-rt target depend on the top-level target The new step is to check if a command named "runtime_register_component" is defined, and to call it with the component name. The runtime_register_component command is defined in llvm/runtimes/CMakeLists.txt, and presently just adds the component to a list of sub-components, which later gets used to generate target mappings. With this patch a new workflow for runtimes builds is supported. The new workflow when building runtimes from the LLVM runtimes directory is: > cmake [...] > ninja runtimes-configure > ninja asan The "runtimes-configure" target builds all the dependencies for configuring the runtimes projects, and runs CMake on the runtimes projects. Running the runtimes CMake generates a list of targets to bind into the top-level CMake so subsequent build invocations will have access to some of Compiler-RT's targets through the top-level build. Note: This patch does exclude some top-level targets from compiler-rt libraries because they either don't install files (sanitizer_common), or don't have a cooresponding `check` target (stats). llvm-svn: 279863
2016-08-27 04:52:22 +08:00
add_compiler_rt_component(scudo)
include_directories(..)
set(SCUDO_CFLAGS ${SANITIZER_COMMON_CFLAGS})
# SANITIZER_COMMON_CFLAGS include -fno-builtin, but we actually want builtins!
list(APPEND SCUDO_CFLAGS -fbuiltin)
append_rtti_flag(OFF SCUDO_CFLAGS)
# Too many existing bugs, needs cleanup.
append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format SCUDO_CFLAGS)
set(SCUDO_MINIMAL_DYNAMIC_LIBS ${SANITIZER_COMMON_LINK_LIBS})
append_list_if(COMPILER_RT_HAS_LIBDL dl SCUDO_MINIMAL_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBRT rt SCUDO_MINIMAL_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread SCUDO_MINIMAL_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBLOG log SCUDO_MINIMAL_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer
SCUDO_CFLAGS)
set(SCUDO_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
# Use gc-sections by default to avoid unused code being pulled in.
list(APPEND SCUDO_DYNAMIC_LINK_FLAGS -Wl,--gc-sections)
if(ANDROID)
# Put most Sanitizer shared libraries in the global group. For more details, see
# android-changes-for-ndk-developers.md#changes-to-library-search-order
if (COMPILER_RT_HAS_Z_GLOBAL)
list(APPEND SCUDO_DYNAMIC_LINK_FLAGS -Wl,-z,global)
endif()
endif()
# The minimal Scudo runtime does not include the UBSan runtime.
set(SCUDO_MINIMAL_OBJECT_LIBS
RTSanitizerCommonNoTermination
RTSanitizerCommonLibc
RTInterception)
if (COMPILER_RT_HAS_GWP_ASAN)
list(APPEND SCUDO_MINIMAL_OBJECT_LIBS
RTGwpAsan RTGwpAsanOptionsParser RTGwpAsanBacktraceLibc
RTGwpAsanSegvHandler)
list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS)
endif()
set(SCUDO_OBJECT_LIBS ${SCUDO_MINIMAL_OBJECT_LIBS})
set(SCUDO_DYNAMIC_LIBS ${SCUDO_MINIMAL_DYNAMIC_LIBS})
if (FUCHSIA)
list(APPEND SCUDO_CFLAGS -nostdinc++)
list(APPEND SCUDO_DYNAMIC_LINK_FLAGS -nostdlib++)
else()
list(APPEND SCUDO_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES})
list(APPEND SCUDO_OBJECT_LIBS
RTSanitizerCommonCoverage
RTSanitizerCommonSymbolizer
RTUbsan)
endif()
set(SCUDO_SOURCES
scudo_allocator.cpp
scudo_crc32.cpp
scudo_errors.cpp
scudo_flags.cpp
scudo_malloc.cpp
scudo_termination.cpp
scudo_tsd_exclusive.cpp
scudo_tsd_shared.cpp
scudo_utils.cpp)
set(SCUDO_CXX_SOURCES
scudo_new_delete.cpp)
2018-07-10 21:00:17 +08:00
set(SCUDO_HEADERS
scudo_allocator.h
scudo_allocator_combined.h
scudo_allocator_secondary.h
scudo_crc32.h
scudo_errors.h
scudo_flags.h
scudo_flags.inc
scudo_interface_internal.h
scudo_platform.h
scudo_tsd.h
scudo_tsd_exclusive.inc
scudo_tsd_shared.inc
scudo_utils.h)
[compiler-rt] [scudo] Use -mcrc32 on x86 when available Update the hardware CRC32 logic in scudo to support using `-mcrc32` instead of `-msse4.2`. The CRC32 intrinsics use the former flag in the newer compiler versions, e.g. in clang since 12fa608af44a. With these versions of clang, passing `-msse4.2` is insufficient to enable the instructions and causes build failures when `-march` does not enable CRC32 implicitly: /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.cpp:20:10: error: always_inline function '_mm_crc32_u32' requires target feature 'crc32', but would be inlined into function 'computeHardwareCRC32' that is compiled without support for 'crc32' return CRC32_INTRINSIC(Crc, Data); ^ /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.h:27:27: note: expanded from macro 'CRC32_INTRINSIC' # define CRC32_INTRINSIC FIRST_32_SECOND_64(_mm_crc32_u32, _mm_crc32_u64) ^ /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/../sanitizer_common/sanitizer_platform.h:132:36: note: expanded from macro 'FIRST_32_SECOND_64' # define FIRST_32_SECOND_64(a, b) (a) ^ 1 error generated. For backwards compatibility, use `-mcrc32` when available and fall back to `-msse4.2`. The `<smmintrin.h>` header remains in use as it still works and is compatible with GCC, while clang's `<crc32intrin.h>` is not. Use __builtin_ia32*() rather than _mm_crc32*() when using `-mcrc32` to preserve compatibility with GCC. _mm_crc32*() are aliases to __builtin_ia32*() in both compilers but GCC requires `-msse4.2` for the former, while both use `-mcrc32` for the latter. Originally reported in https://bugs.gentoo.org/835870. Differential Revision: https://reviews.llvm.org/D122789
2022-03-31 15:55:25 +08:00
# Enable the necessary instruction set for scudo_crc32.cpp, if available.
# Newer compiler versions use -mcrc32 rather than -msse4.2.
if (COMPILER_RT_HAS_MCRC32_FLAG)
set_source_files_properties(scudo_crc32.cpp PROPERTIES COMPILE_FLAGS -mcrc32)
elseif (COMPILER_RT_HAS_MSSE4_2_FLAG)
set_source_files_properties(scudo_crc32.cpp PROPERTIES COMPILE_FLAGS -msse4.2)
endif()
# Enable the AArch64 CRC32 feature for scudo_crc32.cpp, if available.
# Note that it is enabled by default starting with armv8.1-a.
if (COMPILER_RT_HAS_MCRC_FLAG)
set_source_files_properties(scudo_crc32.cpp PROPERTIES COMPILE_FLAGS -mcrc)
endif()
if(COMPILER_RT_HAS_SCUDO)
add_compiler_rt_runtime(clang_rt.scudo_minimal
STATIC
ARCHS ${SCUDO_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES}
2018-07-10 21:00:17 +08:00
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
OBJECT_LIBS ${SCUDO_MINIMAL_OBJECT_LIBS}
CFLAGS ${SCUDO_CFLAGS}
PARENT_TARGET scudo)
add_compiler_rt_runtime(clang_rt.scudo_cxx_minimal
STATIC
ARCHS ${SCUDO_SUPPORTED_ARCH}
SOURCES ${SCUDO_CXX_SOURCES}
2018-07-10 21:00:17 +08:00
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS}
PARENT_TARGET scudo)
add_compiler_rt_runtime(clang_rt.scudo
STATIC
ARCHS ${SCUDO_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES}
2018-07-10 21:00:17 +08:00
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
CFLAGS ${SCUDO_CFLAGS}
PARENT_TARGET scudo)
add_compiler_rt_runtime(clang_rt.scudo_cxx
STATIC
ARCHS ${SCUDO_SUPPORTED_ARCH}
SOURCES ${SCUDO_CXX_SOURCES}
2018-07-10 21:00:17 +08:00
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
OBJECT_LIBS RTUbsan_cxx
CFLAGS ${SCUDO_CFLAGS}
PARENT_TARGET scudo)
add_compiler_rt_runtime(clang_rt.scudo_minimal
SHARED
ARCHS ${SCUDO_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES} ${SCUDO_CXX_SOURCES}
2018-07-10 21:00:17 +08:00
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
OBJECT_LIBS ${SCUDO_MINIMAL_OBJECT_LIBS}
CFLAGS ${SCUDO_CFLAGS}
LINK_FLAGS ${SCUDO_DYNAMIC_LINK_FLAGS}
LINK_LIBS ${SCUDO_MINIMAL_DYNAMIC_LIBS}
PARENT_TARGET scudo)
add_compiler_rt_runtime(clang_rt.scudo
SHARED
ARCHS ${SCUDO_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES} ${SCUDO_CXX_SOURCES}
2018-07-10 21:00:17 +08:00
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
CFLAGS ${SCUDO_CFLAGS}
LINK_FLAGS ${SCUDO_DYNAMIC_LINK_FLAGS}
LINK_LIBS ${SCUDO_DYNAMIC_LIBS}
PARENT_TARGET scudo)
endif()