xref: /openbsd-src/gnu/llvm/compiler-rt/lib/memprof/CMakeLists.txt (revision 810390e339a5425391477d5d41c78d7cab2424ac)
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_mibmap.cpp
12  memprof_posix.cpp
13  memprof_rawprofile.cpp
14  memprof_rtl.cpp
15  memprof_shadow_setup.cpp
16  memprof_stack.cpp
17  memprof_stats.cpp
18  memprof_thread.cpp
19  )
20
21set(MEMPROF_CXX_SOURCES
22  memprof_new_delete.cpp
23  )
24
25set(MEMPROF_PREINIT_SOURCES
26  memprof_preinit.cpp
27  )
28
29SET(MEMPROF_HEADERS
30  memprof_allocator.h
31  memprof_descriptions.h
32  memprof_flags.h
33  memprof_flags.inc
34  memprof_init_version.h
35  memprof_interceptors.h
36  memprof_interceptors_memintrinsics.h
37  memprof_interface_internal.h
38  memprof_internal.h
39  memprof_mapping.h
40  memprof_meminfoblock.h
41  memprof_mibmap.h
42  memprof_rawprofile.h
43  memprof_stack.h
44  memprof_stats.h
45  memprof_thread.h
46  )
47
48include_directories(..)
49include_directories(../../include)
50
51set(MEMPROF_CFLAGS ${SANITIZER_COMMON_CFLAGS})
52set(MEMPROF_COMMON_DEFINITIONS "")
53
54# Too many existing bugs, needs cleanup.
55append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format MEMPROF_CFLAGS)
56
57append_rtti_flag(OFF MEMPROF_CFLAGS)
58
59set(MEMPROF_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
60
61set(MEMPROF_DYNAMIC_DEFINITIONS
62  ${MEMPROF_COMMON_DEFINITIONS} MEMPROF_DYNAMIC=1)
63
64set(MEMPROF_DYNAMIC_CFLAGS ${MEMPROF_CFLAGS})
65append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
66  -ftls-model=initial-exec MEMPROF_DYNAMIC_CFLAGS)
67
68set(MEMPROF_DYNAMIC_LIBS
69  ${COMPILER_RT_UNWINDER_LINK_LIBS}
70  ${SANITIZER_CXX_ABI_LIBRARIES}
71  ${SANITIZER_COMMON_LINK_LIBS})
72
73append_list_if(COMPILER_RT_HAS_LIBDL dl MEMPROF_DYNAMIC_LIBS)
74append_list_if(COMPILER_RT_HAS_LIBRT rt MEMPROF_DYNAMIC_LIBS)
75append_list_if(COMPILER_RT_HAS_LIBM m MEMPROF_DYNAMIC_LIBS)
76append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread MEMPROF_DYNAMIC_LIBS)
77append_list_if(COMPILER_RT_HAS_LIBLOG log MEMPROF_DYNAMIC_LIBS)
78
79# Compile MemProf sources into an object library.
80
81add_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}
88  DEPS ${MEMPROF_DEPS})
89
90add_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}
96  DEPS ${MEMPROF_DEPS})
97add_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})
104add_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})
111
112file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
113add_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})
119
120# Build MemProf runtimes shipped with Clang.
121add_compiler_rt_component(memprof)
122
123# Build separate libraries for each target.
124
125set(MEMPROF_COMMON_RUNTIME_OBJECT_LIBS
126  RTInterception
127  RTSanitizerCommon
128  RTSanitizerCommonLibc
129  RTSanitizerCommonCoverage
130  RTSanitizerCommonSymbolizer)
131
132add_compiler_rt_runtime(clang_rt.memprof
133  STATIC
134  ARCHS ${MEMPROF_SUPPORTED_ARCH}
135  OBJECT_LIBS RTMemprof_preinit
136              RTMemprof
137              ${MEMPROF_COMMON_RUNTIME_OBJECT_LIBS}
138  CFLAGS ${MEMPROF_CFLAGS}
139  DEFS ${MEMPROF_COMMON_DEFINITIONS}
140  PARENT_TARGET memprof)
141
142add_compiler_rt_runtime(clang_rt.memprof_cxx
143  STATIC
144  ARCHS ${MEMPROF_SUPPORTED_ARCH}
145  OBJECT_LIBS RTMemprof_cxx
146  CFLAGS ${MEMPROF_CFLAGS}
147  DEFS ${MEMPROF_COMMON_DEFINITIONS}
148  PARENT_TARGET memprof)
149
150add_compiler_rt_runtime(clang_rt.memprof-preinit
151  STATIC
152  ARCHS ${MEMPROF_SUPPORTED_ARCH}
153  OBJECT_LIBS RTMemprof_preinit
154  CFLAGS ${MEMPROF_CFLAGS}
155  DEFS ${MEMPROF_COMMON_DEFINITIONS}
156  PARENT_TARGET memprof)
157
158foreach(arch ${MEMPROF_SUPPORTED_ARCH})
159  if (UNIX)
160    add_sanitizer_rt_version_list(clang_rt.memprof-dynamic-${arch}
161                                  LIBS clang_rt.memprof-${arch} clang_rt.memprof_cxx-${arch}
162                                  EXTRA memprof.syms.extra)
163    set(VERSION_SCRIPT_FLAG
164         -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.memprof-dynamic-${arch}.vers)
165    set_property(SOURCE
166      ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
167      APPEND PROPERTY
168      OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.memprof-dynamic-${arch}.vers)
169  else()
170    set(VERSION_SCRIPT_FLAG)
171  endif()
172
173  set(MEMPROF_DYNAMIC_WEAK_INTERCEPTION)
174
175  add_compiler_rt_runtime(clang_rt.memprof
176    SHARED
177    ARCHS ${arch}
178    OBJECT_LIBS ${MEMPROF_COMMON_RUNTIME_OBJECT_LIBS}
179            RTMemprof_dynamic
180            # The only purpose of RTMemprof_dynamic_version_script_dummy is to
181            # carry a dependency of the shared runtime on the version script.
182            # Replacing it with a straightforward
183            # add_dependencies(clang_rt.memprof-dynamic-${arch} clang_rt.memprof-dynamic-${arch}-version-list)
184            # generates an order-only dependency in ninja.
185            RTMemprof_dynamic_version_script_dummy
186            ${MEMPROF_DYNAMIC_WEAK_INTERCEPTION}
187    CFLAGS ${MEMPROF_DYNAMIC_CFLAGS}
188    LINK_FLAGS ${MEMPROF_DYNAMIC_LINK_FLAGS}
189              ${VERSION_SCRIPT_FLAG}
190    LINK_LIBS ${MEMPROF_DYNAMIC_LIBS}
191    DEFS ${MEMPROF_DYNAMIC_DEFINITIONS}
192    PARENT_TARGET memprof)
193
194  if (SANITIZER_USE_SYMBOLS)
195    add_sanitizer_rt_symbols(clang_rt.memprof_cxx
196      ARCHS ${arch})
197    add_dependencies(memprof clang_rt.memprof_cxx-${arch}-symbols)
198    add_sanitizer_rt_symbols(clang_rt.memprof
199      ARCHS ${arch}
200      EXTRA memprof.syms.extra)
201    add_dependencies(memprof clang_rt.memprof-${arch}-symbols)
202  endif()
203endforeach()
204
205
206if(COMPILER_RT_INCLUDE_TESTS)
207  add_subdirectory(tests)
208endif()
209