Index: build/config/compiler/BUILD.gn |
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn |
index ae12eda3ba7b556e4c7f0a0b25e71ccd767995fc..81269d6957ec4a2b2477245eba1ba158a10c82ec 100644 |
--- a/build/config/compiler/BUILD.gn |
+++ b/build/config/compiler/BUILD.gn |
@@ -10,6 +10,8 @@ if (is_posix) { |
import("//build/config/gcc/gcc_version.gni") |
} |
+import("//build/toolchain/ccache.gni") |
+ |
declare_args() { |
# Normally, Android builds are lightly optimized, even for debug builds, to |
# keep binary size down. Setting this flag to true disables such optimization |
@@ -20,6 +22,17 @@ declare_args() { |
# only two architectures that are currently checked in). Turn this off when |
# you are using a custom toolchain and need to control -B in cflags. |
linux_use_bundled_binutils = is_linux && cpu_arch == "x64" |
+ |
+ # Compile in such a way as to enable profiling of the generated code. For |
+ # example, don't omit the frame pointer and leave in symbols. |
+ enable_profiling = false |
+ |
+ # Compile in such a way as to make it possible for the profiler to unwind full |
+ # stack frames. Setting this flag has a large effect on the performance of the |
+ # generated code than just setting profiling, but gives the profiler more |
+ # information to analyze. |
+ # Requires profiling to be set to true. |
+ enable_full_stack_frames_for_profiling = false |
} |
use_gold = is_linux && cpu_arch == "x64" |
@@ -30,7 +43,7 @@ if (!is_win) { |
# with some utilities such as icecc and ccache. Requires gold and |
# gcc >= 4.8 or clang. |
# http://gcc.gnu.org/wiki/DebugFission |
- use_debug_fission = use_gold && linux_use_bundled_binutils |
+ use_debug_fission = use_gold && linux_use_bundled_binutils && !use_ccache |
} |
# default_include_dirs --------------------------------------------------------- |
@@ -77,19 +90,16 @@ config("compiler") { |
"/FS", # Preserve previous PDB behavior. |
] |
if (is_component_build) { |
- cflags += [ |
- "/EHsc", # Assume C functions can't throw exceptions and don't catch |
- # structured exceptions (only C++ ones). |
- ] |
+ cflags += [ "/EHsc" ] # Assume C functions can't throw exceptions and don't catch |
+ # structured exceptions (only C++ ones). |
} |
} else { |
# Common GCC compiler flags setup. |
# -------------------------------- |
- cflags += [ |
- "-fno-strict-aliasing", # See http://crbug.com/32204 |
- ] |
+ cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204 |
cflags_cc += [ |
"-fno-threadsafe-statics", |
+ |
# Not exporting C++ inline functions can generally be applied anywhere |
# so we do so here. Normal function visibility is controlled by |
# //build/config/gcc:symbol_visibility_hidden. |
@@ -100,7 +110,10 @@ config("compiler") { |
if (is_mac) { |
cflags += [ "-fstack-protector-all" ] |
} else if (is_linux) { |
- cflags += [ "-fstack-protector", "--param=ssp-buffer-size=4" ] |
+ cflags += [ |
+ "-fstack-protector", |
+ "--param=ssp-buffer-size=4", |
+ ] |
} |
# Linker warnings. |
@@ -142,11 +155,10 @@ config("compiler") { |
# when turning clang on or off. (defines are passed via the command line, |
# and build system rebuild things when their commandline changes). Nothing |
# should ever read this define. |
- defines += [ |
- "CR_CLANG_REVISION=" + |
- exec_script( |
- "//tools/clang/scripts/posix-print-revision.py", [], "value") |
- ] |
+ defines += [ "CR_CLANG_REVISION=" + |
+ exec_script("//tools/clang/scripts/posix-print-revision.py", |
+ [], |
+ "value") ] |
} |
# Mac-specific compiler flags setup. |
@@ -157,16 +169,22 @@ config("compiler") { |
# CPU architecture. |
if (cpu_arch == "x64") { |
- common_mac_flags += [ "-arch", "x86_64" ] |
+ common_mac_flags += [ |
+ "-arch", |
+ "x86_64", |
+ ] |
} else if (cpu_arch == "x86") { |
- common_mac_flags += [ "-arch", "i386" ] |
+ common_mac_flags += [ |
+ "-arch", |
+ "i386", |
+ ] |
} |
cflags += common_mac_flags |
# Without this, the constructors and destructors of a C++ object inside |
# an Objective C struct won't be called, which is very bad. |
- cflags_objcc = [ "-fobjc-call-cxx-cdtors", ] |
+ cflags_objcc = [ "-fobjc-call-cxx-cdtors" ] |
cflags_c += [ "-std=c99" ] |
cflags_cc += [ "-std=gnu++11" ] |
@@ -176,15 +194,35 @@ config("compiler") { |
# Non-Mac Posix compiler flags setup. |
# ----------------------------------- |
if (gcc_version >= 48) { |
- cflags_cc += [ |
- "-std=gnu++11", |
+ cflags_cc += [ "-std=gnu++11" ] |
+ } |
+ |
+ if (enable_profiling && !is_debug) { |
+ # The GYP build spams this define into every compilation unit, as we do |
+ # here, but it only appears to be used in base and a couple other places. |
+ # TODO(abarth): Should we move this define closer to where it's used? |
+ defines += [ "ENABLE_PROFILING" ] |
+ |
+ cflags += [ |
+ "-fno-omit-frame-pointer", |
+ "-g", |
] |
+ |
+ if (enable_full_stack_frames_for_profiling) { |
+ cflags += [ |
+ "-fno-inline", |
+ "-fno-optimize-sibling-calls", |
+ ] |
+ } |
} |
# CPU architecture. We may or may not be doing a cross compile now, so for |
# simplicity we always explicitly set the architecture. |
if (cpu_arch == "x64") { |
- cflags += [ "-m64", "-march=x86-64", ] |
+ cflags += [ |
+ "-m64", |
+ "-march=x86-64", |
+ ] |
ldflags += [ "-m64" ] |
} else if (cpu_arch == "x86") { |
cflags += [ "-m32" ] |
@@ -194,6 +232,7 @@ config("compiler") { |
# Else building libyuv gives clang's register allocator issues, |
# see llvm.org/PR15798 / crbug.com/233709 |
"-momit-leaf-frame-pointer", |
+ |
# Align the stack on 16-byte boundaries, http://crbug.com/418554. |
"-mstack-alignment=16", |
"-mstackrealign", |
@@ -225,6 +264,7 @@ config("compiler") { |
# compiler (r5-r7). This can be verified using |
# webkit_unit_tests' WTF.Checked_int8_t test. |
"-fno-tree-sra", |
+ |
# The following option is disabled to improve binary |
# size and performance in gcc 4.9. |
"-fno-caller-saves", |
@@ -267,9 +307,7 @@ config("compiler") { |
# ------------------------------------ |
if (is_linux) { |
cflags += [ "-pthread" ] |
- ldflags += [ |
- "-pthread", |
- ] |
+ ldflags += [ "-pthread" ] |
} |
if (use_gold) { |
# Use gold for linking on 64-bit Linux only (on 32-bit it runs out of |
@@ -308,12 +346,8 @@ config("compiler") { |
# Clang-specific compiler flags setup. |
# ------------------------------------ |
if (is_clang) { |
- cflags += [ |
- "-fcolor-diagnostics", |
- ] |
- cflags_cc += [ |
- "-std=gnu++11", |
- ] |
+ cflags += [ "-fcolor-diagnostics" ] |
+ cflags_cc += [ "-std=gnu++11" ] |
} |
# Android-specific flags setup. |
@@ -326,9 +360,7 @@ config("compiler") { |
] |
if (!is_clang) { |
# Clang doesn't support these flags. |
- cflags += [ |
- "-finline-limit=64", |
- ] |
+ cflags += [ "-finline-limit=64" ] |
} |
if (is_android_webview_build) { |
# Android predefines this as 1; undefine it here so Chromium can redefine |
@@ -359,13 +391,14 @@ config("compiler") { |
ldflags += [ "-fuse-ld=gold" ] |
if (is_clang) { |
# Let clang find the ld.gold in the NDK. |
- ldflags += [ "--gcc-toolchain=" + rebase_path(android_toolchain_root, |
- root_build_dir) ] |
+ ldflags += [ "--gcc-toolchain=" + |
+ rebase_path(android_toolchain_root, root_build_dir) ] |
} |
} |
ldflags += [ |
"-Wl,--no-undefined", |
+ |
# Don't export symbols from statically linked libraries. |
"-Wl,--exclude-libs=ALL", |
] |
@@ -378,9 +411,7 @@ config("compiler") { |
if (is_clang) { |
if (cpu_arch == "arm") { |
- cflags += [ |
- "-target arm-linux-androideabi", |
- ] |
+ cflags += [ "-target arm-linux-androideabi" ] |
ldflags += [ "-target arm-linux-androideabi" ] |
} else if (cpu_arch == "x86") { |
cflags += [ "-target x86-linux-androideabi" ] |
@@ -392,9 +423,7 @@ config("compiler") { |
config("compiler_arm_fpu") { |
if (cpu_arch == "arm" && !is_android_webview_build) { |
- cflags = [ |
- "-mfpu=$arm_fpu", |
- ] |
+ cflags = [ "-mfpu=$arm_fpu" ] |
} |
} |
@@ -481,15 +510,9 @@ config("runtime_library") { |
# caution. |
android_stlport_root = "$android_ndk_root/sources/cxx-stl/stlport" |
- cflags += [ |
- "-isystem" + rebase_path("$android_stlport_root/stlport", |
- root_build_dir) |
- ] |
- if (arm_use_thumb) { |
- lib_dirs += [ "$android_stlport_root/libs/$android_app_abi/thumb" ] |
- } else { |
- lib_dirs += [ "$android_stlport_root/libs/$android_app_abi" ] |
- } |
+ cflags += [ "-isystem" + |
+ rebase_path("$android_stlport_root/stlport", root_build_dir) ] |
+ lib_dirs += [ "$android_stlport_root/libs/$android_app_abi" ] |
if (component_mode == "shared_library") { |
libs += [ "stlport_shared" ] |
@@ -518,7 +541,6 @@ config("runtime_library") { |
"dl", |
"m", |
] |
- |
} |
} |
@@ -529,9 +551,7 @@ config("runtime_library") { |
config("chromium_code") { |
if (is_win) { |
- cflags = [ |
- "/W4", # Warning level 4. |
- ] |
+ cflags = [ "/W4" ] # Warning level 4. |
} else { |
cflags = [ |
"-Wall", |
@@ -629,8 +649,7 @@ config("no_rtti") { |
config("default_warnings") { |
if (is_win) { |
cflags = [ |
- "/WX", # Treat warnings as errors. |
- |
+ "/WX", # Treat warnings as errors. |
# Warnings permanently disabled: |
# TODO(GYP) The GYP build doesn't have this globally enabled but disabled |
@@ -685,8 +704,6 @@ config("default_warnings") { |
# have to turn off this warning (and be careful about how object |
# destruction happens in such cases). |
"/wd4611", |
- |
- |
# Warnings to evaluate and possibly fix/reenable later: |
"/wd4100", # Unreferenced formal function parameter. |
@@ -713,9 +730,7 @@ config("default_warnings") { |
cflags_cc = [] |
if (is_mac) { |
- cflags += [ |
- "-Wnewline-eof", |
- ] |
+ cflags += [ "-Wnewline-eof" ] |
} |
if (is_clang) { |
@@ -753,6 +768,7 @@ config("default_warnings") { |
cflags_cc += [ |
# See comment for -Wno-c++11-narrowing. |
"-Wno-narrowing", |
+ |
# TODO(thakis): Remove, http://crbug.com/263960 |
"-Wno-literal-suffix", |
] |
@@ -779,6 +795,7 @@ config("default_warnings") { |
# correctly when building with the Android build system. |
# TODO(torne): Fix this in WebKit. |
"-Wno-error=c++0x-compat", |
+ |
# Other things unrelated to -Wextra: |
"-Wno-non-virtual-dtor", |
"-Wno-sign-promo", |
@@ -789,9 +806,7 @@ config("default_warnings") { |
# Don't warn about the "typedef 'foo' locally defined but not used" |
# for gcc 4.8. |
# TODO: remove this flag once all builds work. See crbug.com/227506 |
- cflags += [ |
- "-Wno-unused-local-typedefs", |
- ] |
+ cflags += [ "-Wno-unused-local-typedefs" ] |
} |
} |
} |
@@ -822,7 +837,7 @@ if (is_win) { |
"/O2", |
"/Ob2", # both explicit and auto inlining. |
"/Oy-", # disable omitting frame pointers, must be after /o2. |
- "/Os", # favor size over speed. |
+ "/Os", # favor size over speed. |
] |
common_optimize_on_ldflags = [] |
} else { |
@@ -830,6 +845,7 @@ if (is_win) { |
# Don't emit the GCC version ident directives, they just end up in the |
# .comment section taking up binary size. |
"-fno-ident", |
+ |
# Put data and code in their own sections, so that unused symbols |
# can be removed at link time with --gc-sections. |
"-fdata-sections", |
@@ -850,9 +866,7 @@ if (is_win) { |
if (is_mac) { |
if (symbol_level == 2) { |
# Mac dead code stripping requires symbols. |
- common_optimize_on_ldflags += [ |
- "-Wl,-dead_strip", |
- ] |
+ common_optimize_on_ldflags += [ "-Wl,-dead_strip" ] |
} |
} else { |
# Non-Mac Posix linker flags. |
@@ -871,17 +885,11 @@ config("optimize") { |
cflags = common_optimize_on_cflags |
ldflags = common_optimize_on_ldflags |
if (is_win) { |
- cflags += [ |
- "/Os", # favor size over speed. |
- ] |
+ cflags += [ "/Os" ] # favor size over speed. |
} else if (is_android || is_ios) { |
- cflags += [ |
- "-Os", # Favor size over speed. |
- ] |
+ cflags += [ "-Os" ] # Favor size over speed. |
} else { |
- cflags += [ |
- "-O2", |
- ] |
+ cflags += [ "-O2" ] |
} |
} |
@@ -917,32 +925,25 @@ config("optimize_max") { |
cflags = common_optimize_on_cflags |
ldflags = common_optimize_on_ldflags |
if (is_win) { |
- cflags -= [ |
- "/Os", |
- ] |
- cflags += [ |
- "/Ot", # Favor speed over size. |
- ] |
+ cflags -= [ "/Os" ] |
+ cflags += [ "/Ot" ] # Favor speed over size. |
if (is_official_build) { |
# TODO(GYP): TODO(dpranke): Should these only be on in an official |
# build, or on all the time? For now we'll require official build so |
# that the compile is clean. |
cflags += [ |
- "/GL", # Whole program optimization. |
+ "/GL", # Whole program optimization. |
+ |
# Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds. |
# Probably anything that this would catch that wouldn't be caught in a |
# normal build isn't going to actually be a bug, so the incremental |
# value of C4702 for PGO builds is likely very small. |
"/wd4702", |
] |
- ldflags += [ |
- "/LTCG", |
- ] |
+ ldflags += [ "/LTCG" ] |
} |
} else { |
- cflags += [ |
- "-O2", |
- ] |
+ cflags += [ "-O2" ] |
} |
} |
@@ -950,7 +951,12 @@ config("optimize_max") { |
config("symbols") { |
if (is_win) { |
- cflags = [ "/Zi" ] # Produce PDB file, no edit and continue. |
+ import("//build/toolchain/goma.gni") |
+ if (use_goma) { |
+ cflags = [ "/Z7" ] # No PDB file |
+ } else { |
+ cflags = [ "/Zi" ] # Produce PDB file, no edit and continue. |
+ } |
ldflags = [ "/DEBUG" ] |
} else { |
cflags = [ "-g2" ] |