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",
67 # We don't list dynamic_annotations.c since its copy is already
68 # present in the dynamic_annotations target.
69 "$tcmalloc_dir/src/base/elf_mem_image.cc",
70 "$tcmalloc_dir/src/base/elf_mem_image.h",
71 "$tcmalloc_dir/src/base/linuxthreads.cc",
72 "$tcmalloc_dir/src/base/linuxthreads.h",
73 "$tcmalloc_dir/src/base/logging.cc",
74 "$tcmalloc_dir/src/base/logging.h",
75 "$tcmalloc_dir/src/base/low_level_alloc.cc",
76 "$tcmalloc_dir/src/base/low_level_alloc.h",
77 "$tcmalloc_dir/src/base/spinlock.cc",
78 "$tcmalloc_dir/src/base/spinlock.h",
79 "$tcmalloc_dir/src/base/spinlock_internal.cc",
80 "$tcmalloc_dir/src/base/spinlock_internal.h",
81 "$tcmalloc_dir/src/base/synchronization_profiling.h",
82 "$tcmalloc_dir/src/base/sysinfo.cc",
83 "$tcmalloc_dir/src/base/sysinfo.h",
84 "$tcmalloc_dir/src/base/thread_lister.c",
85 "$tcmalloc_dir/src/base/thread_lister.h",
86 "$tcmalloc_dir/src/base/vdso_support.cc",
87 "$tcmalloc_dir/src/base/vdso_support.h",
88 "$tcmalloc_dir/src/central_freelist.cc",
89 "$tcmalloc_dir/src/central_freelist.h",
90 "$tcmalloc_dir/src/common.cc",
91 "$tcmalloc_dir/src/common.h",
93 # #included by debugallocation_shim.cc
94 #"$tcmalloc_dir/src/debugallocation.cc",
95 "$tcmalloc_dir/src/deep-heap-profile.cc",
96 "$tcmalloc_dir/src/deep-heap-profile.h",
97 "$tcmalloc_dir/src/free_list.cc",
98 "$tcmalloc_dir/src/free_list.h",
99 "$tcmalloc_dir/src/heap-profile-table.cc",
100 "$tcmalloc_dir/src/heap-profile-table.h",
101 "$tcmalloc_dir/src/heap-profiler.cc",
102 "$tcmalloc_dir/src/internal_logging.cc",
103 "$tcmalloc_dir/src/internal_logging.h",
104 "$tcmalloc_dir/src/linked_list.h",
105 "$tcmalloc_dir/src/malloc_extension.cc",
106 "$tcmalloc_dir/src/malloc_hook-inl.h",
107 "$tcmalloc_dir/src/malloc_hook.cc",
108 "$tcmalloc_dir/src/maybe_threads.cc",
109 "$tcmalloc_dir/src/maybe_threads.h",
110 "$tcmalloc_dir/src/memory_region_map.cc",
111 "$tcmalloc_dir/src/memory_region_map.h",
112 "$tcmalloc_dir/src/page_heap.cc",
113 "$tcmalloc_dir/src/page_heap.h",
114 "$tcmalloc_dir/src/profile-handler.cc",
115 "$tcmalloc_dir/src/profile-handler.h",
116 "$tcmalloc_dir/src/profiledata.cc",
117 "$tcmalloc_dir/src/profiledata.h",
118 "$tcmalloc_dir/src/profiler.cc",
119 "$tcmalloc_dir/src/raw_printer.cc",
120 "$tcmalloc_dir/src/raw_printer.h",
121 "$tcmalloc_dir/src/sampler.cc",
122 "$tcmalloc_dir/src/sampler.h",
123 "$tcmalloc_dir/src/span.cc",
124 "$tcmalloc_dir/src/span.h",
125 "$tcmalloc_dir/src/stack_trace_table.cc",
126 "$tcmalloc_dir/src/stack_trace_table.h",
127 "$tcmalloc_dir/src/stacktrace.cc",
128 "$tcmalloc_dir/src/static_vars.cc",
129 "$tcmalloc_dir/src/static_vars.h",
130 "$tcmalloc_dir/src/symbolize.cc",
131 "$tcmalloc_dir/src/symbolize.h",
132 "$tcmalloc_dir/src/system-alloc.cc",
133 "$tcmalloc_dir/src/system-alloc.h",
135 # #included by debugallocation_shim.cc
136 #"$tcmalloc_dir/src/tcmalloc.cc",
137 "$tcmalloc_dir/src/thread_cache.cc",
138 "$tcmalloc_dir/src/thread_cache.h",
139 "$tcmalloc_dir/src/windows/port.cc",
140 "$tcmalloc_dir/src/windows/port.h",
142 "debugallocation_shim.cc",
144 # These are both #included by allocator_shim for maximal linking.
145 #"generic_allocators.cc",
149 # Disable the heap checker in tcmalloc.
150 defines = [ "NO_HEAP_CHECK" ]
154 "$tcmalloc_dir/src/base",
158 configs -= [ "//build/config/compiler:chromium_code" ]
159 configs += [ "//build/config/compiler:no_chromium_code" ]
165 "$tcmalloc_dir/src/base/elf_mem_image.cc",
166 "$tcmalloc_dir/src/base/elf_mem_image.h",
167 "$tcmalloc_dir/src/base/linuxthreads.cc",
168 "$tcmalloc_dir/src/base/linuxthreads.h",
169 "$tcmalloc_dir/src/base/vdso_support.cc",
170 "$tcmalloc_dir/src/base/vdso_support.h",
171 "$tcmalloc_dir/src/maybe_threads.cc",
172 "$tcmalloc_dir/src/maybe_threads.h",
173 "$tcmalloc_dir/src/symbolize.h",
174 "$tcmalloc_dir/src/system-alloc.cc",
175 "$tcmalloc_dir/src/system-alloc.h",
177 # included by allocator_shim.cc
178 "debugallocation_shim.cc",
181 "$tcmalloc_dir/src/base/thread_lister.c",
182 "$tcmalloc_dir/src/base/thread_lister.h",
183 "$tcmalloc_dir/src/profile-handler.cc",
184 "$tcmalloc_dir/src/profile-handler.h",
185 "$tcmalloc_dir/src/profiledata.cc",
186 "$tcmalloc_dir/src/profiledata.h",
187 "$tcmalloc_dir/src/profiler.cc",
189 defines += [ "PERFTOOLS_DLL_DECL=" ]
192 # Tcmalloc defines this itself, and we don't want duplicate definition
194 "//build/config/win:nominmax",
197 public_configs = [ ":nocmt" ]
199 deps += [ ":prep_libc" ]
202 if (is_linux || is_android) {
204 "$tcmalloc_dir/src/system-alloc.h",
205 "$tcmalloc_dir/src/windows/port.cc",
206 "$tcmalloc_dir/src/windows/port.h",
208 # TODO(willchan): Support allocator shim later on.
212 # We enable all warnings by default, but upstream disables a few.
213 # Keep "-Wno-*" flags in sync with upstream by comparing against:
214 # http://code.google.com/p/google-perftools/source/browse/trunk/Makefile.am
217 "-Wno-unused-result",
220 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
223 # Don't let linker rip this symbol out, otherwise the heap&cpu
224 # profilers will not initialize properly on startup.
225 "-Wl,-uIsHeapProfilerRunning,-uProfilerStart",
227 # Do the same for heap leak checker.
228 "-Wl,-u_Z21InitialMallocHook_NewPKvj,-u_Z22InitialMallocHook_MMapPKvS0_jiiix,-u_Z22InitialMallocHook_SbrkPKvi",
229 "-Wl,-u_Z21InitialMallocHook_NewPKvm,-u_Z22InitialMallocHook_MMapPKvS0_miiil,-u_Z22InitialMallocHook_SbrkPKvl",
230 "-Wl,-u_ZN15HeapLeakChecker12IgnoreObjectEPKv,-u_ZN15HeapLeakChecker14UnIgnoreObjectEPKv",
234 # Make sure the allocation library is optimized as much as possible when
235 # we"re in release mode.
237 configs -= [ "//build/config/compiler:optimize" ]
238 configs += [ "//build/config/compiler:optimize_max" ]
241 deps += [ "//base/third_party/dynamic_annotations" ]
244 ldflags = [ "/ignore:4006:4221" ]
249 source_set("allocator_extension_thunks") {
250 visibility = [ "//base/*" ]
252 "allocator_extension_thunks.cc",
253 "allocator_extension_thunks.h",
255 if (is_android && !is_debug) {
256 configs -= [ "//build/config/compiler:optimize" ]
257 configs += [ "//build/config/compiler:optimize_max" ]