blob: 7813282aad4e14dca717004b29fbaf99ebadcace [file] [log] [blame]
Philipp Schrader9b1790e2018-03-10 20:21:30 -08001licenses(["notice"])
Brian Silverman660d6092015-11-26 18:41:59 -05002
Austin Schuhdde64052019-12-11 20:28:00 -08003load("//tools/build_rules:select.bzl", "compiler_select", "cpu_select")
Philipp Schrader9b1790e2018-03-10 20:21:30 -08004load("//tools/build_rules:empty_main.bzl", "empty_main_if_asan")
Brian Silverman660d6092015-11-26 18:41:59 -05005
6common_copts = [
Austin Schuhdde64052019-12-11 20:28:00 -08007 #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
Austin Schuhdde64052019-12-11 20:28:00 -080023 #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
Austin Schuhdde64052019-12-11 20:28:00 -080035 #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",
Austin Schuha4f69d62020-02-28 13:58:14 -080089 "-DPACKAGE_STRING=\\\"gperftools\\ 2.4\\\"",
Austin Schuha5778ae2020-10-21 21:15:35 -070090 "-DPACKAGE_BUGREPORT=\\\"https://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,
Austin Schuhdde64052019-12-11 20:28:00 -0800139 includes = ["src"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800140 linkopts = [
141 "-lrt",
142 "-lpthread",
143 ],
Austin Schuha4f69d62020-02-28 13:58:14 -0800144 nocopts = "-std=gnu\\+\\+1y",
Philipp Schraderdada1072020-11-24 11:34:46 -0800145 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800146 visibility = ["//visibility:public"],
147 deps = [
148 "//third_party/empty_config_h",
149 ],
150 alwayslink = True,
Brian Silverman660d6092015-11-26 18:41:59 -0500151)
152
153cc_library(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800154 name = "testutil",
155 srcs = [
156 "src/tests/testutil.cc",
Brian Silverman660d6092015-11-26 18:41:59 -0500157 ],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800158 hdrs = [
159 "src/tests/testutil.h",
160 ],
161 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800162 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800163 deps = [
164 ":tcmalloc",
165 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500166)
167
168cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800169 name = "low_level_alloc_unittest",
170 size = "medium",
171 srcs = [
172 "src/tests/low_level_alloc_unittest.cc",
173 ],
174 copts = common_copts,
175 defines = [
176 "NO_TCMALLOC_SAMPLES",
177 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800178 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800179 deps = [
180 ":tcmalloc",
181 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500182)
183
184cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800185 name = "atomicops_unittest",
186 size = "small",
187 srcs = [
188 "src/tests/atomicops_unittest.cc",
189 ],
190 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800191 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800192 deps = [
193 ":tcmalloc",
194 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500195)
196
197cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800198 name = "stacktrace_unittest",
199 size = "small",
200 srcs = [
201 "src/tests/stacktrace_unittest.cc",
202 ],
203 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800204 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800205 deps = [
206 ":tcmalloc",
207 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500208)
209
210cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800211 name = "tcmalloc_unittest",
212 size = "small",
213 srcs = empty_main_if_asan([
214 "src/tests/tcmalloc_unittest.cc",
215 ]),
216 copts = common_copts + [
217 "-fno-builtin",
Austin Schuhdde64052019-12-11 20:28:00 -0800218 #Add this back in when we upgrade clang.
219 #'-Wno-mismatched-new-delete',
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800220 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800221 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800222 deps = [
223 ":tcmalloc",
224 ":testutil",
225 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500226)
227
228cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800229 name = "tcmalloc_large_unittest",
230 size = "small",
231 srcs = empty_main_if_asan([
232 "src/tests/tcmalloc_large_unittest.cc",
233 ]),
234 copts = common_copts + [
235 "-fno-builtin",
236 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800237 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800238 deps = [
239 ":tcmalloc",
240 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500241)
242
243cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800244 name = "addressmap_unittest",
245 size = "medium",
246 srcs = [
247 "src/tests/addressmap_unittest.cc",
248 ],
249 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800250 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800251 deps = [
252 ":tcmalloc",
253 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500254)
255
256cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800257 name = "system_alloc_unittest",
258 size = "small",
259 srcs = empty_main_if_asan([
260 "src/tests/system-alloc_unittest.cc",
261 ]),
262 copts = common_copts + [
263 "-fno-builtin",
264 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800265 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800266 deps = [
267 ":tcmalloc",
268 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500269)
270
271cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800272 name = "packed_cache_test",
273 size = "small",
274 srcs = [
275 "src/tests/packed-cache_test.cc",
276 ],
277 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800278 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800279 deps = [
280 ":tcmalloc",
281 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500282)
283
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800284cc_test(
285 name = "frag_unittest",
286 size = "small",
287 srcs = [
288 "src/tests/frag_unittest.cc",
289 ],
290 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800291 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800292 deps = [
293 ":tcmalloc",
294 ],
295)
296
297cc_test(
298 name = "markidle_unittest",
299 size = "small",
300 srcs = empty_main_if_asan([
301 "src/tests/markidle_unittest.cc",
302 ]),
303 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800304 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800305 deps = [
306 ":tcmalloc",
307 ":testutil",
308 ],
309)
310
311cc_test(
312 name = "current_allocated_bytes_test",
313 size = "small",
314 srcs = [
315 "src/tests/current_allocated_bytes_test.cc",
316 ],
317 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800318 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800319 deps = [
320 ":tcmalloc",
321 ],
322)
323
324cc_test(
325 name = "malloc_hook_test",
326 size = "small",
327 srcs = [
328 "src/tests/malloc_hook_test.cc",
329 ],
330 copts = common_copts + compiler_select({
331 "gcc": [
332 "-Wno-maybe-uninitialized",
333 ],
334 "clang": [],
335 }),
Philipp Schraderdada1072020-11-24 11:34:46 -0800336 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800337 deps = [
338 ":tcmalloc",
339 ":testutil",
340 ],
341)
342
343cc_test(
344 name = "malloc_extension_test",
345 size = "small",
346 srcs = empty_main_if_asan([
347 "src/tests/malloc_extension_test.cc",
348 ]),
349 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800350 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800351 deps = [
352 ":tcmalloc",
353 ],
354)
355
356cc_test(
357 name = "malloc_extension_c_test",
358 size = "small",
359 srcs = empty_main_if_asan([
360 "src/tests/malloc_extension_c_test.c",
361 ]),
362 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800363 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800364 deps = [
365 ":tcmalloc",
366 ],
367)
368
369cc_test(
370 name = "memalign_unittest",
371 size = "small",
372 srcs = empty_main_if_asan([
373 "src/tests/memalign_unittest.cc",
374 ]),
375 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800376 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800377 deps = [
378 ":tcmalloc",
379 ":testutil",
380 ],
381)
382
383cc_test(
384 name = "page_heap_test",
385 size = "small",
386 srcs = [
387 "src/tests/page_heap_test.cc",
388 ],
389 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800390 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800391 deps = [
392 ":tcmalloc",
393 ],
394)
395
396cc_test(
397 name = "pagemap_unittest",
398 size = "small",
399 srcs = empty_main_if_asan([
400 "src/tests/pagemap_unittest.cc",
401 ]),
402 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800403 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800404 deps = [
405 ":tcmalloc",
406 ],
407)
408
409cc_test(
410 name = "realloc_unittest",
411 size = "small",
412 srcs = [
413 "src/tests/realloc_unittest.cc",
414 ],
415 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800416 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800417 deps = [
418 ":tcmalloc",
419 ],
420)
421
422cc_test(
423 name = "stack_trace_table_test",
424 size = "small",
425 srcs = [
426 "src/tests/stack_trace_table_test.cc",
427 ],
428 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800429 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800430 deps = [
431 ":tcmalloc",
432 ],
433)
434
435cc_test(
436 name = "thread_dealloc_unittest",
437 size = "small",
438 srcs = [
439 "src/tests/thread_dealloc_unittest.cc",
440 ],
441 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800442 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800443 deps = [
444 ":tcmalloc",
445 ":testutil",
446 ],
447)
448
449"""
Brian Silverman660d6092015-11-26 18:41:59 -0500450We don't build this because it actually needs to be in a separate binary.
451cc_test(
452 name = 'debugallocation_test',
453 srcs = [
454 'src/tests/debugallocation_test.cc',
455 ],
456 deps = [
457 ':tcmalloc',
458 ],
459 copts = common_copts,
460 size = 'small',
461)
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800462"""
Brian Silverman660d6092015-11-26 18:41:59 -0500463
464cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800465 name = "tcmalloc_large_heap_fragmentation_unittest",
466 size = "small",
467 srcs = empty_main_if_asan([
468 "src/tests/large_heap_fragmentation_unittest.cc",
469 ]),
470 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800471 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800472 deps = [
473 ":tcmalloc",
474 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500475)
476
477cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800478 name = "raw_printer_test",
479 size = "small",
480 srcs = [
481 "src/tests/raw_printer_test.cc",
482 ],
483 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800484 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800485 deps = [
486 ":tcmalloc",
487 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500488)
489
490cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800491 name = "getpc_test",
492 size = "small",
493 srcs = empty_main_if_asan([
494 "src/tests/getpc_test.cc",
495 ]),
496 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800497 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800498 deps = [
499 ":tcmalloc",
500 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500501)
502
503cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800504 name = "profiledata_unittest",
505 size = "small",
506 srcs = [
507 "src/tests/profiledata_unittest.cc",
508 ],
509 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800510 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800511 deps = [
512 ":tcmalloc",
513 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500514)
515
516cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800517 name = "profile_handler_unittest",
518 size = "small",
519 srcs = [
520 "src/tests/profile-handler_unittest.cc",
521 ],
522 copts = common_copts,
523 flaky = True,
Philipp Schraderdada1072020-11-24 11:34:46 -0800524 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800525 deps = [
526 ":tcmalloc",
527 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500528)
529
530cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800531 name = "heap_profiler_unittest",
532 size = "small",
533 srcs = [
534 "src/tests/heap-profiler_unittest.cc",
535 ],
536 copts = common_copts,
Philipp Schraderdada1072020-11-24 11:34:46 -0800537 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800538 deps = [
539 ":tcmalloc",
540 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500541)
542
543cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800544 name = "sampler_test",
545 size = "small",
546 srcs = [
547 "src/tests/sampler_test.cc",
548 ],
549 copts = common_copts + [
550 "-Wno-type-limits",
551 ],
Philipp Schraderdada1072020-11-24 11:34:46 -0800552 target_compatible_with = ["@platforms//os:linux"],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800553 deps = [
554 ":tcmalloc",
555 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500556)