diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2023-09-05 12:37:36 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2023-10-17 13:53:46 +0000 |
commit | 5a424f4a7b188b75da63eb697f63558af0b17f6f (patch) | |
tree | 54c427fcbc567dac8181ab5fd22d20e72cc51609 /chromium/build/config/compiler/BUILD.gn | |
parent | acbcf08a6dffdfe90a6eaf661fcd6923f0de2447 (diff) |
BASELINE: Update Chromium to 116.0.5845.183
Change-Id: Iaaf57e02c218c93993a5044c659b63674e2c8a12
Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/512320
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/build/config/compiler/BUILD.gn')
-rw-r--r-- | chromium/build/config/compiler/BUILD.gn | 243 |
1 files changed, 196 insertions, 47 deletions
diff --git a/chromium/build/config/compiler/BUILD.gn b/chromium/build/config/compiler/BUILD.gn index 28c2255ba80..ae742b0b85a 100644 --- a/chromium/build/config/compiler/BUILD.gn +++ b/chromium/build/config/compiler/BUILD.gn @@ -181,6 +181,13 @@ declare_args() { # Allow projects that wish to stay on C++17 to override Chromium's default. # TODO(crbug.com/1402249): evaluate removing this end of 2023 use_cxx17 = false + + # Enable ShadowCallStack for compiled binaries. SCS stores a pointer to a + # shadow call stack in register x18. Hence, x18 must not be used by the OS + # or libraries. We assume that to be the case for high end Android + # configurations. For more details see + # https://clang.llvm.org/docs/ShadowCallStack.html + enable_shadow_call_stack = false } declare_args() { @@ -212,7 +219,12 @@ if (is_android || (is_chromeos_ash && is_chromeos_device)) { # another variable. chrome_orderfile_path = default_chrome_orderfile } else if (is_chromeos_ash && is_chromeos_device) { - chrome_orderfile_path = "//chromeos/profiles/chromeos.orderfile.txt" + if (chromeos_afdo_platform == "arm" || + chromeos_afdo_platform == "arm-exp") { + chrome_orderfile_path = "//chromeos/profiles/chromeos.arm.orderfile.txt" + } else { + chrome_orderfile_path = "//chromeos/profiles/chromeos.orderfile.txt" + } } } } @@ -260,9 +272,11 @@ config("compiler") { cflags_cc = [] cflags_objc = [] cflags_objcc = [] + rustflags = [] ldflags = [] defines = [] configs = [] + rustflags = [] # System-specific flags. If your compiler flags apply to one of the # categories here, add it to the associated file to keep this shared config @@ -322,28 +336,44 @@ config("compiler") { # -------------------------------- cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204 - # Stack protection. - if (is_apple) { - # The strong variant of the stack protector significantly increases - # binary size, so only enable it in debug mode. - if (is_debug) { - cflags += [ "-fstack-protector-strong" ] - } else { - cflags += [ "-fstack-protector" ] - } - } else if ((is_posix && !is_chromeos && !is_nacl) || is_fuchsia) { - # TODO(phajdan.jr): Use -fstack-protector-strong when our gcc supports it. - # See also https://crbug.com/533294 - if (current_os != "zos") { - cflags += [ "--param=ssp-buffer-size=4" ] - } + # Stack protection. ShadowCallStack and Stack protector address the same + # problems. Therefore, we only enable one or the other. Clang advertises SCS as + # a stronger alternative to StackProtector, so we give SCS precedence over SP. + if (enable_shadow_call_stack) { + # On Aarch64, SCS requires the x18 register to be unused because it will hold + # a pointer to the shadow stack. For Android we know that Clang doesn't use + # x18 by default. On other OSs adding "-ffixed-x18" might be required. + assert(is_android) + + scs_parameters = [ + "-fsanitize=shadow-call-stack", + "-fno-stack-protector", + ] + cflags += scs_parameters + ldflags += scs_parameters + } else { + if (is_apple) { + # The strong variant of the stack protector significantly increases + # binary size, so only enable it in debug mode. + if (is_debug) { + cflags += [ "-fstack-protector-strong" ] + } else { + cflags += [ "-fstack-protector" ] + } + } else if ((is_posix && !is_chromeos && !is_nacl) || is_fuchsia) { + # TODO(phajdan.jr): Use -fstack-protector-strong when our gcc supports it. + # See also https://crbug.com/533294 + if (current_os != "zos") { + cflags += [ "--param=ssp-buffer-size=4" ] + } - # The x86 toolchain currently has problems with stack-protector. - if (is_android && current_cpu == "x86") { - cflags += [ "-fno-stack-protector" ] - } else if (current_os != "aix") { - # Not available on aix. - cflags += [ "-fstack-protector" ] + # The x86 toolchain currently has problems with stack-protector. + if (is_android && current_cpu == "x86") { + cflags += [ "-fno-stack-protector" ] + } else if (current_os != "aix") { + # Not available on aix. + cflags += [ "-fstack-protector" ] + } } } @@ -420,9 +450,11 @@ config("compiler") { "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", ] + rustflags += [ "-Cforce-unwind-tables=no" ] defines += [ "NO_UNWIND_TABLES" ] } else { cflags += [ "-funwind-tables" ] + rustflags += [ "-Cforce-unwind-tables=yes" ] } } } @@ -450,6 +482,7 @@ config("compiler") { asmflags += [ "-fPIC" ] cflags += [ "-fPIC" ] ldflags += [ "-fPIC" ] + rustflags += [ "-Crelocation-model=pic" ] if (!is_clang) { # Use pipes for communicating between sub-processes. Faster. @@ -740,6 +773,15 @@ config("compiler") { # arm32. if (!is_android || current_cpu == "arm64") { cflags += [ "-fwhole-program-vtables" ] + + # whole-program-vtables implies -fsplit-lto-unit, and Rust needs to match + # behaviour. Rust needs to know the linker will be doing LTO in this case + # or it rejects the Zsplit-lto-unit flag. + rustflags += [ + "-Zsplit-lto-unit", + "-Clinker-plugin-lto=yes", + ] + if (!is_win) { ldflags += [ "-fwhole-program-vtables" ] } @@ -847,6 +889,24 @@ config("compiler") { } } + if (clang_embed_bitcode) { + assert(!use_thin_lto, + "clang_embed_bitcode is only supported in non-ThinLTO builds") + cflags += [ + "-Xclang", + "-fembed-bitcode=all", + ] + } + + if (lld_emit_indexes_and_imports) { + assert(use_thin_lto, + "lld_emit_indexes_and_imports is only supported with ThinLTO builds") + ldflags += [ + "-Wl,--save-temps=import", + "-Wl,--thinlto-emit-index-files", + ] + } + # Pass the same C/C++ flags to the objective C/C++ compiler. cflags_objc += cflags_c cflags_objcc += cflags_cc @@ -859,9 +919,38 @@ config("compiler") { asmflags += cflags_c } + if (is_chromeos_device && !is_nacl) { + # On ChromeOS devices, we want to ensure we're using Chrome's allocator + # symbols for all C++ new/delete operator overloads. PartitionAlloc + # and other local allocators should always take precedence over system or + # preloaded allocators. These are the mangled symbol names. + # See b/280115910 for details. + ldflags += [ + "-Wl,--export-dynamic-symbol=_ZdaPv,-u,_ZdaPv", + "-Wl,--export-dynamic-symbol=_ZdaPvRKSt9nothrow_t,-u,_ZdaPvRKSt9nothrow_t", + "-Wl,--export-dynamic-symbol=_ZdlPv,-u,_ZdlPv", + "-Wl,--export-dynamic-symbol=_ZdlPvm,-u,_ZdlPvm", + "-Wl,--export-dynamic-symbol=_ZdlPvRKSt9nothrow_t,-u,_ZdlPvRKSt9nothrow_t", + "-Wl,--export-dynamic-symbol=_Znam,-u,_Znam", + "-Wl,--export-dynamic-symbol=_ZnamRKSt9nothrow_t,-u,_ZnamRKSt9nothrow_t", + "-Wl,--export-dynamic-symbol=_Znwm,-u,_Znwm", + "-Wl,--export-dynamic-symbol=_ZnwmRKSt9nothrow_t,-u,_ZnwmRKSt9nothrow_t", + "-Wl,--export-dynamic-symbol=_ZdaPvmSt11align_val_t,-u,_ZdaPvmSt11align_val_t", + "-Wl,--export-dynamic-symbol=_ZdaPvSt11align_val_t,-u,_ZdaPvSt11align_val_t", + "-Wl,--export-dynamic-symbol=_ZdaPvSt11align_val_tRKSt9nothrow_t,-u,_ZdaPvSt11align_val_tRKSt9nothrow_t", + "-Wl,--export-dynamic-symbol=_ZdlPvmSt11align_val_t,-u,_ZdlPvmSt11align_val_t", + "-Wl,--export-dynamic-symbol=_ZdlPvSt11align_val_t,-u,_ZdlPvSt11align_val_t", + "-Wl,--export-dynamic-symbol=_ZdlPvSt11align_val_tRKSt9nothrow_t,-u,_ZdlPvSt11align_val_tRKSt9nothrow_t", + "-Wl,--export-dynamic-symbol=_ZnamSt11align_val_t,-u,_ZnamSt11align_val_t", + "-Wl,--export-dynamic-symbol=_ZnamSt11align_val_tRKSt9nothrow_t,-u,_ZnamSt11align_val_tRKSt9nothrow_t", + "-Wl,--export-dynamic-symbol=_ZnwmSt11align_val_t,-u,_ZnwmSt11align_val_t", + "-Wl,--export-dynamic-symbol=_ZnwmSt11align_val_tRKSt9nothrow_t,-u,_ZnwmSt11align_val_tRKSt9nothrow_t", + ] + } + # Rust compiler flags setup. # --------------------------- - rustflags = [ + rustflags += [ # Overflow checks are optional in Rust, but even if switched # off they do not cause undefined behavior (the overflowing # behavior is defined). Because containers are bounds-checked @@ -880,11 +969,6 @@ config("compiler") { # to compile dylibs on Android, such as for constructing unit test APKs. "-Cdefault-linker-libraries", - # Require `unsafe` blocks even in `unsafe` fns. This is intended to become - # an error by default eventually; see - # https://github.com/rust-lang/rust/issues/71668 - "-Dunsafe_op_in_unsafe_fn", - # To make Rust .d files compatible with ninja "-Zdep-info-omit-d-target", @@ -896,6 +980,13 @@ config("compiler") { # directory from appearing in build outputs. "-Zremap-cwd-prefix=.", ] + + if (!is_win || force_rustc_color_output) { + # Colorize error output. The analogous flag is passed for clang. This must + # be platform-gated since rustc will unconditionally output ANSI escape + # sequences, ignoring the platform, when stderr is not a terminal. + rustflags += [ "--color=always" ] + } if (rust_abi_target != "") { rustflags += [ "--target=$rust_abi_target" ] } @@ -906,20 +997,27 @@ config("compiler") { if (is_official_build) { rustflags += [ "-Ccodegen-units=1" ] } -} + if (!rust_prebuilt_stdlib) { + # When building against the Chromium Rust stdlib (which we compile) always + # abort instead of unwinding when panic occurs. In official builds, panics + # abort immediately (this is configured in the stdlib) to keep binary size + # down. So we unconditionally match behaviour in unofficial too. + rustflags += [ + "-Cpanic=abort", + "-Zpanic_abort_tests", + ] + } -# Defers LTO optimization to the linker, for use when: -# * Having the C++ toolchain do the linking against Rust staticlibs, and it -# will be using LTO. -# * Having Rust toolchain invoke the linker, and you're linking Rust and C++ -# together, so this defers LTO to the linker. -# -# Otherwise, Rust does LTO during compilation. -# -# https://doc.rust-lang.org/rustc/linker-plugin-lto.html -config("rust_defer_lto_to_linker") { - if (!is_debug && use_thin_lto && is_a_target_toolchain) { - rustflags = [ "-Clinker-plugin-lto" ] + # Normally, this would be defined in the `runtime_library` config but NaCl + # saigo libc++ does not use the custom hermetic libc++. Unfortunately, there + # isn't really a better config to add this define for the define to + # consistently apply in both Chromium and non-Chromium code *and* non-NaCl + # and NaCl code. + # + # TODO(https://crbug.com/702997): Move this back to the `runtime_library` + # config when NaCl is removed. + if (use_safe_libcxx) { + defines += [ "_LIBCPP_ENABLE_ASSERTIONS=1" ] } } @@ -935,6 +1033,9 @@ config("thinlto_optimize_default") { ldflags = [ "-Wl,--lto-O" + lto_opt_level ] } + # We always point Rust to a linker that performs LTO, so we don't want Rust + # to preemptively do so during compilation too or they conflict. But we do + # want Rust to generate LTO metadata in order for the linker to do its job. rustflags = [ "-Clinker-plugin-lto=yes" ] } } @@ -961,6 +1062,9 @@ config("thinlto_optimize_max") { ldflags = [ "-Wl,--lto-O" + lto_opt_level ] } + # We always point Rust to a linker that performs LTO, so we don't want Rust + # to preemptively do so during compilation too or they conflict. But we do + # want Rust to generate LTO metadata in order for the linker to do its job. rustflags = [ "-Clinker-plugin-lto=yes" ] } } @@ -1266,7 +1370,7 @@ config("compiler_cpu_abi") { ldflags += [ "-m64" ] } } else if (current_cpu == "riscv64") { - if (is_clang) { + if (is_clang && !is_android) { cflags += [ "--target=riscv64-linux-gnu" ] ldflags += [ "--target=riscv64-linux-gnu" ] } @@ -1485,6 +1589,16 @@ config("runtime_library") { configs += [ "//build/config/c++:runtime_library" ] } + # Rust and C++ both provide intrinsics for LLVM to call for math operations. We + # want to use the C++ intrinsics, not the ones in the Rust compiler_builtins + # library. The Rust symbols are marked as weak, so that they can be replaced by + # the C++ symbols. This config ensures the C++ symbols exist and are strong in + # order to cause that replacement to occur by explicitly linking in clang's + # compiler-rt library. + if (is_clang && toolchain_has_rust) { + configs += [ "//build/config/clang:compiler_builtins" ] + } + # TODO(crbug.com/830987): Come up with a better name for is POSIX + Fuchsia # configuration. if (is_posix || is_fuchsia) { @@ -1656,9 +1770,21 @@ config("default_warnings") { # TODO(crbug.com/1412713) Evaluate and possibly enable. "-Wno-deprecated-this-capture", ] + + if (llvm_force_head_revision) { + # TODO(https://crbug.com/1448905): Evaluate and possibly enable. + cflags += [ "-Wno-builtin-macro-redefined" ] + } } } } + + # Rust warnings + + # Require `unsafe` blocks even in `unsafe` fns. This is intended to become + # an error by default eventually; see + # https://github.com/rust-lang/rust/issues/71668 + rustflags = [ "-Dunsafe_op_in_unsafe_fn" ] } # prevent_unsafe_narrowing ---------------------------------------------------- @@ -1861,7 +1987,7 @@ config("no_chromium_code") { config("noshadowing") { # This flag has to be disabled for nacl because the nacl compiler is too # strict about shadowing. - if (is_clang && (!is_nacl || is_nacl_saigo)) { + if (is_clang && (!is_nacl || is_nacl_saigo) && !llvm_force_head_revision) { cflags = [ "-Wshadow" ] } } @@ -2547,10 +2673,18 @@ config("symbols") { # This config guarantees to hold symbol for stack trace which are shown to user # when crash happens in unittests running on buildbot. config("minimal_symbols") { + rustflags = [] if (is_win) { # Functions, files, and line tables only. cflags = [] + if (is_clang) { + cflags += [ + # Disable putting the compiler command line into the debug info to + # prevent some types of non-determinism. + "-gno-codeview-command-line", + ] + } if (is_clang && use_lld && use_ghash) { cflags += [ "-gcodeview-ghash" ] ldflags = [ "/DEBUG:GHASH" ] @@ -2574,15 +2708,18 @@ config("minimal_symbols") { # at least 10.11. # TODO(thakis): Remove this once mac_deployment_target is 10.11. cflags += [ "-gdwarf-4" ] + rustflags += [ "-Zdwarf-version=4" ] } else if (!use_dwarf5 && !is_nacl && current_os != "aix") { # On aix -gdwarf causes linker failures due to thread_local variables. # Recent clang versions default to DWARF5 on Linux, and Android is about # to switch. TODO: Adopt that in controlled way. cflags += [ "-gdwarf-4" ] + rustflags += [ "-Zdwarf-version=4" ] } if (use_dwarf5 && !is_nacl) { cflags += [ "-gdwarf-5" ] + rustflags += [ "-Zdwarf-version=5" ] } # The gcc-based nacl compilers don't support -fdebug-compilation-dir (see @@ -2614,7 +2751,7 @@ config("minimal_symbols") { asmflags = cflags } - rustflags = [ "-Cdebuginfo=1" ] + rustflags += [ "-Cdebuginfo=1" ] } # This configuration contains function names only. That is, the compiler is @@ -2658,10 +2795,22 @@ config("strip_debug") { } if (is_apple) { - # On Mac and iOS, this enables support for ARC (automatic ref-counting). - # See http://clang.llvm.org/docs/AutomaticReferenceCounting.html. + # On macOS and iOS, this enables support for ARC (automatic reference + # counting). See http://clang.llvm.org/docs/AutomaticReferenceCounting.html. + # + # -fobjc-arc enables ARC overall. + # + # ARC does not add exception handlers to pure Objective-C code, but does add + # them to Objective-C++ code with the rationale that C++ pervasively adds them + # in for exception safety. However, exceptions are banned in Chromium code for + # C++ and exceptions in Objective-C code are intended to be fatal, so + # -fno-objc-arc-exceptions is specified to disable these unwanted exception + # handlers. config("enable_arc") { - common_flags = [ "-fobjc-arc" ] + common_flags = [ + "-fobjc-arc", + "-fno-objc-arc-exceptions", + ] cflags_objc = common_flags cflags_objcc = common_flags } |