• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1add_compiler_rt_component(scudo)
2
3include_directories(..)
4
5set(SCUDO_CFLAGS ${SANITIZER_COMMON_CFLAGS})
6# SANITIZER_COMMON_CFLAGS include -fno-builtin, but we actually want builtins!
7list(APPEND SCUDO_CFLAGS -fbuiltin)
8append_rtti_flag(OFF SCUDO_CFLAGS)
9
10set(SCUDO_MINIMAL_DYNAMIC_LIBS ${SANITIZER_COMMON_LINK_LIBS})
11append_list_if(COMPILER_RT_HAS_LIBDL dl SCUDO_MINIMAL_DYNAMIC_LIBS)
12append_list_if(COMPILER_RT_HAS_LIBRT rt SCUDO_MINIMAL_DYNAMIC_LIBS)
13append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread SCUDO_MINIMAL_DYNAMIC_LIBS)
14append_list_if(COMPILER_RT_HAS_LIBLOG log SCUDO_MINIMAL_DYNAMIC_LIBS)
15append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer
16               SCUDO_CFLAGS)
17
18set(SCUDO_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
19# Use gc-sections by default to avoid unused code being pulled in.
20list(APPEND SCUDO_DYNAMIC_LINK_FLAGS -Wl,--gc-sections)
21
22if(ANDROID)
23# Put most Sanitizer shared libraries in the global group. For more details, see
24# android-changes-for-ndk-developers.md#changes-to-library-search-order
25  if (COMPILER_RT_HAS_Z_GLOBAL)
26    list(APPEND SCUDO_DYNAMIC_LINK_FLAGS -Wl,-z,global)
27  endif()
28endif()
29
30# The minimal Scudo runtime does not inlude the UBSan runtime.
31set(SCUDO_MINIMAL_OBJECT_LIBS
32  RTSanitizerCommonNoTermination
33  RTSanitizerCommonLibc
34  RTInterception)
35
36if (COMPILER_RT_HAS_GWP_ASAN)
37  # Currently, Scudo uses the GwpAsan flag parser. This backs onto the flag
38  # parsing mechanism of sanitizer_common. Once Scudo has its own flag parsing,
39  # and parses GwpAsan options, you can remove this dependency.
40  list(APPEND SCUDO_MINIMAL_OBJECT_LIBS RTGwpAsan RTGwpAsanOptionsParser
41                                        RTGwpAsanBacktraceLibc
42                                        RTGwpAsanSegvHandler)
43  list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS)
44endif()
45
46set(SCUDO_OBJECT_LIBS ${SCUDO_MINIMAL_OBJECT_LIBS})
47set(SCUDO_DYNAMIC_LIBS ${SCUDO_MINIMAL_DYNAMIC_LIBS})
48
49if (FUCHSIA)
50  list(APPEND SCUDO_CFLAGS -nostdinc++)
51  list(APPEND SCUDO_DYNAMIC_LINK_FLAGS -nostdlib++)
52else()
53  list(APPEND SCUDO_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES})
54  list(APPEND SCUDO_OBJECT_LIBS
55    RTSanitizerCommonCoverage
56    RTSanitizerCommonSymbolizer
57    RTUbsan)
58endif()
59
60set(SCUDO_SOURCES
61  scudo_allocator.cpp
62  scudo_crc32.cpp
63  scudo_errors.cpp
64  scudo_flags.cpp
65  scudo_malloc.cpp
66  scudo_termination.cpp
67  scudo_tsd_exclusive.cpp
68  scudo_tsd_shared.cpp
69  scudo_utils.cpp)
70
71set(SCUDO_CXX_SOURCES
72  scudo_new_delete.cpp)
73
74set(SCUDO_HEADERS
75  scudo_allocator.h
76  scudo_allocator_combined.h
77  scudo_allocator_secondary.h
78  scudo_crc32.h
79  scudo_errors.h
80  scudo_flags.h
81  scudo_flags.inc
82  scudo_interface_internal.h
83  scudo_platform.h
84  scudo_tsd.h
85  scudo_tsd_exclusive.inc
86  scudo_tsd_shared.inc
87  scudo_utils.h)
88
89# Enable the SSE 4.2 instruction set for scudo_crc32.cpp, if available.
90if (COMPILER_RT_HAS_MSSE4_2_FLAG)
91  set_source_files_properties(scudo_crc32.cpp PROPERTIES COMPILE_FLAGS -msse4.2)
92endif()
93
94# Enable the AArch64 CRC32 feature for scudo_crc32.cpp, if available.
95# Note that it is enabled by default starting with armv8.1-a.
96if (COMPILER_RT_HAS_MCRC_FLAG)
97  set_source_files_properties(scudo_crc32.cpp PROPERTIES COMPILE_FLAGS -mcrc)
98endif()
99
100if(COMPILER_RT_HAS_SCUDO)
101  add_compiler_rt_runtime(clang_rt.scudo_minimal
102    STATIC
103    ARCHS ${SCUDO_SUPPORTED_ARCH}
104    SOURCES ${SCUDO_SOURCES}
105    ADDITIONAL_HEADERS ${SCUDO_HEADERS}
106    OBJECT_LIBS ${SCUDO_MINIMAL_OBJECT_LIBS}
107    CFLAGS ${SCUDO_CFLAGS}
108    PARENT_TARGET scudo)
109  add_compiler_rt_runtime(clang_rt.scudo_cxx_minimal
110    STATIC
111    ARCHS ${SCUDO_SUPPORTED_ARCH}
112    SOURCES ${SCUDO_CXX_SOURCES}
113    ADDITIONAL_HEADERS ${SCUDO_HEADERS}
114    CFLAGS ${SCUDO_CFLAGS}
115    PARENT_TARGET scudo)
116
117  add_compiler_rt_runtime(clang_rt.scudo
118    STATIC
119    ARCHS ${SCUDO_SUPPORTED_ARCH}
120    SOURCES ${SCUDO_SOURCES}
121    ADDITIONAL_HEADERS ${SCUDO_HEADERS}
122    OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
123    CFLAGS ${SCUDO_CFLAGS}
124    PARENT_TARGET scudo)
125  add_compiler_rt_runtime(clang_rt.scudo_cxx
126    STATIC
127    ARCHS ${SCUDO_SUPPORTED_ARCH}
128    SOURCES ${SCUDO_CXX_SOURCES}
129    ADDITIONAL_HEADERS ${SCUDO_HEADERS}
130    OBJECT_LIBS RTUbsan_cxx
131    CFLAGS ${SCUDO_CFLAGS}
132    PARENT_TARGET scudo)
133
134  add_compiler_rt_runtime(clang_rt.scudo_minimal
135    SHARED
136    ARCHS ${SCUDO_SUPPORTED_ARCH}
137    SOURCES ${SCUDO_SOURCES} ${SCUDO_CXX_SOURCES}
138    ADDITIONAL_HEADERS ${SCUDO_HEADERS}
139    OBJECT_LIBS ${SCUDO_MINIMAL_OBJECT_LIBS}
140    CFLAGS ${SCUDO_CFLAGS}
141    LINK_FLAGS ${SCUDO_DYNAMIC_LINK_FLAGS}
142    LINK_LIBS ${SCUDO_MINIMAL_DYNAMIC_LIBS}
143    PARENT_TARGET scudo)
144
145  add_compiler_rt_runtime(clang_rt.scudo
146    SHARED
147    ARCHS ${SCUDO_SUPPORTED_ARCH}
148    SOURCES ${SCUDO_SOURCES} ${SCUDO_CXX_SOURCES}
149    ADDITIONAL_HEADERS ${SCUDO_HEADERS}
150    OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
151    CFLAGS ${SCUDO_CFLAGS}
152    LINK_FLAGS ${SCUDO_DYNAMIC_LINK_FLAGS}
153    LINK_LIBS ${SCUDO_DYNAMIC_LIBS}
154    PARENT_TARGET scudo)
155endif()
156