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