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.
12 if (use_allocator == "tcmalloc") {
19 # This config and libc modification are only used on Windows.
21 import("//build/config/win/visual_studio_version.gni")
25 "/NODEFAULTLIB:libcmt",
26 "/NODEFAULTLIB:libcmtd",
28 libs = [ rebase_path("$target_gen_dir/allocator/libcmt.lib") ]
32 script = "prep_libc.py"
34 "$target_gen_dir/allocator/libcmt.lib",
37 visual_studio_path + "/vc/lib",
38 rebase_path("$target_gen_dir/allocator"),
44 if (use_allocator == "tcmalloc") {
45 # tcmalloc currently won't compile on Android.
46 source_set("tcmalloc") {
47 tcmalloc_dir = "//third_party/tcmalloc/chromium"
49 # Don't check tcmalloc's includes. These files include various files like
50 # base/foo.h and they actually refer to tcmalloc's forked copy of base
51 # rather than the regular one, which confuses the header checker.
52 check_includes = false
55 # Generated for our configuration from tcmalloc"s build
57 "$tcmalloc_dir/src/config.h",
58 "$tcmalloc_dir/src/config_android.h",
59 "$tcmalloc_dir/src/config_linux.h",
60 "$tcmalloc_dir/src/config_win.h",
62 # tcmalloc native and forked files.
63 "$tcmalloc_dir/src/base/abort.cc",
64 "$tcmalloc_dir/src/base/abort.h",
65 "$tcmalloc_dir/src/base/arm_instruction_set_select.h",
66 "$tcmalloc_dir/src/base/atomicops-internals-arm-generic.h",
67 "$tcmalloc_dir/src/base/atomicops-internals-arm-v6plus.h",
68 "$tcmalloc_dir/src/base/atomicops-internals-linuxppc.h",
69 "$tcmalloc_dir/src/base/atomicops-internals-macosx.h",
70 "$tcmalloc_dir/src/base/atomicops-internals-windows.h",
71 "$tcmalloc_dir/src/base/atomicops-internals-x86.cc",
72 "$tcmalloc_dir/src/base/atomicops-internals-x86.h",
73 "$tcmalloc_dir/src/base/atomicops.h",
74 "$tcmalloc_dir/src/base/basictypes.h",
75 "$tcmalloc_dir/src/base/commandlineflags.h",
76 "$tcmalloc_dir/src/base/cycleclock.h",
78 # We don't list dynamic_annotations.c since its copy is already
79 # present in the dynamic_annotations target.
80 "$tcmalloc_dir/src/base/elf_mem_image.cc",
81 "$tcmalloc_dir/src/base/elf_mem_image.h",
82 "$tcmalloc_dir/src/base/linuxthreads.cc",
83 "$tcmalloc_dir/src/base/linuxthreads.h",
84 "$tcmalloc_dir/src/base/logging.cc",
85 "$tcmalloc_dir/src/base/logging.h",
86 "$tcmalloc_dir/src/base/low_level_alloc.cc",
87 "$tcmalloc_dir/src/base/low_level_alloc.h",
88 "$tcmalloc_dir/src/base/spinlock.cc",
89 "$tcmalloc_dir/src/base/spinlock.h",
90 "$tcmalloc_dir/src/base/spinlock_internal.cc",
91 "$tcmalloc_dir/src/base/spinlock_internal.h",
92 "$tcmalloc_dir/src/base/synchronization_profiling.h",
93 "$tcmalloc_dir/src/base/sysinfo.cc",
94 "$tcmalloc_dir/src/base/sysinfo.h",
95 "$tcmalloc_dir/src/base/thread_lister.c",
96 "$tcmalloc_dir/src/base/thread_lister.h",
97 "$tcmalloc_dir/src/base/vdso_support.cc",
98 "$tcmalloc_dir/src/base/vdso_support.h",
99 "$tcmalloc_dir/src/central_freelist.cc",
100 "$tcmalloc_dir/src/central_freelist.h",
101 "$tcmalloc_dir/src/common.cc",
102 "$tcmalloc_dir/src/common.h",
104 # #included by debugallocation_shim.cc
105 #"$tcmalloc_dir/src/debugallocation.cc",
106 "$tcmalloc_dir/src/deep-heap-profile.cc",
107 "$tcmalloc_dir/src/deep-heap-profile.h",
108 "$tcmalloc_dir/src/free_list.cc",
109 "$tcmalloc_dir/src/free_list.h",
110 "$tcmalloc_dir/src/heap-profile-table.cc",
111 "$tcmalloc_dir/src/heap-profile-table.h",
112 "$tcmalloc_dir/src/heap-profiler.cc",
113 "$tcmalloc_dir/src/internal_logging.cc",
114 "$tcmalloc_dir/src/internal_logging.h",
115 "$tcmalloc_dir/src/linked_list.h",
116 "$tcmalloc_dir/src/malloc_extension.cc",
117 "$tcmalloc_dir/src/malloc_hook-inl.h",
118 "$tcmalloc_dir/src/malloc_hook.cc",
119 "$tcmalloc_dir/src/maybe_threads.cc",
120 "$tcmalloc_dir/src/maybe_threads.h",
121 "$tcmalloc_dir/src/memory_region_map.cc",
122 "$tcmalloc_dir/src/memory_region_map.h",
123 "$tcmalloc_dir/src/page_heap.cc",
124 "$tcmalloc_dir/src/page_heap.h",
125 "$tcmalloc_dir/src/profile-handler.cc",
126 "$tcmalloc_dir/src/profile-handler.h",
127 "$tcmalloc_dir/src/profiledata.cc",
128 "$tcmalloc_dir/src/profiledata.h",
129 "$tcmalloc_dir/src/profiler.cc",
130 "$tcmalloc_dir/src/raw_printer.cc",
131 "$tcmalloc_dir/src/raw_printer.h",
132 "$tcmalloc_dir/src/sampler.cc",
133 "$tcmalloc_dir/src/sampler.h",
134 "$tcmalloc_dir/src/span.cc",
135 "$tcmalloc_dir/src/span.h",
136 "$tcmalloc_dir/src/stack_trace_table.cc",
137 "$tcmalloc_dir/src/stack_trace_table.h",
138 "$tcmalloc_dir/src/stacktrace.cc",
139 "$tcmalloc_dir/src/static_vars.cc",
140 "$tcmalloc_dir/src/static_vars.h",
141 "$tcmalloc_dir/src/symbolize.cc",
142 "$tcmalloc_dir/src/symbolize.h",
143 "$tcmalloc_dir/src/system-alloc.cc",
144 "$tcmalloc_dir/src/system-alloc.h",
146 # #included by debugallocation_shim.cc
147 #"$tcmalloc_dir/src/tcmalloc.cc",
148 "$tcmalloc_dir/src/thread_cache.cc",
149 "$tcmalloc_dir/src/thread_cache.h",
150 "$tcmalloc_dir/src/windows/port.cc",
151 "$tcmalloc_dir/src/windows/port.h",
153 "debugallocation_shim.cc",
155 # These are both #included by allocator_shim for maximal linking.
156 #"generic_allocators.cc",
160 # Disable the heap checker in tcmalloc.
161 defines = [ "NO_HEAP_CHECK" ]
165 "$tcmalloc_dir/src/base",
169 configs -= [ "//build/config/compiler:chromium_code" ]
170 configs += [ "//build/config/compiler:no_chromium_code" ]
176 "$tcmalloc_dir/src/base/elf_mem_image.cc",
177 "$tcmalloc_dir/src/base/elf_mem_image.h",
178 "$tcmalloc_dir/src/base/linuxthreads.cc",
179 "$tcmalloc_dir/src/base/linuxthreads.h",
180 "$tcmalloc_dir/src/base/vdso_support.cc",
181 "$tcmalloc_dir/src/base/vdso_support.h",
182 "$tcmalloc_dir/src/maybe_threads.cc",
183 "$tcmalloc_dir/src/maybe_threads.h",
184 "$tcmalloc_dir/src/symbolize.h",
185 "$tcmalloc_dir/src/system-alloc.cc",
186 "$tcmalloc_dir/src/system-alloc.h",
188 # included by allocator_shim.cc
189 "debugallocation_shim.cc",
192 "$tcmalloc_dir/src/base/thread_lister.c",
193 "$tcmalloc_dir/src/base/thread_lister.h",
194 "$tcmalloc_dir/src/profile-handler.cc",
195 "$tcmalloc_dir/src/profile-handler.h",
196 "$tcmalloc_dir/src/profiledata.cc",
197 "$tcmalloc_dir/src/profiledata.h",
198 "$tcmalloc_dir/src/profiler.cc",
200 defines += [ "PERFTOOLS_DLL_DECL=" ]
203 # Tcmalloc defines this itself, and we don't want duplicate definition
205 "//build/config/win:nominmax",
208 public_configs = [ ":nocmt" ]
210 deps += [ ":prep_libc" ]
213 if (is_linux || is_android) {
215 "$tcmalloc_dir/src/system-alloc.h",
216 "$tcmalloc_dir/src/windows/port.cc",
217 "$tcmalloc_dir/src/windows/port.h",
219 # TODO(willchan): Support allocator shim later on.
223 # We enable all warnings by default, but upstream disables a few.
224 # Keep "-Wno-*" flags in sync with upstream by comparing against:
225 # http://code.google.com/p/google-perftools/source/browse/trunk/Makefile.am
228 "-Wno-unused-result",
231 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
234 # Don't let linker rip this symbol out, otherwise the heap&cpu
235 # profilers will not initialize properly on startup.
236 "-Wl,-uIsHeapProfilerRunning,-uProfilerStart",
238 # Do the same for heap leak checker.
239 "-Wl,-u_Z21InitialMallocHook_NewPKvj,-u_Z22InitialMallocHook_MMapPKvS0_jiiix,-u_Z22InitialMallocHook_SbrkPKvi",
240 "-Wl,-u_Z21InitialMallocHook_NewPKvm,-u_Z22InitialMallocHook_MMapPKvS0_miiil,-u_Z22InitialMallocHook_SbrkPKvl",
241 "-Wl,-u_ZN15HeapLeakChecker12IgnoreObjectEPKv,-u_ZN15HeapLeakChecker14UnIgnoreObjectEPKv",
245 # Make sure the allocation library is optimized as much as possible when
246 # we"re in release mode.
248 configs -= [ "//build/config/compiler:optimize" ]
249 configs += [ "//build/config/compiler:optimize_max" ]
252 deps += [ "//base/third_party/dynamic_annotations" ]
255 ldflags = [ "/ignore:4006:4221" ]
260 source_set("allocator_extension_thunks") {
261 visibility = [ "//base/*" ]
263 "allocator_extension_thunks.cc",
264 "allocator_extension_thunks.h",
266 if (is_android && !is_debug) {
267 configs -= [ "//build/config/compiler:optimize" ]
268 configs += [ "//build/config/compiler:optimize_max" ]