blob: ada871269a233c7d9543b647939e941cdcbb11a5 [file] [log] [blame]
Brian Silverman660d6092015-11-26 18:41:59 -05001licenses(['notice'])
2
3load('/tools/build_rules/select', 'cpu_select', 'compiler_select')
4load('/tools/build_rules/empty_main', 'empty_main_if_asan')
5
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 Silvermanb61fa502016-01-02 14:14:11 -0800140 alwayslink = True,
Brian Silverman660d6092015-11-26 18:41:59 -0500141 nocopts = '-std=gnu\+\+1y',
142)
143
144cc_library(
145 name = 'testutil',
146 srcs = [
147 'src/tests/testutil.cc',
148 ],
149 hdrs = [
150 'src/tests/testutil.h',
151 ],
152 deps = [
153 ':tcmalloc',
154 ],
155 copts = common_copts,
156)
157
158cc_test(
159 name = 'low_level_alloc_unittest',
160 srcs = [
161 'src/tests/low_level_alloc_unittest.cc',
162 ],
163 defines = [
164 'NO_TCMALLOC_SAMPLES',
165 ],
166 deps = [
167 ':tcmalloc',
168 ],
169 copts = common_copts,
170 size = 'medium',
171)
172
173cc_test(
174 name = 'atomicops_unittest',
175 srcs = [
176 'src/tests/atomicops_unittest.cc',
177 ],
178 deps = [
179 ':tcmalloc',
180 ],
181 copts = common_copts,
182 size = 'small',
183)
184
185cc_test(
186 name = 'stacktrace_unittest',
187 srcs = [
188 'src/tests/stacktrace_unittest.cc',
189 ],
190 deps = [
191 ':tcmalloc',
192 ],
193 copts = common_copts,
194 size = 'small',
195)
196
197cc_test(
198 name = 'tcmalloc_unittest',
199 srcs = empty_main_if_asan([
200 'src/tests/tcmalloc_unittest.cc',
201 ]),
202 deps = [
203 ':tcmalloc',
204 ':testutil',
205 ],
206 copts = common_copts + [
207 '-fno-builtin',
208 ],
209 size = 'small',
210)
211
212cc_test(
213 name = 'tcmalloc_large_unittest',
214 srcs = empty_main_if_asan([
215 'src/tests/tcmalloc_large_unittest.cc',
216 ]),
217 deps = [
218 ':tcmalloc',
219 ],
220 copts = common_copts + [
221 '-fno-builtin',
222 ],
223 size = 'small',
224)
225
226cc_test(
227 name = 'addressmap_unittest',
228 srcs = [
229 'src/tests/addressmap_unittest.cc',
230 ],
231 deps = [
232 ':tcmalloc',
233 ],
234 copts = common_copts,
Brian Silvermaned79de62015-11-28 18:10:17 -0500235 size = 'medium',
Brian Silverman660d6092015-11-26 18:41:59 -0500236)
237
238cc_test(
239 name = 'system_alloc_unittest',
240 srcs = empty_main_if_asan([
241 'src/tests/system-alloc_unittest.cc',
242 ]),
243 deps = [
244 ':tcmalloc',
245 ],
246 copts = common_copts + [
247 '-fno-builtin',
248 ],
249 size = 'small',
250)
251
252cc_test(
253 name = 'packed_cache_test',
254 srcs = [
255 'src/tests/packed-cache_test.cc',
256 ],
257 deps = [
258 ':tcmalloc',
259 ],
260 copts = common_copts,
261 size = 'small',
262)
263
264cc_test(
265 name = 'frag_unittest',
266 srcs = [
267 'src/tests/frag_unittest.cc',
268 ],
269 deps = [
270 ':tcmalloc',
271 ],
272 copts = common_copts,
273 size = 'small',
274)
275
276cc_test(
277 name = 'markidle_unittest',
278 srcs = empty_main_if_asan([
279 'src/tests/markidle_unittest.cc',
280 ]),
281 deps = [
282 ':tcmalloc',
283 ':testutil',
284 ],
285 copts = common_copts,
286 size = 'small',
287)
288
289cc_test(
290 name = 'current_allocated_bytes_test',
291 srcs = [
292 'src/tests/current_allocated_bytes_test.cc',
293 ],
294 deps = [
295 ':tcmalloc',
296 ],
297 copts = common_copts,
298 size = 'small',
299)
300
301cc_test(
302 name = 'malloc_hook_test',
303 srcs = [
304 'src/tests/malloc_hook_test.cc',
305 ],
306 deps = [
307 ':tcmalloc',
308 ':testutil',
309 ],
310 copts = common_copts + compiler_select({
311 'gcc': [
312 '-Wno-maybe-uninitialized',
313 ],
314 'clang': [],
315 }),
316 size = 'small',
317)
318
319cc_test(
320 name = 'malloc_extension_test',
321 srcs = empty_main_if_asan([
322 'src/tests/malloc_extension_test.cc',
323 ]),
324 deps = [
325 ':tcmalloc',
326 ],
327 copts = common_copts,
328 size = 'small',
329)
330
331cc_test(
332 name = 'malloc_extension_c_test',
333 srcs = empty_main_if_asan([
334 'src/tests/malloc_extension_c_test.c',
335 ]),
336 deps = [
337 ':tcmalloc',
338 ],
339 copts = common_copts,
340 size = 'small',
341)
342
343cc_test(
344 name = 'memalign_unittest',
345 srcs = empty_main_if_asan([
346 'src/tests/memalign_unittest.cc',
347 ]),
348 deps = [
349 ':tcmalloc',
350 ':testutil',
351 ],
352 copts = common_copts,
353 size = 'small',
354)
355
356cc_test(
357 name = 'page_heap_test',
358 srcs = [
359 'src/tests/page_heap_test.cc',
360 ],
361 deps = [
362 ':tcmalloc',
363 ],
364 copts = common_copts,
365 size = 'small',
366)
367
368cc_test(
369 name = 'pagemap_unittest',
370 srcs = empty_main_if_asan([
371 'src/tests/pagemap_unittest.cc',
372 ]),
373 deps = [
374 ':tcmalloc',
375 ],
376 copts = common_copts,
377 size = 'small',
378)
379
380cc_test(
381 name = 'realloc_unittest',
382 srcs = [
383 'src/tests/realloc_unittest.cc',
384 ],
385 deps = [
386 ':tcmalloc',
387 ],
388 copts = common_copts,
389 size = 'small',
390)
391
392cc_test(
393 name = 'stack_trace_table_test',
394 srcs = [
395 'src/tests/stack_trace_table_test.cc',
396 ],
397 deps = [
398 ':tcmalloc',
399 ],
400 copts = common_copts,
401 size = 'small',
402)
403
404cc_test(
405 name = 'thread_dealloc_unittest',
406 srcs = [
407 'src/tests/thread_dealloc_unittest.cc',
408 ],
409 deps = [
410 ':tcmalloc',
411 ':testutil',
412 ],
413 copts = common_copts,
414 size = 'small',
415)
416
417'''
418We don't build this because it actually needs to be in a separate binary.
419cc_test(
420 name = 'debugallocation_test',
421 srcs = [
422 'src/tests/debugallocation_test.cc',
423 ],
424 deps = [
425 ':tcmalloc',
426 ],
427 copts = common_copts,
428 size = 'small',
429)
430'''
431
432cc_test(
433 name = 'tcmalloc_large_heap_fragmentation_unittest',
434 srcs = empty_main_if_asan([
435 'src/tests/large_heap_fragmentation_unittest.cc',
436 ]),
437 deps = [
438 ':tcmalloc',
439 ],
440 copts = common_copts,
441 size = 'small',
442)
443
444cc_test(
445 name = 'raw_printer_test',
446 srcs = [
447 'src/tests/raw_printer_test.cc',
448 ],
449 deps = [
450 ':tcmalloc',
451 ],
452 copts = common_copts,
453 size = 'small',
454)
455
456cc_test(
457 name = 'getpc_test',
458 srcs = empty_main_if_asan([
459 'src/tests/getpc_test.cc',
460 ]),
461 deps = [
462 ':tcmalloc',
463 ],
464 copts = common_copts,
465 size = 'small',
466)
467
468cc_test(
469 name = 'profiledata_unittest',
470 srcs = [
471 'src/tests/profiledata_unittest.cc',
472 ],
473 deps = [
474 ':tcmalloc',
475 ],
476 copts = common_copts,
477 size = 'small',
478)
479
480cc_test(
481 name = 'profile_handler_unittest',
482 srcs = [
483 'src/tests/profile-handler_unittest.cc',
484 ],
485 deps = [
486 ':tcmalloc',
487 ],
488 copts = common_copts,
489 flaky = True,
490 size = 'small',
491)
492
493cc_test(
494 name = 'heap_profiler_unittest',
495 srcs = [
496 'src/tests/heap-profiler_unittest.cc',
497 ],
498 deps = [
499 ':tcmalloc',
500 ],
501 copts = common_copts,
502 size = 'small',
503)
504
505cc_test(
506 name = 'sampler_test',
507 srcs = [
508 'src/tests/sampler_test.cc',
509 ],
510 deps = [
511 ':tcmalloc',
512 ],
513 copts = common_copts + [
514 '-Wno-type-limits',
515 ],
516 size = 'small',
517)