• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 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
5import("//build/config/allocator.gni")
6
7# Only executables and not libraries should depend on the allocator target;
8# only the application (the final executable) knows what allocator makes sense.
9# This "allocator" meta-target will forward to the default allocator according
10# to the build settings.
11group("allocator") {
12  if (use_allocator == "tcmalloc") {
13    deps = [ ":tcmalloc" ]
14  }
15}
16
17# This config and libc modification are only used on Windows.
18if (is_win) {
19  import("//build/config/win/visual_studio_version.gni")
20
21  config("nocmt") {
22    ldflags = [
23      "/NODEFAULTLIB:libcmt",
24      "/NODEFAULTLIB:libcmtd",
25    ]
26    libs = [ rebase_path("$target_gen_dir/allocator/libcmt.lib") ]
27  }
28
29  action("prep_libc") {
30    script = "prep_libc.py"
31    outputs = [ "$target_gen_dir/allocator/libcmt.lib" ]
32    args = [
33      visual_studio_path + "/vc/lib",
34      rebase_path("$target_gen_dir/allocator"),
35      cpu_arch,
36    ]
37  }
38}
39
40if (!is_android) {
41  # tcmalloc currently won't compile on Android.
42  source_set("tcmalloc") {
43    tcmalloc_dir = "//third_party/tcmalloc/chromium"
44
45    sources = [
46      # Generated for our configuration from tcmalloc"s build
47      # and checked in.
48      "$tcmalloc_dir/src/config.h",
49      "$tcmalloc_dir/src/config_android.h",
50      "$tcmalloc_dir/src/config_linux.h",
51      "$tcmalloc_dir/src/config_win.h",
52
53      # tcmalloc native and forked files.
54      "$tcmalloc_dir/src/base/abort.cc",
55      "$tcmalloc_dir/src/base/abort.h",
56      "$tcmalloc_dir/src/base/arm_instruction_set_select.h",
57      # We don't list dynamic_annotations.c since its copy is already
58      # present in the dynamic_annotations target.
59      "$tcmalloc_dir/src/base/elf_mem_image.cc",
60      "$tcmalloc_dir/src/base/elf_mem_image.h",
61      "$tcmalloc_dir/src/base/linuxthreads.cc",
62      "$tcmalloc_dir/src/base/linuxthreads.h",
63      "$tcmalloc_dir/src/base/logging.cc",
64      "$tcmalloc_dir/src/base/logging.h",
65      "$tcmalloc_dir/src/base/low_level_alloc.cc",
66      "$tcmalloc_dir/src/base/low_level_alloc.h",
67      "$tcmalloc_dir/src/base/spinlock.cc",
68      "$tcmalloc_dir/src/base/spinlock.h",
69      "$tcmalloc_dir/src/base/spinlock_internal.cc",
70      "$tcmalloc_dir/src/base/spinlock_internal.h",
71      "$tcmalloc_dir/src/base/synchronization_profiling.h",
72      "$tcmalloc_dir/src/base/sysinfo.cc",
73      "$tcmalloc_dir/src/base/sysinfo.h",
74      "$tcmalloc_dir/src/base/thread_lister.c",
75      "$tcmalloc_dir/src/base/thread_lister.h",
76      "$tcmalloc_dir/src/base/vdso_support.cc",
77      "$tcmalloc_dir/src/base/vdso_support.h",
78      "$tcmalloc_dir/src/central_freelist.cc",
79      "$tcmalloc_dir/src/central_freelist.h",
80      "$tcmalloc_dir/src/common.cc",
81      "$tcmalloc_dir/src/common.h",
82      # #included by debugallocation_shim.cc
83      #"$tcmalloc_dir/src/debugallocation.cc",
84      "$tcmalloc_dir/src/deep-heap-profile.cc",
85      "$tcmalloc_dir/src/deep-heap-profile.h",
86      "$tcmalloc_dir/src/free_list.cc",
87      "$tcmalloc_dir/src/free_list.h",
88      "$tcmalloc_dir/src/heap-profile-table.cc",
89      "$tcmalloc_dir/src/heap-profile-table.h",
90      "$tcmalloc_dir/src/heap-profiler.cc",
91      "$tcmalloc_dir/src/internal_logging.cc",
92      "$tcmalloc_dir/src/internal_logging.h",
93      "$tcmalloc_dir/src/linked_list.h",
94      "$tcmalloc_dir/src/malloc_extension.cc",
95      "$tcmalloc_dir/src/malloc_hook-inl.h",
96      "$tcmalloc_dir/src/malloc_hook.cc",
97      "$tcmalloc_dir/src/maybe_threads.cc",
98      "$tcmalloc_dir/src/maybe_threads.h",
99      "$tcmalloc_dir/src/memory_region_map.cc",
100      "$tcmalloc_dir/src/memory_region_map.h",
101      "$tcmalloc_dir/src/page_heap.cc",
102      "$tcmalloc_dir/src/page_heap.h",
103      "$tcmalloc_dir/src/profile-handler.cc",
104      "$tcmalloc_dir/src/profile-handler.h",
105      "$tcmalloc_dir/src/profiledata.cc",
106      "$tcmalloc_dir/src/profiledata.h",
107      "$tcmalloc_dir/src/profiler.cc",
108      "$tcmalloc_dir/src/raw_printer.cc",
109      "$tcmalloc_dir/src/raw_printer.h",
110      "$tcmalloc_dir/src/sampler.cc",
111      "$tcmalloc_dir/src/sampler.h",
112      "$tcmalloc_dir/src/span.cc",
113      "$tcmalloc_dir/src/span.h",
114      "$tcmalloc_dir/src/stack_trace_table.cc",
115      "$tcmalloc_dir/src/stack_trace_table.h",
116      "$tcmalloc_dir/src/stacktrace.cc",
117      "$tcmalloc_dir/src/static_vars.cc",
118      "$tcmalloc_dir/src/static_vars.h",
119      "$tcmalloc_dir/src/symbolize.cc",
120      "$tcmalloc_dir/src/symbolize.h",
121      "$tcmalloc_dir/src/system-alloc.cc",
122      "$tcmalloc_dir/src/system-alloc.h",
123      # #included by debugallocation_shim.cc
124      #"$tcmalloc_dir/src/tcmalloc.cc",
125      "$tcmalloc_dir/src/thread_cache.cc",
126      "$tcmalloc_dir/src/thread_cache.h",
127      "$tcmalloc_dir/src/windows/port.cc",
128      "$tcmalloc_dir/src/windows/port.h",
129
130      "allocator_shim.cc",
131      "allocator_shim.h",
132      "debugallocation_shim.cc",
133
134      # These are both #included by allocator_shim for maximal linking.
135      #"generic_allocators.cc",
136      #"win_allocator.cc",
137    ]
138
139    # Disable the heap checker in tcmalloc.
140    defines = [ "NO_HEAP_CHECK" ]
141
142    include_dirs = [
143      ".",
144      "$tcmalloc_dir/src/base",
145      "$tcmalloc_dir/src",
146    ]
147
148    configs -= [ "//build/config/compiler:chromium_code" ]
149    configs += [ "//build/config/compiler:no_chromium_code" ]
150
151    deps = []
152
153    if (is_win) {
154      sources -= [
155        "$tcmalloc_dir/src/base/elf_mem_image.cc",
156        "$tcmalloc_dir/src/base/elf_mem_image.h",
157        "$tcmalloc_dir/src/base/linuxthreads.cc",
158        "$tcmalloc_dir/src/base/linuxthreads.h",
159        "$tcmalloc_dir/src/base/vdso_support.cc",
160        "$tcmalloc_dir/src/base/vdso_support.h",
161        "$tcmalloc_dir/src/maybe_threads.cc",
162        "$tcmalloc_dir/src/maybe_threads.h",
163        "$tcmalloc_dir/src/symbolize.h",
164        "$tcmalloc_dir/src/system-alloc.cc",
165        "$tcmalloc_dir/src/system-alloc.h",
166
167        # included by allocator_shim.cc
168        "debugallocation_shim.cc",
169
170        # cpuprofiler
171        "$tcmalloc_dir/src/base/thread_lister.c",
172        "$tcmalloc_dir/src/base/thread_lister.h",
173        "$tcmalloc_dir/src/profiledata.cc",
174        "$tcmalloc_dir/src/profiledata.h",
175        "$tcmalloc_dir/src/profile-handler.cc",
176        "$tcmalloc_dir/src/profile-handler.h",
177        "$tcmalloc_dir/src/profiler.cc",
178      ]
179      defines += [ "PERFTOOLS_DLL_DECL=" ]
180
181      configs -= [
182        # Tcmalloc defines this itself, and we don't want duplicate definition
183        # warnings.
184        "//build/config/win:nominmax",
185      ]
186
187      public_configs = [ ":nocmt" ]
188
189      deps += [
190        ":prep_libc",
191      ]
192    }
193
194    if (is_linux || is_android) {
195      sources -= [
196        "$tcmalloc_dir/src/system-alloc.h",
197        "$tcmalloc_dir/src/windows/port.cc",
198        "$tcmalloc_dir/src/windows/port.h",
199
200        # TODO(willchan): Support allocator shim later on.
201        "allocator_shim.cc",
202      ]
203
204      # We enable all warnings by default, but upstream disables a few.
205      # Keep "-Wno-*" flags in sync with upstream by comparing against:
206      # http://code.google.com/p/google-perftools/source/browse/trunk/Makefile.am
207      cflags = [
208        "-Wno-sign-compare",
209        "-Wno-unused-result",
210      ]
211
212      configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
213
214      ldflags = [
215        # Don't let linker rip this symbol out, otherwise the heap&cpu
216        # profilers will not initialize properly on startup.
217        "-Wl,-uIsHeapProfilerRunning,-uProfilerStart",
218        # Do the same for heap leak checker.
219        "-Wl,-u_Z21InitialMallocHook_NewPKvj,-u_Z22InitialMallocHook_MMapPKvS0_jiiix,-u_Z22InitialMallocHook_SbrkPKvi",
220        "-Wl,-u_Z21InitialMallocHook_NewPKvm,-u_Z22InitialMallocHook_MMapPKvS0_miiil,-u_Z22InitialMallocHook_SbrkPKvl",
221        "-Wl,-u_ZN15HeapLeakChecker12IgnoreObjectEPKv,-u_ZN15HeapLeakChecker14UnIgnoreObjectEPKv",
222      ]
223    }
224
225    # Make sure the allocation library is optimized as much as possible when
226    # we"re in release mode.
227    if (!is_debug) {
228      configs -= [ "//build/config/compiler:optimize" ]
229      configs += [ "//build/config/compiler:optimize_max" ]
230    }
231
232    deps += [
233      "//base/third_party/dynamic_annotations",
234    ]
235
236    if (is_win) {
237      ldflags = [ "/ignore:4006:4221" ]
238    }
239  }
240}  # !is_android
241
242source_set("allocator_extension_thunks") {
243  visibility = [ "//base/*" ]
244  sources = [
245    "allocator_extension_thunks.cc",
246    "allocator_extension_thunks.h",
247  ]
248  if (is_android && !is_debug) {
249    configs -= [ "//build/config/compiler:optimize" ]
250    configs += [ "//build/config/compiler:optimize_max" ]
251  }
252}
253