Home | History | Annotate | Download | only in allocator
      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     # Only executables and not libraries should depend on the
     26     # allocator target; only the application (the final executable)
     27     # knows what allocator makes sense.
     28     {
     29       'target_name': 'allocator',
     30       # TODO(primiano): This should be type: none for the noop cases (an empty
     31       # static lib can confuse some gyp generators). Fix it once the refactoring
     32       # (crbug.com/564618) bring this file to a saner state (fewer conditions).
     33       'type': 'static_library',
     34       'conditions': [
     35         ['OS=="win" and win_use_allocator_shim==1', {
     36           'msvs_settings': {
     37             # TODO(sgk):  merge this with build/common.gypi settings
     38             'VCLibrarianTool': {
     39               'AdditionalOptions': ['/ignore:4006,4221'],
     40             },
     41             'VCLinkerTool': {
     42               'AdditionalOptions': ['/ignore:4006'],
     43             },
     44           },
     45           'dependencies': [
     46             'libcmt',
     47           ],
     48           'include_dirs': [
     49             '../..',
     50           ],
     51           'sources': [
     52             'allocator_shim_win.cc',
     53           ],
     54           'configurations': {
     55             'Debug_Base': {
     56               'msvs_settings': {
     57                 'VCCLCompilerTool': {
     58                   'RuntimeLibrary': '0',
     59                 },
     60               },
     61             },
     62           },
     63           'direct_dependent_settings': {
     64             'configurations': {
     65               'Common_Base': {
     66                 'msvs_settings': {
     67                   'VCLinkerTool': {
     68                     'IgnoreDefaultLibraryNames': ['libcmtd.lib', 'libcmt.lib'],
     69                     'AdditionalDependencies': [
     70                       '<(SHARED_INTERMEDIATE_DIR)/allocator/libcmt.lib'
     71                     ],
     72                   },
     73                 },
     74               },
     75             },
     76           },
     77         }],  # OS=="win"
     78         ['use_allocator=="tcmalloc"', {
     79           # Disable the heap checker in tcmalloc.
     80           'defines': [
     81             'NO_HEAP_CHECK',
     82           ],
     83           'dependencies': [
     84             '../third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
     85           ],
     86           # The order of this include_dirs matters, as tc-malloc has its own
     87           # base/ mini-fork. Do not factor these out of this conditions section.
     88           'include_dirs': [
     89             '.',
     90             '<(tcmalloc_dir)/src/base',
     91             '<(tcmalloc_dir)/src',
     92             '../..',
     93           ],
     94           'sources': [
     95             # Generated for our configuration from tcmalloc's build
     96             # and checked in.
     97             '<(tcmalloc_dir)/src/config.h',
     98             '<(tcmalloc_dir)/src/config_android.h',
     99             '<(tcmalloc_dir)/src/config_linux.h',
    100             '<(tcmalloc_dir)/src/config_win.h',
    101 
    102             # all tcmalloc native and forked files
    103             '<(tcmalloc_dir)/src/addressmap-inl.h',
    104             '<(tcmalloc_dir)/src/base/abort.cc',
    105             '<(tcmalloc_dir)/src/base/abort.h',
    106             '<(tcmalloc_dir)/src/base/arm_instruction_set_select.h',
    107             '<(tcmalloc_dir)/src/base/atomicops-internals-arm-generic.h',
    108             '<(tcmalloc_dir)/src/base/atomicops-internals-arm-v6plus.h',
    109             '<(tcmalloc_dir)/src/base/atomicops-internals-linuxppc.h',
    110             '<(tcmalloc_dir)/src/base/atomicops-internals-macosx.h',
    111             '<(tcmalloc_dir)/src/base/atomicops-internals-windows.h',
    112             '<(tcmalloc_dir)/src/base/atomicops-internals-x86.cc',
    113             '<(tcmalloc_dir)/src/base/atomicops-internals-x86.h',
    114             '<(tcmalloc_dir)/src/base/atomicops.h',
    115             '<(tcmalloc_dir)/src/base/commandlineflags.h',
    116             '<(tcmalloc_dir)/src/base/cycleclock.h',
    117             # We don't list dynamic_annotations.c since its copy is already
    118             # present in the dynamic_annotations target.
    119             '<(tcmalloc_dir)/src/base/dynamic_annotations.h',
    120             '<(tcmalloc_dir)/src/base/elf_mem_image.cc',
    121             '<(tcmalloc_dir)/src/base/elf_mem_image.h',
    122             '<(tcmalloc_dir)/src/base/elfcore.h',
    123             '<(tcmalloc_dir)/src/base/googleinit.h',
    124             '<(tcmalloc_dir)/src/base/linux_syscall_support.h',
    125             '<(tcmalloc_dir)/src/base/linuxthreads.cc',
    126             '<(tcmalloc_dir)/src/base/linuxthreads.h',
    127             '<(tcmalloc_dir)/src/base/logging.cc',
    128             '<(tcmalloc_dir)/src/base/logging.h',
    129             '<(tcmalloc_dir)/src/base/low_level_alloc.cc',
    130             '<(tcmalloc_dir)/src/base/low_level_alloc.h',
    131             '<(tcmalloc_dir)/src/base/simple_mutex.h',
    132             '<(tcmalloc_dir)/src/base/spinlock.cc',
    133             '<(tcmalloc_dir)/src/base/spinlock.h',
    134             '<(tcmalloc_dir)/src/base/spinlock_internal.cc',
    135             '<(tcmalloc_dir)/src/base/spinlock_internal.h',
    136             '<(tcmalloc_dir)/src/base/spinlock_linux-inl.h',
    137             '<(tcmalloc_dir)/src/base/spinlock_posix-inl.h',
    138             '<(tcmalloc_dir)/src/base/spinlock_win32-inl.h',
    139             '<(tcmalloc_dir)/src/base/stl_allocator.h',
    140             '<(tcmalloc_dir)/src/base/synchronization_profiling.h',
    141             '<(tcmalloc_dir)/src/base/sysinfo.cc',
    142             '<(tcmalloc_dir)/src/base/sysinfo.h',
    143             '<(tcmalloc_dir)/src/base/thread_annotations.h',
    144             '<(tcmalloc_dir)/src/base/thread_lister.c',
    145             '<(tcmalloc_dir)/src/base/thread_lister.h',
    146             '<(tcmalloc_dir)/src/base/vdso_support.cc',
    147             '<(tcmalloc_dir)/src/base/vdso_support.h',
    148             '<(tcmalloc_dir)/src/central_freelist.cc',
    149             '<(tcmalloc_dir)/src/central_freelist.h',
    150             '<(tcmalloc_dir)/src/common.cc',
    151             '<(tcmalloc_dir)/src/common.h',
    152             '<(tcmalloc_dir)/src/debugallocation.cc',
    153             '<(tcmalloc_dir)/src/free_list.cc',
    154             '<(tcmalloc_dir)/src/free_list.h',
    155             '<(tcmalloc_dir)/src/getpc.h',
    156             '<(tcmalloc_dir)/src/gperftools/heap-checker.h',
    157             '<(tcmalloc_dir)/src/gperftools/heap-profiler.h',
    158             '<(tcmalloc_dir)/src/gperftools/malloc_extension.h',
    159             '<(tcmalloc_dir)/src/gperftools/malloc_extension_c.h',
    160             '<(tcmalloc_dir)/src/gperftools/malloc_hook.h',
    161             '<(tcmalloc_dir)/src/gperftools/malloc_hook_c.h',
    162             '<(tcmalloc_dir)/src/gperftools/profiler.h',
    163             '<(tcmalloc_dir)/src/gperftools/stacktrace.h',
    164             '<(tcmalloc_dir)/src/gperftools/tcmalloc.h',
    165             '<(tcmalloc_dir)/src/heap-checker-bcad.cc',
    166             '<(tcmalloc_dir)/src/heap-checker.cc',
    167             '<(tcmalloc_dir)/src/heap-profile-table.cc',
    168             '<(tcmalloc_dir)/src/heap-profile-table.h',
    169             '<(tcmalloc_dir)/src/heap-profiler.cc',
    170             '<(tcmalloc_dir)/src/internal_logging.cc',
    171             '<(tcmalloc_dir)/src/internal_logging.h',
    172             '<(tcmalloc_dir)/src/libc_override.h',
    173             '<(tcmalloc_dir)/src/libc_override_gcc_and_weak.h',
    174             '<(tcmalloc_dir)/src/libc_override_glibc.h',
    175             '<(tcmalloc_dir)/src/libc_override_osx.h',
    176             '<(tcmalloc_dir)/src/libc_override_redefine.h',
    177             '<(tcmalloc_dir)/src/linked_list.h',
    178             '<(tcmalloc_dir)/src/malloc_extension.cc',
    179             '<(tcmalloc_dir)/src/malloc_hook-inl.h',
    180             '<(tcmalloc_dir)/src/malloc_hook.cc',
    181             '<(tcmalloc_dir)/src/malloc_hook_mmap_freebsd.h',
    182             '<(tcmalloc_dir)/src/malloc_hook_mmap_linux.h',
    183             '<(tcmalloc_dir)/src/maybe_threads.cc',
    184             '<(tcmalloc_dir)/src/maybe_threads.h',
    185             '<(tcmalloc_dir)/src/memfs_malloc.cc',
    186             '<(tcmalloc_dir)/src/memory_region_map.cc',
    187             '<(tcmalloc_dir)/src/memory_region_map.h',
    188             '<(tcmalloc_dir)/src/packed-cache-inl.h',
    189             '<(tcmalloc_dir)/src/page_heap.cc',
    190             '<(tcmalloc_dir)/src/page_heap.h',
    191             '<(tcmalloc_dir)/src/page_heap_allocator.h',
    192             '<(tcmalloc_dir)/src/pagemap.h',
    193             '<(tcmalloc_dir)/src/profile-handler.cc',
    194             '<(tcmalloc_dir)/src/profile-handler.h',
    195             '<(tcmalloc_dir)/src/profiledata.cc',
    196             '<(tcmalloc_dir)/src/profiledata.h',
    197             '<(tcmalloc_dir)/src/profiler.cc',
    198             '<(tcmalloc_dir)/src/raw_printer.cc',
    199             '<(tcmalloc_dir)/src/raw_printer.h',
    200             '<(tcmalloc_dir)/src/sampler.cc',
    201             '<(tcmalloc_dir)/src/sampler.h',
    202             '<(tcmalloc_dir)/src/span.cc',
    203             '<(tcmalloc_dir)/src/span.h',
    204             '<(tcmalloc_dir)/src/stack_trace_table.cc',
    205             '<(tcmalloc_dir)/src/stack_trace_table.h',
    206             '<(tcmalloc_dir)/src/stacktrace.cc',
    207             '<(tcmalloc_dir)/src/stacktrace_arm-inl.h',
    208             '<(tcmalloc_dir)/src/stacktrace_config.h',
    209             '<(tcmalloc_dir)/src/stacktrace_generic-inl.h',
    210             '<(tcmalloc_dir)/src/stacktrace_libunwind-inl.h',
    211             '<(tcmalloc_dir)/src/stacktrace_powerpc-inl.h',
    212             '<(tcmalloc_dir)/src/stacktrace_win32-inl.h',
    213             '<(tcmalloc_dir)/src/stacktrace_with_context.cc',
    214             '<(tcmalloc_dir)/src/stacktrace_x86-inl.h',
    215             '<(tcmalloc_dir)/src/static_vars.cc',
    216             '<(tcmalloc_dir)/src/static_vars.h',
    217             '<(tcmalloc_dir)/src/symbolize.cc',
    218             '<(tcmalloc_dir)/src/symbolize.h',
    219             '<(tcmalloc_dir)/src/system-alloc.cc',
    220             '<(tcmalloc_dir)/src/system-alloc.h',
    221             '<(tcmalloc_dir)/src/tcmalloc.cc',
    222             '<(tcmalloc_dir)/src/tcmalloc_guard.h',
    223             '<(tcmalloc_dir)/src/thread_cache.cc',
    224             '<(tcmalloc_dir)/src/thread_cache.h',
    225 
    226             'debugallocation_shim.cc',
    227           ],
    228           # sources! means that these are not compiled directly.
    229           'sources!': [
    230             # We simply don't use these, but list them above so that IDE
    231             # users can view the full available source for reference, etc.
    232             '<(tcmalloc_dir)/src/addressmap-inl.h',
    233             '<(tcmalloc_dir)/src/base/atomicops-internals-linuxppc.h',
    234             '<(tcmalloc_dir)/src/base/atomicops-internals-macosx.h',
    235             '<(tcmalloc_dir)/src/base/atomicops-internals-x86-msvc.h',
    236             '<(tcmalloc_dir)/src/base/atomicops-internals-x86.h',
    237             '<(tcmalloc_dir)/src/base/atomicops.h',
    238             '<(tcmalloc_dir)/src/base/commandlineflags.h',
    239             '<(tcmalloc_dir)/src/base/cycleclock.h',
    240             '<(tcmalloc_dir)/src/base/elf_mem_image.h',
    241             '<(tcmalloc_dir)/src/base/elfcore.h',
    242             '<(tcmalloc_dir)/src/base/googleinit.h',
    243             '<(tcmalloc_dir)/src/base/linux_syscall_support.h',
    244             '<(tcmalloc_dir)/src/base/simple_mutex.h',
    245             '<(tcmalloc_dir)/src/base/spinlock_linux-inl.h',
    246             '<(tcmalloc_dir)/src/base/spinlock_posix-inl.h',
    247             '<(tcmalloc_dir)/src/base/spinlock_win32-inl.h',
    248             '<(tcmalloc_dir)/src/base/stl_allocator.h',
    249             '<(tcmalloc_dir)/src/base/thread_annotations.h',
    250             '<(tcmalloc_dir)/src/getpc.h',
    251             '<(tcmalloc_dir)/src/gperftools/heap-checker.h',
    252             '<(tcmalloc_dir)/src/gperftools/heap-profiler.h',
    253             '<(tcmalloc_dir)/src/gperftools/malloc_extension.h',
    254             '<(tcmalloc_dir)/src/gperftools/malloc_extension_c.h',
    255             '<(tcmalloc_dir)/src/gperftools/malloc_hook.h',
    256             '<(tcmalloc_dir)/src/gperftools/malloc_hook_c.h',
    257             '<(tcmalloc_dir)/src/gperftools/profiler.h',
    258             '<(tcmalloc_dir)/src/gperftools/stacktrace.h',
    259             '<(tcmalloc_dir)/src/gperftools/tcmalloc.h',
    260             '<(tcmalloc_dir)/src/heap-checker-bcad.cc',
    261             '<(tcmalloc_dir)/src/heap-checker.cc',
    262             '<(tcmalloc_dir)/src/libc_override.h',
    263             '<(tcmalloc_dir)/src/libc_override_gcc_and_weak.h',
    264             '<(tcmalloc_dir)/src/libc_override_glibc.h',
    265             '<(tcmalloc_dir)/src/libc_override_osx.h',
    266             '<(tcmalloc_dir)/src/libc_override_redefine.h',
    267             '<(tcmalloc_dir)/src/malloc_hook_mmap_freebsd.h',
    268             '<(tcmalloc_dir)/src/malloc_hook_mmap_linux.h',
    269             '<(tcmalloc_dir)/src/memfs_malloc.cc',
    270             '<(tcmalloc_dir)/src/packed-cache-inl.h',
    271             '<(tcmalloc_dir)/src/page_heap_allocator.h',
    272             '<(tcmalloc_dir)/src/pagemap.h',
    273             '<(tcmalloc_dir)/src/stacktrace_arm-inl.h',
    274             '<(tcmalloc_dir)/src/stacktrace_config.h',
    275             '<(tcmalloc_dir)/src/stacktrace_generic-inl.h',
    276             '<(tcmalloc_dir)/src/stacktrace_libunwind-inl.h',
    277             '<(tcmalloc_dir)/src/stacktrace_powerpc-inl.h',
    278             '<(tcmalloc_dir)/src/stacktrace_win32-inl.h',
    279             '<(tcmalloc_dir)/src/stacktrace_with_context.cc',
    280             '<(tcmalloc_dir)/src/stacktrace_x86-inl.h',
    281             '<(tcmalloc_dir)/src/tcmalloc_guard.h',
    282 
    283             # Included by debugallocation_shim.cc.
    284             '<(tcmalloc_dir)/src/debugallocation.cc',
    285             '<(tcmalloc_dir)/src/tcmalloc.cc',
    286           ],
    287           'variables': {
    288             'clang_warning_flags': [
    289               # tcmalloc initializes some fields in the wrong order.
    290               '-Wno-reorder',
    291               # tcmalloc contains some unused local template specializations.
    292               '-Wno-unused-function',
    293               # tcmalloc uses COMPILE_ASSERT without static_assert but with
    294               # typedefs.
    295               '-Wno-unused-local-typedefs',
    296               # for magic2_ in debugallocation.cc (only built in Debug builds)
    297               # typedefs.
    298               '-Wno-unused-private-field',
    299             ],
    300           },
    301           'conditions': [
    302             ['OS=="linux" or OS=="freebsd" or OS=="solaris" or OS=="android"', {
    303               'sources!': [
    304                 '<(tcmalloc_dir)/src/system-alloc.h',
    305               ],
    306               # We enable all warnings by default, but upstream disables a few.
    307               # Keep "-Wno-*" flags in sync with upstream by comparing against:
    308               # http://code.google.com/p/google-perftools/source/browse/trunk/Makefile.am
    309               'cflags': [
    310                 '-Wno-sign-compare',
    311                 '-Wno-unused-result',
    312               ],
    313               'cflags!': [
    314                 '-fvisibility=hidden',
    315               ],
    316               'link_settings': {
    317                 'ldflags': [
    318                   # Don't let linker rip this symbol out, otherwise the heap&cpu
    319                   # profilers will not initialize properly on startup.
    320                   '-Wl,-uIsHeapProfilerRunning,-uProfilerStart',
    321                   # Do the same for heap leak checker.
    322                   '-Wl,-u_Z21InitialMallocHook_NewPKvj,-u_Z22InitialMallocHook_MMapPKvS0_jiiix,-u_Z22InitialMallocHook_SbrkPKvi',
    323                   '-Wl,-u_Z21InitialMallocHook_NewPKvm,-u_Z22InitialMallocHook_MMapPKvS0_miiil,-u_Z22InitialMallocHook_SbrkPKvl',
    324                   '-Wl,-u_ZN15HeapLeakChecker12IgnoreObjectEPKv,-u_ZN15HeapLeakChecker14UnIgnoreObjectEPKv',
    325                 ],
    326               },
    327             }],
    328             ['profiling!=1', {
    329               'sources!': [
    330                 # cpuprofiler
    331                 '<(tcmalloc_dir)/src/base/thread_lister.c',
    332                 '<(tcmalloc_dir)/src/base/thread_lister.h',
    333                 '<(tcmalloc_dir)/src/profile-handler.cc',
    334                 '<(tcmalloc_dir)/src/profile-handler.h',
    335                 '<(tcmalloc_dir)/src/profiledata.cc',
    336                 '<(tcmalloc_dir)/src/profiledata.h',
    337                 '<(tcmalloc_dir)/src/profiler.cc',
    338               ],
    339             }],
    340           ],
    341           'configurations': {
    342             'Debug_Base': {
    343               'conditions': [
    344                 ['disable_debugallocation==0', {
    345                   'defines': [
    346                     # Use debugallocation for Debug builds to catch problems
    347                     # early and cleanly, http://crbug.com/30715 .
    348                     'TCMALLOC_FOR_DEBUGALLOCATION',
    349                   ],
    350                 }],
    351               ],
    352             },
    353           },
    354         }],  # use_allocator=="tcmalloc
    355         # For CrOS builds with vtable verification. According to the author of
    356         # crrev.com/10854031 this is used in conjuction with some other CrOS
    357         # build flag, to enable verification of any allocator that uses virtual
    358         # function calls.
    359         ['use_vtable_verify==1', {
    360           'cflags': [
    361             '-fvtable-verify=preinit',
    362           ],
    363         }],
    364         ['order_profiling != 0', {
    365           'target_conditions' : [
    366             ['_toolset=="target"', {
    367               'cflags!': [ '-finstrument-functions' ],
    368             }],
    369           ],
    370         }],
    371       ],  # conditions of 'allocator' target.
    372     },  # 'allocator' target.
    373   ],  # targets.
    374   'conditions': [
    375     ['OS=="win" and component!="shared_library"', {
    376       'targets': [
    377         {
    378           'target_name': 'libcmt',
    379           'type': 'none',
    380           'actions': [
    381             {
    382               'action_name': 'libcmt',
    383               'inputs': [
    384                 'prep_libc.py',
    385               ],
    386               'outputs': [
    387                 '<(SHARED_INTERMEDIATE_DIR)/allocator/libcmt.lib',
    388               ],
    389               'action': [
    390                 'python',
    391                 'prep_libc.py',
    392                 '$(VCInstallDir)lib',
    393                 '<(SHARED_INTERMEDIATE_DIR)/allocator',
    394                 '<(target_arch)',
    395               ],
    396             },
    397           ],
    398         },
    399       ],
    400     }],
    401   ],
    402 }
    403