blob: 4fa332f479ac72887f8c0c930821a2066e3dfad4 [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 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',
211 ],
212 size = 'small',
213)
214
215cc_test(
216 name = 'tcmalloc_large_unittest',
217 srcs = empty_main_if_asan([
218 'src/tests/tcmalloc_large_unittest.cc',
219 ]),
220 deps = [
221 ':tcmalloc',
222 ],
223 copts = common_copts + [
224 '-fno-builtin',
225 ],
226 size = 'small',
227)
228
229cc_test(
230 name = 'addressmap_unittest',
231 srcs = [
232 'src/tests/addressmap_unittest.cc',
233 ],
234 deps = [
235 ':tcmalloc',
236 ],
237 copts = common_copts,
Brian Silvermaned79de62015-11-28 18:10:17 -0500238 size = 'medium',
Brian Silverman660d6092015-11-26 18:41:59 -0500239)
240
241cc_test(
242 name = 'system_alloc_unittest',
243 srcs = empty_main_if_asan([
244 'src/tests/system-alloc_unittest.cc',
245 ]),
246 deps = [
247 ':tcmalloc',
248 ],
249 copts = common_copts + [
250 '-fno-builtin',
251 ],
252 size = 'small',
253)
254
255cc_test(
256 name = 'packed_cache_test',
257 srcs = [
258 'src/tests/packed-cache_test.cc',
259 ],
260 deps = [
261 ':tcmalloc',
262 ],
263 copts = common_copts,
264 size = 'small',
265)
266
267cc_test(
268 name = 'frag_unittest',
269 srcs = [
270 'src/tests/frag_unittest.cc',
271 ],
272 deps = [
273 ':tcmalloc',
274 ],
275 copts = common_copts,
276 size = 'small',
277)
278
279cc_test(
280 name = 'markidle_unittest',
281 srcs = empty_main_if_asan([
282 'src/tests/markidle_unittest.cc',
283 ]),
284 deps = [
285 ':tcmalloc',
286 ':testutil',
287 ],
288 copts = common_copts,
289 size = 'small',
290)
291
292cc_test(
293 name = 'current_allocated_bytes_test',
294 srcs = [
295 'src/tests/current_allocated_bytes_test.cc',
296 ],
297 deps = [
298 ':tcmalloc',
299 ],
300 copts = common_copts,
301 size = 'small',
302)
303
304cc_test(
305 name = 'malloc_hook_test',
306 srcs = [
307 'src/tests/malloc_hook_test.cc',
308 ],
309 deps = [
310 ':tcmalloc',
311 ':testutil',
312 ],
313 copts = common_copts + compiler_select({
314 'gcc': [
315 '-Wno-maybe-uninitialized',
316 ],
317 'clang': [],
318 }),
319 size = 'small',
320)
321
322cc_test(
323 name = 'malloc_extension_test',
324 srcs = empty_main_if_asan([
325 'src/tests/malloc_extension_test.cc',
326 ]),
327 deps = [
328 ':tcmalloc',
329 ],
330 copts = common_copts,
331 size = 'small',
332)
333
334cc_test(
335 name = 'malloc_extension_c_test',
336 srcs = empty_main_if_asan([
337 'src/tests/malloc_extension_c_test.c',
338 ]),
339 deps = [
340 ':tcmalloc',
341 ],
342 copts = common_copts,
343 size = 'small',
344)
345
346cc_test(
347 name = 'memalign_unittest',
348 srcs = empty_main_if_asan([
349 'src/tests/memalign_unittest.cc',
350 ]),
351 deps = [
352 ':tcmalloc',
353 ':testutil',
354 ],
355 copts = common_copts,
356 size = 'small',
357)
358
359cc_test(
360 name = 'page_heap_test',
361 srcs = [
362 'src/tests/page_heap_test.cc',
363 ],
364 deps = [
365 ':tcmalloc',
366 ],
367 copts = common_copts,
368 size = 'small',
369)
370
371cc_test(
372 name = 'pagemap_unittest',
373 srcs = empty_main_if_asan([
374 'src/tests/pagemap_unittest.cc',
375 ]),
376 deps = [
377 ':tcmalloc',
378 ],
379 copts = common_copts,
380 size = 'small',
381)
382
383cc_test(
384 name = 'realloc_unittest',
385 srcs = [
386 'src/tests/realloc_unittest.cc',
387 ],
388 deps = [
389 ':tcmalloc',
390 ],
391 copts = common_copts,
392 size = 'small',
393)
394
395cc_test(
396 name = 'stack_trace_table_test',
397 srcs = [
398 'src/tests/stack_trace_table_test.cc',
399 ],
400 deps = [
401 ':tcmalloc',
402 ],
403 copts = common_copts,
404 size = 'small',
405)
406
407cc_test(
408 name = 'thread_dealloc_unittest',
409 srcs = [
410 'src/tests/thread_dealloc_unittest.cc',
411 ],
412 deps = [
413 ':tcmalloc',
414 ':testutil',
415 ],
416 copts = common_copts,
417 size = 'small',
418)
419
420'''
421We don't build this because it actually needs to be in a separate binary.
422cc_test(
423 name = 'debugallocation_test',
424 srcs = [
425 'src/tests/debugallocation_test.cc',
426 ],
427 deps = [
428 ':tcmalloc',
429 ],
430 copts = common_copts,
431 size = 'small',
432)
433'''
434
435cc_test(
436 name = 'tcmalloc_large_heap_fragmentation_unittest',
437 srcs = empty_main_if_asan([
438 'src/tests/large_heap_fragmentation_unittest.cc',
439 ]),
440 deps = [
441 ':tcmalloc',
442 ],
443 copts = common_copts,
444 size = 'small',
445)
446
447cc_test(
448 name = 'raw_printer_test',
449 srcs = [
450 'src/tests/raw_printer_test.cc',
451 ],
452 deps = [
453 ':tcmalloc',
454 ],
455 copts = common_copts,
456 size = 'small',
457)
458
459cc_test(
460 name = 'getpc_test',
461 srcs = empty_main_if_asan([
462 'src/tests/getpc_test.cc',
463 ]),
464 deps = [
465 ':tcmalloc',
466 ],
467 copts = common_copts,
468 size = 'small',
469)
470
471cc_test(
472 name = 'profiledata_unittest',
473 srcs = [
474 'src/tests/profiledata_unittest.cc',
475 ],
476 deps = [
477 ':tcmalloc',
478 ],
479 copts = common_copts,
480 size = 'small',
481)
482
483cc_test(
484 name = 'profile_handler_unittest',
485 srcs = [
486 'src/tests/profile-handler_unittest.cc',
487 ],
488 deps = [
489 ':tcmalloc',
490 ],
491 copts = common_copts,
492 flaky = True,
493 size = 'small',
494)
495
496cc_test(
497 name = 'heap_profiler_unittest',
498 srcs = [
499 'src/tests/heap-profiler_unittest.cc',
500 ],
501 deps = [
502 ':tcmalloc',
503 ],
504 copts = common_copts,
505 size = 'small',
506)
507
508cc_test(
509 name = 'sampler_test',
510 srcs = [
511 'src/tests/sampler_test.cc',
512 ],
513 deps = [
514 ':tcmalloc',
515 ],
516 copts = common_copts + [
517 '-Wno-type-limits',
518 ],
519 size = 'small',
520)