1 # Build for the Memory Profiler runtime support library.
5 memprof_descriptions.cpp
7 memprof_interceptors.cpp
8 memprof_interceptors_memintrinsics.cpp
10 memprof_malloc_linux.cpp
13 memprof_rawprofile.cpp
15 memprof_shadow_setup.cpp
21 set(MEMPROF_CXX_SOURCES
22 memprof_new_delete.cpp
25 set(MEMPROF_PREINIT_SOURCES
31 memprof_descriptions.h
34 memprof_init_version.h
35 memprof_interceptors.h
36 memprof_interceptors_memintrinsics.h
37 memprof_interface_internal.h
47 include_directories(..)
48 include_directories(../../include)
50 set(MEMPROF_CFLAGS ${SANITIZER_COMMON_CFLAGS})
51 set(MEMPROF_COMMON_DEFINITIONS "")
53 # Too many existing bugs, needs cleanup.
54 append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format MEMPROF_CFLAGS)
56 append_rtti_flag(OFF MEMPROF_CFLAGS)
58 set(MEMPROF_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
60 set(MEMPROF_DYNAMIC_DEFINITIONS
61 ${MEMPROF_COMMON_DEFINITIONS} MEMPROF_DYNAMIC=1)
63 set(MEMPROF_DYNAMIC_CFLAGS ${MEMPROF_CFLAGS})
64 append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
65 -ftls-model=initial-exec MEMPROF_DYNAMIC_CFLAGS)
67 set(MEMPROF_DYNAMIC_LIBS
68 ${COMPILER_RT_UNWINDER_LINK_LIBS}
69 ${SANITIZER_CXX_ABI_LIBRARIES}
70 ${SANITIZER_COMMON_LINK_LIBS})
72 append_list_if(COMPILER_RT_HAS_LIBDL dl MEMPROF_DYNAMIC_LIBS)
73 append_list_if(COMPILER_RT_HAS_LIBRT rt MEMPROF_DYNAMIC_LIBS)
74 append_list_if(COMPILER_RT_HAS_LIBM m MEMPROF_DYNAMIC_LIBS)
75 append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread MEMPROF_DYNAMIC_LIBS)
76 append_list_if(COMPILER_RT_HAS_LIBLOG log MEMPROF_DYNAMIC_LIBS)
78 # Compile MemProf sources into an object library.
80 add_compiler_rt_object_libraries(RTMemprof_dynamic
81 OS ${SANITIZER_COMMON_SUPPORTED_OS}
82 ARCHS ${MEMPROF_SUPPORTED_ARCH}
83 SOURCES ${MEMPROF_SOURCES} ${MEMPROF_CXX_SOURCES}
84 ADDITIONAL_HEADERS ${MEMPROF_HEADERS}
85 CFLAGS ${MEMPROF_DYNAMIC_CFLAGS}
86 DEFS ${MEMPROF_DYNAMIC_DEFINITIONS}
89 add_compiler_rt_object_libraries(RTMemprof
90 ARCHS ${MEMPROF_SUPPORTED_ARCH}
91 SOURCES ${MEMPROF_SOURCES}
92 ADDITIONAL_HEADERS ${MEMPROF_HEADERS}
93 CFLAGS ${MEMPROF_CFLAGS}
94 DEFS ${MEMPROF_COMMON_DEFINITIONS}
96 add_compiler_rt_object_libraries(RTMemprof_cxx
97 ARCHS ${MEMPROF_SUPPORTED_ARCH}
98 SOURCES ${MEMPROF_CXX_SOURCES}
99 ADDITIONAL_HEADERS ${MEMPROF_HEADERS}
100 CFLAGS ${MEMPROF_CFLAGS}
101 DEFS ${MEMPROF_COMMON_DEFINITIONS}
102 DEPS ${MEMPROF_DEPS})
103 add_compiler_rt_object_libraries(RTMemprof_preinit
104 ARCHS ${MEMPROF_SUPPORTED_ARCH}
105 SOURCES ${MEMPROF_PREINIT_SOURCES}
106 ADDITIONAL_HEADERS ${MEMPROF_HEADERS}
107 CFLAGS ${MEMPROF_CFLAGS}
108 DEFS ${MEMPROF_COMMON_DEFINITIONS}
109 DEPS ${MEMPROF_DEPS})
111 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
112 add_compiler_rt_object_libraries(RTMemprof_dynamic_version_script_dummy
113 ARCHS ${MEMPROF_SUPPORTED_ARCH}
114 SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
115 CFLAGS ${MEMPROF_DYNAMIC_CFLAGS}
116 DEFS ${MEMPROF_DYNAMIC_DEFINITIONS}
117 DEPS ${MEMPROF_DEPS})
119 # Build MemProf runtimes shipped with Clang.
120 add_compiler_rt_component(memprof)
122 # Build separate libraries for each target.
124 set(MEMPROF_COMMON_RUNTIME_OBJECT_LIBS
127 RTSanitizerCommonLibc
128 RTSanitizerCommonCoverage
129 RTSanitizerCommonSymbolizer
131 # RTSanitizerCommonSymbolizerInternal
134 add_compiler_rt_runtime(clang_rt.memprof
136 ARCHS ${MEMPROF_SUPPORTED_ARCH}
137 OBJECT_LIBS RTMemprof_preinit
139 ${MEMPROF_COMMON_RUNTIME_OBJECT_LIBS}
140 CFLAGS ${MEMPROF_CFLAGS}
141 DEFS ${MEMPROF_COMMON_DEFINITIONS}
142 PARENT_TARGET memprof)
144 add_compiler_rt_runtime(clang_rt.memprof_cxx
146 ARCHS ${MEMPROF_SUPPORTED_ARCH}
147 OBJECT_LIBS RTMemprof_cxx
148 CFLAGS ${MEMPROF_CFLAGS}
149 DEFS ${MEMPROF_COMMON_DEFINITIONS}
150 PARENT_TARGET memprof)
152 add_compiler_rt_runtime(clang_rt.memprof-preinit
154 ARCHS ${MEMPROF_SUPPORTED_ARCH}
155 OBJECT_LIBS RTMemprof_preinit
156 CFLAGS ${MEMPROF_CFLAGS}
157 DEFS ${MEMPROF_COMMON_DEFINITIONS}
158 PARENT_TARGET memprof)
160 foreach(arch ${MEMPROF_SUPPORTED_ARCH})
162 add_sanitizer_rt_version_list(clang_rt.memprof-dynamic-${arch}
163 LIBS clang_rt.memprof-${arch} clang_rt.memprof_cxx-${arch}
164 EXTRA memprof.syms.extra)
165 set(VERSION_SCRIPT_FLAG
166 -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.memprof-dynamic-${arch}.vers)
168 ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
170 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.memprof-dynamic-${arch}.vers)
172 set(VERSION_SCRIPT_FLAG)
175 set(MEMPROF_DYNAMIC_WEAK_INTERCEPTION)
177 add_compiler_rt_runtime(clang_rt.memprof
180 OBJECT_LIBS ${MEMPROF_COMMON_RUNTIME_OBJECT_LIBS}
182 # The only purpose of RTMemprof_dynamic_version_script_dummy is to
183 # carry a dependency of the shared runtime on the version script.
184 # Replacing it with a straightforward
185 # add_dependencies(clang_rt.memprof-dynamic-${arch} clang_rt.memprof-dynamic-${arch}-version-list)
186 # generates an order-only dependency in ninja.
187 RTMemprof_dynamic_version_script_dummy
188 ${MEMPROF_DYNAMIC_WEAK_INTERCEPTION}
189 CFLAGS ${MEMPROF_DYNAMIC_CFLAGS}
190 LINK_FLAGS ${MEMPROF_DYNAMIC_LINK_FLAGS}
191 ${VERSION_SCRIPT_FLAG}
192 LINK_LIBS ${MEMPROF_DYNAMIC_LIBS}
193 DEFS ${MEMPROF_DYNAMIC_DEFINITIONS}
194 PARENT_TARGET memprof)
196 if (SANITIZER_USE_SYMBOLS)
197 add_sanitizer_rt_symbols(clang_rt.memprof_cxx
199 add_dependencies(memprof clang_rt.memprof_cxx-${arch}-symbols)
200 add_sanitizer_rt_symbols(clang_rt.memprof
202 EXTRA memprof.syms.extra)
203 add_dependencies(memprof clang_rt.memprof-${arch}-symbols)
208 if(COMPILER_RT_INCLUDE_TESTS)
209 add_subdirectory(tests)