brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.8 KiB · db494a9 Raw
253 lines · plain
1add_compiler_rt_component(scudo_standalone)2 3include_directories(../.. include)4 5set(SCUDO_CFLAGS)6 7list(APPEND SCUDO_CFLAGS8  -Werror=conversion9  -Wall10  -Wextra11  -pedantic12  -g13  -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_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SCUDO_CFLAGS)19 20append_list_if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions SCUDO_CFLAGS)21 22append_list_if(COMPILER_RT_HAS_WNO_PEDANTIC -Wno-pedantic SCUDO_CFLAGS)23 24# FIXME: find cleaner way to agree with GWPAsan flags25append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SCUDO_CFLAGS)26 27if(COMPILER_RT_DEBUG)28  list(APPEND SCUDO_CFLAGS -O0 -DSCUDO_DEBUG=1 -DSCUDO_ENABLE_HOOKS=1)29else()30  list(APPEND SCUDO_CFLAGS -O3)31endif()32 33append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_FLAG -Werror=thread-safety34  SCUDO_CFLAGS)35 36set(SCUDO_LINK_FLAGS)37 38list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro)39 40list(APPEND SCUDO_LINK_FLAGS -ffunction-sections -fdata-sections -Wl,--gc-sections)41 42# We don't use the C++ standard library, so avoid including it by mistake.43append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS)44append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SCUDO_LINK_FLAGS)45 46if(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)47  list(APPEND SCUDO_CFLAGS "--sysroot=${COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH}")48endif()49 50if(ANDROID)51  list(APPEND SCUDO_CFLAGS -fno-emulated-tls)52 53# Put the shared library in the global group. For more details, see54# android-changes-for-ndk-developers.md#changes-to-library-search-order55  append_list_if(COMPILER_RT_HAS_Z_GLOBAL -Wl,-z,global SCUDO_LINK_FLAGS)56endif()57 58set(SCUDO_HEADERS59  allocator_common.h60  allocator_config.h61  allocator_config_wrapper.h62  atomic_helpers.h63  bytemap.h64  checksum.h65  chunk.h66  condition_variable.h67  condition_variable_base.h68  condition_variable_linux.h69  combined.h70  common.h71  flags_parser.h72  flags.h73  fuchsia.h74  internal_defs.h75  linux.h76  list.h77  memtag.h78  mem_map.h79  mem_map_base.h80  mem_map_fuchsia.h81  mem_map_linux.h82  mutex.h83  options.h84  platform.h85  primary32.h86  primary64.h87  quarantine.h88  release.h89  report.h90  report_linux.h91  secondary.h92  size_class_allocator.h93  size_class_map.h94  stack_depot.h95  stats.h96  string_utils.h97  timing.h98  tsd_exclusive.h99  tsd_shared.h100  tsd.h101  type_traits.h102  vector.h103  wrappers_c_checks.h104  wrappers_c.h105 106  include/scudo/interface.h107  )108 109set(SCUDO_SOURCES110  checksum.cpp111  common.cpp112  condition_variable_linux.cpp113  crc32_hw.cpp114  flags_parser.cpp115  flags.cpp116  fuchsia.cpp117  linux.cpp118  mem_map.cpp119  mem_map_fuchsia.cpp120  mem_map_linux.cpp121  release.cpp122  report.cpp123  report_linux.cpp124  string_utils.cpp125  timing.cpp126  )127 128# Temporary hack until LLVM libc supports inttypes.h print format macros129# See: https://github.com/llvm/llvm-project/issues/63317#issuecomment-1591906241130if(LLVM_LIBC_INCLUDE_SCUDO)131  list(REMOVE_ITEM SCUDO_HEADERS timing.h)132  list(REMOVE_ITEM SCUDO_SOURCES timing.cpp)133endif()134 135# Enable the necessary instruction set for scudo_crc32.cpp, if available.136# Newer compiler versions use -mcrc32 rather than -msse4.2.137if (COMPILER_RT_HAS_MCRC32_FLAG)138  set_source_files_properties(crc32_hw.cpp PROPERTIES COMPILE_FLAGS -mcrc32)139elseif (COMPILER_RT_HAS_MSSE4_2_FLAG)140  set_source_files_properties(crc32_hw.cpp PROPERTIES COMPILE_FLAGS -msse4.2)141endif()142 143# Enable the AArch64 CRC32 feature for crc32_hw.cpp, if available.144# Note that it is enabled by default starting with armv8.1-a.145if (COMPILER_RT_HAS_MCRC_FLAG)146  set_source_files_properties(crc32_hw.cpp PROPERTIES COMPILE_FLAGS -mcrc)147endif()148 149set(SCUDO_SOURCES_C_WRAPPERS150  wrappers_c.cpp151  )152 153set(SCUDO_SOURCES_CXX_WRAPPERS154  wrappers_cpp.cpp155  )156 157set(SCUDO_OBJECT_LIBS)158set(SCUDO_LINK_LIBS)159 160if (COMPILER_RT_HAS_GWP_ASAN)161  if(COMPILER_RT_USE_LLVM_UNWINDER)162    list(APPEND SCUDO_LINK_LIBS ${COMPILER_RT_UNWINDER_LINK_LIBS} dl)163  elseif (COMPILER_RT_HAS_GCC_S_LIB)164    list(APPEND SCUDO_LINK_LIBS gcc_s)165  elseif (COMPILER_RT_HAS_GCC_LIB)166    list(APPEND SCUDO_LINK_LIBS gcc)167  elseif (NOT COMPILER_RT_USE_BUILTINS_LIBRARY)168    message(FATAL_ERROR "No suitable unwinder library")169  endif()170 171  add_dependencies(scudo_standalone gwp_asan)172  list(APPEND SCUDO_OBJECT_LIBS173       RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler174       RTGwpAsanOptionsParser)175 176  append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer177                                                         -mno-omit-leaf-frame-pointer178                 SCUDO_CFLAGS)179  list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS)180 181endif()182 183if(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)184  include_directories(${COMPILER_RT_BINARY_DIR}/../libc/include/)185 186  set(SCUDO_DEPS libc-headers)187 188  list(APPEND SCUDO_CFLAGS "-ffreestanding")189endif()190 191append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread SCUDO_LINK_FLAGS)192 193append_list_if(FUCHSIA zircon SCUDO_LINK_LIBS)194 195if(COMPILER_RT_DEFAULT_TARGET_ARCH MATCHES "mips|mips64|mipsel|mips64el")196  list(APPEND SCUDO_LINK_LIBS atomic)197endif()198 199add_compiler_rt_object_libraries(RTScudoStandalone200  ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}201  SOURCES ${SCUDO_SOURCES}202  ADDITIONAL_HEADERS ${SCUDO_HEADERS}203  CFLAGS ${SCUDO_CFLAGS}204  DEPS ${SCUDO_DEPS})205add_compiler_rt_object_libraries(RTScudoStandaloneCWrappers206  ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}207  SOURCES ${SCUDO_SOURCES_C_WRAPPERS}208  ADDITIONAL_HEADERS ${SCUDO_HEADERS}209  CFLAGS ${SCUDO_CFLAGS}210  DEPS ${SCUDO_DEPS})211add_compiler_rt_object_libraries(RTScudoStandaloneCxxWrappers212  ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}213  SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS}214  ADDITIONAL_HEADERS ${SCUDO_HEADERS}215  CFLAGS ${SCUDO_CFLAGS}216  DEPS ${SCUDO_DEPS})217 218add_compiler_rt_runtime(clang_rt.scudo_standalone219  STATIC220  ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}221  SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS}222  ADDITIONAL_HEADERS ${SCUDO_HEADERS}223  CFLAGS ${SCUDO_CFLAGS}224  DEPS ${SCUDO_DEPS}225  OBJECT_LIBS ${SCUDO_OBJECT_LIBS}226  PARENT_TARGET scudo_standalone)227add_compiler_rt_runtime(clang_rt.scudo_standalone_cxx228  STATIC229  ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}230  SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS}231  ADDITIONAL_HEADERS ${SCUDO_HEADERS}232  CFLAGS ${SCUDO_CFLAGS}233  DEPS ${SCUDO_DEPS}234  PARENT_TARGET scudo_standalone)235 236if(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)237  add_compiler_rt_runtime(clang_rt.scudo_standalone238    SHARED239    ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}240    SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS} ${SCUDO_SOURCES_CXX_WRAPPERS}241    ADDITIONAL_HEADERS ${SCUDO_HEADERS}242    CFLAGS ${SCUDO_CFLAGS}243    DEPS ${SCUDO_DEPS}244    OBJECT_LIBS ${SCUDO_OBJECT_LIBS}245    LINK_FLAGS ${SCUDO_LINK_FLAGS}246    LINK_LIBS ${SCUDO_LINK_LIBS}247    PARENT_TARGET scudo_standalone)248endif()249 250if(COMPILER_RT_INCLUDE_TESTS)251  add_subdirectory(tests)252endif()253