From de7c195f7c113e7c323942e1c378f221213e51e1 Mon Sep 17 00:00:00 2001 From: Alexander Frick Date: Mon, 22 Jan 2024 09:06:18 -0600 Subject: [PATCH] update main BUILD.gns --- arm/build/config/compiler/BUILD.gn | 132 ++++++++++++++++------ arm/raspi/raspi_args.gn | 1 + other/AVX2/build/config/compiler/BUILD.gn | 106 +++++++++++------ other/CrOS/build/config/compiler/BUILD.gn | 115 +++++++++++++------ other/SSE3/build/config/compiler/BUILD.gn | 106 +++++++++++------ src/build/config/compiler/BUILD.gn | 120 +++++++++++++------- 6 files changed, 411 insertions(+), 169 deletions(-) diff --git a/arm/build/config/compiler/BUILD.gn b/arm/build/config/compiler/BUILD.gn index 464a3445..fe156def 100644 --- a/arm/build/config/compiler/BUILD.gn +++ b/arm/build/config/compiler/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2023 The Chromium Authors and Alex313031 +# Copyright 2024 The Chromium Authors and Alex313031 # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -19,6 +19,7 @@ import("//build/config/rust.gni") import("//build/config/ui.gni") import("//build/config/unwind.gni") import("//build/toolchain/cc_wrapper.gni") +import("//build/toolchain/cros/cros_config.gni") import("//build/toolchain/goma.gni") import("//build/toolchain/rbe.gni") import("//build/toolchain/toolchain.gni") @@ -74,6 +75,9 @@ declare_args() { # Whether to enable LLVM's Polly optimizations. See https://polly.llvm.org/ use_polly = false + # Whether to use Raspberry Pi specific optimizations. + is_raspi = false + # Enable fatal linker warnings. Building Chromium with certain versions # of binutils can cause linker warning. fatal_linker_warnings = true @@ -135,6 +139,11 @@ declare_args() { (is_chromeos || is_android || is_win || is_linux || is_mac || (is_ios && use_lld)) && is_official_build + # Whether to enable thin lto incremental builds. + # See: https://clang.llvm.org/docs/ThinLTO.html#incremental + # The cache can lead to non-determinism: https://crbug.com/1486045 + thin_lto_enable_cache = false + # Initialize all local variables with a pattern. This flag will fill # uninitialized floating-point types (and 32-bit pointers) with 0xFF and the # rest with 0xAA. This makes behavior of uninitialized memory bugs consistent, @@ -489,6 +498,11 @@ config("compiler") { asmflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] cflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] } + + # dsymutil is not available in the system, on bots, for rustc to call. Our + # linker_driver.py script runs dsymutil itself, which is set to be the + # linker for Rust targets as well. + rustflags += [ "-Csplit-debuginfo=unpacked" ] } # Linux/Android/Fuchsia common flags setup. @@ -619,6 +633,24 @@ config("compiler") { } } + # TODO(crbug.com/1488374): This causes binary size growth and potentially + # other problems. + # TODO(crbug.com/1491036): This isn't supported by Cronet's mainline llvm version. + if (default_toolchain != "//build/toolchain/cros:target" && + !llvm_android_mainline) { + cflags += [ + "-mllvm", + "-split-threshold-for-reg-with-hint=0", + ] + if (use_thin_lto && is_a_target_toolchain) { + if (is_win) { + ldflags += [ "-mllvm:-split-threshold-for-reg-with-hint=0" ] + } else { + ldflags += [ "-Wl,-mllvm,-split-threshold-for-reg-with-hint=0" ] + } + } + } + # TODO(crbug.com/1235145): Investigate why/if this should be needed. if (is_win) { cflags += [ "/clang:-ffp-contract=fast" ] @@ -675,8 +707,7 @@ config("compiler") { } } else if (is_win) { cflags_c += [ "/std:c11" ] - if ((defined(use_cxx17) && use_cxx17) || - (!is_clang && defined(msvc_use_cxx17) && msvc_use_cxx17)) { + if (defined(use_cxx17) && use_cxx17) { cflags_cc += [ "/std:c++17" ] } else { cflags_cc += [ "/std:c++20" ] @@ -723,9 +754,26 @@ config("compiler") { "-fsplit-lto-unit", ] - # Limit the size of the ThinLTO cache to the lesser of 10% of - # available disk space, 40GB and 100000 files. - # cache_policy = "cache_size=10%:cache_size_bytes=40g:cache_size_files=100000" + if (thin_lto_enable_cache) { + # Limit the size of the ThinLTO cache to the lesser of 10% of + # available disk space, 40GB and 100000 files. + cache_policy = + "cache_size=10%:cache_size_bytes=40g:cache_size_files=100000" + cache_dir = rebase_path("$root_out_dir/thinlto-cache", root_build_dir) + if (is_win) { + ldflags += [ + "/lldltocache:$cache_dir", + "/lldltocachepolicy:$cache_policy", + ] + } else { + if (is_apple) { + ldflags += [ "-Wl,-cache_path_lto,$cache_dir" ] + } else { + ldflags += [ "-Wl,--thinlto-cache-dir=$cache_dir" ] + } + ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ] + } + } # An import limit of 30 has better performance (per speedometer) and lower # binary size than the default setting of 100. @@ -740,9 +788,6 @@ config("compiler") { "-mllvm:-import-hot-multiplier=15", "-mllvm:-import-cold-multiplier=2", "-mllvm:-disable-auto-upgrade-debug-info", - # "/lldltocache:" + - # rebase_path("$root_out_dir/thinlto-cache", root_build_dir), - # "/lldltocachepolicy:$cache_policy", ] } else { ldflags += [ "-flto=thin" ] @@ -756,18 +801,6 @@ config("compiler") { # TODO(thakis): Check if '=0' (that is, number of cores, instead # of "all" which means number of hardware threads) is faster. ldflags += [ "-Wl,--thinlto-jobs=all" ] - if (is_apple) { - ldflags += [ - "-Wl,-cache_path_lto," + - rebase_path("$root_out_dir/thinlto-cache", root_build_dir), - "-Wcrl,object_path_lto", - ] - } else { - ldflags += - [ "-Wl,-O3" ] - } - - # ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ] if (is_chromeos) { # ARM was originally set lower than x86 to keep the size @@ -783,6 +816,10 @@ config("compiler") { ldflags += [ "-Wl,-mllvm,-import-instr-limit=$import_instr_limit" ] + if (is_apple) { + ldflags += [ "-Wcrl,object_path_lto" ] + } + if (!is_chromeos) { # TODO(https://crbug.com/972449): turn on for ChromeOS when that # toolchain has this flag. @@ -832,6 +869,9 @@ config("compiler") { if (compiler_timing) { if (is_clang && !is_nacl) { cflags += [ "-ftime-trace" ] + if (use_lld && is_mac) { + ldflags += [ "-Wl,--time-trace" ] + } } else if (is_win) { cflags += [ # "Documented" here: @@ -1145,11 +1185,16 @@ config("compiler_cpu_abi") { cflags += [ "-m64", "-O3", + "-msse3", + "-mssse3", + "-msse4", + "-msse4.1", + "-msse4.2", "-mavx", "-maes", "-mpclmul", ] - ldflags += [ "-m64", "-Wl,-O3", "-mavx", "-maes", "-mpclmul", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2", ] + ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-mssse3", "-msse4", "-msse4.1", "-msse4.2", "-mavx", "-maes", "-mpclmul", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2", ] } else if (current_cpu == "x86") { cflags += [ "-m32" ] ldflags += [ "-m32", "-Wl,-O3", "-msse3", ] @@ -1858,14 +1903,6 @@ config("default_warnings") { "-Wno-ignored-pragma-optimize", ] - if (llvm_force_head_revision && !is_nacl && enable_precompiled_headers && - !is_win) { - cflags += [ - # TODO(crbug.com/1486799) Find a long-term solution. - "-Wno-deprecated-include-gch", - ] - } - if (!is_nacl) { cflags += [ # TODO(crbug.com/1343975) Evaluate and possibly enable. @@ -1876,6 +1913,18 @@ config("default_warnings") { # TODO(crbug.com/1412713) Evaluate and possibly enable. "-Wno-deprecated-this-capture", + + # TODO(https://crbug.com/1491833): Fix and re-enable. + "-Wno-invalid-offsetof", + + # TODO(crbug.com/1494809): Evaluate and possibly enable. + "-Wno-vla-extension", + + # TODO(https://crbug.com/1490607): Fix and re-enable. + "-Wno-thread-safety-reference-return", + + # TODO(crbug.com/1495100): Evaluate and possibly enable. + "-Wno-delayed-template-parsing-in-cxx20", ] } } @@ -1976,9 +2025,10 @@ config("chromium_code") { # disabled, so only do that for Release build. fortify_level = "2" - # ChromeOS supports a high-quality _FORTIFY_SOURCE=3 implementation - # with a few custom glibc patches. Use that if it's available. - if (is_chromeos_ash) { + # ChromeOS's toolchain supports a high-quality _FORTIFY_SOURCE=3 + # implementation with a few custom glibc patches. Use that if it's + # available. + if (is_chromeos_device && !lacros_use_chromium_toolchain) { fortify_level = "3" } defines += [ "_FORTIFY_SOURCE=" + fortify_level ] @@ -2281,6 +2331,10 @@ if (is_win) { "-Xclang", "-O3", ] + if (current_cpu == "arm64") { + common_optimize_on_ldflags += [ "-march=armv8-a+simd", ] + } + common_optimize_on_ldflags += [ ] @@ -2313,10 +2367,22 @@ if (is_win) { common_optimize_on_cflags = [] common_optimize_on_ldflags = [] + if (current_cpu == "arm64") { + common_optimize_on_cflags += [ "-march=armv8-a+simd", ] + } + + if (is_raspi == true) { + common_optimize_on_cflags += [ "-mtune=cortex-a72", ] + } + common_optimize_on_cflags += [ "-O3", ] + if (current_cpu == "arm64") { + common_optimize_on_ldflags += [ "-march=armv8-a+simd", ] + } + common_optimize_on_ldflags += [ "-Wl,-O3", ] diff --git a/arm/raspi/raspi_args.gn b/arm/raspi/raspi_args.gn index eb37aa2f..7b972149 100644 --- a/arm/raspi/raspi_args.gn +++ b/arm/raspi/raspi_args.gn @@ -4,6 +4,7 @@ google_default_client_secret = "" target_os = "linux" target_cpu = "arm64" v8_target_cpu = "arm64" +is_raspi = true # sysroot = "/home/alex/chromium/src/build/linux/debian_bullseye_arm64-sysroot" arm_version = 8 arm_arch = "armv8-a" diff --git a/other/AVX2/build/config/compiler/BUILD.gn b/other/AVX2/build/config/compiler/BUILD.gn index d4780ffe..87fb15e6 100644 --- a/other/AVX2/build/config/compiler/BUILD.gn +++ b/other/AVX2/build/config/compiler/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2023 The Chromium Authors and Alex313031 +# Copyright 2024 The Chromium Authors and Alex313031 # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -19,6 +19,7 @@ import("//build/config/rust.gni") import("//build/config/ui.gni") import("//build/config/unwind.gni") import("//build/toolchain/cc_wrapper.gni") +import("//build/toolchain/cros/cros_config.gni") import("//build/toolchain/goma.gni") import("//build/toolchain/rbe.gni") import("//build/toolchain/toolchain.gni") @@ -135,6 +136,11 @@ declare_args() { (is_chromeos || is_android || is_win || is_linux || is_mac || (is_ios && use_lld)) && is_official_build + # Whether to enable thin lto incremental builds. + # See: https://clang.llvm.org/docs/ThinLTO.html#incremental + # The cache can lead to non-determinism: https://crbug.com/1486045 + thin_lto_enable_cache = false + # Initialize all local variables with a pattern. This flag will fill # uninitialized floating-point types (and 32-bit pointers) with 0xFF and the # rest with 0xAA. This makes behavior of uninitialized memory bugs consistent, @@ -489,6 +495,11 @@ config("compiler") { asmflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] cflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] } + + # dsymutil is not available in the system, on bots, for rustc to call. Our + # linker_driver.py script runs dsymutil itself, which is set to be the + # linker for Rust targets as well. + rustflags += [ "-Csplit-debuginfo=unpacked" ] } # Linux/Android/Fuchsia common flags setup. @@ -619,6 +630,24 @@ config("compiler") { } } + # TODO(crbug.com/1488374): This causes binary size growth and potentially + # other problems. + # TODO(crbug.com/1491036): This isn't supported by Cronet's mainline llvm version. + if (default_toolchain != "//build/toolchain/cros:target" && + !llvm_android_mainline) { + cflags += [ + "-mllvm", + "-split-threshold-for-reg-with-hint=0", + ] + if (use_thin_lto && is_a_target_toolchain) { + if (is_win) { + ldflags += [ "-mllvm:-split-threshold-for-reg-with-hint=0" ] + } else { + ldflags += [ "-Wl,-mllvm,-split-threshold-for-reg-with-hint=0" ] + } + } + } + # TODO(crbug.com/1235145): Investigate why/if this should be needed. if (is_win) { cflags += [ "/clang:-ffp-contract=fast" ] @@ -675,8 +704,7 @@ config("compiler") { } } else if (is_win) { cflags_c += [ "/std:c11" ] - if ((defined(use_cxx17) && use_cxx17) || - (!is_clang && defined(msvc_use_cxx17) && msvc_use_cxx17)) { + if (defined(use_cxx17) && use_cxx17) { cflags_cc += [ "/std:c++17" ] } else { cflags_cc += [ "/std:c++20" ] @@ -723,9 +751,26 @@ config("compiler") { "-fsplit-lto-unit", ] - # Limit the size of the ThinLTO cache to the lesser of 10% of - # available disk space, 40GB and 100000 files. - # cache_policy = "cache_size=10%:cache_size_bytes=40g:cache_size_files=100000" + if (thin_lto_enable_cache) { + # Limit the size of the ThinLTO cache to the lesser of 10% of + # available disk space, 40GB and 100000 files. + cache_policy = + "cache_size=10%:cache_size_bytes=40g:cache_size_files=100000" + cache_dir = rebase_path("$root_out_dir/thinlto-cache", root_build_dir) + if (is_win) { + ldflags += [ + "/lldltocache:$cache_dir", + "/lldltocachepolicy:$cache_policy", + ] + } else { + if (is_apple) { + ldflags += [ "-Wl,-cache_path_lto,$cache_dir" ] + } else { + ldflags += [ "-Wl,--thinlto-cache-dir=$cache_dir" ] + } + ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ] + } + } # An import limit of 30 has better performance (per speedometer) and lower # binary size than the default setting of 100. @@ -740,9 +785,6 @@ config("compiler") { "-mllvm:-import-hot-multiplier=15", "-mllvm:-import-cold-multiplier=2", "-mllvm:-disable-auto-upgrade-debug-info", - # "/lldltocache:" + - # rebase_path("$root_out_dir/thinlto-cache", root_build_dir), - # "/lldltocachepolicy:$cache_policy", ] } else { ldflags += [ "-flto=thin" ] @@ -756,18 +798,6 @@ config("compiler") { # TODO(thakis): Check if '=0' (that is, number of cores, instead # of "all" which means number of hardware threads) is faster. ldflags += [ "-Wl,--thinlto-jobs=all" ] - if (is_apple) { - ldflags += [ - "-Wl,-cache_path_lto," + - rebase_path("$root_out_dir/thinlto-cache", root_build_dir), - "-Wcrl,object_path_lto", - ] - } else { - ldflags += - [ "-Wl,-O3" ] - } - - # ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ] if (is_chromeos) { # ARM was originally set lower than x86 to keep the size @@ -783,6 +813,10 @@ config("compiler") { ldflags += [ "-Wl,-mllvm,-import-instr-limit=$import_instr_limit" ] + if (is_apple) { + ldflags += [ "-Wcrl,object_path_lto" ] + } + if (!is_chromeos) { # TODO(https://crbug.com/972449): turn on for ChromeOS when that # toolchain has this flag. @@ -828,6 +862,9 @@ config("compiler") { if (compiler_timing) { if (is_clang && !is_nacl) { cflags += [ "-ftime-trace" ] + if (use_lld && is_mac) { + ldflags += [ "-Wl,--time-trace" ] + } } else if (is_win) { cflags += [ # "Documented" here: @@ -1854,14 +1891,6 @@ config("default_warnings") { "-Wno-ignored-pragma-optimize", ] - if (llvm_force_head_revision && !is_nacl && enable_precompiled_headers && - !is_win) { - cflags += [ - # TODO(crbug.com/1486799) Find a long-term solution. - "-Wno-deprecated-include-gch", - ] - } - if (!is_nacl) { cflags += [ # TODO(crbug.com/1343975) Evaluate and possibly enable. @@ -1872,6 +1901,18 @@ config("default_warnings") { # TODO(crbug.com/1412713) Evaluate and possibly enable. "-Wno-deprecated-this-capture", + + # TODO(https://crbug.com/1491833): Fix and re-enable. + "-Wno-invalid-offsetof", + + # TODO(crbug.com/1494809): Evaluate and possibly enable. + "-Wno-vla-extension", + + # TODO(https://crbug.com/1490607): Fix and re-enable. + "-Wno-thread-safety-reference-return", + + # TODO(crbug.com/1495100): Evaluate and possibly enable. + "-Wno-delayed-template-parsing-in-cxx20", ] } } @@ -1972,9 +2013,10 @@ config("chromium_code") { # disabled, so only do that for Release build. fortify_level = "2" - # ChromeOS supports a high-quality _FORTIFY_SOURCE=3 implementation - # with a few custom glibc patches. Use that if it's available. - if (is_chromeos_ash) { + # ChromeOS's toolchain supports a high-quality _FORTIFY_SOURCE=3 + # implementation with a few custom glibc patches. Use that if it's + # available. + if (is_chromeos_device && !lacros_use_chromium_toolchain) { fortify_level = "3" } defines += [ "_FORTIFY_SOURCE=" + fortify_level ] diff --git a/other/CrOS/build/config/compiler/BUILD.gn b/other/CrOS/build/config/compiler/BUILD.gn index d58411bf..12c2dd61 100644 --- a/other/CrOS/build/config/compiler/BUILD.gn +++ b/other/CrOS/build/config/compiler/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2023 The Chromium Authors and Alex313031 +# Copyright 2024 The Chromium Authors and Alex313031 # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -19,6 +19,7 @@ import("//build/config/rust.gni") import("//build/config/ui.gni") import("//build/config/unwind.gni") import("//build/toolchain/cc_wrapper.gni") +import("//build/toolchain/cros/cros_config.gni") import("//build/toolchain/goma.gni") import("//build/toolchain/rbe.gni") import("//build/toolchain/toolchain.gni") @@ -135,6 +136,11 @@ declare_args() { (is_chromeos || is_android || is_win || is_linux || is_mac || (is_ios && use_lld)) && is_official_build + # Whether to enable thin lto incremental builds. + # See: https://clang.llvm.org/docs/ThinLTO.html#incremental + # The cache can lead to non-determinism: https://crbug.com/1486045 + thin_lto_enable_cache = false + # Initialize all local variables with a pattern. This flag will fill # uninitialized floating-point types (and 32-bit pointers) with 0xFF and the # rest with 0xAA. This makes behavior of uninitialized memory bugs consistent, @@ -489,6 +495,11 @@ config("compiler") { asmflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] cflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] } + + # dsymutil is not available in the system, on bots, for rustc to call. Our + # linker_driver.py script runs dsymutil itself, which is set to be the + # linker for Rust targets as well. + rustflags += [ "-Csplit-debuginfo=unpacked" ] } # Linux/Android/Fuchsia common flags setup. @@ -619,6 +630,24 @@ config("compiler") { } } + # TODO(crbug.com/1488374): This causes binary size growth and potentially + # other problems. + # TODO(crbug.com/1491036): This isn't supported by Cronet's mainline llvm version. + if (default_toolchain != "//build/toolchain/cros:target" && + !llvm_android_mainline) { + cflags += [ + "-mllvm", + "-split-threshold-for-reg-with-hint=0", + ] + if (use_thin_lto && is_a_target_toolchain) { + if (is_win) { + ldflags += [ "-mllvm:-split-threshold-for-reg-with-hint=0" ] + } else { + ldflags += [ "-Wl,-mllvm,-split-threshold-for-reg-with-hint=0" ] + } + } + } + # TODO(crbug.com/1235145): Investigate why/if this should be needed. if (is_win) { cflags += [ "/clang:-ffp-contract=off" ] @@ -675,8 +704,7 @@ config("compiler") { } } else if (is_win) { cflags_c += [ "/std:c11" ] - if ((defined(use_cxx17) && use_cxx17) || - (!is_clang && defined(msvc_use_cxx17) && msvc_use_cxx17)) { + if (defined(use_cxx17) && use_cxx17) { cflags_cc += [ "/std:c++17" ] } else { cflags_cc += [ "/std:c++20" ] @@ -723,9 +751,26 @@ config("compiler") { "-fsplit-lto-unit", ] - # Limit the size of the ThinLTO cache to the lesser of 10% of - # available disk space, 40GB and 100000 files. - # cache_policy = "cache_size=10%:cache_size_bytes=40g:cache_size_files=100000" + if (thin_lto_enable_cache) { + # Limit the size of the ThinLTO cache to the lesser of 10% of + # available disk space, 40GB and 100000 files. + cache_policy = + "cache_size=10%:cache_size_bytes=40g:cache_size_files=100000" + cache_dir = rebase_path("$root_out_dir/thinlto-cache", root_build_dir) + if (is_win) { + ldflags += [ + "/lldltocache:$cache_dir", + "/lldltocachepolicy:$cache_policy", + ] + } else { + if (is_apple) { + ldflags += [ "-Wl,-cache_path_lto,$cache_dir" ] + } else { + ldflags += [ "-Wl,--thinlto-cache-dir=$cache_dir" ] + } + ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ] + } + } # An import limit of 30 has better performance (per speedometer) and lower # binary size than the default setting of 100. @@ -740,9 +785,6 @@ config("compiler") { "-mllvm:-import-hot-multiplier=15", "-mllvm:-import-cold-multiplier=2", "-mllvm:-disable-auto-upgrade-debug-info", - # "/lldltocache:" + - # rebase_path("$root_out_dir/thinlto-cache", root_build_dir), - # "/lldltocachepolicy:$cache_policy", ] } else { ldflags += [ "-flto=thin" ] @@ -756,18 +798,6 @@ config("compiler") { # TODO(thakis): Check if '=0' (that is, number of cores, instead # of "all" which means number of hardware threads) is faster. ldflags += [ "-Wl,--thinlto-jobs=all" ] - if (is_apple) { - ldflags += [ - "-Wl,-cache_path_lto," + - rebase_path("$root_out_dir/thinlto-cache", root_build_dir), - "-Wcrl,object_path_lto", - ] - } else { - ldflags += - [ "-Wl,-O3" ] - } - - # ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ] if (is_chromeos) { # ARM was originally set lower than x86 to keep the size @@ -783,6 +813,10 @@ config("compiler") { ldflags += [ "-Wl,-mllvm,-import-instr-limit=$import_instr_limit" ] + if (is_apple) { + ldflags += [ "-Wcrl,object_path_lto" ] + } + if (!is_chromeos) { # TODO(https://crbug.com/972449): turn on for ChromeOS when that # toolchain has this flag. @@ -828,6 +862,9 @@ config("compiler") { if (compiler_timing) { if (is_clang && !is_nacl) { cflags += [ "-ftime-trace" ] + if (use_lld && is_mac) { + ldflags += [ "-Wl,--time-trace" ] + } } else if (is_win) { cflags += [ # "Documented" here: @@ -1141,9 +1178,12 @@ config("compiler_cpu_abi") { cflags += [ "-m64", "-O3", + "-msse3", + "-mssse3", + "-msse4", "-msse4.1", ] - ldflags += [ "-m64", "-Wl,-O3", "-msse4.1", ] + ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-mssse3", "-msse4", "-msse4.1", ] } else if (current_cpu == "x86") { cflags += [ "-m32" ] ldflags += [ "-m32", "-Wl,-O3", "-msse3", ] @@ -1852,14 +1892,6 @@ config("default_warnings") { "-Wno-ignored-pragma-optimize", ] - if (llvm_force_head_revision && !is_nacl && enable_precompiled_headers && - !is_win) { - cflags += [ - # TODO(crbug.com/1486799) Find a long-term solution. - "-Wno-deprecated-include-gch", - ] - } - if (!is_nacl) { cflags += [ # TODO(crbug.com/1343975) Evaluate and possibly enable. @@ -1870,6 +1902,18 @@ config("default_warnings") { # TODO(crbug.com/1412713) Evaluate and possibly enable. "-Wno-deprecated-this-capture", + + # TODO(https://crbug.com/1491833): Fix and re-enable. + "-Wno-invalid-offsetof", + + # TODO(crbug.com/1494809): Evaluate and possibly enable. + "-Wno-vla-extension", + + # TODO(https://crbug.com/1490607): Fix and re-enable. + "-Wno-thread-safety-reference-return", + + # TODO(crbug.com/1495100): Evaluate and possibly enable. + "-Wno-delayed-template-parsing-in-cxx20", ] } } @@ -1970,9 +2014,10 @@ config("chromium_code") { # disabled, so only do that for Release build. fortify_level = "2" - # ChromeOS supports a high-quality _FORTIFY_SOURCE=3 implementation - # with a few custom glibc patches. Use that if it's available. - if (is_chromeos_ash) { + # ChromeOS's toolchain supports a high-quality _FORTIFY_SOURCE=3 + # implementation with a few custom glibc patches. Use that if it's + # available. + if (is_chromeos_device && !lacros_use_chromium_toolchain) { fortify_level = "3" } defines += [ "_FORTIFY_SOURCE=" + fortify_level ] @@ -2284,6 +2329,9 @@ if (is_win) { "-mllvm", "-enable-dfa-jump-thread", "/O2", "/clang:-O3", + "/clang:-msse3", + "/clang:-mssse3", + "/clang:-msse4", "/clang:-msse4.1", "-Xclang", "-O3", ] @@ -2342,6 +2390,7 @@ if (is_win) { ] common_optimize_on_ldflags += [ + "-Wl,-mllvm,-freroll-loops", "-Wl,-mllvm,-enable-gvn-hoist", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2", "-Wl,-O3", diff --git a/other/SSE3/build/config/compiler/BUILD.gn b/other/SSE3/build/config/compiler/BUILD.gn index 6ee82b9b..fc8207ae 100644 --- a/other/SSE3/build/config/compiler/BUILD.gn +++ b/other/SSE3/build/config/compiler/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2023 The Chromium Authors and Alex313031 +# Copyright 2024 The Chromium Authors and Alex313031 # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -19,6 +19,7 @@ import("//build/config/rust.gni") import("//build/config/ui.gni") import("//build/config/unwind.gni") import("//build/toolchain/cc_wrapper.gni") +import("//build/toolchain/cros/cros_config.gni") import("//build/toolchain/goma.gni") import("//build/toolchain/rbe.gni") import("//build/toolchain/toolchain.gni") @@ -135,6 +136,11 @@ declare_args() { (is_chromeos || is_android || is_win || is_linux || is_mac || (is_ios && use_lld)) && is_official_build + # Whether to enable thin lto incremental builds. + # See: https://clang.llvm.org/docs/ThinLTO.html#incremental + # The cache can lead to non-determinism: https://crbug.com/1486045 + thin_lto_enable_cache = false + # Initialize all local variables with a pattern. This flag will fill # uninitialized floating-point types (and 32-bit pointers) with 0xFF and the # rest with 0xAA. This makes behavior of uninitialized memory bugs consistent, @@ -489,6 +495,11 @@ config("compiler") { asmflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] cflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] } + + # dsymutil is not available in the system, on bots, for rustc to call. Our + # linker_driver.py script runs dsymutil itself, which is set to be the + # linker for Rust targets as well. + rustflags += [ "-Csplit-debuginfo=unpacked" ] } # Linux/Android/Fuchsia common flags setup. @@ -619,6 +630,24 @@ config("compiler") { } } + # TODO(crbug.com/1488374): This causes binary size growth and potentially + # other problems. + # TODO(crbug.com/1491036): This isn't supported by Cronet's mainline llvm version. + if (default_toolchain != "//build/toolchain/cros:target" && + !llvm_android_mainline) { + cflags += [ + "-mllvm", + "-split-threshold-for-reg-with-hint=0", + ] + if (use_thin_lto && is_a_target_toolchain) { + if (is_win) { + ldflags += [ "-mllvm:-split-threshold-for-reg-with-hint=0" ] + } else { + ldflags += [ "-Wl,-mllvm,-split-threshold-for-reg-with-hint=0" ] + } + } + } + # TODO(crbug.com/1235145): Investigate why/if this should be needed. if (is_win) { cflags += [ "/clang:-ffp-contract=off" ] @@ -675,8 +704,7 @@ config("compiler") { } } else if (is_win) { cflags_c += [ "/std:c11" ] - if ((defined(use_cxx17) && use_cxx17) || - (!is_clang && defined(msvc_use_cxx17) && msvc_use_cxx17)) { + if (defined(use_cxx17) && use_cxx17) { cflags_cc += [ "/std:c++17" ] } else { cflags_cc += [ "/std:c++20" ] @@ -723,9 +751,26 @@ config("compiler") { "-fsplit-lto-unit", ] - # Limit the size of the ThinLTO cache to the lesser of 10% of - # available disk space, 40GB and 100000 files. - # cache_policy = "cache_size=10%:cache_size_bytes=40g:cache_size_files=100000" + if (thin_lto_enable_cache) { + # Limit the size of the ThinLTO cache to the lesser of 10% of + # available disk space, 40GB and 100000 files. + cache_policy = + "cache_size=10%:cache_size_bytes=40g:cache_size_files=100000" + cache_dir = rebase_path("$root_out_dir/thinlto-cache", root_build_dir) + if (is_win) { + ldflags += [ + "/lldltocache:$cache_dir", + "/lldltocachepolicy:$cache_policy", + ] + } else { + if (is_apple) { + ldflags += [ "-Wl,-cache_path_lto,$cache_dir" ] + } else { + ldflags += [ "-Wl,--thinlto-cache-dir=$cache_dir" ] + } + ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ] + } + } # An import limit of 30 has better performance (per speedometer) and lower # binary size than the default setting of 100. @@ -740,9 +785,6 @@ config("compiler") { "-mllvm:-import-hot-multiplier=15", "-mllvm:-import-cold-multiplier=2", "-mllvm:-disable-auto-upgrade-debug-info", - # "/lldltocache:" + - # rebase_path("$root_out_dir/thinlto-cache", root_build_dir), - # "/lldltocachepolicy:$cache_policy", ] } else { ldflags += [ "-flto=thin" ] @@ -756,18 +798,6 @@ config("compiler") { # TODO(thakis): Check if '=0' (that is, number of cores, instead # of "all" which means number of hardware threads) is faster. ldflags += [ "-Wl,--thinlto-jobs=all" ] - if (is_apple) { - ldflags += [ - "-Wl,-cache_path_lto," + - rebase_path("$root_out_dir/thinlto-cache", root_build_dir), - "-Wcrl,object_path_lto", - ] - } else { - ldflags += - [ "-Wl,-O3" ] - } - - # ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ] if (is_chromeos) { # ARM was originally set lower than x86 to keep the size @@ -783,6 +813,10 @@ config("compiler") { ldflags += [ "-Wl,-mllvm,-import-instr-limit=$import_instr_limit" ] + if (is_apple) { + ldflags += [ "-Wcrl,object_path_lto" ] + } + if (!is_chromeos) { # TODO(https://crbug.com/972449): turn on for ChromeOS when that # toolchain has this flag. @@ -828,6 +862,9 @@ config("compiler") { if (compiler_timing) { if (is_clang && !is_nacl) { cflags += [ "-ftime-trace" ] + if (use_lld && is_mac) { + ldflags += [ "-Wl,--time-trace" ] + } } else if (is_win) { cflags += [ # "Documented" here: @@ -1852,14 +1889,6 @@ config("default_warnings") { "-Wno-ignored-pragma-optimize", ] - if (llvm_force_head_revision && !is_nacl && enable_precompiled_headers && - !is_win) { - cflags += [ - # TODO(crbug.com/1486799) Find a long-term solution. - "-Wno-deprecated-include-gch", - ] - } - if (!is_nacl) { cflags += [ # TODO(crbug.com/1343975) Evaluate and possibly enable. @@ -1870,6 +1899,18 @@ config("default_warnings") { # TODO(crbug.com/1412713) Evaluate and possibly enable. "-Wno-deprecated-this-capture", + + # TODO(https://crbug.com/1491833): Fix and re-enable. + "-Wno-invalid-offsetof", + + # TODO(crbug.com/1494809): Evaluate and possibly enable. + "-Wno-vla-extension", + + # TODO(https://crbug.com/1490607): Fix and re-enable. + "-Wno-thread-safety-reference-return", + + # TODO(crbug.com/1495100): Evaluate and possibly enable. + "-Wno-delayed-template-parsing-in-cxx20", ] } } @@ -1970,9 +2011,10 @@ config("chromium_code") { # disabled, so only do that for Release build. fortify_level = "2" - # ChromeOS supports a high-quality _FORTIFY_SOURCE=3 implementation - # with a few custom glibc patches. Use that if it's available. - if (is_chromeos_ash) { + # ChromeOS's toolchain supports a high-quality _FORTIFY_SOURCE=3 + # implementation with a few custom glibc patches. Use that if it's + # available. + if (is_chromeos_device && !lacros_use_chromium_toolchain) { fortify_level = "3" } defines += [ "_FORTIFY_SOURCE=" + fortify_level ] diff --git a/src/build/config/compiler/BUILD.gn b/src/build/config/compiler/BUILD.gn index 311bb684..c445d2f1 100644 --- a/src/build/config/compiler/BUILD.gn +++ b/src/build/config/compiler/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2023 The Chromium Authors and Alex313031 +# Copyright 2024 The Chromium Authors and Alex313031 # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -19,6 +19,7 @@ import("//build/config/rust.gni") import("//build/config/ui.gni") import("//build/config/unwind.gni") import("//build/toolchain/cc_wrapper.gni") +import("//build/toolchain/cros/cros_config.gni") import("//build/toolchain/goma.gni") import("//build/toolchain/rbe.gni") import("//build/toolchain/toolchain.gni") @@ -135,6 +136,11 @@ declare_args() { (is_chromeos || is_android || is_win || is_linux || is_mac || (is_ios && use_lld)) && is_official_build + # Whether to enable thin lto incremental builds. + # See: https://clang.llvm.org/docs/ThinLTO.html#incremental + # The cache can lead to non-determinism: https://crbug.com/1486045 + thin_lto_enable_cache = false + # Initialize all local variables with a pattern. This flag will fill # uninitialized floating-point types (and 32-bit pointers) with 0xFF and the # rest with 0xAA. This makes behavior of uninitialized memory bugs consistent, @@ -489,6 +495,11 @@ config("compiler") { asmflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] cflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] } + + # dsymutil is not available in the system, on bots, for rustc to call. Our + # linker_driver.py script runs dsymutil itself, which is set to be the + # linker for Rust targets as well. + rustflags += [ "-Csplit-debuginfo=unpacked" ] } # Linux/Android/Fuchsia common flags setup. @@ -619,6 +630,24 @@ config("compiler") { } } + # TODO(crbug.com/1488374): This causes binary size growth and potentially + # other problems. + # TODO(crbug.com/1491036): This isn't supported by Cronet's mainline llvm version. + if (default_toolchain != "//build/toolchain/cros:target" && + !llvm_android_mainline) { + cflags += [ + "-mllvm", + "-split-threshold-for-reg-with-hint=0", + ] + if (use_thin_lto && is_a_target_toolchain) { + if (is_win) { + ldflags += [ "-mllvm:-split-threshold-for-reg-with-hint=0" ] + } else { + ldflags += [ "-Wl,-mllvm,-split-threshold-for-reg-with-hint=0" ] + } + } + } + # TODO(crbug.com/1235145): Investigate why/if this should be needed. if (is_win) { cflags += [ "/clang:-ffp-contract=off" ] @@ -675,8 +704,7 @@ config("compiler") { } } else if (is_win) { cflags_c += [ "/std:c11" ] - if ((defined(use_cxx17) && use_cxx17) || - (!is_clang && defined(msvc_use_cxx17) && msvc_use_cxx17)) { + if (defined(use_cxx17) && use_cxx17) { cflags_cc += [ "/std:c++17" ] } else { cflags_cc += [ "/std:c++20" ] @@ -723,9 +751,26 @@ config("compiler") { "-fsplit-lto-unit", ] - # Limit the size of the ThinLTO cache to the lesser of 10% of - # available disk space, 40GB and 100000 files. - # cache_policy = "cache_size=10%:cache_size_bytes=40g:cache_size_files=100000" + if (thin_lto_enable_cache) { + # Limit the size of the ThinLTO cache to the lesser of 10% of + # available disk space, 40GB and 100000 files. + cache_policy = + "cache_size=10%:cache_size_bytes=40g:cache_size_files=100000" + cache_dir = rebase_path("$root_out_dir/thinlto-cache", root_build_dir) + if (is_win) { + ldflags += [ + "/lldltocache:$cache_dir", + "/lldltocachepolicy:$cache_policy", + ] + } else { + if (is_apple) { + ldflags += [ "-Wl,-cache_path_lto,$cache_dir" ] + } else { + ldflags += [ "-Wl,--thinlto-cache-dir=$cache_dir" ] + } + ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ] + } + } # An import limit of 30 has better performance (per speedometer) and lower # binary size than the default setting of 100. @@ -740,9 +785,6 @@ config("compiler") { "-mllvm:-import-hot-multiplier=15", "-mllvm:-import-cold-multiplier=2", "-mllvm:-disable-auto-upgrade-debug-info", - # "/lldltocache:" + - # rebase_path("$root_out_dir/thinlto-cache", root_build_dir), - # "/lldltocachepolicy:$cache_policy", ] } else { ldflags += [ "-flto=thin" ] @@ -756,18 +798,6 @@ config("compiler") { # TODO(thakis): Check if '=0' (that is, number of cores, instead # of "all" which means number of hardware threads) is faster. ldflags += [ "-Wl,--thinlto-jobs=all" ] - if (is_apple) { - ldflags += [ - "-Wl,-cache_path_lto," + - rebase_path("$root_out_dir/thinlto-cache", root_build_dir), - "-Wcrl,object_path_lto", - ] - } else { - ldflags += - [ "-Wl,-O3" ] - } - - # ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ] if (is_chromeos) { # ARM was originally set lower than x86 to keep the size @@ -783,6 +813,10 @@ config("compiler") { ldflags += [ "-Wl,-mllvm,-import-instr-limit=$import_instr_limit" ] + if (is_apple) { + ldflags += [ "-Wcrl,object_path_lto" ] + } + if (!is_chromeos) { # TODO(https://crbug.com/972449): turn on for ChromeOS when that # toolchain has this flag. @@ -828,6 +862,9 @@ config("compiler") { if (compiler_timing) { if (is_clang && !is_nacl) { cflags += [ "-ftime-trace" ] + if (use_lld && is_mac) { + ldflags += [ "-Wl,--time-trace" ] + } } else if (is_win) { cflags += [ # "Documented" here: @@ -1062,11 +1099,11 @@ config("thinlto_optimize_default") { if (is_win) { ldflags = [ "/opt:lldlto=" + lto_opt_level ] ldflags += [ "-mllvm:-enable-pre=false", ] - # ldflags += [ "-opt:lldltocgo=" + lto_opt_level ] + ldflags += [ "-opt:lldltocgo=" + lto_opt_level ] } else { ldflags = [ "-Wl,--lto-O" + lto_opt_level ] ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ] - # ldflags += [ "-Wl,-mllvm,-enable-pre=false", ] + ldflags += [ "-Wl,-mllvm,-enable-pre=false", ] } if (toolchain_supports_rust_thin_lto) { @@ -1100,11 +1137,11 @@ config("thinlto_optimize_max") { if (is_win) { ldflags = [ "/opt:lldlto=" + lto_opt_level ] ldflags += [ "-mllvm:-enable-pre=false", ] - # ldflags += [ "-opt:lldltocgo=" + lto_opt_level ] + ldflags += [ "-opt:lldltocgo=" + lto_opt_level ] } else { ldflags = [ "-Wl,--lto-O" + lto_opt_level ] ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ] - # ldflags += [ "-Wl,-mllvm,-enable-pre=false", ] + ldflags += [ "-Wl,-mllvm,-enable-pre=false", ] } if (toolchain_supports_rust_thin_lto) { @@ -1146,11 +1183,11 @@ config("compiler_cpu_abi") { "-msse4", "-msse4.1", "-msse4.2", - "-mavx", - "-maes", "-mpclmul", + "-maes", + "-mavx", ] - ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-mssse3", "-msse4", "-msse4.1", "-msse4.2", "-mavx", "-maes", "-mpclmul", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2", ] + ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-mssse3", "-msse4", "-msse4.1", "-msse4.2", "-mpclmul", "-maes", "-mavx", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2", ] } else if (current_cpu == "x86") { cflags += [ "-m32" ] ldflags += [ "-m32", "-Wl,-O3", "-msse3", ] @@ -1859,14 +1896,6 @@ config("default_warnings") { "-Wno-ignored-pragma-optimize", ] - if (llvm_force_head_revision && !is_nacl && enable_precompiled_headers && - !is_win) { - cflags += [ - # TODO(crbug.com/1486799) Find a long-term solution. - "-Wno-deprecated-include-gch", - ] - } - if (!is_nacl) { cflags += [ # TODO(crbug.com/1343975) Evaluate and possibly enable. @@ -1877,6 +1906,18 @@ config("default_warnings") { # TODO(crbug.com/1412713) Evaluate and possibly enable. "-Wno-deprecated-this-capture", + + # TODO(https://crbug.com/1491833): Fix and re-enable. + "-Wno-invalid-offsetof", + + # TODO(crbug.com/1494809): Evaluate and possibly enable. + "-Wno-vla-extension", + + # TODO(https://crbug.com/1490607): Fix and re-enable. + "-Wno-thread-safety-reference-return", + + # TODO(crbug.com/1495100): Evaluate and possibly enable. + "-Wno-delayed-template-parsing-in-cxx20", ] } } @@ -1977,9 +2018,10 @@ config("chromium_code") { # disabled, so only do that for Release build. fortify_level = "2" - # ChromeOS supports a high-quality _FORTIFY_SOURCE=3 implementation - # with a few custom glibc patches. Use that if it's available. - if (is_chromeos_ash) { + # ChromeOS's toolchain supports a high-quality _FORTIFY_SOURCE=3 + # implementation with a few custom glibc patches. Use that if it's + # available. + if (is_chromeos_device && !lacros_use_chromium_toolchain) { fortify_level = "3" } defines += [ "_FORTIFY_SOURCE=" + fortify_level ]