summaryrefslogtreecommitdiff
path: root/src/third_party/gperftools-2.5/SConscript
blob: f18a43a8ad9db06e3ee6ad5f80915badc2d73866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- mode: python -*-

Import("env")
Import("has_option")
Import("debugBuild")

files = [
    'src/base/dynamic_annotations.c',
    'src/base/elf_mem_image.cc',
    'src/base/logging.cc',
    'src/base/spinlock.cc',
    'src/base/spinlock_internal.cc',
    'src/base/sysinfo.cc',
    'src/base/vdso_support.cc',
    'src/central_freelist.cc',
    'src/common.cc',
    'src/internal_logging.cc',
    'src/malloc_extension.cc',
    'src/malloc_hook.cc',
    'src/memfs_malloc.cc',
    'src/page_heap.cc',
    'src/sampler.cc',
    'src/span.cc',
    'src/stack_trace_table.cc',
    'src/stacktrace.cc',
    'src/static_vars.cc',
    'src/symbolize.cc',
    'src/thread_cache.cc',
    ]

if env.TargetOSIs('windows'):
    files += [
        'src/tcmalloc.cc',
        'src/windows/port.cc',
        'src/windows/system-alloc.cc',
        'src/fake_stacktrace_scope.cc',
        ]
else:
    files += [
        'src/emergency_malloc_for_stacktrace.cc',
        'src/maybe_threads.cc',
        'src/system-alloc.cc',
        ]

    if not debugBuild:
        files += ['src/tcmalloc.cc'],
    else:
        files += ['src/debugallocation.cc']

if has_option( 'use-cpu-profiler' ):
    files += [
        'src/profile-handler.cc',
        'src/profiledata.cc',
        'src/profiler.cc',
        ]

__malloc_hook_fragment = '''
#include <malloc.h>
void* (* volatile __malloc_hook)(size_t, const void*) = 0;
'''

def __checkMallocHookVolatile(check_context):
    check_context.Message("Checking if __malloc_hook is declared volatile... ")
    is_malloc_hook_volatile = check_context.TryCompile(__malloc_hook_fragment, '.cc')
    check_context.Result(is_malloc_hook_volatile)
    malloc_hook_define = 'MALLOC_HOOK_MAYBE_VOLATILE='
    if is_malloc_hook_volatile:
        malloc_hook_define += 'volatile'
    check_context.env.Append(CPPDEFINES=[malloc_hook_define])


conf = Configure(env.Clone(), custom_tests=dict(CheckMallocHookVolatile=__checkMallocHookVolatile))
conf.CheckMallocHookVolatile()

if has_option('use-cpu-profiler'):
    if not conf.CheckLib('unwind', autoadd=False):
        env.ConfError("Compiling with --use-cpu-profiler requires having libunwind installed")
    conf.env.Append(
        CPPDEFINES=["NO_FRAME_POINTER", ("HAVE_LIBUNWIND_H", "1"), 'HAVE_UCONTEXT_H'],
        SYSLIBDEPS=['unwind']
    )

env = conf.Finish()

env.Append(CPPPATH=["build_" + env["TARGET_OS"] + "_" + env["TARGET_ARCH"]])

env.Append( CPPDEFINES=[ "NO_TCMALLOC_SAMPLES", "NO_HEAP_CHECK"] )

# The build system doesn't define NDEBUG globally for historical reasons, however, TCMalloc
# expects that NDEBUG is used to select between preferring the mmap or the sbrk allocator. For
# non-debug builds, we want to prefer the sbrk allocator since this is TCMallocs preferred
# production deployment configuration. See the use of NDEBUG and kDebugMode in
# src/system-alloc.cc for more details.
if not debugBuild:
    env.Append( CPPDEFINES=["NDEBUG"] )

env.Prepend( CPPPATH=["src/"] )

def removeIfPresent(lst, item):
    try:
        lst.remove(item)
    except ValueError:
        pass

for to_remove in ['-Werror', "-Wsign-compare","-Wall"]:
    removeIfPresent(env['CCFLAGS'], to_remove)

# GCC on PowerPC under C++11 mode does not define __linux which gperftools depends on
if env['TARGET_ARCH'] == 'ppc64le':
    env.Append( CPPDEFINES=[ "__linux"] )

env.Library(
    target='tcmalloc_minimal',
    source=files,
)