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
40 memprof_meminfoblock.h
48 include_directories(..)
49 include_directories(../../include)
51 set(MEMPROF_CFLAGS ${SANITIZER_COMMON_CFLAGS})
52 set(MEMPROF_COMMON_DEFINITIONS "")
54 # Too many existing bugs, needs cleanup.
55 append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format MEMPROF_CFLAGS)
57 append_rtti_flag(OFF MEMPROF_CFLAGS)
59 set(MEMPROF_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
61 set(MEMPROF_DYNAMIC_DEFINITIONS
62 ${MEMPROF_COMMON_DEFINITIONS} MEMPROF_DYNAMIC=1)
64 set(MEMPROF_DYNAMIC_CFLAGS ${MEMPROF_CFLAGS})
65 append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
66 -ftls-model=initial-exec MEMPROF_DYNAMIC_CFLAGS)
68 set(MEMPROF_DYNAMIC_LIBS
69 ${COMPILER_RT_UNWINDER_LINK_LIBS}
70 ${SANITIZER_CXX_ABI_LIBRARIES}
71 ${SANITIZER_COMMON_LINK_LIBS})
73 append_list_if(COMPILER_RT_HAS_LIBDL dl MEMPROF_DYNAMIC_LIBS)
74 append_list_if(COMPILER_RT_HAS_LIBRT rt MEMPROF_DYNAMIC_LIBS)
75 append_list_if(COMPILER_RT_HAS_LIBM m MEMPROF_DYNAMIC_LIBS)
76 append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread MEMPROF_DYNAMIC_LIBS)
77 append_list_if(COMPILER_RT_HAS_LIBLOG log MEMPROF_DYNAMIC_LIBS)
79 # Compile MemProf sources into an object library.
81 add_compiler_rt_object_libraries(RTMemprof_dynamic
82 OS ${SANITIZER_COMMON_SUPPORTED_OS}
83 ARCHS ${MEMPROF_SUPPORTED_ARCH}
84 SOURCES ${MEMPROF_SOURCES} ${MEMPROF_CXX_SOURCES}
85 ADDITIONAL_HEADERS ${MEMPROF_HEADERS}
86 CFLAGS ${MEMPROF_DYNAMIC_CFLAGS}
87 DEFS ${MEMPROF_DYNAMIC_DEFINITIONS}
90 add_compiler_rt_object_libraries(RTMemprof
91 ARCHS ${MEMPROF_SUPPORTED_ARCH}
92 SOURCES ${MEMPROF_SOURCES}
93 ADDITIONAL_HEADERS ${MEMPROF_HEADERS}
94 CFLAGS ${MEMPROF_CFLAGS}
95 DEFS ${MEMPROF_COMMON_DEFINITIONS}
97 add_compiler_rt_object_libraries(RTMemprof_cxx
98 ARCHS ${MEMPROF_SUPPORTED_ARCH}
99 SOURCES ${MEMPROF_CXX_SOURCES}
100 ADDITIONAL_HEADERS ${MEMPROF_HEADERS}
101 CFLAGS ${MEMPROF_CFLAGS}
102 DEFS ${MEMPROF_COMMON_DEFINITIONS}
103 DEPS ${MEMPROF_DEPS})
104 add_compiler_rt_object_libraries(RTMemprof_preinit
105 ARCHS ${MEMPROF_SUPPORTED_ARCH}
106 SOURCES ${MEMPROF_PREINIT_SOURCES}
107 ADDITIONAL_HEADERS ${MEMPROF_HEADERS}
108 CFLAGS ${MEMPROF_CFLAGS}
109 DEFS ${MEMPROF_COMMON_DEFINITIONS}
110 DEPS ${MEMPROF_DEPS})
112 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
113 add_compiler_rt_object_libraries(RTMemprof_dynamic_version_script_dummy
114 ARCHS ${MEMPROF_SUPPORTED_ARCH}
115 SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
116 CFLAGS ${MEMPROF_DYNAMIC_CFLAGS}
117 DEFS ${MEMPROF_DYNAMIC_DEFINITIONS}
118 DEPS ${MEMPROF_DEPS})
120 # Build MemProf runtimes shipped with Clang.
121 add_compiler_rt_component(memprof)
123 # Build separate libraries for each target.
125 set(MEMPROF_COMMON_RUNTIME_OBJECT_LIBS
128 RTSanitizerCommonLibc
129 RTSanitizerCommonCoverage
130 RTSanitizerCommonSymbolizer
132 # RTSanitizerCommonSymbolizerInternal
135 add_compiler_rt_runtime(clang_rt.memprof
137 ARCHS ${MEMPROF_SUPPORTED_ARCH}
138 OBJECT_LIBS RTMemprof_preinit
140 ${MEMPROF_COMMON_RUNTIME_OBJECT_LIBS}
141 CFLAGS ${MEMPROF_CFLAGS}
142 DEFS ${MEMPROF_COMMON_DEFINITIONS}
143 PARENT_TARGET memprof)
145 add_compiler_rt_runtime(clang_rt.memprof_cxx
147 ARCHS ${MEMPROF_SUPPORTED_ARCH}
148 OBJECT_LIBS RTMemprof_cxx
149 CFLAGS ${MEMPROF_CFLAGS}
150 DEFS ${MEMPROF_COMMON_DEFINITIONS}
151 PARENT_TARGET memprof)
153 add_compiler_rt_runtime(clang_rt.memprof-preinit
155 ARCHS ${MEMPROF_SUPPORTED_ARCH}
156 OBJECT_LIBS RTMemprof_preinit
157 CFLAGS ${MEMPROF_CFLAGS}
158 DEFS ${MEMPROF_COMMON_DEFINITIONS}
159 PARENT_TARGET memprof)
161 foreach(arch ${MEMPROF_SUPPORTED_ARCH})
163 add_sanitizer_rt_version_list(clang_rt.memprof-dynamic-${arch}
164 LIBS clang_rt.memprof-${arch} clang_rt.memprof_cxx-${arch}
165 EXTRA memprof.syms.extra)
166 set(VERSION_SCRIPT_FLAG
167 -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.memprof-dynamic-${arch}.vers)
169 ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
171 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.memprof-dynamic-${arch}.vers)
173 set(VERSION_SCRIPT_FLAG)
176 set(MEMPROF_DYNAMIC_WEAK_INTERCEPTION)
178 add_compiler_rt_runtime(clang_rt.memprof
181 OBJECT_LIBS ${MEMPROF_COMMON_RUNTIME_OBJECT_LIBS}
183 # The only purpose of RTMemprof_dynamic_version_script_dummy is to
184 # carry a dependency of the shared runtime on the version script.
185 # Replacing it with a straightforward
186 # add_dependencies(clang_rt.memprof-dynamic-${arch} clang_rt.memprof-dynamic-${arch}-version-list)
187 # generates an order-only dependency in ninja.
188 RTMemprof_dynamic_version_script_dummy
189 ${MEMPROF_DYNAMIC_WEAK_INTERCEPTION}
190 CFLAGS ${MEMPROF_DYNAMIC_CFLAGS}
191 LINK_FLAGS ${MEMPROF_DYNAMIC_LINK_FLAGS}
192 ${VERSION_SCRIPT_FLAG}
193 LINK_LIBS ${MEMPROF_DYNAMIC_LIBS}
194 DEFS ${MEMPROF_DYNAMIC_DEFINITIONS}
195 PARENT_TARGET memprof)
197 if (SANITIZER_USE_SYMBOLS)
198 add_sanitizer_rt_symbols(clang_rt.memprof_cxx
200 add_dependencies(memprof clang_rt.memprof_cxx-${arch}-symbols)
201 add_sanitizer_rt_symbols(clang_rt.memprof
203 EXTRA memprof.syms.extra)
204 add_dependencies(memprof clang_rt.memprof-${arch}-symbols)
209 if(COMPILER_RT_INCLUDE_TESTS)
210 add_subdirectory(tests)