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.
5 import("//build/config/allocator.gni")
8 # Provide a way to force disable debugallocation in Debug builds,
9 # e.g. for profiling (it's more rare to profile Debug builds,
10 # but people sometimes need to do that).
11 enable_debugallocation = is_debug
14 # Only executables and not libraries should depend on the allocator target;
15 # only the application (the final executable) knows what allocator makes sense.
16 # This "allocator" meta-target will forward to the default allocator according
17 # to the build settings.
20 if (use_allocator == "tcmalloc") {
21 public_deps += [ ":tcmalloc" ]
24 # This condition expresses the win_use_allocator_shim in the GYP build.
25 if (is_win && !is_component_build) {
26 public_deps += [ ":allocator_shim" ]
30 # This config defines ALLOCATOR_SHIM in the same conditions that the allocator
31 # shim will be used by the allocator target.
33 # TODO(brettw) this is only used in one place and is kind of mess, because it
34 # assumes that the library using it will eventually be linked with
35 # //base/allocator in the default way. Clean this up and delete this.
36 config("allocator_shim_define") {
37 if (is_win && !is_component_build) {
38 defines = [ "ALLOCATOR_SHIM" ]
42 config("tcmalloc_flags") {
43 if (enable_debugallocation) {
45 # Use debugallocation for Debug builds to catch problems early
46 # and cleanly, http://crbug.com/30715 .
47 "TCMALLOC_FOR_DEBUGALLOCATION",
52 # This config and libc modification are only used on Windows.
54 import("//build/config/win/visual_studio_version.gni")
58 "/NODEFAULTLIB:libcmt",
59 "/NODEFAULTLIB:libcmtd",
61 libs = [ rebase_path("$target_gen_dir/allocator/libcmt.lib") ]
64 if (!is_component_build) {
66 script = "prep_libc.py"
68 "$target_gen_dir/allocator/libcmt.lib",
71 visual_studio_path + "/vc/lib",
72 rebase_path("$target_gen_dir/allocator"),
77 source_set("allocator_shim") {
79 "allocator_shim_win.cc",
81 configs -= [ "//build/config/compiler:chromium_code" ]
82 configs += [ "//build/config/compiler:no_chromium_code" ]
84 public_configs = [ ":nocmt" ]
92 if (use_allocator == "tcmalloc") {
93 # tcmalloc currently won't compile on Android.
94 source_set("tcmalloc") {
95 tcmalloc_dir = "//third_party/tcmalloc/chromium"
97 # Don't check tcmalloc's includes. These files include various files like
98 # base/foo.h and they actually refer to tcmalloc's forked copy of base
99 # rather than the regular one, which confuses the header checker.
100 check_includes = false
103 # Generated for our configuration from tcmalloc's build
105 "$tcmalloc_dir/src/config.h",
106 "$tcmalloc_dir/src/config_android.h",
107 "$tcmalloc_dir/src/config_linux.h",
108 "$tcmalloc_dir/src/config_win.h",
110 # tcmalloc native and forked files.
111 "$tcmalloc_dir/src/base/abort.cc",
112 "$tcmalloc_dir/src/base/abort.h",
113 "$tcmalloc_dir/src/base/arm_instruction_set_select.h",
114 "$tcmalloc_dir/src/base/atomicops-internals-arm-generic.h",
115 "$tcmalloc_dir/src/base/atomicops-internals-arm-v6plus.h",
116 "$tcmalloc_dir/src/base/atomicops-internals-linuxppc.h",
117 "$tcmalloc_dir/src/base/atomicops-internals-macosx.h",
118 "$tcmalloc_dir/src/base/atomicops-internals-windows.h",
119 "$tcmalloc_dir/src/base/atomicops-internals-x86.cc",
120 "$tcmalloc_dir/src/base/atomicops-internals-x86.h",
121 "$tcmalloc_dir/src/base/atomicops.h",
122 "$tcmalloc_dir/src/base/basictypes.h",
123 "$tcmalloc_dir/src/base/commandlineflags.h",
124 "$tcmalloc_dir/src/base/cycleclock.h",
126 # We don't list dynamic_annotations.c since its copy is already
127 # present in the dynamic_annotations target.
128 "$tcmalloc_dir/src/base/elf_mem_image.cc",
129 "$tcmalloc_dir/src/base/elf_mem_image.h",
130 "$tcmalloc_dir/src/base/linuxthreads.cc",
131 "$tcmalloc_dir/src/base/linuxthreads.h",
132 "$tcmalloc_dir/src/base/logging.cc",
133 "$tcmalloc_dir/src/base/logging.h",
134 "$tcmalloc_dir/src/base/low_level_alloc.cc",
135 "$tcmalloc_dir/src/base/low_level_alloc.h",
136 "$tcmalloc_dir/src/base/spinlock.cc",
137 "$tcmalloc_dir/src/base/spinlock.h",
138 "$tcmalloc_dir/src/base/spinlock_internal.cc",
139 "$tcmalloc_dir/src/base/spinlock_internal.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_lister.c",
144 "$tcmalloc_dir/src/base/thread_lister.h",
145 "$tcmalloc_dir/src/base/vdso_support.cc",
146 "$tcmalloc_dir/src/base/vdso_support.h",
147 "$tcmalloc_dir/src/central_freelist.cc",
148 "$tcmalloc_dir/src/central_freelist.h",
149 "$tcmalloc_dir/src/common.cc",
150 "$tcmalloc_dir/src/common.h",
152 # #included by debugallocation_shim.cc
153 #"$tcmalloc_dir/src/debugallocation.cc",
154 "$tcmalloc_dir/src/free_list.cc",
155 "$tcmalloc_dir/src/free_list.h",
156 "$tcmalloc_dir/src/heap-profile-table.cc",
157 "$tcmalloc_dir/src/heap-profile-table.h",
158 "$tcmalloc_dir/src/heap-profiler.cc",
159 "$tcmalloc_dir/src/internal_logging.cc",
160 "$tcmalloc_dir/src/internal_logging.h",
161 "$tcmalloc_dir/src/linked_list.h",
162 "$tcmalloc_dir/src/malloc_extension.cc",
163 "$tcmalloc_dir/src/malloc_hook-inl.h",
164 "$tcmalloc_dir/src/malloc_hook.cc",
165 "$tcmalloc_dir/src/maybe_threads.cc",
166 "$tcmalloc_dir/src/maybe_threads.h",
167 "$tcmalloc_dir/src/memory_region_map.cc",
168 "$tcmalloc_dir/src/memory_region_map.h",
169 "$tcmalloc_dir/src/page_heap.cc",
170 "$tcmalloc_dir/src/page_heap.h",
171 "$tcmalloc_dir/src/profile-handler.cc",
172 "$tcmalloc_dir/src/profile-handler.h",
173 "$tcmalloc_dir/src/profiledata.cc",
174 "$tcmalloc_dir/src/profiledata.h",
175 "$tcmalloc_dir/src/profiler.cc",
176 "$tcmalloc_dir/src/raw_printer.cc",
177 "$tcmalloc_dir/src/raw_printer.h",
178 "$tcmalloc_dir/src/sampler.cc",
179 "$tcmalloc_dir/src/sampler.h",
180 "$tcmalloc_dir/src/span.cc",
181 "$tcmalloc_dir/src/span.h",
182 "$tcmalloc_dir/src/stack_trace_table.cc",
183 "$tcmalloc_dir/src/stack_trace_table.h",
184 "$tcmalloc_dir/src/stacktrace.cc",
185 "$tcmalloc_dir/src/static_vars.cc",
186 "$tcmalloc_dir/src/static_vars.h",
187 "$tcmalloc_dir/src/symbolize.cc",
188 "$tcmalloc_dir/src/symbolize.h",
189 "$tcmalloc_dir/src/system-alloc.cc",
190 "$tcmalloc_dir/src/system-alloc.h",
192 # #included by debugallocation_shim.cc
193 #"$tcmalloc_dir/src/tcmalloc.cc",
194 "$tcmalloc_dir/src/thread_cache.cc",
195 "$tcmalloc_dir/src/thread_cache.h",
196 "$tcmalloc_dir/src/windows/port.cc",
197 "$tcmalloc_dir/src/windows/port.h",
198 "debugallocation_shim.cc",
200 # These are both #included by allocator_shim for maximal linking.
201 #"generic_allocators.cc",
205 # Disable the heap checker in tcmalloc.
206 defines = [ "NO_HEAP_CHECK" ]
210 "$tcmalloc_dir/src/base",
214 configs -= [ "//build/config/compiler:chromium_code" ]
216 "//build/config/compiler:no_chromium_code",
224 "$tcmalloc_dir/src/base/elf_mem_image.cc",
225 "$tcmalloc_dir/src/base/elf_mem_image.h",
226 "$tcmalloc_dir/src/base/linuxthreads.cc",
227 "$tcmalloc_dir/src/base/linuxthreads.h",
228 "$tcmalloc_dir/src/base/vdso_support.cc",
229 "$tcmalloc_dir/src/base/vdso_support.h",
230 "$tcmalloc_dir/src/maybe_threads.cc",
231 "$tcmalloc_dir/src/maybe_threads.h",
232 "$tcmalloc_dir/src/symbolize.h",
233 "$tcmalloc_dir/src/system-alloc.cc",
234 "$tcmalloc_dir/src/system-alloc.h",
237 "$tcmalloc_dir/src/base/thread_lister.c",
238 "$tcmalloc_dir/src/base/thread_lister.h",
239 "$tcmalloc_dir/src/profile-handler.cc",
240 "$tcmalloc_dir/src/profile-handler.h",
241 "$tcmalloc_dir/src/profiledata.cc",
242 "$tcmalloc_dir/src/profiledata.h",
243 "$tcmalloc_dir/src/profiler.cc",
245 defines += [ "PERFTOOLS_DLL_DECL=" ]
248 # Tcmalloc defines this itself, and we don't want duplicate definition
250 "//build/config/win:nominmax",
253 public_configs = [ ":nocmt" ]
255 deps += [ ":prep_libc" ]
258 if (is_linux || is_android) {
260 "$tcmalloc_dir/src/system-alloc.h",
261 "$tcmalloc_dir/src/windows/port.cc",
262 "$tcmalloc_dir/src/windows/port.h",
265 # We enable all warnings by default, but upstream disables a few.
266 # Keep "-Wno-*" flags in sync with upstream by comparing against:
267 # http://code.google.com/p/google-perftools/source/browse/trunk/Makefile.am
270 "-Wno-unused-result",
273 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
276 # Don't let linker rip this symbol out, otherwise the heap&cpu
277 # profilers will not initialize properly on startup.
278 "-Wl,-uIsHeapProfilerRunning,-uProfilerStart",
280 # Do the same for heap leak checker.
281 "-Wl,-u_Z21InitialMallocHook_NewPKvj,-u_Z22InitialMallocHook_MMapPKvS0_jiiix,-u_Z22InitialMallocHook_SbrkPKvi",
282 "-Wl,-u_Z21InitialMallocHook_NewPKvm,-u_Z22InitialMallocHook_MMapPKvS0_miiil,-u_Z22InitialMallocHook_SbrkPKvl",
283 "-Wl,-u_ZN15HeapLeakChecker12IgnoreObjectEPKv,-u_ZN15HeapLeakChecker14UnIgnoreObjectEPKv",
287 # Make sure the allocation library is optimized as much as possible when
288 # we"re in release mode.
290 configs -= [ "//build/config/compiler:default_optimization" ]
291 configs += [ "//build/config/compiler:optimize_max" ]
294 deps += [ "//base/third_party/dynamic_annotations" ]
297 ldflags = [ "/ignore:4006:4221" ]
302 source_set("allocator_extension_thunks") {
303 visibility = [ "//base/*" ]
305 "allocator_extension_thunks.cc",
306 "allocator_extension_thunks.h",
308 if (is_android && !is_debug) {
309 configs -= [ "//build/config/compiler:default_optimization" ]
310 configs += [ "//build/config/compiler:optimize_max" ]