• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2012 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5{
6  'target_defaults': {
7    'variables': {
8      # This code gets run a lot and debugged rarely, so it should be fast
9      # by default. See http://crbug.com/388949.
10      'debug_optimize': '2',
11      'win_debug_Optimization': '0',
12      # Run time checks are incompatible with any level of optimizations.
13      'win_debug_RuntimeChecks': '0',
14    },
15  },
16  'variables': {
17    'tcmalloc_dir': '../../third_party/tcmalloc/chromium',
18    'use_vtable_verify%': 0,
19    # Provide a way to force disable debugallocation in Debug builds
20    # e.g. for profiling (it's more rare to profile Debug builds,
21    # but people sometimes need to do that).
22    'disable_debugallocation%': 0,
23  },
24  'targets': [
25    # The only targets that should depend on allocator are 'base' and
26    # executables that don't depend, directly or indirectly, on base (a few).
27    # All the other targets get a transitive dependency on this target via base.
28    {
29      'target_name': 'allocator',
30      'variables': {
31        'conditions': [
32          ['use_allocator!="none" or (OS=="win" and win_use_allocator_shim==1)', {
33            'allocator_target_type%': 'static_library',
34          }, {
35            'allocator_target_type%': 'none',
36          }],
37        ],
38      },
39      'type': '<(allocator_target_type)',
40      'toolsets': ['host', 'target'],
41      'conditions': [
42        ['OS=="win" and win_use_allocator_shim==1', {
43          'msvs_settings': {
44            # TODO(sgk):  merge this with build/common.gypi settings
45            'VCLibrarianTool': {
46              'AdditionalOptions': ['/ignore:4006,4221'],
47            },
48            'VCLinkerTool': {
49              'AdditionalOptions': ['/ignore:4006'],
50            },
51          },
52          'include_dirs': [
53            '../..',
54          ],
55          'sources': [
56            'allocator_shim_win.cc',
57            'allocator_shim_win.h',
58          ],
59          'configurations': {
60            'Debug_Base': {
61              'msvs_settings': {
62                'VCCLCompilerTool': {
63                  'RuntimeLibrary': '0',
64                },
65              },
66            },
67          },
68        }],  # OS=="win"
69        ['use_allocator=="tcmalloc"', {
70          # Disable the heap checker in tcmalloc.
71          'defines': [
72            'NO_HEAP_CHECK',
73          ],
74          'dependencies': [
75            '../third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
76          ],
77          # The order of this include_dirs matters, as tc-malloc has its own
78          # base/ mini-fork. Do not factor these out of this conditions section.
79          'include_dirs': [
80            '.',
81            '<(tcmalloc_dir)/src/base',
82            '<(tcmalloc_dir)/src',
83            '../..',
84          ],
85          'sources': [
86            # Generated for our configuration from tcmalloc's build
87            # and checked in.
88            '<(tcmalloc_dir)/src/config.h',
89            '<(tcmalloc_dir)/src/config_android.h',
90            '<(tcmalloc_dir)/src/config_linux.h',
91            '<(tcmalloc_dir)/src/config_win.h',
92
93            # all tcmalloc native and forked files
94            '<(tcmalloc_dir)/src/addressmap-inl.h',
95            '<(tcmalloc_dir)/src/base/abort.cc',
96            '<(tcmalloc_dir)/src/base/abort.h',
97            '<(tcmalloc_dir)/src/base/arm_instruction_set_select.h',
98            '<(tcmalloc_dir)/src/base/atomicops-internals-arm-generic.h',
99            '<(tcmalloc_dir)/src/base/atomicops-internals-arm-v6plus.h',
100            '<(tcmalloc_dir)/src/base/atomicops-internals-linuxppc.h',
101            '<(tcmalloc_dir)/src/base/atomicops-internals-macosx.h',
102            '<(tcmalloc_dir)/src/base/atomicops-internals-windows.h',
103            '<(tcmalloc_dir)/src/base/atomicops-internals-x86.cc',
104            '<(tcmalloc_dir)/src/base/atomicops-internals-x86.h',
105            '<(tcmalloc_dir)/src/base/atomicops.h',
106            '<(tcmalloc_dir)/src/base/commandlineflags.h',
107            '<(tcmalloc_dir)/src/base/cycleclock.h',
108            # We don't list dynamic_annotations.c since its copy is already
109            # present in the dynamic_annotations target.
110            '<(tcmalloc_dir)/src/base/dynamic_annotations.h',
111            '<(tcmalloc_dir)/src/base/elf_mem_image.cc',
112            '<(tcmalloc_dir)/src/base/elf_mem_image.h',
113            '<(tcmalloc_dir)/src/base/elfcore.h',
114            '<(tcmalloc_dir)/src/base/googleinit.h',
115            '<(tcmalloc_dir)/src/base/linux_syscall_support.h',
116            '<(tcmalloc_dir)/src/base/linuxthreads.cc',
117            '<(tcmalloc_dir)/src/base/linuxthreads.h',
118            '<(tcmalloc_dir)/src/base/logging.cc',
119            '<(tcmalloc_dir)/src/base/logging.h',
120            '<(tcmalloc_dir)/src/base/low_level_alloc.cc',
121            '<(tcmalloc_dir)/src/base/low_level_alloc.h',
122            '<(tcmalloc_dir)/src/base/simple_mutex.h',
123            '<(tcmalloc_dir)/src/base/spinlock.cc',
124            '<(tcmalloc_dir)/src/base/spinlock.h',
125            '<(tcmalloc_dir)/src/base/spinlock_internal.cc',
126            '<(tcmalloc_dir)/src/base/spinlock_internal.h',
127            '<(tcmalloc_dir)/src/base/spinlock_linux-inl.h',
128            '<(tcmalloc_dir)/src/base/spinlock_posix-inl.h',
129            '<(tcmalloc_dir)/src/base/spinlock_win32-inl.h',
130            '<(tcmalloc_dir)/src/base/stl_allocator.h',
131            '<(tcmalloc_dir)/src/base/synchronization_profiling.h',
132            '<(tcmalloc_dir)/src/base/sysinfo.cc',
133            '<(tcmalloc_dir)/src/base/sysinfo.h',
134            '<(tcmalloc_dir)/src/base/thread_annotations.h',
135            '<(tcmalloc_dir)/src/base/thread_lister.c',
136            '<(tcmalloc_dir)/src/base/thread_lister.h',
137            '<(tcmalloc_dir)/src/base/vdso_support.cc',
138            '<(tcmalloc_dir)/src/base/vdso_support.h',
139            '<(tcmalloc_dir)/src/central_freelist.cc',
140            '<(tcmalloc_dir)/src/central_freelist.h',
141            '<(tcmalloc_dir)/src/common.cc',
142            '<(tcmalloc_dir)/src/common.h',
143            '<(tcmalloc_dir)/src/debugallocation.cc',
144            '<(tcmalloc_dir)/src/free_list.cc',
145            '<(tcmalloc_dir)/src/free_list.h',
146            '<(tcmalloc_dir)/src/getpc.h',
147            '<(tcmalloc_dir)/src/gperftools/heap-checker.h',
148            '<(tcmalloc_dir)/src/gperftools/heap-profiler.h',
149            '<(tcmalloc_dir)/src/gperftools/malloc_extension.h',
150            '<(tcmalloc_dir)/src/gperftools/malloc_extension_c.h',
151            '<(tcmalloc_dir)/src/gperftools/malloc_hook.h',
152            '<(tcmalloc_dir)/src/gperftools/malloc_hook_c.h',
153            '<(tcmalloc_dir)/src/gperftools/profiler.h',
154            '<(tcmalloc_dir)/src/gperftools/stacktrace.h',
155            '<(tcmalloc_dir)/src/gperftools/tcmalloc.h',
156            '<(tcmalloc_dir)/src/heap-checker-bcad.cc',
157            '<(tcmalloc_dir)/src/heap-checker.cc',
158            '<(tcmalloc_dir)/src/heap-profile-table.cc',
159            '<(tcmalloc_dir)/src/heap-profile-table.h',
160            '<(tcmalloc_dir)/src/heap-profiler.cc',
161            '<(tcmalloc_dir)/src/internal_logging.cc',
162            '<(tcmalloc_dir)/src/internal_logging.h',
163            '<(tcmalloc_dir)/src/libc_override.h',
164            '<(tcmalloc_dir)/src/libc_override_gcc_and_weak.h',
165            '<(tcmalloc_dir)/src/libc_override_glibc.h',
166            '<(tcmalloc_dir)/src/libc_override_osx.h',
167            '<(tcmalloc_dir)/src/libc_override_redefine.h',
168            '<(tcmalloc_dir)/src/linked_list.h',
169            '<(tcmalloc_dir)/src/malloc_extension.cc',
170            '<(tcmalloc_dir)/src/malloc_hook-inl.h',
171            '<(tcmalloc_dir)/src/malloc_hook.cc',
172            '<(tcmalloc_dir)/src/malloc_hook_mmap_freebsd.h',
173            '<(tcmalloc_dir)/src/malloc_hook_mmap_linux.h',
174            '<(tcmalloc_dir)/src/maybe_threads.cc',
175            '<(tcmalloc_dir)/src/maybe_threads.h',
176            '<(tcmalloc_dir)/src/memfs_malloc.cc',
177            '<(tcmalloc_dir)/src/memory_region_map.cc',
178            '<(tcmalloc_dir)/src/memory_region_map.h',
179            '<(tcmalloc_dir)/src/packed-cache-inl.h',
180            '<(tcmalloc_dir)/src/page_heap.cc',
181            '<(tcmalloc_dir)/src/page_heap.h',
182            '<(tcmalloc_dir)/src/page_heap_allocator.h',
183            '<(tcmalloc_dir)/src/pagemap.h',
184            '<(tcmalloc_dir)/src/profile-handler.cc',
185            '<(tcmalloc_dir)/src/profile-handler.h',
186            '<(tcmalloc_dir)/src/profiledata.cc',
187            '<(tcmalloc_dir)/src/profiledata.h',
188            '<(tcmalloc_dir)/src/profiler.cc',
189            '<(tcmalloc_dir)/src/raw_printer.cc',
190            '<(tcmalloc_dir)/src/raw_printer.h',
191            '<(tcmalloc_dir)/src/sampler.cc',
192            '<(tcmalloc_dir)/src/sampler.h',
193            '<(tcmalloc_dir)/src/span.cc',
194            '<(tcmalloc_dir)/src/span.h',
195            '<(tcmalloc_dir)/src/stack_trace_table.cc',
196            '<(tcmalloc_dir)/src/stack_trace_table.h',
197            '<(tcmalloc_dir)/src/stacktrace.cc',
198            '<(tcmalloc_dir)/src/stacktrace_arm-inl.h',
199            '<(tcmalloc_dir)/src/stacktrace_config.h',
200            '<(tcmalloc_dir)/src/stacktrace_generic-inl.h',
201            '<(tcmalloc_dir)/src/stacktrace_libunwind-inl.h',
202            '<(tcmalloc_dir)/src/stacktrace_powerpc-inl.h',
203            '<(tcmalloc_dir)/src/stacktrace_win32-inl.h',
204            '<(tcmalloc_dir)/src/stacktrace_with_context.cc',
205            '<(tcmalloc_dir)/src/stacktrace_x86-inl.h',
206            '<(tcmalloc_dir)/src/static_vars.cc',
207            '<(tcmalloc_dir)/src/static_vars.h',
208            '<(tcmalloc_dir)/src/symbolize.cc',
209            '<(tcmalloc_dir)/src/symbolize.h',
210            '<(tcmalloc_dir)/src/system-alloc.cc',
211            '<(tcmalloc_dir)/src/system-alloc.h',
212            '<(tcmalloc_dir)/src/tcmalloc.cc',
213            '<(tcmalloc_dir)/src/tcmalloc_guard.h',
214            '<(tcmalloc_dir)/src/thread_cache.cc',
215            '<(tcmalloc_dir)/src/thread_cache.h',
216
217            'debugallocation_shim.cc',
218          ],
219          # sources! means that these are not compiled directly.
220          'sources!': [
221            # We simply don't use these, but list them above so that IDE
222            # users can view the full available source for reference, etc.
223            '<(tcmalloc_dir)/src/addressmap-inl.h',
224            '<(tcmalloc_dir)/src/base/atomicops-internals-linuxppc.h',
225            '<(tcmalloc_dir)/src/base/atomicops-internals-macosx.h',
226            '<(tcmalloc_dir)/src/base/atomicops-internals-x86-msvc.h',
227            '<(tcmalloc_dir)/src/base/atomicops-internals-x86.h',
228            '<(tcmalloc_dir)/src/base/atomicops.h',
229            '<(tcmalloc_dir)/src/base/commandlineflags.h',
230            '<(tcmalloc_dir)/src/base/cycleclock.h',
231            '<(tcmalloc_dir)/src/base/elf_mem_image.h',
232            '<(tcmalloc_dir)/src/base/elfcore.h',
233            '<(tcmalloc_dir)/src/base/googleinit.h',
234            '<(tcmalloc_dir)/src/base/linux_syscall_support.h',
235            '<(tcmalloc_dir)/src/base/simple_mutex.h',
236            '<(tcmalloc_dir)/src/base/spinlock_linux-inl.h',
237            '<(tcmalloc_dir)/src/base/spinlock_posix-inl.h',
238            '<(tcmalloc_dir)/src/base/spinlock_win32-inl.h',
239            '<(tcmalloc_dir)/src/base/stl_allocator.h',
240            '<(tcmalloc_dir)/src/base/thread_annotations.h',
241            '<(tcmalloc_dir)/src/getpc.h',
242            '<(tcmalloc_dir)/src/gperftools/heap-checker.h',
243            '<(tcmalloc_dir)/src/gperftools/heap-profiler.h',
244            '<(tcmalloc_dir)/src/gperftools/malloc_extension.h',
245            '<(tcmalloc_dir)/src/gperftools/malloc_extension_c.h',
246            '<(tcmalloc_dir)/src/gperftools/malloc_hook.h',
247            '<(tcmalloc_dir)/src/gperftools/malloc_hook_c.h',
248            '<(tcmalloc_dir)/src/gperftools/profiler.h',
249            '<(tcmalloc_dir)/src/gperftools/stacktrace.h',
250            '<(tcmalloc_dir)/src/gperftools/tcmalloc.h',
251            '<(tcmalloc_dir)/src/heap-checker-bcad.cc',
252            '<(tcmalloc_dir)/src/heap-checker.cc',
253            '<(tcmalloc_dir)/src/libc_override.h',
254            '<(tcmalloc_dir)/src/libc_override_gcc_and_weak.h',
255            '<(tcmalloc_dir)/src/libc_override_glibc.h',
256            '<(tcmalloc_dir)/src/libc_override_osx.h',
257            '<(tcmalloc_dir)/src/libc_override_redefine.h',
258            '<(tcmalloc_dir)/src/malloc_hook_mmap_freebsd.h',
259            '<(tcmalloc_dir)/src/malloc_hook_mmap_linux.h',
260            '<(tcmalloc_dir)/src/memfs_malloc.cc',
261            '<(tcmalloc_dir)/src/packed-cache-inl.h',
262            '<(tcmalloc_dir)/src/page_heap_allocator.h',
263            '<(tcmalloc_dir)/src/pagemap.h',
264            '<(tcmalloc_dir)/src/stacktrace_arm-inl.h',
265            '<(tcmalloc_dir)/src/stacktrace_config.h',
266            '<(tcmalloc_dir)/src/stacktrace_generic-inl.h',
267            '<(tcmalloc_dir)/src/stacktrace_libunwind-inl.h',
268            '<(tcmalloc_dir)/src/stacktrace_powerpc-inl.h',
269            '<(tcmalloc_dir)/src/stacktrace_win32-inl.h',
270            '<(tcmalloc_dir)/src/stacktrace_with_context.cc',
271            '<(tcmalloc_dir)/src/stacktrace_x86-inl.h',
272            '<(tcmalloc_dir)/src/tcmalloc_guard.h',
273
274            # Included by debugallocation_shim.cc.
275            '<(tcmalloc_dir)/src/debugallocation.cc',
276            '<(tcmalloc_dir)/src/tcmalloc.cc',
277          ],
278          'variables': {
279            'clang_warning_flags': [
280              # tcmalloc initializes some fields in the wrong order.
281              '-Wno-reorder',
282              # tcmalloc contains some unused local template specializations.
283              '-Wno-unused-function',
284              # tcmalloc uses COMPILE_ASSERT without static_assert but with
285              # typedefs.
286              '-Wno-unused-local-typedefs',
287              # for magic2_ in debugallocation.cc (only built in Debug builds)
288              # typedefs.
289              '-Wno-unused-private-field',
290            ],
291          },
292          'conditions': [
293            ['OS=="linux" or OS=="freebsd" or OS=="solaris" or OS=="android"', {
294              'sources!': [
295                '<(tcmalloc_dir)/src/system-alloc.h',
296              ],
297              # We enable all warnings by default, but upstream disables a few.
298              # Keep "-Wno-*" flags in sync with upstream by comparing against:
299              # http://code.google.com/p/google-perftools/source/browse/trunk/Makefile.am
300              'cflags': [
301                '-Wno-sign-compare',
302                '-Wno-unused-result',
303              ],
304              'link_settings': {
305                'ldflags': [
306                  # Don't let linker rip this symbol out, otherwise the heap&cpu
307                  # profilers will not initialize properly on startup.
308                  '-Wl,-uIsHeapProfilerRunning,-uProfilerStart',
309                  # Do the same for heap leak checker.
310                  '-Wl,-u_Z21InitialMallocHook_NewPKvj,-u_Z22InitialMallocHook_MMapPKvS0_jiiix,-u_Z22InitialMallocHook_SbrkPKvi',
311                  '-Wl,-u_Z21InitialMallocHook_NewPKvm,-u_Z22InitialMallocHook_MMapPKvS0_miiil,-u_Z22InitialMallocHook_SbrkPKvl',
312                  '-Wl,-u_ZN15HeapLeakChecker12IgnoreObjectEPKv,-u_ZN15HeapLeakChecker14UnIgnoreObjectEPKv',
313                ],
314              },
315              # Compiling tcmalloc with -fvisibility=default is only necessary when
316              # not using the allocator shim, which provides the correct visibility
317              # annotations for those symbols which need to be exported (see
318              # //base/allocator/allocator_shim_override_glibc_weak_symbols.h and
319              # //base/allocator/allocator_shim_internals.h for the definition of
320              # SHIM_ALWAYS_EXPORT).
321              'conditions': [
322                ['use_experimental_allocator_shim==0', {
323                  'cflags!': [
324                    '-fvisibility=hidden',
325                  ],
326                }],
327              ],
328            }],
329            ['profiling!=1', {
330              'sources!': [
331                # cpuprofiler
332                '<(tcmalloc_dir)/src/base/thread_lister.c',
333                '<(tcmalloc_dir)/src/base/thread_lister.h',
334                '<(tcmalloc_dir)/src/profile-handler.cc',
335                '<(tcmalloc_dir)/src/profile-handler.h',
336                '<(tcmalloc_dir)/src/profiledata.cc',
337                '<(tcmalloc_dir)/src/profiledata.h',
338                '<(tcmalloc_dir)/src/profiler.cc',
339              ],
340            }],
341            ['use_experimental_allocator_shim==1', {
342              'defines': [
343                'TCMALLOC_DONT_REPLACE_SYSTEM_ALLOC',
344              ],
345            }]
346          ],
347          'configurations': {
348            'Debug_Base': {
349              'conditions': [
350                ['disable_debugallocation==0', {
351                  'defines': [
352                    # Use debugallocation for Debug builds to catch problems
353                    # early and cleanly, http://crbug.com/30715 .
354                    'TCMALLOC_FOR_DEBUGALLOCATION',
355                  ],
356                }],
357              ],
358            },
359          },
360        }],  # use_allocator=="tcmalloc
361        # For CrOS builds with vtable verification. According to the author of
362        # crrev.com/10854031 this is used in conjuction with some other CrOS
363        # build flag, to enable verification of any allocator that uses virtual
364        # function calls.
365        ['use_vtable_verify==1', {
366          'cflags': [
367            '-fvtable-verify=preinit',
368          ],
369        }],
370        ['order_profiling != 0', {
371          'target_conditions' : [
372            ['_toolset=="target"', {
373              'cflags!': [ '-finstrument-functions' ],
374            }],
375          ],
376        }],
377      ],  # conditions of 'allocator' target.
378    },  # 'allocator' target.
379    {
380      # GN: //base/allocator:features
381      # When referenced from a target that might be compiled in the host
382      # toolchain, always refer to 'allocator_features#target'.
383      'target_name': 'allocator_features',
384      'includes': [ '../../build/buildflag_header.gypi' ],
385      'variables': {
386        'buildflag_header_path': 'base/allocator/features.h',
387        'buildflag_flags': [
388          'USE_EXPERIMENTAL_ALLOCATOR_SHIM=<(use_experimental_allocator_shim)',
389        ],
390      },
391    },  # 'allocator_features' target.
392  ],  # targets.
393  'conditions': [
394    ['use_experimental_allocator_shim==1', {
395      'targets': [
396        {
397          # GN: //base/allocator:unified_allocator_shim
398          'target_name': 'unified_allocator_shim',
399          'toolsets': ['host', 'target'],
400          'type': 'static_library',
401          'defines': [ 'BASE_IMPLEMENTATION' ],
402          'sources': [
403            'allocator_shim.cc',
404            'allocator_shim.h',
405            'allocator_shim_internals.h',
406            'allocator_shim_override_cpp_symbols.h',
407            'allocator_shim_override_libc_symbols.h',
408          ],
409          'include_dirs': [
410            '../..',
411          ],
412          'conditions': [
413            ['OS=="linux" and use_allocator=="tcmalloc"', {
414              'sources': [
415                'allocator_shim_default_dispatch_to_tcmalloc.cc',
416                'allocator_shim_override_glibc_weak_symbols.h',
417              ],
418            }],
419            ['use_allocator=="none" and (OS=="linux" or (OS=="android" and _toolset == "host" and host_os == "linux"))', {
420              'sources': [
421                'allocator_shim_default_dispatch_to_glibc.cc',
422              ],
423            }],
424            ['OS=="android" and _toolset == "target"', {
425              'sources': [
426                'allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc',
427                'allocator_shim_override_linker_wrapped_symbols.h',
428              ],
429              # On Android all references to malloc & friends symbols are
430              # rewritten, at link time, and routed to the shim.
431              # See //base/allocator/README.md.
432              'all_dependent_settings': {
433                'ldflags': [
434                  '-Wl,-wrap,calloc',
435                  '-Wl,-wrap,free',
436                  '-Wl,-wrap,malloc',
437                  '-Wl,-wrap,memalign',
438                  '-Wl,-wrap,posix_memalign',
439                  '-Wl,-wrap,pvalloc',
440                  '-Wl,-wrap,realloc',
441                  '-Wl,-wrap,valloc',
442                ],
443              },
444            }],
445          ]
446        },  # 'unified_allocator_shim' target.
447      ],
448    }]
449  ],
450}
451