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