1# Build for the Memory Profiler runtime support library. 2 3set(MEMPROF_SOURCES 4 memprof_allocator.cpp 5 memprof_descriptions.cpp 6 memprof_flags.cpp 7 memprof_interceptors.cpp 8 memprof_interceptors_memintrinsics.cpp 9 memprof_linux.cpp 10 memprof_malloc_linux.cpp 11 memprof_posix.cpp 12 memprof_rtl.cpp 13 memprof_shadow_setup.cpp 14 memprof_stack.cpp 15 memprof_stats.cpp 16 memprof_thread.cpp 17 ) 18 19set(MEMPROF_CXX_SOURCES 20 memprof_new_delete.cpp 21 ) 22 23set(MEMPROF_PREINIT_SOURCES 24 memprof_preinit.cpp 25 ) 26 27SET(MEMPROF_HEADERS 28 memprof_allocator.h 29 memprof_descriptions.h 30 memprof_flags.h 31 memprof_flags.inc 32 memprof_init_version.h 33 memprof_interceptors.h 34 memprof_interceptors_memintrinsics.h 35 memprof_interface_internal.h 36 memprof_internal.h 37 memprof_mapping.h 38 memprof_stack.h 39 memprof_stats.h 40 memprof_thread.h 41 ) 42 43include_directories(..) 44 45set(MEMPROF_CFLAGS ${SANITIZER_COMMON_CFLAGS}) 46set(MEMPROF_COMMON_DEFINITIONS "") 47 48append_rtti_flag(OFF MEMPROF_CFLAGS) 49 50set(MEMPROF_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS}) 51 52set(MEMPROF_DYNAMIC_DEFINITIONS 53 ${MEMPROF_COMMON_DEFINITIONS} MEMPROF_DYNAMIC=1) 54 55set(MEMPROF_DYNAMIC_CFLAGS ${MEMPROF_CFLAGS}) 56append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC 57 -ftls-model=initial-exec MEMPROF_DYNAMIC_CFLAGS) 58 59set(MEMPROF_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS}) 60 61append_list_if(COMPILER_RT_HAS_LIBDL dl MEMPROF_DYNAMIC_LIBS) 62append_list_if(COMPILER_RT_HAS_LIBRT rt MEMPROF_DYNAMIC_LIBS) 63append_list_if(COMPILER_RT_HAS_LIBM m MEMPROF_DYNAMIC_LIBS) 64append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread MEMPROF_DYNAMIC_LIBS) 65append_list_if(COMPILER_RT_HAS_LIBLOG log MEMPROF_DYNAMIC_LIBS) 66 67# Compile MemProf sources into an object library. 68 69add_compiler_rt_object_libraries(RTMemprof_dynamic 70 OS ${SANITIZER_COMMON_SUPPORTED_OS} 71 ARCHS ${MEMPROF_SUPPORTED_ARCH} 72 SOURCES ${MEMPROF_SOURCES} ${MEMPROF_CXX_SOURCES} 73 ADDITIONAL_HEADERS ${MEMPROF_HEADERS} 74 CFLAGS ${MEMPROF_DYNAMIC_CFLAGS} 75 DEFS ${MEMPROF_DYNAMIC_DEFINITIONS} 76 DEPS ${MEMPROF_DEPS}) 77 78add_compiler_rt_object_libraries(RTMemprof 79 ARCHS ${MEMPROF_SUPPORTED_ARCH} 80 SOURCES ${MEMPROF_SOURCES} 81 ADDITIONAL_HEADERS ${MEMPROF_HEADERS} 82 CFLAGS ${MEMPROF_CFLAGS} 83 DEFS ${MEMPROF_COMMON_DEFINITIONS} 84 DEPS ${MEMPROF_DEPS}) 85add_compiler_rt_object_libraries(RTMemprof_cxx 86 ARCHS ${MEMPROF_SUPPORTED_ARCH} 87 SOURCES ${MEMPROF_CXX_SOURCES} 88 ADDITIONAL_HEADERS ${MEMPROF_HEADERS} 89 CFLAGS ${MEMPROF_CFLAGS} 90 DEFS ${MEMPROF_COMMON_DEFINITIONS} 91 DEPS ${MEMPROF_DEPS}) 92add_compiler_rt_object_libraries(RTMemprof_preinit 93 ARCHS ${MEMPROF_SUPPORTED_ARCH} 94 SOURCES ${MEMPROF_PREINIT_SOURCES} 95 ADDITIONAL_HEADERS ${MEMPROF_HEADERS} 96 CFLAGS ${MEMPROF_CFLAGS} 97 DEFS ${MEMPROF_COMMON_DEFINITIONS} 98 DEPS ${MEMPROF_DEPS}) 99 100file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "") 101add_compiler_rt_object_libraries(RTMemprof_dynamic_version_script_dummy 102 ARCHS ${MEMPROF_SUPPORTED_ARCH} 103 SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp 104 CFLAGS ${MEMPROF_DYNAMIC_CFLAGS} 105 DEFS ${MEMPROF_DYNAMIC_DEFINITIONS} 106 DEPS ${MEMPROF_DEPS}) 107 108# Build MemProf runtimes shipped with Clang. 109add_compiler_rt_component(memprof) 110 111# Build separate libraries for each target. 112 113set(MEMPROF_COMMON_RUNTIME_OBJECT_LIBS 114 RTInterception 115 RTSanitizerCommon 116 RTSanitizerCommonLibc 117 RTSanitizerCommonCoverage 118 RTSanitizerCommonSymbolizer) 119 120add_compiler_rt_runtime(clang_rt.memprof 121 STATIC 122 ARCHS ${MEMPROF_SUPPORTED_ARCH} 123 OBJECT_LIBS RTMemprof_preinit 124 RTMemprof 125 ${MEMPROF_COMMON_RUNTIME_OBJECT_LIBS} 126 CFLAGS ${MEMPROF_CFLAGS} 127 DEFS ${MEMPROF_COMMON_DEFINITIONS} 128 PARENT_TARGET memprof) 129 130add_compiler_rt_runtime(clang_rt.memprof_cxx 131 STATIC 132 ARCHS ${MEMPROF_SUPPORTED_ARCH} 133 OBJECT_LIBS RTMemprof_cxx 134 CFLAGS ${MEMPROF_CFLAGS} 135 DEFS ${MEMPROF_COMMON_DEFINITIONS} 136 PARENT_TARGET memprof) 137 138add_compiler_rt_runtime(clang_rt.memprof-preinit 139 STATIC 140 ARCHS ${MEMPROF_SUPPORTED_ARCH} 141 OBJECT_LIBS RTMemprof_preinit 142 CFLAGS ${MEMPROF_CFLAGS} 143 DEFS ${MEMPROF_COMMON_DEFINITIONS} 144 PARENT_TARGET memprof) 145 146foreach(arch ${MEMPROF_SUPPORTED_ARCH}) 147 if (UNIX) 148 add_sanitizer_rt_version_list(clang_rt.memprof-dynamic-${arch} 149 LIBS clang_rt.memprof-${arch} clang_rt.memprof_cxx-${arch} 150 EXTRA memprof.syms.extra) 151 set(VERSION_SCRIPT_FLAG 152 -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.memprof-dynamic-${arch}.vers) 153 set_property(SOURCE 154 ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp 155 APPEND PROPERTY 156 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.memprof-dynamic-${arch}.vers) 157 else() 158 set(VERSION_SCRIPT_FLAG) 159 endif() 160 161 set(MEMPROF_DYNAMIC_WEAK_INTERCEPTION) 162 163 add_compiler_rt_runtime(clang_rt.memprof 164 SHARED 165 ARCHS ${arch} 166 OBJECT_LIBS ${MEMPROF_COMMON_RUNTIME_OBJECT_LIBS} 167 RTMemprof_dynamic 168 # The only purpose of RTMemprof_dynamic_version_script_dummy is to 169 # carry a dependency of the shared runtime on the version script. 170 # Replacing it with a straightforward 171 # add_dependencies(clang_rt.memprof-dynamic-${arch} clang_rt.memprof-dynamic-${arch}-version-list) 172 # generates an order-only dependency in ninja. 173 RTMemprof_dynamic_version_script_dummy 174 ${MEMPROF_DYNAMIC_WEAK_INTERCEPTION} 175 CFLAGS ${MEMPROF_DYNAMIC_CFLAGS} 176 LINK_FLAGS ${MEMPROF_DYNAMIC_LINK_FLAGS} 177 ${VERSION_SCRIPT_FLAG} 178 LINK_LIBS ${MEMPROF_DYNAMIC_LIBS} 179 DEFS ${MEMPROF_DYNAMIC_DEFINITIONS} 180 PARENT_TARGET memprof) 181 182 if (SANITIZER_USE_SYMBOLS) 183 add_sanitizer_rt_symbols(clang_rt.memprof_cxx 184 ARCHS ${arch}) 185 add_dependencies(memprof clang_rt.memprof_cxx-${arch}-symbols) 186 add_sanitizer_rt_symbols(clang_rt.memprof 187 ARCHS ${arch} 188 EXTRA memprof.syms.extra) 189 add_dependencies(memprof clang_rt.memprof-${arch}-symbols) 190 endif() 191endforeach() 192