Move sanitizer and symbol flags out of BUILDCONFIG

TBR=mmoss@chromium.org (chrome/installer/linux)
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1324623005

Cr-Original-Commit-Position: refs/heads/master@{#348727}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 4cab0f1c83325704d637168c43fabc894f97939d
This commit is contained in:
brettw 2015-09-14 14:40:01 -07:00 коммит произвёл Commit bot
Родитель b98cedcffe
Коммит b5bb956088
6 изменённых файлов: 211 добавлений и 149 удалений

Просмотреть файл

@ -111,14 +111,6 @@ if (current_os == "") {
# even if the value is overridden, which is wasteful. See first bullet.
declare_args() {
# How many symbols to include in the build. This affects the performance of
# the build since the symbols are large and dealing with them is slow.
# 2 means regular build with symbols.
# 1 means minimal symbols, usually enough for backtraces only.
# 0 means no symbols.
# -1 means auto-set (off in release, regular in debug).
symbol_level = -1
# Component build.
is_component_build = false
@ -133,18 +125,6 @@ declare_args() {
is_clang = current_os == "mac" || current_os == "ios" ||
current_os == "linux" || current_os == "chromeos"
# Compile for Address Sanitizer to find memory bugs.
is_asan = false
# Compile for Leak Sanitizer to find leaks.
is_lsan = false
# Compile for Memory Sanitizer to find uninitialized reads.
is_msan = false
# Compile for Thread Sanitizer to find threading bugs.
is_tsan = false
if (current_os == "chromeos") {
# Allows the target toolchain to be injected as arguments. This is needed
# to support the CrOS build system which supports per-build-configuration
@ -176,7 +156,7 @@ declare_args() {
# and there's only one config to remove that's the same in all cases for
# targets that want to override it. It also means that the associated flags can
# be non-global.
using_new_global_compiler_configs = false
using_new_global_compiler_configs = true
# To assist in a multi-sided landing of updating the default optimization
# config. When false, this file sets up the default optimization config to be
@ -184,7 +164,15 @@ using_new_global_compiler_configs = false
# always set the config "default_optimization".
#
# TODO(brettw) remove this when all repos are updated.
using_new_optimization_config = false
using_new_optimization_config = true
# To assist in a multi-sided landing of updating the default optimization
# config. When false, this file sets up the default optimization config to be
# either "no_optimize" (debug) or "optimize" (release). When true it will
# always set the config "default_optimization".
#
# TODO(brettw) remove this when all repos are updated.
using_new_optimization_config = true
# =============================================================================
# OS DEFINITIONS
@ -386,16 +374,6 @@ if (!is_chromeos) {
# your platform/toolkit/feature doesn't apply.
set_sources_assignment_filter(sources_assignment_filter)
# =============================================================================
# BUILD OPTIONS
# =============================================================================
# These Sanitizers all imply using the Clang compiler. On Windows they either
# don't work or work differently.
if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
is_clang = true
}
# =============================================================================
# TARGET DEFAULTS
# =============================================================================
@ -413,6 +391,8 @@ _native_compiler_configs = [
"//build/config/compiler:compiler_arm_fpu",
"//build/config/compiler:chromium_code",
"//build/config/compiler:default_include_dirs",
"//build/config/compiler:default_optimization",
"//build/config/compiler:default_symbols",
"//build/config/compiler:no_rtti",
"//build/config/compiler:runtime_library",
]
@ -441,7 +421,6 @@ if (is_linux) {
} else if (is_mac) {
_native_compiler_configs += [ "//build/config/mac:sdk" ]
} else if (is_ios) {
_native_compiler_configs += [ "//build/config/ios:sdk" ]
} else if (is_android) {
_native_compiler_configs += [ "//build/config/android:sdk" ]
}
@ -453,41 +432,12 @@ if (is_clang && !is_nacl) {
]
}
# Optimizations and debug checking.
# Debug/release-related defines.
if (is_debug) {
_native_compiler_configs += [ "//build/config:debug" ]
_default_optimization_config = "//build/config/compiler:no_optimize"
} else {
_native_compiler_configs += [ "//build/config:release" ]
_default_optimization_config = "//build/config/compiler:optimize"
}
_native_compiler_configs += [ _default_optimization_config ]
# If it wasn't manually set, set to an appropriate default.
if (symbol_level == -1) {
# Linux is slowed by having symbols as part of the target binary, whereas
# Mac and Windows have them separate, so in Release Linux, default them off.
if (is_debug || !is_linux) {
symbol_level = 2
} else if (is_asan || is_lsan || is_tsan || is_msan) {
# Sanitizers require symbols for filename suppressions to work.
symbol_level = 1
} else {
symbol_level = 0
}
}
# Symbol setup.
if (symbol_level == 2) {
_default_symbols_config = "//build/config/compiler:symbols"
} else if (symbol_level == 1) {
_default_symbols_config = "//build/config/compiler:minimal_symbols"
} else if (symbol_level == 0) {
_default_symbols_config = "//build/config/compiler:no_symbols"
} else {
assert(false, "Bad value for symbol_level.")
}
_native_compiler_configs += [ _default_symbols_config ]
# Windows linker setup for EXEs and DLLs.
if (is_win) {

Просмотреть файл

@ -4,6 +4,9 @@
import("//build/config/android/config.gni")
import("//build/config/chrome_build.gni")
import("//build/config/compiler/compiler.gni")
import("//build/toolchain/ccache.gni")
if (current_cpu == "arm") {
import("//build/config/arm.gni")
}
@ -17,9 +20,6 @@ if (is_win) {
import("//build/config/win/visual_studio_version.gni")
}
import("//build/toolchain/ccache.gni")
import("//build/config/sanitizers/sanitizers.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
@ -84,11 +84,6 @@ config("default_include_dirs") {
]
}
# TODO(GYP) bug 527515: is_ubsan, is_ubsan_vptr
if (!is_win) {
using_sanitizer = is_asan || is_lsan || is_tsan || is_msan
}
# compiler ---------------------------------------------------------------------
#
# Base compiler configuration.
@ -1211,14 +1206,15 @@ config("no_incompatible_pointer_warnings") {
# Optimization -----------------------------------------------------------------
#
# Note that BUILDCONFIG.gn sets up a variable "default_optimization_config"
# which it will assign to the config it implicitly applies to every target. If
# you want to override the optimization level for your target, remove this
# config (which will expand differently for debug or release builds), and then
# add back the one you want to override it with:
# The BUILDCONFIG file sets the "default_optimization" config on targets by
# default. It will be equivalent to either "optimize" (release) or
# "no_optimize" (debug) optimization configs.
#
# configs -= default_optimization_config
# configs += [ "//build/config/compiler/optimize_max" ]
# You can override the optimization level on a per-target basis by removing the
# default config and then adding the named one you want:
#
# configs -= [ "//build/config/compiler:default_optimization" ]
# configs += [ "//build/config/compiler:optimize_max" ]
# Shared settings for both "optimize" and "optimize_max" configs.
# IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags.
@ -1301,43 +1297,57 @@ if (is_win) {
}
}
# Default "optimization on" config. On Windows, this favors size over speed.
# Default "optimization on" config. Set up variables so the
# "default_optimization" config can re-use these settings.
if (is_win) {
# Favor size over speed, /O1 must be before the common flags. The GYP
# build also specifies /Os and /GF but these are implied by /O1.
optimize_cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
} else if (is_android || is_ios) {
# Favor size over speed.
optimize_cflags = [ "-Os" ] + common_optimize_on_cflags
} else {
# Linux & Mac favor speed over size.
# TODO(brettw) it's weird that Mac and desktop Linux are different. We should
# explore favoring size over speed in this case as well.
optimize_cflags = [ "-O2" ] + common_optimize_on_cflags
}
optimize_ldflags = common_optimize_on_ldflags
config("optimize") {
if (is_win) {
# Favor size over speed, /O1 must be before the common flags. The GYP
# build also specifies /Os and /GF but these are implied by /O1.
cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ]
} else if (is_android || is_ios) {
cflags = [ "-Os" ] + common_optimize_on_cflags # Favor size over speed.
} else {
cflags = [ "-O2" ] + common_optimize_on_cflags
}
ldflags = common_optimize_on_ldflags
cflags = optimize_cflags
ldflags = optimize_ldflags
}
# Turn off optimizations.
config("no_optimize") {
if (is_win) {
cflags = [
"/Od", # Disable optimization.
"/Ob0", # Disable all inlining (on by default).
"/RTC1", # Runtime checks for stack frame and uninitialized variables.
]
} else if (is_android && !android_full_debug) {
# On Android we kind of optimize some things that don't affect debugging
# much even when optimization is disabled to get the binary size down.
cflags = [
"-Os",
"-fdata-sections",
"-ffunction-sections",
]
if (!using_sanitizer) {
cflags += [ "-fomit-frame-pointer" ]
}
ldflags = common_optimize_on_ldflags
} else {
cflags = [ "-O0" ]
# Turn off optimizations. Set up variables so the
# "default_optimization" config can re-use these settings.
if (is_win) {
no_optimize_cflags = [
"/Od", # Disable optimization.
"/Ob0", # Disable all inlining (on by default).
"/RTC1", # Runtime checks for stack frame and uninitialized variables.
]
no_optimize_ldflags = []
} else if (is_android && !android_full_debug) {
# On Android we kind of optimize some things that don't affect debugging
# much even when optimization is disabled to get the binary size down.
no_optimize_cflags = [
"-Os",
"-fdata-sections",
"-ffunction-sections",
]
if (!using_sanitizer) {
no_optimize_cflags += [ "-fomit-frame-pointer" ]
}
no_optimize_ldflags = common_optimize_on_ldflags
} else {
no_optimize_cflags = [ "-O0" ]
no_optimize_ldflags = []
}
config("no_optimize") {
cflags = no_optimize_cflags
ldflags = no_optimize_ldflags
}
# Turns up the optimization level. On Windows, this implies whole program
@ -1368,53 +1378,105 @@ config("optimize_max") {
}
}
# The default optimization applied to all targets. This will be equivalent to
# either "optimize" or "no_optimize", depending on the build flags.
config("default_optimization") {
if (is_debug) {
cflags = no_optimize_cflags
ldflags = no_optimize_ldflags
} else {
cflags = optimize_cflags
ldflags = optimize_ldflags
}
}
# Symbols ----------------------------------------------------------------------
config("symbols") {
if (is_win) {
import("//build/toolchain/goma.gni")
if (use_goma) {
cflags = [ "/Z7" ] # No PDB file
} else {
cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
}
if (is_win_fastlink) {
# Tell VS 2015+ to create a PDB that references debug
# information in .obj and .lib files instead of copying
# it all. This flag is incompatible with /PROFILE
ldflags = [ "/DEBUG:FASTLINK" ]
} else {
ldflags = [ "/DEBUG" ]
}
# The BUILDCONFIG file sets the "default_symbols" config on targets by
# default. It will be equivalent to one the three specific symbol levels.
#
# You can override the symbol level on a per-target basis by removing the
# default config and then adding the named one you want:
#
# configs -= [ "//build/config/compiler:default_symbols" ]
# configs += [ "//build/config/compiler:symbols" ]
# Full symbols.
if (is_win) {
import("//build/toolchain/goma.gni")
if (use_goma) {
symbols_cflags = [ "/Z7" ] # No PDB file
} else {
cflags = [ "-g2" ]
if (use_debug_fission) {
cflags += [ "-gsplit-dwarf" ]
}
symbols_cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
}
if (is_win_fastlink) {
# Tell VS 2015+ to create a PDB that references debug
# information in .obj and .lib files instead of copying
# it all. This flag is incompatible with /PROFILE
symbols_ldflags = [ "/DEBUG:FASTLINK" ]
} else {
symbols_ldflags = [ "/DEBUG" ]
}
} else {
symbols_cflags = [ "-g2" ]
if (use_debug_fission) {
symbols_cflags += [ "-gsplit-dwarf" ]
}
symbols_ldflags = []
}
config("symbols") {
cflags = symbols_cflags
ldflags = symbols_ldflags
}
# Minimal symbols.
if (is_win) {
# Linker symbols for backtraces only.
minimal_symbols_cflags = []
if (is_win_fastlink) {
# Tell VS 2015+ to create a PDB that references debug
# information in .obj and .lib files instead of copying
# it all. This flag is incompatible with /PROFILE
minimal_symbols_ldflags = [ "/DEBUG:FASTLINK" ]
} else {
minimal_symbols_ldflags = [ "/DEBUG" ]
}
} else {
minimal_symbols_cflags = [ "-g1" ]
if (use_debug_fission) {
minimal_symbols_cflags += [ "-gsplit-dwarf" ]
}
minimal_symbols_ldflags = []
}
config("minimal_symbols") {
if (is_win) {
# Linker symbols for backtraces only.
if (is_win_fastlink) {
# Tell VS 2015+ to create a PDB that references debug
# information in .obj and .lib files instead of copying
# it all. This flag is incompatible with /PROFILE
ldflags = [ "/DEBUG:FASTLINK" ]
} else {
ldflags = [ "/DEBUG" ]
}
} else {
cflags = [ "-g1" ]
if (use_debug_fission) {
cflags += [ "-gsplit-dwarf" ]
}
}
cflags = minimal_symbols_cflags
ldflags = minimal_symbols_ldflags
}
# No symbols.
if (is_win) {
no_symbols_cflags = []
} else {
no_symbols_cflags = [ "-g0" ]
}
config("no_symbols") {
if (!is_win) {
cflags = [ "-g0" ]
cflags = no_symbols_cflags
}
# Default symbols.
config("default_symbols") {
if (symbol_level == 0) {
cflags = no_symbols_cflags
} else if (symbol_level == 1) {
cflags = minimal_symbols_cflags
ldflags = minimal_symbols_ldflags
} else if (symbol_level == 2) {
cflags = symbols_cflags
ldflags = symbols_ldflags
} else {
assert(false)
}
}

Просмотреть файл

@ -0,0 +1,30 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/sanitizers/sanitizers.gni")
declare_args() {
# How many symbols to include in the build. This affects the performance of
# the build since the symbols are large and dealing with them is slow.
# 2 means regular build with symbols.
# 1 means minimal symbols, usually enough for backtraces only.
# 0 means no symbols.
# -1 means auto-set according to debug/release and platform.
symbol_level = -1
}
# If it wasn't manually set, set to an appropriate default.
assert(symbol_level >= -1 && symbol_level <= 2, "Invalid symbol_level")
if (symbol_level == -1) {
# Linux is slowed by having symbols as part of the target binary, whereas
# Mac and Windows have them separate, so in Release Linux, default them off.
if (is_debug || !is_linux) {
symbol_level = 2
} else if (is_asan || is_lsan || is_tsan || is_msan) {
# Sanitizers require symbols for filename suppressions to work.
symbol_level = 1
} else {
symbol_level = 0
}
}

Просмотреть файл

@ -3,6 +3,18 @@
# found in the LICENSE file.
declare_args() {
# Compile for Address Sanitizer to find memory bugs.
is_asan = false
# Compile for Leak Sanitizer to find leaks.
is_lsan = false
# Compile for Memory Sanitizer to find uninitialized reads.
is_msan = false
# Compile for Thread Sanitizer to find threading bugs.
is_tsan = false
# Use libc++ (buildtools/third_party/libc++ and
# buildtools/third_party/libc++abi) instead of stdlibc++ as standard library.
# This is intended to be used for instrumented builds.
@ -32,6 +44,12 @@ declare_args() {
use_cfi_diag = false
}
# TODO(GYP) bug 527515: is_ubsan, is_ubsan_vptr
using_sanitizer = is_asan || is_lsan || is_tsan || is_msan
assert(!using_sanitizer || is_clang,
"Sanitizers (is_*san) require setting is_clang = true in 'gn args'")
# MSan only links Chrome properly in release builds (brettw -- 9/1/2015). The
# same is possibly true for the other non-ASan sanitizers. But regardless of
# whether it links, one would normally never run a sanitizer in debug mode.

Просмотреть файл

@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/compiler/compiler.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/win/visual_studio_version.gni")

Просмотреть файл

@ -5,6 +5,7 @@
# Do not use the targets in this file unless you need a certain libjpeg
# implementation. Use the meta target //third_party:jpeg instead.
import("//build/config/sanitizers/sanitizers.gni")
if (current_cpu == "arm") {
import("//build/config/arm.gni")
}