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