blob: c0fa7c0392b7681023477e9469e14cc40f0d0b19 [file] [log] [blame]
Brian Silverman660d6092015-11-26 18:41:59 -05001licenses(['notice'])
2
Austin Schuh4f857292018-02-15 23:42:04 -08003load('//tools/build_rules:select.bzl', 'cpu_select', 'compiler_select')
4load('//tools/build_rules:empty_main.bzl', 'empty_main_if_asan')
Brian Silverman660d6092015-11-26 18:41:59 -05005
6common_copts = [
7 # Stuff from their Makefile.
Austin Schuh94f51e92017-10-30 19:25:32 -07008 '-Wno-cast-align',
Brian Silverman660d6092015-11-26 18:41:59 -05009 '-Wno-sign-compare',
10 '-fno-builtin-malloc',
11 '-fno-builtin-free',
12 '-fno-builtin-realloc',
13 '-fno-builtin-calloc',
14 '-fno-builtin-cfree',
15 '-fno-builtin-memalign',
16 '-fno-builtin-posix_memalign',
17 '-fno-builtin-valloc',
18 '-fno-builtin-pvalloc',
19 '-Wno-unused-result',
20 '-fno-omit-frame-pointer',
21 '-DNDEBUG',
22
23 # Stuff to make it work for us.
24 '-Ithird_party/gperftools/src/',
25 '-Ithird_party/empty_config_h',
26 '-Wno-unused-parameter',
27 '-Wno-missing-field-initializers',
28 '-Wno-unused-function',
29 '-Wno-unused-variable',
30 '-Wno-format-nonliteral',
31 '-Wno-switch-enum',
32 '-Wno-error=cast-align',
33 '-Wno-error=cast-qual',
34
35 # Stuff pulled out of config.h.
36 '-DHAVE_BUILTIN_EXPECT=1',
37 '-DHAVE_DECL_CFREE=1',
38 '-DHAVE_DECL_MEMALIGN=1',
39 '-DHAVE_DECL_POSIX_MEMALIGN=1',
40 '-DHAVE_DECL_PVALLOC=1',
41 '-DHAVE_DECL_UNAME=1',
42 '-DHAVE_DECL_VALLOC=1',
43 '-DHAVE_DLFCN_H=1',
44 '-DHAVE_ELF32_VERSYM=1',
45 '-DHAVE_EXECINFO_H=1',
46 '-DHAVE_FCNTL_H=1',
47 '-DHAVE_FEATURES_H=1',
48 '-DHAVE_FORK=1',
49 '-DHAVE_GETEUID=1',
50 '-DHAVE_GLOB_H=1',
51 '-DHAVE_GRP_H=1',
52 '-DHAVE_INTTYPES_H=1',
53 '-DHAVE_LINUX_PTRACE_H=1',
54 '-DHAVE_LINUX_SIGEV_THREAD_ID=1',
55 '-DHAVE_MALLOC_H=1',
56 '-DHAVE_MEMORY_H=1',
57 '-DHAVE_MMAP=1',
58 '-DHAVE_NAMESPACES=1',
59 '-DHAVE_POLL_H=1',
60 '-DHAVE_PROGRAM_INVOCATION_NAME=1',
61 '-DHAVE_PTHREAD=1',
62 '-DHAVE_PWD_H=1',
63 '-DHAVE_SBRK=1',
64 '-DHAVE_SCHED_H=1',
65 '-DHAVE_STDINT_H=1',
66 '-DHAVE_STDLIB_H=1',
67 '-DHAVE_STRINGS_H=1',
68 '-DHAVE_STRING_H=1',
69 '-DHAVE_STRUCT_MALLINFO=1',
70 '-DHAVE_SYS_CDEFS_H=1',
71 '-DHAVE_SYS_PRCTL_H=1',
72 '-DHAVE_SYS_RESOURCE_H=1',
73 '-DHAVE_SYS_SOCKET_H=1',
74 '-DHAVE_SYS_STAT_H=1',
75 '-DHAVE_SYS_SYSCALL_H=1',
76 '-DHAVE_SYS_TYPES_H=1',
77 '-DHAVE_SYS_UCONTEXT_H=1',
78 '-DHAVE_SYS_WAIT_H=1',
79 '-DHAVE_TLS=1',
80 '-DHAVE_UCONTEXT_H=1',
81 '-DHAVE_UNISTD_H=1',
82 '-DHAVE_UNWIND_H=1',
83 '-DHAVE___ATTRIBUTE__=1',
84 '-DHAVE___ENVIRON=1',
85 '-DMALLOC_HOOK_MAYBE_VOLATILE=volatile',
86 '-DPERFTOOLS_DLL_DECL=',
87 '-DSTDC_HEADERS=1',
88 '-DSTL_NAMESPACE=std',
89 '-DPACKAGE_STRING=\\"gperftools\\ 2.4\\"',
90 '-DPACKAGE_BUGREPORT=\\"http://frc971.org/contact\\"',
91 '-DPACKAGE_VERSION=\\"2.4\\"',
92] + cpu_select({
93 'amd64': [
94 '-DHAVE_GETPAGESZE=1',
95 '-DHAVE_SYS_PARAM_H=1',
96 '-DPC_FROM_UCONTEXT=uc_mcontext.gregs[REG_RIP]',
97 '-DPRIdS=\\"ld\\"',
98 '-DPRIuS=\\"lu\\"',
99 '-DPRIxS=\\"lx\\"',
100 ],
Brian Silverman0d57fc82016-01-24 21:02:53 -0500101 'arm': [
Brian Silverman660d6092015-11-26 18:41:59 -0500102 '-DPC_FROM_UCONTEXT=uc_mcontext.arm_pc',
103 '-DPRIdS=\\"d\\"',
104 '-DPRIuS=\\"u\\"',
105 '-DPRIxS=\\"x\\"',
106 ],
107}) + compiler_select({
108 'clang': [
109 '-Wno-unused-const-variable',
110 '-Wno-gnu-alignof-expression',
111 '-Wno-unused-private-field',
112 ],
113 'gcc': [],
114})
115
116cc_library(
117 name = 'tcmalloc',
118 visibility = ['//visibility:public'],
119 hdrs = glob([
120 'src/*.h',
121 'src/base/*.h',
122 'src/gperftools/*.h',
123 ]) + [
124 'src/third_party/valgrind.h',
125 ],
126 srcs = glob(include = [
127 'src/*.cc',
128 'src/*.c',
129 'src/base/*.cc',
130 'src/base/*.c',
131 ], exclude = [
132 '**/*_unittest.cc',
133 '**/*_test.cc',
134 'src/debugallocation.cc',
135 ]),
136 deps = [
Brian Silverman660d6092015-11-26 18:41:59 -0500137 '//third_party/empty_config_h',
138 ],
139 copts = common_copts,
Brian Silvermand1c19fb2016-07-07 00:10:57 -0700140 linkopts = [
Philipp Schraderb3a057e2018-03-10 18:59:40 -0800141 '-lrt',
Brian Silvermand1c19fb2016-07-07 00:10:57 -0700142 '-pthread',
143 ],
Brian Silvermanb61fa502016-01-02 14:14:11 -0800144 alwayslink = True,
Brian Silverman660d6092015-11-26 18:41:59 -0500145 nocopts = '-std=gnu\+\+1y',
146)
147
148cc_library(
149 name = 'testutil',
150 srcs = [
151 'src/tests/testutil.cc',
152 ],
153 hdrs = [
154 'src/tests/testutil.h',
155 ],
156 deps = [
157 ':tcmalloc',
158 ],
159 copts = common_copts,
160)
161
162cc_test(
163 name = 'low_level_alloc_unittest',
164 srcs = [
165 'src/tests/low_level_alloc_unittest.cc',
166 ],
167 defines = [
168 'NO_TCMALLOC_SAMPLES',
169 ],
170 deps = [
171 ':tcmalloc',
172 ],
173 copts = common_copts,
174 size = 'medium',
175)
176
177cc_test(
178 name = 'atomicops_unittest',
179 srcs = [
180 'src/tests/atomicops_unittest.cc',
181 ],
182 deps = [
183 ':tcmalloc',
184 ],
185 copts = common_copts,
186 size = 'small',
187)
188
189cc_test(
190 name = 'stacktrace_unittest',
191 srcs = [
192 'src/tests/stacktrace_unittest.cc',
193 ],
194 deps = [
195 ':tcmalloc',
196 ],
197 copts = common_copts,
198 size = 'small',
199)
200
201cc_test(
202 name = 'tcmalloc_unittest',
203 srcs = empty_main_if_asan([
204 'src/tests/tcmalloc_unittest.cc',
205 ]),
206 deps = [
207 ':tcmalloc',
208 ':testutil',
209 ],
210 copts = common_copts + [
211 '-fno-builtin',
Adrian Brandemuehl2ed74352017-08-23 20:29:57 -0700212 # Add this back in when we upgrade clang.
213 #'-Wno-mismatched-new-delete',
Brian Silverman660d6092015-11-26 18:41:59 -0500214 ],
215 size = 'small',
216)
217
218cc_test(
219 name = 'tcmalloc_large_unittest',
220 srcs = empty_main_if_asan([
221 'src/tests/tcmalloc_large_unittest.cc',
222 ]),
223 deps = [
224 ':tcmalloc',
225 ],
226 copts = common_copts + [
227 '-fno-builtin',
228 ],
229 size = 'small',
230)
231
232cc_test(
233 name = 'addressmap_unittest',
234 srcs = [
235 'src/tests/addressmap_unittest.cc',
236 ],
237 deps = [
238 ':tcmalloc',
239 ],
240 copts = common_copts,
Brian Silvermaned79de62015-11-28 18:10:17 -0500241 size = 'medium',
Brian Silverman660d6092015-11-26 18:41:59 -0500242)
243
244cc_test(
245 name = 'system_alloc_unittest',
246 srcs = empty_main_if_asan([
247 'src/tests/system-alloc_unittest.cc',
248 ]),
249 deps = [
250 ':tcmalloc',
251 ],
252 copts = common_copts + [
253 '-fno-builtin',
254 ],
255 size = 'small',
256)
257
258cc_test(
259 name = 'packed_cache_test',
260 srcs = [
261 'src/tests/packed-cache_test.cc',
262 ],
263 deps = [
264 ':tcmalloc',
265 ],
266 copts = common_copts,
267 size = 'small',
268)
269
270cc_test(
271 name = 'frag_unittest',
272 srcs = [
273 'src/tests/frag_unittest.cc',
274 ],
275 deps = [
276 ':tcmalloc',
277 ],
278 copts = common_copts,
279 size = 'small',
280)
281
282cc_test(
283 name = 'markidle_unittest',
284 srcs = empty_main_if_asan([
285 'src/tests/markidle_unittest.cc',
286 ]),
287 deps = [
288 ':tcmalloc',
289 ':testutil',
290 ],
291 copts = common_copts,
292 size = 'small',
293)
294
295cc_test(
296 name = 'current_allocated_bytes_test',
297 srcs = [
298 'src/tests/current_allocated_bytes_test.cc',
299 ],
300 deps = [
301 ':tcmalloc',
302 ],
303 copts = common_copts,
304 size = 'small',
305)
306
307cc_test(
308 name = 'malloc_hook_test',
309 srcs = [
310 'src/tests/malloc_hook_test.cc',
311 ],
312 deps = [
313 ':tcmalloc',
314 ':testutil',
315 ],
316 copts = common_copts + compiler_select({
317 'gcc': [
318 '-Wno-maybe-uninitialized',
319 ],
320 'clang': [],
321 }),
322 size = 'small',
323)
324
325cc_test(
326 name = 'malloc_extension_test',
327 srcs = empty_main_if_asan([
328 'src/tests/malloc_extension_test.cc',
329 ]),
330 deps = [
331 ':tcmalloc',
332 ],
333 copts = common_copts,
334 size = 'small',
335)
336
337cc_test(
338 name = 'malloc_extension_c_test',
339 srcs = empty_main_if_asan([
340 'src/tests/malloc_extension_c_test.c',
341 ]),
342 deps = [
343 ':tcmalloc',
344 ],
345 copts = common_copts,
346 size = 'small',
347)
348
349cc_test(
350 name = 'memalign_unittest',
351 srcs = empty_main_if_asan([
352 'src/tests/memalign_unittest.cc',
353 ]),
354 deps = [
355 ':tcmalloc',
356 ':testutil',
357 ],
358 copts = common_copts,
359 size = 'small',
360)
361
362cc_test(
363 name = 'page_heap_test',
364 srcs = [
365 'src/tests/page_heap_test.cc',
366 ],
367 deps = [
368 ':tcmalloc',
369 ],
370 copts = common_copts,
371 size = 'small',
372)
373
374cc_test(
375 name = 'pagemap_unittest',
376 srcs = empty_main_if_asan([
377 'src/tests/pagemap_unittest.cc',
378 ]),
379 deps = [
380 ':tcmalloc',
381 ],
382 copts = common_copts,
383 size = 'small',
384)
385
386cc_test(
387 name = 'realloc_unittest',
388 srcs = [
389 'src/tests/realloc_unittest.cc',
390 ],
391 deps = [
392 ':tcmalloc',
393 ],
394 copts = common_copts,
395 size = 'small',
396)
397
398cc_test(
399 name = 'stack_trace_table_test',
400 srcs = [
401 'src/tests/stack_trace_table_test.cc',
402 ],
403 deps = [
404 ':tcmalloc',
405 ],
406 copts = common_copts,
407 size = 'small',
408)
409
410cc_test(
411 name = 'thread_dealloc_unittest',
412 srcs = [
413 'src/tests/thread_dealloc_unittest.cc',
414 ],
415 deps = [
416 ':tcmalloc',
417 ':testutil',
418 ],
419 copts = common_copts,
420 size = 'small',
421)
422
423'''
424We don't build this because it actually needs to be in a separate binary.
425cc_test(
426 name = 'debugallocation_test',
427 srcs = [
428 'src/tests/debugallocation_test.cc',
429 ],
430 deps = [
431 ':tcmalloc',
432 ],
433 copts = common_copts,
434 size = 'small',
435)
436'''
437
438cc_test(
439 name = 'tcmalloc_large_heap_fragmentation_unittest',
440 srcs = empty_main_if_asan([
441 'src/tests/large_heap_fragmentation_unittest.cc',
442 ]),
443 deps = [
444 ':tcmalloc',
445 ],
446 copts = common_copts,
447 size = 'small',
448)
449
450cc_test(
451 name = 'raw_printer_test',
452 srcs = [
453 'src/tests/raw_printer_test.cc',
454 ],
455 deps = [
456 ':tcmalloc',
457 ],
458 copts = common_copts,
459 size = 'small',
460)
461
462cc_test(
463 name = 'getpc_test',
464 srcs = empty_main_if_asan([
465 'src/tests/getpc_test.cc',
466 ]),
467 deps = [
468 ':tcmalloc',
469 ],
470 copts = common_copts,
471 size = 'small',
472)
473
474cc_test(
475 name = 'profiledata_unittest',
476 srcs = [
477 'src/tests/profiledata_unittest.cc',
478 ],
479 deps = [
480 ':tcmalloc',
481 ],
482 copts = common_copts,
483 size = 'small',
484)
485
486cc_test(
487 name = 'profile_handler_unittest',
488 srcs = [
489 'src/tests/profile-handler_unittest.cc',
490 ],
491 deps = [
492 ':tcmalloc',
493 ],
494 copts = common_copts,
495 flaky = True,
496 size = 'small',
497)
498
499cc_test(
500 name = 'heap_profiler_unittest',
501 srcs = [
502 'src/tests/heap-profiler_unittest.cc',
503 ],
504 deps = [
505 ':tcmalloc',
506 ],
507 copts = common_copts,
508 size = 'small',
509)
510
511cc_test(
512 name = 'sampler_test',
513 srcs = [
514 'src/tests/sampler_test.cc',
515 ],
516 deps = [
517 ':tcmalloc',
518 ],
519 copts = common_copts + [
520 '-Wno-type-limits',
521 ],
522 size = 'small',
523)