• 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")
6import("//build/config/compiler/compiler.gni")
7
8if (is_win) {
9  import("//build/config/win/visual_studio_version.gni")
10}
11
12declare_args() {
13  # Provide a way to force disable debugallocation in Debug builds,
14  # e.g. for profiling (it's more rare to profile Debug builds,
15  # but people sometimes need to do that).
16  enable_debugallocation = is_debug
17}
18
19# Only executables and not libraries should depend on the allocator target;
20# only the application (the final executable) knows what allocator makes sense.
21# This "allocator" meta-target will forward to the default allocator according
22# to the build settings.
23group("allocator") {
24  public_deps = []
25  if (use_allocator == "tcmalloc") {
26    public_deps += [ ":tcmalloc" ]
27  }
28
29  # This condition expresses the win_use_allocator_shim in the GYP build.
30  if (is_win && !is_component_build && visual_studio_version != "2015") {
31    public_deps += [ ":allocator_shim" ]
32  }
33}
34
35# This config defines ALLOCATOR_SHIM in the same conditions that the allocator
36# shim will be used by the allocator target.
37#
38# TODO(brettw) this is only used in one place and is kind of mess, because it
39# assumes that the library using it will eventually be linked with
40# //base/allocator in the default way. Clean this up and delete this.
41config("allocator_shim_define") {
42  if (is_win && !is_component_build && visual_studio_version != "2015") {
43    defines = [ "ALLOCATOR_SHIM" ]
44  }
45}
46
47config("tcmalloc_flags") {
48  if (enable_debugallocation) {
49    defines = [
50      # Use debugallocation for Debug builds to catch problems early
51      # and cleanly, http://crbug.com/30715 .
52      "TCMALLOC_FOR_DEBUGALLOCATION",
53    ]
54  }
55  if (is_clang) {
56    cflags = [
57      # tcmalloc initializes some fields in the wrong order.
58      "-Wno-reorder",
59
60      # tcmalloc contains some unused local template specializations.
61      "-Wno-unused-function",
62
63      # tcmalloc uses COMPILE_ASSERT without static_assert but with
64      # typedefs.
65      "-Wno-unused-local-typedefs",
66
67      # for magic2_ in debugallocation.cc (only built in Debug builds)
68      # typedefs.
69      "-Wno-unused-private-field",
70    ]
71  }
72}
73
74# This config and libc modification are only used on Windows.
75if (is_win) {
76  config("nocmt") {
77    ldflags = [
78      "/NODEFAULTLIB:libcmt",
79      "/NODEFAULTLIB:libcmtd",
80    ]
81    libs = [ rebase_path("$target_gen_dir/allocator/libcmt.lib") ]
82  }
83
84  if (!is_component_build && visual_studio_version != "2015") {
85    action("prep_libc") {
86      script = "prep_libc.py"
87      outputs = [
88        "$target_gen_dir/allocator/libcmt.lib",
89      ]
90      args = [
91        visual_studio_path + "/vc/lib",
92        rebase_path("$target_gen_dir/allocator"),
93        current_cpu,
94
95        # The environment file in the build directory. This is required because
96        # the Windows toolchain setup saves the VC paths and such so that
97        # running "mc.exe" will work with the configured toolchain. This file
98        # is in the root build dir.
99        "environment.$current_cpu",
100      ]
101    }
102
103    source_set("allocator_shim") {
104      sources = [
105        "allocator_shim_win.cc",
106      ]
107      configs -= [ "//build/config/compiler:chromium_code" ]
108      configs += [ "//build/config/compiler:no_chromium_code" ]
109
110      public_configs = [ ":nocmt" ]
111      deps = [
112        ":prep_libc",
113        "//base",
114      ]
115    }
116  }
117}
118
119if (use_allocator == "tcmalloc") {
120  # tcmalloc currently won't compile on Android.
121  source_set("tcmalloc") {
122    tcmalloc_dir = "//third_party/tcmalloc/chromium"
123
124    # Don't check tcmalloc's includes. These files include various files like
125    # base/foo.h and they actually refer to tcmalloc's forked copy of base
126    # rather than the regular one, which confuses the header checker.
127    check_includes = false
128
129    sources = [
130      # Generated for our configuration from tcmalloc's build
131      # and checked in.
132      "$tcmalloc_dir/src/config.h",
133      "$tcmalloc_dir/src/config_android.h",
134      "$tcmalloc_dir/src/config_linux.h",
135      "$tcmalloc_dir/src/config_win.h",
136
137      # tcmalloc native and forked files.
138      "$tcmalloc_dir/src/base/abort.cc",
139      "$tcmalloc_dir/src/base/abort.h",
140      "$tcmalloc_dir/src/base/arm_instruction_set_select.h",
141      "$tcmalloc_dir/src/base/atomicops-internals-arm-generic.h",
142      "$tcmalloc_dir/src/base/atomicops-internals-arm-v6plus.h",
143      "$tcmalloc_dir/src/base/atomicops-internals-linuxppc.h",
144      "$tcmalloc_dir/src/base/atomicops-internals-macosx.h",
145      "$tcmalloc_dir/src/base/atomicops-internals-windows.h",
146      "$tcmalloc_dir/src/base/atomicops-internals-x86.cc",
147      "$tcmalloc_dir/src/base/atomicops-internals-x86.h",
148      "$tcmalloc_dir/src/base/atomicops.h",
149      "$tcmalloc_dir/src/base/commandlineflags.h",
150      "$tcmalloc_dir/src/base/cycleclock.h",
151
152      # We don't list dynamic_annotations.c since its copy is already
153      # present in the dynamic_annotations target.
154      "$tcmalloc_dir/src/base/elf_mem_image.cc",
155      "$tcmalloc_dir/src/base/elf_mem_image.h",
156      "$tcmalloc_dir/src/base/linuxthreads.cc",
157      "$tcmalloc_dir/src/base/linuxthreads.h",
158      "$tcmalloc_dir/src/base/logging.cc",
159      "$tcmalloc_dir/src/base/logging.h",
160      "$tcmalloc_dir/src/base/low_level_alloc.cc",
161      "$tcmalloc_dir/src/base/low_level_alloc.h",
162      "$tcmalloc_dir/src/base/spinlock.cc",
163      "$tcmalloc_dir/src/base/spinlock.h",
164      "$tcmalloc_dir/src/base/spinlock_internal.cc",
165      "$tcmalloc_dir/src/base/spinlock_internal.h",
166      "$tcmalloc_dir/src/base/synchronization_profiling.h",
167      "$tcmalloc_dir/src/base/sysinfo.cc",
168      "$tcmalloc_dir/src/base/sysinfo.h",
169      "$tcmalloc_dir/src/base/vdso_support.cc",
170      "$tcmalloc_dir/src/base/vdso_support.h",
171      "$tcmalloc_dir/src/central_freelist.cc",
172      "$tcmalloc_dir/src/central_freelist.h",
173      "$tcmalloc_dir/src/common.cc",
174      "$tcmalloc_dir/src/common.h",
175
176      # #included by debugallocation_shim.cc
177      #"$tcmalloc_dir/src/debugallocation.cc",
178      "$tcmalloc_dir/src/free_list.cc",
179      "$tcmalloc_dir/src/free_list.h",
180      "$tcmalloc_dir/src/heap-profile-table.cc",
181      "$tcmalloc_dir/src/heap-profile-table.h",
182      "$tcmalloc_dir/src/heap-profiler.cc",
183      "$tcmalloc_dir/src/internal_logging.cc",
184      "$tcmalloc_dir/src/internal_logging.h",
185      "$tcmalloc_dir/src/linked_list.h",
186      "$tcmalloc_dir/src/malloc_extension.cc",
187      "$tcmalloc_dir/src/malloc_hook-inl.h",
188      "$tcmalloc_dir/src/malloc_hook.cc",
189      "$tcmalloc_dir/src/maybe_threads.cc",
190      "$tcmalloc_dir/src/maybe_threads.h",
191      "$tcmalloc_dir/src/memory_region_map.cc",
192      "$tcmalloc_dir/src/memory_region_map.h",
193      "$tcmalloc_dir/src/page_heap.cc",
194      "$tcmalloc_dir/src/page_heap.h",
195      "$tcmalloc_dir/src/raw_printer.cc",
196      "$tcmalloc_dir/src/raw_printer.h",
197      "$tcmalloc_dir/src/sampler.cc",
198      "$tcmalloc_dir/src/sampler.h",
199      "$tcmalloc_dir/src/span.cc",
200      "$tcmalloc_dir/src/span.h",
201      "$tcmalloc_dir/src/stack_trace_table.cc",
202      "$tcmalloc_dir/src/stack_trace_table.h",
203      "$tcmalloc_dir/src/stacktrace.cc",
204      "$tcmalloc_dir/src/static_vars.cc",
205      "$tcmalloc_dir/src/static_vars.h",
206      "$tcmalloc_dir/src/symbolize.cc",
207      "$tcmalloc_dir/src/symbolize.h",
208      "$tcmalloc_dir/src/system-alloc.cc",
209      "$tcmalloc_dir/src/system-alloc.h",
210
211      # #included by debugallocation_shim.cc
212      #"$tcmalloc_dir/src/tcmalloc.cc",
213      "$tcmalloc_dir/src/thread_cache.cc",
214      "$tcmalloc_dir/src/thread_cache.h",
215      "$tcmalloc_dir/src/windows/port.cc",
216      "$tcmalloc_dir/src/windows/port.h",
217      "debugallocation_shim.cc",
218
219      # These are both #included by allocator_shim for maximal linking.
220      #"generic_allocators.cc",
221      #"win_allocator.cc",
222    ]
223
224    # Disable the heap checker in tcmalloc.
225    defines = [ "NO_HEAP_CHECK" ]
226
227    include_dirs = [
228      ".",
229      "$tcmalloc_dir/src/base",
230      "$tcmalloc_dir/src",
231    ]
232
233    configs -= [ "//build/config/compiler:chromium_code" ]
234    configs += [
235      "//build/config/compiler:no_chromium_code",
236      ":tcmalloc_flags",
237    ]
238
239    deps = []
240
241    if (enable_profiling) {
242      sources += [
243        "$tcmalloc_dir/src/base/thread_lister.c",
244        "$tcmalloc_dir/src/base/thread_lister.h",
245        "$tcmalloc_dir/src/profile-handler.cc",
246        "$tcmalloc_dir/src/profile-handler.h",
247        "$tcmalloc_dir/src/profiledata.cc",
248        "$tcmalloc_dir/src/profiledata.h",
249        "$tcmalloc_dir/src/profiler.cc",
250      ]
251      defines += [ "ENABLE_PROFILING=1" ]
252    }
253
254    if (is_linux || is_android) {
255      sources -= [
256        "$tcmalloc_dir/src/system-alloc.h",
257        "$tcmalloc_dir/src/windows/port.cc",
258        "$tcmalloc_dir/src/windows/port.h",
259      ]
260
261      # We enable all warnings by default, but upstream disables a few.
262      # Keep "-Wno-*" flags in sync with upstream by comparing against:
263      # http://code.google.com/p/google-perftools/source/browse/trunk/Makefile.am
264      cflags = [
265        "-Wno-sign-compare",
266        "-Wno-unused-result",
267      ]
268
269      configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
270
271      ldflags = [
272        # Don't let linker rip this symbol out, otherwise the heap&cpu
273        # profilers will not initialize properly on startup.
274        "-Wl,-uIsHeapProfilerRunning,-uProfilerStart",
275
276        # Do the same for heap leak checker.
277        "-Wl,-u_Z21InitialMallocHook_NewPKvj,-u_Z22InitialMallocHook_MMapPKvS0_jiiix,-u_Z22InitialMallocHook_SbrkPKvi",
278        "-Wl,-u_Z21InitialMallocHook_NewPKvm,-u_Z22InitialMallocHook_MMapPKvS0_miiil,-u_Z22InitialMallocHook_SbrkPKvl",
279        "-Wl,-u_ZN15HeapLeakChecker12IgnoreObjectEPKv,-u_ZN15HeapLeakChecker14UnIgnoreObjectEPKv",
280      ]
281    }
282
283    # Make sure the allocation library is optimized as much as possible when
284    # we"re in release mode.
285    if (!is_debug) {
286      configs -= [ "//build/config/compiler:default_optimization" ]
287      configs += [ "//build/config/compiler:optimize_max" ]
288    }
289
290    deps += [ "//base/third_party/dynamic_annotations" ]
291  }
292}  # use_allocator == "tcmalloc"
293