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