From 96ede16a4e38efba5792cb69d1ad020b586da237 Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Thu, 6 Sep 2018 13:45:44 +0200 Subject: [PATCH] Enable -Wexit-time-destructors and -Wglobal-constructors. This CL enables -Wexit-time-destructors and -Wglobal-constructors on rtc_static_library and rtc_source_set build targets. It also adds the possibility to suppress these warnings because they trigger in a few places. The long term goal is to avoid regressions on this and remove all the suppressions. Bug: webrtc:9693 Change-Id: I4c1ecc137ef9e87ec5e66981ce95d96fb082727c Reviewed-on: https://webrtc-review.googlesource.com/98380 Reviewed-by: Karl Wiberg Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#24604} --- BUILD.gn | 26 +++++++++++++++++++ modules/audio_coding/BUILD.gn | 4 +++ modules/audio_device/BUILD.gn | 3 +++ .../audio_processing/agc2/rnn_vad/BUILD.gn | 1 + modules/congestion_controller/bbr/BUILD.gn | 1 + .../congestion_controller/goog_cc/BUILD.gn | 5 +++- modules/congestion_controller/pcc/BUILD.gn | 1 + modules/remote_bitrate_estimator/BUILD.gn | 4 +++ modules/video_capture/BUILD.gn | 2 ++ ortc/BUILD.gn | 1 + pc/BUILD.gn | 1 + rtc_base/BUILD.gn | 8 ++++++ sdk/BUILD.gn | 7 +++++ sdk/android/BUILD.gn | 5 ++++ system_wrappers/BUILD.gn | 2 ++ webrtc.gni | 9 +++++++ 16 files changed, 79 insertions(+), 1 deletion(-) diff --git a/BUILD.gn b/BUILD.gn index 0fd2a2ae59..418408b7fa 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -166,6 +166,32 @@ config("common_inherited_config") { } } +# TODO(bugs.webrtc.org/9693): Remove the possibility to suppress this warning +# as soon as WebRTC compiles without it. +config("no_exit_time_destructors") { + if (is_clang) { + cflags = [ "-Wno-exit-time-destructors" ] + } +} + +# TODO(bugs.webrtc.org/9693): Remove the possibility to suppress this warning +# as soon as WebRTC compiles without it. +config("no_global_constructors") { + if (is_clang) { + cflags = [ "-Wno-global-constructors" ] + } +} + +config("rtc_prod_config") { + # Ideally, WebRTC production code (but not test code) should have these flags. + if (is_clang) { + cflags = [ + "-Wexit-time-destructors", + "-Wglobal-constructors", + ] + } +} + config("common_config") { cflags = [] cflags_c = [] diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn index 4d24aff8ee..a08bcf3717 100644 --- a/modules/audio_coding/BUILD.gn +++ b/modules/audio_coding/BUILD.gn @@ -1156,6 +1156,10 @@ rtc_source_set("neteq_test_tools") { rtc_source_set("neteq_tools") { visibility += webrtc_default_visibility + configs += [ + "../..:no_exit_time_destructors", + "../..:no_global_constructors", + ] sources = [ "neteq/tools/fake_decode_from_file.cc", "neteq/tools/fake_decode_from_file.h", diff --git a/modules/audio_device/BUILD.gn b/modules/audio_device/BUILD.gn index d60949f52b..964cfefcc2 100644 --- a/modules/audio_device/BUILD.gn +++ b/modules/audio_device/BUILD.gn @@ -147,6 +147,7 @@ rtc_source_set("audio_device_name") { } rtc_source_set("windows_core_audio_utility") { + public_configs = [ "../..:no_global_constructors" ] if (is_win && !build_with_chromium) { sources = [ "win/core_audio_utility_win.cc", @@ -303,6 +304,7 @@ rtc_source_set("audio_device_impl") { defines += [ "WEBRTC_DUMMY_FILE_DEVICES" ] } else { if (is_linux) { + configs += [ "../../..:no_global_constructors" ] sources += [ "linux/alsasymboltable_linux.cc", "linux/alsasymboltable_linux.h", @@ -320,6 +322,7 @@ rtc_source_set("audio_device_impl") { defines += [ "WEBRTC_USE_X11" ] } if (rtc_include_pulse_audio) { + configs += [ "../..:no_exit_time_destructors" ] sources += [ "linux/audio_device_pulse_linux.cc", "linux/audio_device_pulse_linux.h", diff --git a/modules/audio_processing/agc2/rnn_vad/BUILD.gn b/modules/audio_processing/agc2/rnn_vad/BUILD.gn index d1edecea33..867a9bb57f 100644 --- a/modules/audio_processing/agc2/rnn_vad/BUILD.gn +++ b/modules/audio_processing/agc2/rnn_vad/BUILD.gn @@ -9,6 +9,7 @@ import("../../../../webrtc.gni") rtc_source_set("rnn_vad") { + configs += [ "../../../..:no_global_constructors" ] sources = [ "common.h", "features_extraction.cc", diff --git a/modules/congestion_controller/bbr/BUILD.gn b/modules/congestion_controller/bbr/BUILD.gn index a424c118f4..dac3c4729e 100644 --- a/modules/congestion_controller/bbr/BUILD.gn +++ b/modules/congestion_controller/bbr/BUILD.gn @@ -23,6 +23,7 @@ rtc_static_library("bbr") { rtc_source_set("bbr_controller") { visibility = [ ":*" ] + configs += [ "../../..:no_global_constructors" ] sources = [ "bbr_network_controller.cc", "bbr_network_controller.h", diff --git a/modules/congestion_controller/goog_cc/BUILD.gn b/modules/congestion_controller/goog_cc/BUILD.gn index 74219f3de4..10aea3efe3 100644 --- a/modules/congestion_controller/goog_cc/BUILD.gn +++ b/modules/congestion_controller/goog_cc/BUILD.gn @@ -17,7 +17,10 @@ config("bwe_test_logging") { } rtc_static_library("goog_cc") { - configs += [ ":bwe_test_logging" ] + configs += [ + ":bwe_test_logging", + "../../..:no_global_constructors", + ] sources = [ "goog_cc_factory.cc", "goog_cc_network_control.cc", diff --git a/modules/congestion_controller/pcc/BUILD.gn b/modules/congestion_controller/pcc/BUILD.gn index 0f28d822f7..5f78cc663d 100644 --- a/modules/congestion_controller/pcc/BUILD.gn +++ b/modules/congestion_controller/pcc/BUILD.gn @@ -26,6 +26,7 @@ rtc_static_library("pcc_controller") { "pcc_network_controller.cc", "pcc_network_controller.h", ] + configs += [ "../../..:no_global_constructors" ] deps = [ ":bitrate_controller", ":monitor_interval", diff --git a/modules/remote_bitrate_estimator/BUILD.gn b/modules/remote_bitrate_estimator/BUILD.gn index 12612032bf..0758b0a870 100644 --- a/modules/remote_bitrate_estimator/BUILD.gn +++ b/modules/remote_bitrate_estimator/BUILD.gn @@ -33,6 +33,10 @@ rtc_static_library("remote_bitrate_estimator") { if (rtc_enable_bwe_test_logging) { defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=1" ] + configs += [ + "../..:no_exit_time_destructors", + "../..:no_global_constructors", + ] sources += [ "test/bwe_test_logging.cc" ] } else { defines = [ "BWE_TEST_LOGGING_COMPILE_TIME_ENABLE=0" ] diff --git a/modules/video_capture/BUILD.gn b/modules/video_capture/BUILD.gn index 43987eabc0..f0b180ce61 100644 --- a/modules/video_capture/BUILD.gn +++ b/modules/video_capture/BUILD.gn @@ -71,6 +71,8 @@ if (!build_with_chromium) { rtc_source_set("video_capture_internal_impl_objc") { visibility = [ ":video_capture_internal_impl" ] + configs += [ "../..:no_global_constructors" ] + deps = [ ":video_capture_module", "../../rtc_base:rtc_base_approved", diff --git a/ortc/BUILD.gn b/ortc/BUILD.gn index d0fb00f5ca..be7b1fbdec 100644 --- a/ortc/BUILD.gn +++ b/ortc/BUILD.gn @@ -14,6 +14,7 @@ if (is_android) { rtc_static_library("ortc") { defines = [] + configs += [ "..:no_exit_time_destructors" ] sources = [ "ortcfactory.cc", "ortcfactory.h", diff --git a/pc/BUILD.gn b/pc/BUILD.gn index da5a1c2135..ba415b8ca9 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -117,6 +117,7 @@ rtc_source_set("rtc_pc") { rtc_static_library("peerconnection") { visibility = [ "*" ] cflags = [] + configs += [ "..:no_exit_time_destructors" ] sources = [ "audiotrack.cc", "audiotrack.h", diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 55424e33c6..11550c7d00 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -208,6 +208,10 @@ rtc_source_set("logging") { "../../webrtc_overrides/rtc_base/logging.h", ] } else { + configs += [ + "..:no_exit_time_destructors", + "..:no_global_constructors", + ] sources = [ "logging.cc", "logging.h", @@ -881,6 +885,10 @@ rtc_static_library("rtc_base_generic") { ] if (is_win) { + configs += [ + "..:no_exit_time_destructors", + "..:no_global_constructors", + ] sources += [ "win32socketinit.cc", "win32socketinit.h", diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index b5fd1048bb..95750fceac 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -531,6 +531,7 @@ if (is_ios || is_mac) { rtc_static_library("videocodec_objc") { visibility = [ "*" ] + configs += [ "..:no_global_constructors" ] sources = [ "objc/components/video_codec/RTCCodecSpecificInfoH264+Private.h", "objc/components/video_codec/RTCCodecSpecificInfoH264.h", @@ -585,6 +586,7 @@ if (is_ios || is_mac) { } rtc_static_library("vpx_codec_constants") { + configs += [ "..:no_global_constructors" ] sources = [ "objc/api/video_codec/RTCVideoCodecConstants.h", "objc/api/video_codec/RTCVideoCodecConstants.mm", @@ -664,6 +666,7 @@ if (is_ios || is_mac) { } rtc_static_library("mediaconstraints_objc") { + configs += [ "..:no_global_constructors" ] sources = [ "objc/api/peerconnection/RTCMediaConstraints+Private.h", "objc/api/peerconnection/RTCMediaConstraints.h", @@ -775,6 +778,10 @@ if (is_ios || is_mac) { "audio_codecs", # TODO(bugs.webrtc.org/8396): Remove. "software_video_codecs", # TODO(bugs.webrtc.org/7925): Remove. ] + configs += [ + "..:no_exit_time_destructors", + "..:no_global_constructors", + ] sources = [ "objc/api/peerconnection/RTCAudioSource+Private.h", "objc/api/peerconnection/RTCAudioSource.h", diff --git a/sdk/android/BUILD.gn b/sdk/android/BUILD.gn index ac94f97930..30012bcdca 100644 --- a/sdk/android/BUILD.gn +++ b/sdk/android/BUILD.gn @@ -602,6 +602,11 @@ if (is_android) { # considered public and are subject to change. visibility = [ "*" ] + configs += [ + "../..:no_exit_time_destructors", + "../..:no_global_constructors", + ] + sources = [ "src/jni/androidnetworkmonitor_jni.h", "src/jni/pc/androidnetworkmonitor.h", diff --git a/system_wrappers/BUILD.gn b/system_wrappers/BUILD.gn index 106c63b055..a7002b8291 100644 --- a/system_wrappers/BUILD.gn +++ b/system_wrappers/BUILD.gn @@ -14,6 +14,7 @@ import("../webrtc.gni") rtc_static_library("system_wrappers") { visibility = [ "*" ] + configs += [ "..:no_exit_time_destructors" ] sources = [ "include/clock.h", "include/cpu_info.h", @@ -144,6 +145,7 @@ rtc_source_set("field_trial_default") { rtc_source_set("runtime_enabled_features_default") { visibility = [ "*" ] + configs += [ "..:no_global_constructors" ] sources = [ "source/runtime_enabled_features_default.cc", ] diff --git a/webrtc.gni b/webrtc.gni index 58631ddc7d..41397f3ff4 100644 --- a/webrtc.gni +++ b/webrtc.gni @@ -266,6 +266,7 @@ rtc_common_inherited_config = webrtc_root + ":common_inherited_config" # Common configs to remove or add in all rtc targets. rtc_remove_configs = [] rtc_add_configs = rtc_common_configs +rtc_prod_configs = [ webrtc_root + ":rtc_prod_config" ] set_defaults("rtc_test") { configs = rtc_add_configs @@ -426,6 +427,10 @@ template("rtc_source_set") { } } + if (!defined(testonly) || !testonly) { + configs += rtc_prod_configs + } + configs += invoker.configs configs -= rtc_remove_configs configs -= invoker.suppressed_configs @@ -530,6 +535,10 @@ template("rtc_static_library") { } } + if (!defined(testonly) || !testonly) { + configs += rtc_prod_configs + } + configs += invoker.configs configs -= rtc_remove_configs configs -= invoker.suppressed_configs