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")
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.
13 if (use_allocator == "tcmalloc") {
14 public_deps += [ ":tcmalloc" ]
17 # This condition expresses the win_use_allocator_shim in the GYP build.
18 if (is_win && !is_component_build) {
19 public_deps += [ ":allocator_shim" ]
23 # This config defines ALLOCATOR_SHIM in the same conditions that the allocator
24 # shim will be used by the allocator target.
26 # TODO(brettw) this is only used in one place and is kind of mess, because it
27 # assumes that the library using it will eventually be linked with
28 # //base/allocator in the default way. Clean this up and delete this.
29 config("allocator_shim_define") {
30 if (is_win && !is_component_build) {
31 defines = [ "ALLOCATOR_SHIM" ]
35 # This config and libc modification are only used on Windows.
37 import("//build/config/win/visual_studio_version.gni")
41 "/NODEFAULTLIB:libcmt",
42 "/NODEFAULTLIB:libcmtd",
44 libs = [ rebase_path("$target_gen_dir/allocator/libcmt.lib") ]
48 script = "prep_libc.py"
50 "$target_gen_dir/allocator/libcmt.lib",
53 visual_studio_path + "/vc/lib",
54 rebase_path("$target_gen_dir/allocator"),
59 source_set("allocator_shim") {
61 "allocator_shim_win.cc",
63 configs -= [ "//build/config/compiler:chromium_code" ]
64 configs += [ "//build/config/compiler:no_chromium_code" ]
66 public_configs = [ ":nocmt" ]
73 if (use_allocator == "tcmalloc") {
74 # tcmalloc currently won't compile on Android.
75 source_set("tcmalloc") {
76 tcmalloc_dir = "//third_party/tcmalloc/chromium"
78 # Don't check tcmalloc's includes. These files include various files like
79 # base/foo.h and they actually refer to tcmalloc's forked copy of base
80 # rather than the regular one, which confuses the header checker.
81 check_includes = false
84 # Generated for our configuration from tcmalloc"s build
86 "$tcmalloc_dir/src/config.h",
87 "$tcmalloc_dir/src/config_android.h",
88 "$tcmalloc_dir/src/config_linux.h",
89 "$tcmalloc_dir/src/config_win.h",
91 # tcmalloc native and forked files.
92 "$tcmalloc_dir/src/base/abort.cc",
93 "$tcmalloc_dir/src/base/abort.h",
94 "$tcmalloc_dir/src/base/arm_instruction_set_select.h",
95 "$tcmalloc_dir/src/base/atomicops-internals-arm-generic.h",
96 "$tcmalloc_dir/src/base/atomicops-internals-arm-v6plus.h",
97 "$tcmalloc_dir/src/base/atomicops-internals-linuxppc.h",
98 "$tcmalloc_dir/src/base/atomicops-internals-macosx.h",
99 "$tcmalloc_dir/src/base/atomicops-internals-windows.h",
100 "$tcmalloc_dir/src/base/atomicops-internals-x86.cc",
101 "$tcmalloc_dir/src/base/atomicops-internals-x86.h",
102 "$tcmalloc_dir/src/base/atomicops.h",
103 "$tcmalloc_dir/src/base/basictypes.h",
104 "$tcmalloc_dir/src/base/commandlineflags.h",
105 "$tcmalloc_dir/src/base/cycleclock.h",
107 # We don't list dynamic_annotations.c since its copy is already
108 # present in the dynamic_annotations target.
109 "$tcmalloc_dir/src/base/elf_mem_image.cc",
110 "$tcmalloc_dir/src/base/elf_mem_image.h",
111 "$tcmalloc_dir/src/base/linuxthreads.cc",
112 "$tcmalloc_dir/src/base/linuxthreads.h",
113 "$tcmalloc_dir/src/base/logging.cc",
114 "$tcmalloc_dir/src/base/logging.h",
115 "$tcmalloc_dir/src/base/low_level_alloc.cc",
116 "$tcmalloc_dir/src/base/low_level_alloc.h",
117 "$tcmalloc_dir/src/base/spinlock.cc",
118 "$tcmalloc_dir/src/base/spinlock.h",
119 "$tcmalloc_dir/src/base/spinlock_internal.cc",
120 "$tcmalloc_dir/src/base/spinlock_internal.h",
121 "$tcmalloc_dir/src/base/synchronization_profiling.h",
122 "$tcmalloc_dir/src/base/sysinfo.cc",
123 "$tcmalloc_dir/src/base/sysinfo.h",
124 "$tcmalloc_dir/src/base/thread_lister.c",
125 "$tcmalloc_dir/src/base/thread_lister.h",
126 "$tcmalloc_dir/src/base/vdso_support.cc",
127 "$tcmalloc_dir/src/base/vdso_support.h",
128 "$tcmalloc_dir/src/central_freelist.cc",
129 "$tcmalloc_dir/src/central_freelist.h",
130 "$tcmalloc_dir/src/common.cc",
131 "$tcmalloc_dir/src/common.h",
133 # #included by debugallocation_shim.cc
134 #"$tcmalloc_dir/src/debugallocation.cc",
135 "$tcmalloc_dir/src/deep-heap-profile.cc",
136 "$tcmalloc_dir/src/deep-heap-profile.h",
137 "$tcmalloc_dir/src/free_list.cc",
138 "$tcmalloc_dir/src/free_list.h",
139 "$tcmalloc_dir/src/heap-profile-table.cc",
140 "$tcmalloc_dir/src/heap-profile-table.h",
141 "$tcmalloc_dir/src/heap-profiler.cc",
142 "$tcmalloc_dir/src/internal_logging.cc",
143 "$tcmalloc_dir/src/internal_logging.h",
144 "$tcmalloc_dir/src/linked_list.h",
145 "$tcmalloc_dir/src/malloc_extension.cc",
146 "$tcmalloc_dir/src/malloc_hook-inl.h",
147 "$tcmalloc_dir/src/malloc_hook.cc",
148 "$tcmalloc_dir/src/maybe_threads.cc",
149 "$tcmalloc_dir/src/maybe_threads.h",
150 "$tcmalloc_dir/src/memory_region_map.cc",
151 "$tcmalloc_dir/src/memory_region_map.h",
152 "$tcmalloc_dir/src/page_heap.cc",
153 "$tcmalloc_dir/src/page_heap.h",
154 "$tcmalloc_dir/src/profile-handler.cc",
155 "$tcmalloc_dir/src/profile-handler.h",
156 "$tcmalloc_dir/src/profiledata.cc",
157 "$tcmalloc_dir/src/profiledata.h",
158 "$tcmalloc_dir/src/profiler.cc",
159 "$tcmalloc_dir/src/raw_printer.cc",
160 "$tcmalloc_dir/src/raw_printer.h",
161 "$tcmalloc_dir/src/sampler.cc",
162 "$tcmalloc_dir/src/sampler.h",
163 "$tcmalloc_dir/src/span.cc",
164 "$tcmalloc_dir/src/span.h",
165 "$tcmalloc_dir/src/stack_trace_table.cc",
166 "$tcmalloc_dir/src/stack_trace_table.h",
167 "$tcmalloc_dir/src/stacktrace.cc",
168 "$tcmalloc_dir/src/static_vars.cc",
169 "$tcmalloc_dir/src/static_vars.h",
170 "$tcmalloc_dir/src/symbolize.cc",
171 "$tcmalloc_dir/src/symbolize.h",
172 "$tcmalloc_dir/src/system-alloc.cc",
173 "$tcmalloc_dir/src/system-alloc.h",
175 # #included by debugallocation_shim.cc
176 #"$tcmalloc_dir/src/tcmalloc.cc",
177 "$tcmalloc_dir/src/thread_cache.cc",
178 "$tcmalloc_dir/src/thread_cache.h",
179 "$tcmalloc_dir/src/windows/port.cc",
180 "$tcmalloc_dir/src/windows/port.h",
181 "debugallocation_shim.cc",
183 # These are both #included by allocator_shim for maximal linking.
184 #"generic_allocators.cc",
188 # Disable the heap checker in tcmalloc.
189 defines = [ "NO_HEAP_CHECK" ]
193 "$tcmalloc_dir/src/base",
197 configs -= [ "//build/config/compiler:chromium_code" ]
198 configs += [ "//build/config/compiler:no_chromium_code" ]
204 "$tcmalloc_dir/src/base/elf_mem_image.cc",
205 "$tcmalloc_dir/src/base/elf_mem_image.h",
206 "$tcmalloc_dir/src/base/linuxthreads.cc",
207 "$tcmalloc_dir/src/base/linuxthreads.h",
208 "$tcmalloc_dir/src/base/vdso_support.cc",
209 "$tcmalloc_dir/src/base/vdso_support.h",
210 "$tcmalloc_dir/src/maybe_threads.cc",
211 "$tcmalloc_dir/src/maybe_threads.h",
212 "$tcmalloc_dir/src/symbolize.h",
213 "$tcmalloc_dir/src/system-alloc.cc",
214 "$tcmalloc_dir/src/system-alloc.h",
217 "$tcmalloc_dir/src/base/thread_lister.c",
218 "$tcmalloc_dir/src/base/thread_lister.h",
219 "$tcmalloc_dir/src/profile-handler.cc",
220 "$tcmalloc_dir/src/profile-handler.h",
221 "$tcmalloc_dir/src/profiledata.cc",
222 "$tcmalloc_dir/src/profiledata.h",
223 "$tcmalloc_dir/src/profiler.cc",
225 defines += [ "PERFTOOLS_DLL_DECL=" ]
228 # Tcmalloc defines this itself, and we don't want duplicate definition
230 "//build/config/win:nominmax",
233 public_configs = [ ":nocmt" ]
235 deps += [ ":prep_libc" ]
238 if (is_linux || is_android) {
240 "$tcmalloc_dir/src/system-alloc.h",
241 "$tcmalloc_dir/src/windows/port.cc",
242 "$tcmalloc_dir/src/windows/port.h",
245 # We enable all warnings by default, but upstream disables a few.
246 # Keep "-Wno-*" flags in sync with upstream by comparing against:
247 # http://code.google.com/p/google-perftools/source/browse/trunk/Makefile.am
250 "-Wno-unused-result",
253 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
256 # Don't let linker rip this symbol out, otherwise the heap&cpu
257 # profilers will not initialize properly on startup.
258 "-Wl,-uIsHeapProfilerRunning,-uProfilerStart",
260 # Do the same for heap leak checker.
261 "-Wl,-u_Z21InitialMallocHook_NewPKvj,-u_Z22InitialMallocHook_MMapPKvS0_jiiix,-u_Z22InitialMallocHook_SbrkPKvi",
262 "-Wl,-u_Z21InitialMallocHook_NewPKvm,-u_Z22InitialMallocHook_MMapPKvS0_miiil,-u_Z22InitialMallocHook_SbrkPKvl",
263 "-Wl,-u_ZN15HeapLeakChecker12IgnoreObjectEPKv,-u_ZN15HeapLeakChecker14UnIgnoreObjectEPKv",
267 # Make sure the allocation library is optimized as much as possible when
268 # we"re in release mode.
270 configs -= [ "//build/config/compiler:optimize" ]
271 configs += [ "//build/config/compiler:optimize_max" ]
274 deps += [ "//base/third_party/dynamic_annotations" ]
277 ldflags = [ "/ignore:4006:4221" ]
282 source_set("allocator_extension_thunks") {
283 visibility = [ "//base/*" ]
285 "allocator_extension_thunks.cc",
286 "allocator_extension_thunks.h",
288 if (is_android && !is_debug) {
289 configs -= [ "//build/config/compiler:optimize" ]
290 configs += [ "//build/config/compiler:optimize_max" ]