Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3038)

Unified Diff: build/config/compiler/BUILD.gn

Issue 1809273002: Enable whole-program virtual function optimization in LTO mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename one more instance of is_lto Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/config/compiler/BUILD.gn
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
index 898b25ff2e07982597603e6b9390211c718ca404..f0c8cd947c34b50c277adc79e56e091c6ba13ead 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -7,6 +7,7 @@ import("//build/config/chrome_build.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/nacl/config.gni")
import("//build/toolchain/cc_wrapper.gni")
+import("//build/toolchain/toolchain.gni")
if (current_cpu == "arm") {
import("//build/config/arm.gni")
@@ -370,6 +371,52 @@ config("compiler") {
}
}
+ # Add flags for link-time optimization. These flags enable
+ # optimizations/transformations that require whole-program visibility at link
+ # time, so they need to be applied to all translation units, and we may end up
+ # with miscompiles if only part of the program is compiled with LTO flags. For
+ # that reason, we cannot allow targets to enable or disable these flags, for
+ # example by disabling the optimize configuration.
+ # TODO(pcc): Make this conditional on is_official_build rather than on gn
+ # flags for specific features.
+ if (!is_debug && (allow_posix_link_time_opt || is_cfi) && !is_nacl) {
+ cflags += [ "-flto" ]
+ ldflags += [ "-flto" ]
+
+ # Apply a lower LTO optimization level as the default is too slow.
+ if (is_linux) {
+ ldflags += [ "-Wl,-plugin-opt,O1" ]
+ } else if (is_mac) {
+ ldflags += [ "-Wl,-mllvm,-O1" ]
+ }
+
+ # Work-around for http://openradar.appspot.com/20356002
+ if (is_mac) {
+ ldflags += [ "-Wl,-all_load" ]
+ }
+
+ # Allows the linker to apply ICF to the LTO object file. Also, when targeting
brettw 2016/04/06 06:25:36 80 cols.
pcc1 2016/04/06 21:42:01 Done.
+ # ARM, without this flag, LTO produces a .text section that is larger than the
+ # maximum call displacement, preventing the linker from relocating calls
+ # (http://llvm.org/PR22999).
+ if (is_linux) {
+ ldflags += [ "-Wl,-plugin-opt,-function-sections" ]
+ }
+
+ # TODO(pcc): Make these flags work correctly with CFI.
+ if (!is_cfi) {
+ cflags += [
+ "-fwhole-program-vtables",
+
+ # TODO(pcc): Remove this flag once the upstream interface change
+ # (http://reviews.llvm.org/D18635) lands.
+ "-fwhole-program-vtables-blacklist=" +
+ rebase_path("//tools/cfi/blacklist.txt", root_build_dir),
+ ]
+ ldflags += [ "-fwhole-program-vtables" ]
+ }
+ }
+
# Pass the same C/C++ flags to the objective C/C++ compiler.
cflags_objc += cflags_c
cflags_objcc += cflags_cc

Powered by Google App Engine
This is Rietveld 408576698