blob: d5a742ea0350af09b0be44fcde9adf00198863eb [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 = [
Philipp Schrader9b1790e2018-03-10 20:21:30 -08007 # Stuff from their Makefile.
8 "-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
Philipp Schrader9b1790e2018-03-10 20:21:30 -080023 # 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",
Brian Silverman660d6092015-11-26 18:41:59 -050034
Philipp Schrader9b1790e2018-03-10 20:21:30 -080035 # 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\\\"",
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 ],
148 alwayslink = True,
Brian Silverman660d6092015-11-26 18:41:59 -0500149)
150
151cc_library(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800152 name = "testutil",
153 srcs = [
154 "src/tests/testutil.cc",
Brian Silverman660d6092015-11-26 18:41:59 -0500155 ],
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800156 hdrs = [
157 "src/tests/testutil.h",
158 ],
159 copts = common_copts,
160 deps = [
161 ":tcmalloc",
162 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500163)
164
165cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800166 name = "low_level_alloc_unittest",
167 size = "medium",
168 srcs = [
169 "src/tests/low_level_alloc_unittest.cc",
170 ],
171 copts = common_copts,
172 defines = [
173 "NO_TCMALLOC_SAMPLES",
174 ],
175 deps = [
176 ":tcmalloc",
177 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500178)
179
180cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800181 name = "atomicops_unittest",
182 size = "small",
183 srcs = [
184 "src/tests/atomicops_unittest.cc",
185 ],
186 copts = common_copts,
187 deps = [
188 ":tcmalloc",
189 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500190)
191
192cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800193 name = "stacktrace_unittest",
194 size = "small",
195 srcs = [
196 "src/tests/stacktrace_unittest.cc",
197 ],
198 copts = common_copts,
199 deps = [
200 ":tcmalloc",
201 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500202)
203
204cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800205 name = "tcmalloc_unittest",
206 size = "small",
207 srcs = empty_main_if_asan([
208 "src/tests/tcmalloc_unittest.cc",
209 ]),
210 copts = common_copts + [
211 "-fno-builtin",
212 # Add this back in when we upgrade clang.
213 #'-Wno-mismatched-new-delete',
214 ],
215 deps = [
216 ":tcmalloc",
217 ":testutil",
218 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500219)
220
221cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800222 name = "tcmalloc_large_unittest",
223 size = "small",
224 srcs = empty_main_if_asan([
225 "src/tests/tcmalloc_large_unittest.cc",
226 ]),
227 copts = common_copts + [
228 "-fno-builtin",
229 ],
230 deps = [
231 ":tcmalloc",
232 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500233)
234
235cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800236 name = "addressmap_unittest",
237 size = "medium",
238 srcs = [
239 "src/tests/addressmap_unittest.cc",
240 ],
241 copts = common_copts,
242 deps = [
243 ":tcmalloc",
244 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500245)
246
247cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800248 name = "system_alloc_unittest",
249 size = "small",
250 srcs = empty_main_if_asan([
251 "src/tests/system-alloc_unittest.cc",
252 ]),
253 copts = common_copts + [
254 "-fno-builtin",
255 ],
256 deps = [
257 ":tcmalloc",
258 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500259)
260
261cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800262 name = "packed_cache_test",
263 size = "small",
264 srcs = [
265 "src/tests/packed-cache_test.cc",
266 ],
267 copts = common_copts,
268 deps = [
269 ":tcmalloc",
270 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500271)
272
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800273cc_test(
274 name = "frag_unittest",
275 size = "small",
276 srcs = [
277 "src/tests/frag_unittest.cc",
278 ],
279 copts = common_copts,
280 deps = [
281 ":tcmalloc",
282 ],
283)
284
285cc_test(
286 name = "markidle_unittest",
287 size = "small",
288 srcs = empty_main_if_asan([
289 "src/tests/markidle_unittest.cc",
290 ]),
291 copts = common_copts,
292 deps = [
293 ":tcmalloc",
294 ":testutil",
295 ],
296)
297
298cc_test(
299 name = "current_allocated_bytes_test",
300 size = "small",
301 srcs = [
302 "src/tests/current_allocated_bytes_test.cc",
303 ],
304 copts = common_copts,
305 deps = [
306 ":tcmalloc",
307 ],
308)
309
310cc_test(
311 name = "malloc_hook_test",
312 size = "small",
313 srcs = [
314 "src/tests/malloc_hook_test.cc",
315 ],
316 copts = common_copts + compiler_select({
317 "gcc": [
318 "-Wno-maybe-uninitialized",
319 ],
320 "clang": [],
321 }),
322 deps = [
323 ":tcmalloc",
324 ":testutil",
325 ],
326)
327
328cc_test(
329 name = "malloc_extension_test",
330 size = "small",
331 srcs = empty_main_if_asan([
332 "src/tests/malloc_extension_test.cc",
333 ]),
334 copts = common_copts,
335 deps = [
336 ":tcmalloc",
337 ],
338)
339
340cc_test(
341 name = "malloc_extension_c_test",
342 size = "small",
343 srcs = empty_main_if_asan([
344 "src/tests/malloc_extension_c_test.c",
345 ]),
346 copts = common_copts,
347 deps = [
348 ":tcmalloc",
349 ],
350)
351
352cc_test(
353 name = "memalign_unittest",
354 size = "small",
355 srcs = empty_main_if_asan([
356 "src/tests/memalign_unittest.cc",
357 ]),
358 copts = common_copts,
359 deps = [
360 ":tcmalloc",
361 ":testutil",
362 ],
363)
364
365cc_test(
366 name = "page_heap_test",
367 size = "small",
368 srcs = [
369 "src/tests/page_heap_test.cc",
370 ],
371 copts = common_copts,
372 deps = [
373 ":tcmalloc",
374 ],
375)
376
377cc_test(
378 name = "pagemap_unittest",
379 size = "small",
380 srcs = empty_main_if_asan([
381 "src/tests/pagemap_unittest.cc",
382 ]),
383 copts = common_copts,
384 deps = [
385 ":tcmalloc",
386 ],
387)
388
389cc_test(
390 name = "realloc_unittest",
391 size = "small",
392 srcs = [
393 "src/tests/realloc_unittest.cc",
394 ],
395 copts = common_copts,
396 deps = [
397 ":tcmalloc",
398 ],
399)
400
401cc_test(
402 name = "stack_trace_table_test",
403 size = "small",
404 srcs = [
405 "src/tests/stack_trace_table_test.cc",
406 ],
407 copts = common_copts,
408 deps = [
409 ":tcmalloc",
410 ],
411)
412
413cc_test(
414 name = "thread_dealloc_unittest",
415 size = "small",
416 srcs = [
417 "src/tests/thread_dealloc_unittest.cc",
418 ],
419 copts = common_copts,
420 deps = [
421 ":tcmalloc",
422 ":testutil",
423 ],
424)
425
426"""
Brian Silverman660d6092015-11-26 18:41:59 -0500427We don't build this because it actually needs to be in a separate binary.
428cc_test(
429 name = 'debugallocation_test',
430 srcs = [
431 'src/tests/debugallocation_test.cc',
432 ],
433 deps = [
434 ':tcmalloc',
435 ],
436 copts = common_copts,
437 size = 'small',
438)
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800439"""
Brian Silverman660d6092015-11-26 18:41:59 -0500440
441cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800442 name = "tcmalloc_large_heap_fragmentation_unittest",
443 size = "small",
444 srcs = empty_main_if_asan([
445 "src/tests/large_heap_fragmentation_unittest.cc",
446 ]),
447 copts = common_copts,
448 deps = [
449 ":tcmalloc",
450 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500451)
452
453cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800454 name = "raw_printer_test",
455 size = "small",
456 srcs = [
457 "src/tests/raw_printer_test.cc",
458 ],
459 copts = common_copts,
460 deps = [
461 ":tcmalloc",
462 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500463)
464
465cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800466 name = "getpc_test",
467 size = "small",
468 srcs = empty_main_if_asan([
469 "src/tests/getpc_test.cc",
470 ]),
471 copts = common_copts,
472 deps = [
473 ":tcmalloc",
474 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500475)
476
477cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800478 name = "profiledata_unittest",
479 size = "small",
480 srcs = [
481 "src/tests/profiledata_unittest.cc",
482 ],
483 copts = common_copts,
484 deps = [
485 ":tcmalloc",
486 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500487)
488
489cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800490 name = "profile_handler_unittest",
491 size = "small",
492 srcs = [
493 "src/tests/profile-handler_unittest.cc",
494 ],
495 copts = common_copts,
496 flaky = True,
497 deps = [
498 ":tcmalloc",
499 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500500)
501
502cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800503 name = "heap_profiler_unittest",
504 size = "small",
505 srcs = [
506 "src/tests/heap-profiler_unittest.cc",
507 ],
508 copts = common_copts,
509 deps = [
510 ":tcmalloc",
511 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500512)
513
514cc_test(
Philipp Schrader9b1790e2018-03-10 20:21:30 -0800515 name = "sampler_test",
516 size = "small",
517 srcs = [
518 "src/tests/sampler_test.cc",
519 ],
520 copts = common_copts + [
521 "-Wno-type-limits",
522 ],
523 deps = [
524 ":tcmalloc",
525 ],
Brian Silverman660d6092015-11-26 18:41:59 -0500526)