blob: f9cf18541d95beb42115e6f4b158685bb1648c48 [file] [log] [blame]
Philipp Schrader9b1790e2018-03-10 20:21:30 -08001licenses(["notice"])
Brian Silverman660d6092015-11-26 18:41:59 -05002
Philipp Schrader9b1790e2018-03-10 20:21:30 -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 = [
Alex Perrycb7da4b2019-08-28 19:35:56 -07007#Stuff from their Makefile.
Philipp Schrader9b1790e2018-03-10 20:21:30 -08008 "-Wno-cast-align",
9 "-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",
Brian Silverman660d6092015-11-26 18:41:59 -050022
Alex Perrycb7da4b2019-08-28 19:35:56 -070023#Stuff to make it work for us.
Philipp Schrader9b1790e2018-03-10 20:21:30 -080024 "-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",
Brian Silverman660d6092015-11-26 18:41:59 -050034
Alex Perrycb7da4b2019-08-28 19:35:56 -070035#Stuff pulled out of config.h.
Philipp Schrader9b1790e2018-03-10 20:21:30 -080036 "-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\\\"",
johnp8a384f92019-01-03 13:10:00 -080090 "-DPACKAGE_BUGREPORT=\\\"http://www.frc971.org/contact\\\"",
Philipp Schrader9b1790e2018-03-10 20:21:30 -080091 "-DPACKAGE_VERSION=\\\"2.4\\\"",
Brian Silverman660d6092015-11-26 18:41:59 -050092] + cpu_select({
Philipp Schrader9b1790e2018-03-10 20:21:30 -080093 "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 ],
101 "arm": [
102 "-DPC_FROM_UCONTEXT=uc_mcontext.arm_pc",
103 "-DPRIdS=\\\"d\\\"",
104 "-DPRIuS=\\\"u\\\"",
105 "-DPRIxS=\\\"x\\\"",
106 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500107}) + compiler_select({
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800108 "clang": [
109 "-Wno-unused-const-variable",
110 "-Wno-gnu-alignof-expression",
111 "-Wno-unused-private-field",
112 ],
113 "gcc": [],
Brian Silverman660d6092015-11-26 18:41:59 -0500114})
115
116cc_library(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800117 name = "tcmalloc",
118 srcs = glob(
119 include = [
120 "src/*.cc",
121 "src/*.c",
122 "src/base/*.cc",
123 "src/base/*.c",
124 ],
125 exclude = [
126 "**/*_unittest.cc",
127 "**/*_test.cc",
128 "src/debugallocation.cc",
129 ],
130 ),
131 hdrs = glob([
132 "src/*.h",
133 "src/base/*.h",
134 "src/gperftools/*.h",
135 ]) + [
136 "src/third_party/valgrind.h",
137 ],
138 copts = common_copts,
139 linkopts = [
140 "-lrt",
141 "-lpthread",
142 ],
143 nocopts = "-std=gnu\+\+1y",
144 visibility = ["//visibility:public"],
145 deps = [
146 "//third_party/empty_config_h",
147 ],
Alex Perrycb7da4b2019-08-28 19:35:56 -0700148 includes = ["src"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800149 alwayslink = True,
Brian Silverman660d6092015-11-26 18:41:59 -0500150)
151
152cc_library(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800153 name = "testutil",
154 srcs = [
155 "src/tests/testutil.cc",
Brian Silverman660d6092015-11-26 18:41:59 -0500156 ],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800157 hdrs = [
158 "src/tests/testutil.h",
159 ],
160 copts = common_copts,
161 deps = [
162 ":tcmalloc",
163 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500164)
165
166cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800167 name = "low_level_alloc_unittest",
168 size = "medium",
169 srcs = [
170 "src/tests/low_level_alloc_unittest.cc",
171 ],
172 copts = common_copts,
173 defines = [
174 "NO_TCMALLOC_SAMPLES",
175 ],
176 deps = [
177 ":tcmalloc",
178 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500179)
180
181cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800182 name = "atomicops_unittest",
183 size = "small",
184 srcs = [
185 "src/tests/atomicops_unittest.cc",
186 ],
187 copts = common_copts,
188 deps = [
189 ":tcmalloc",
190 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500191)
192
193cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800194 name = "stacktrace_unittest",
195 size = "small",
196 srcs = [
197 "src/tests/stacktrace_unittest.cc",
198 ],
199 copts = common_copts,
200 deps = [
201 ":tcmalloc",
202 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500203)
204
205cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800206 name = "tcmalloc_unittest",
207 size = "small",
208 srcs = empty_main_if_asan([
209 "src/tests/tcmalloc_unittest.cc",
210 ]),
211 copts = common_copts + [
212 "-fno-builtin",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700213#Add this back in when we upgrade clang.
214#'-Wno-mismatched-new-delete',
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800215 ],
216 deps = [
217 ":tcmalloc",
218 ":testutil",
219 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500220)
221
222cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800223 name = "tcmalloc_large_unittest",
224 size = "small",
225 srcs = empty_main_if_asan([
226 "src/tests/tcmalloc_large_unittest.cc",
227 ]),
228 copts = common_copts + [
229 "-fno-builtin",
230 ],
231 deps = [
232 ":tcmalloc",
233 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500234)
235
236cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800237 name = "addressmap_unittest",
238 size = "medium",
239 srcs = [
240 "src/tests/addressmap_unittest.cc",
241 ],
242 copts = common_copts,
243 deps = [
244 ":tcmalloc",
245 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500246)
247
248cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800249 name = "system_alloc_unittest",
250 size = "small",
251 srcs = empty_main_if_asan([
252 "src/tests/system-alloc_unittest.cc",
253 ]),
254 copts = common_copts + [
255 "-fno-builtin",
256 ],
257 deps = [
258 ":tcmalloc",
259 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500260)
261
262cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800263 name = "packed_cache_test",
264 size = "small",
265 srcs = [
266 "src/tests/packed-cache_test.cc",
267 ],
268 copts = common_copts,
269 deps = [
270 ":tcmalloc",
271 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500272)
273
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800274cc_test(
275 name = "frag_unittest",
276 size = "small",
277 srcs = [
278 "src/tests/frag_unittest.cc",
279 ],
280 copts = common_copts,
281 deps = [
282 ":tcmalloc",
283 ],
284)
285
286cc_test(
287 name = "markidle_unittest",
288 size = "small",
289 srcs = empty_main_if_asan([
290 "src/tests/markidle_unittest.cc",
291 ]),
292 copts = common_copts,
293 deps = [
294 ":tcmalloc",
295 ":testutil",
296 ],
297)
298
299cc_test(
300 name = "current_allocated_bytes_test",
301 size = "small",
302 srcs = [
303 "src/tests/current_allocated_bytes_test.cc",
304 ],
305 copts = common_copts,
306 deps = [
307 ":tcmalloc",
308 ],
309)
310
311cc_test(
312 name = "malloc_hook_test",
313 size = "small",
314 srcs = [
315 "src/tests/malloc_hook_test.cc",
316 ],
317 copts = common_copts + compiler_select({
318 "gcc": [
319 "-Wno-maybe-uninitialized",
320 ],
321 "clang": [],
322 }),
323 deps = [
324 ":tcmalloc",
325 ":testutil",
326 ],
327)
328
329cc_test(
330 name = "malloc_extension_test",
331 size = "small",
332 srcs = empty_main_if_asan([
333 "src/tests/malloc_extension_test.cc",
334 ]),
335 copts = common_copts,
336 deps = [
337 ":tcmalloc",
338 ],
339)
340
341cc_test(
342 name = "malloc_extension_c_test",
343 size = "small",
344 srcs = empty_main_if_asan([
345 "src/tests/malloc_extension_c_test.c",
346 ]),
347 copts = common_copts,
348 deps = [
349 ":tcmalloc",
350 ],
351)
352
353cc_test(
354 name = "memalign_unittest",
355 size = "small",
356 srcs = empty_main_if_asan([
357 "src/tests/memalign_unittest.cc",
358 ]),
359 copts = common_copts,
360 deps = [
361 ":tcmalloc",
362 ":testutil",
363 ],
364)
365
366cc_test(
367 name = "page_heap_test",
368 size = "small",
369 srcs = [
370 "src/tests/page_heap_test.cc",
371 ],
372 copts = common_copts,
373 deps = [
374 ":tcmalloc",
375 ],
376)
377
378cc_test(
379 name = "pagemap_unittest",
380 size = "small",
381 srcs = empty_main_if_asan([
382 "src/tests/pagemap_unittest.cc",
383 ]),
384 copts = common_copts,
385 deps = [
386 ":tcmalloc",
387 ],
388)
389
390cc_test(
391 name = "realloc_unittest",
392 size = "small",
393 srcs = [
394 "src/tests/realloc_unittest.cc",
395 ],
396 copts = common_copts,
397 deps = [
398 ":tcmalloc",
399 ],
400)
401
402cc_test(
403 name = "stack_trace_table_test",
404 size = "small",
405 srcs = [
406 "src/tests/stack_trace_table_test.cc",
407 ],
408 copts = common_copts,
409 deps = [
410 ":tcmalloc",
411 ],
412)
413
414cc_test(
415 name = "thread_dealloc_unittest",
416 size = "small",
417 srcs = [
418 "src/tests/thread_dealloc_unittest.cc",
419 ],
420 copts = common_copts,
421 deps = [
422 ":tcmalloc",
423 ":testutil",
424 ],
425)
426
427"""
Brian Silverman660d6092015-11-26 18:41:59 -0500428We don't build this because it actually needs to be in a separate binary.
429cc_test(
430 name = 'debugallocation_test',
431 srcs = [
432 'src/tests/debugallocation_test.cc',
433 ],
434 deps = [
435 ':tcmalloc',
436 ],
437 copts = common_copts,
438 size = 'small',
439)
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800440"""
Brian Silverman660d6092015-11-26 18:41:59 -0500441
442cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800443 name = "tcmalloc_large_heap_fragmentation_unittest",
444 size = "small",
445 srcs = empty_main_if_asan([
446 "src/tests/large_heap_fragmentation_unittest.cc",
447 ]),
448 copts = common_copts,
449 deps = [
450 ":tcmalloc",
451 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500452)
453
454cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800455 name = "raw_printer_test",
456 size = "small",
457 srcs = [
458 "src/tests/raw_printer_test.cc",
459 ],
460 copts = common_copts,
461 deps = [
462 ":tcmalloc",
463 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500464)
465
466cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800467 name = "getpc_test",
468 size = "small",
469 srcs = empty_main_if_asan([
470 "src/tests/getpc_test.cc",
471 ]),
472 copts = common_copts,
473 deps = [
474 ":tcmalloc",
475 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500476)
477
478cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800479 name = "profiledata_unittest",
480 size = "small",
481 srcs = [
482 "src/tests/profiledata_unittest.cc",
483 ],
484 copts = common_copts,
485 deps = [
486 ":tcmalloc",
487 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500488)
489
490cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800491 name = "profile_handler_unittest",
492 size = "small",
493 srcs = [
494 "src/tests/profile-handler_unittest.cc",
495 ],
496 copts = common_copts,
497 flaky = True,
498 deps = [
499 ":tcmalloc",
500 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500501)
502
503cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800504 name = "heap_profiler_unittest",
505 size = "small",
506 srcs = [
507 "src/tests/heap-profiler_unittest.cc",
508 ],
509 copts = common_copts,
510 deps = [
511 ":tcmalloc",
512 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500513)
514
515cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800516 name = "sampler_test",
517 size = "small",
518 srcs = [
519 "src/tests/sampler_test.cc",
520 ],
521 copts = common_copts + [
522 "-Wno-type-limits",
523 ],
524 deps = [
525 ":tcmalloc",
526 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500527)