static_initializers.md: Document -Wglobal-constructors
Also moves the config for this from //base -> //build/config/compiler for symmetry with //build/config/compiler:wexit_time_destructors. Bug: None Change-Id: If117e5963df44fdc2f03e01716e8af16e2c91e58 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2453460 Reviewed-by: Nico Weber <thakis@chromium.org> Commit-Queue: Andrew Grieve <agrieve@chromium.org> Cr-Commit-Position: refs/heads/master@{#814731}
This commit is contained in:

committed by
Commit Bot

parent
a1e355fa5a
commit
d50971be38
@@ -92,18 +92,6 @@ if (is_fuchsia) {
|
|||||||
import("//third_party/fuchsia-sdk/sdk/build/fidl_library.gni")
|
import("//third_party/fuchsia-sdk/sdk/build/fidl_library.gni")
|
||||||
}
|
}
|
||||||
|
|
||||||
config("base_flags") {
|
|
||||||
if (is_clang) {
|
|
||||||
cflags = [
|
|
||||||
# Ideally all product code (but no test code) in chrome would have these
|
|
||||||
# flags. But this isn't trivial so start with //base as a minimum
|
|
||||||
# requirement.
|
|
||||||
# https://groups.google.com/a/chromium.org/d/topic/chromium-dev/B9Q5KTD7iCo/discussion
|
|
||||||
"-Wglobal-constructors",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
config("base_implementation") {
|
config("base_implementation") {
|
||||||
defines = [ "BASE_IMPLEMENTATION" ]
|
defines = [ "BASE_IMPLEMENTATION" ]
|
||||||
configs = [ "//build/config/compiler:wexit_time_destructors" ]
|
configs = [ "//build/config/compiler:wexit_time_destructors" ]
|
||||||
@@ -1249,10 +1237,10 @@ component("base") {
|
|||||||
frameworks = []
|
frameworks = []
|
||||||
|
|
||||||
configs += [
|
configs += [
|
||||||
":base_flags",
|
|
||||||
":base_implementation",
|
":base_implementation",
|
||||||
"//build/config:precompiled_headers",
|
"//build/config:precompiled_headers",
|
||||||
"//build/config/compiler:noshadowing",
|
"//build/config/compiler:noshadowing",
|
||||||
|
"//build/config/compiler:wglobal_constructors",
|
||||||
]
|
]
|
||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
|
@@ -1830,9 +1830,18 @@ config("no_exceptions") {
|
|||||||
|
|
||||||
# Warnings ---------------------------------------------------------------------
|
# Warnings ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Generate a warning for code that might emit a static initializer.
|
||||||
|
# See: //docs/static_initializers.md
|
||||||
|
# See: https://groups.google.com/a/chromium.org/d/topic/chromium-dev/B9Q5KTD7iCo/discussion
|
||||||
|
config("wglobal_constructors") {
|
||||||
|
if (is_clang) {
|
||||||
|
cflags = [ "-Wglobal-constructors" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# This will generate warnings when using Clang if code generates exit-time
|
# This will generate warnings when using Clang if code generates exit-time
|
||||||
# destructors, which will slow down closing the program.
|
# destructors, which will slow down closing the program.
|
||||||
# TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
|
# TODO(thakis): Make this a blocklist instead, http://crbug.com/101600
|
||||||
config("wexit_time_destructors") {
|
config("wexit_time_destructors") {
|
||||||
if (is_clang) {
|
if (is_clang) {
|
||||||
cflags = [ "-Wexit-time-destructors" ]
|
cflags = [ "-Wexit-time-destructors" ]
|
||||||
|
@@ -23,6 +23,17 @@ Common fixes include:
|
|||||||
|
|
||||||
## Listing Static Initializers
|
## Listing Static Initializers
|
||||||
|
|
||||||
|
### Method 1 - Ask compiler to report them
|
||||||
|
1. Edit [//build/config/BUILDCONFIG.gn](https://cs.chromium.org/chromium/src/build/config/BUILDCONFIG.gn)
|
||||||
|
and add `"//build/config/compiler:wglobal_constructors"` to `default_compiler_configs`
|
||||||
|
2. Set GN arg `treat_warnings_as_errors=false`
|
||||||
|
3. Compile and look at warnings
|
||||||
|
|
||||||
|
This will produce far more warnings than there are static initializers because
|
||||||
|
it (seems to) trigger on global variables initialized with constexpr
|
||||||
|
constructors.
|
||||||
|
|
||||||
|
### Method 2 - Use objdump to report them
|
||||||
For Linux:
|
For Linux:
|
||||||
|
|
||||||
tools/linux/dump-static-initializers.py out/Release/chrome
|
tools/linux/dump-static-initializers.py out/Release/chrome
|
||||||
|
Reference in New Issue
Block a user