From 87b0b20116246f03d31d68955c1a01baf6a83fa3 Mon Sep 17 00:00:00 2001 From: Alexander David Frick Date: Mon, 30 Jan 2023 06:58:17 -0600 Subject: [PATCH] Update BUILD.gn --- .../i386/SSE2/build/config/compiler/BUILD.gn | 1432 ++++++++++------- 1 file changed, 828 insertions(+), 604 deletions(-) diff --git a/other/i386/SSE2/build/config/compiler/BUILD.gn b/other/i386/SSE2/build/config/compiler/BUILD.gn index d1f2b411..3fbbec74 100644 --- a/other/i386/SSE2/build/config/compiler/BUILD.gn +++ b/other/i386/SSE2/build/config/compiler/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Copyright (c) 2023 The Chromium Authors and Alex313031. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -6,18 +6,20 @@ import("//build/buildflag_header.gni") import("//build/config/android/config.gni") import("//build/config/c++/c++.gni") import("//build/config/chrome_build.gni") -import("//build/config/chromecast_build.gni") import("//build/config/chromeos/args.gni") +import("//build/config/chromeos/ui_mode.gni") import("//build/config/clang/clang.gni") import("//build/config/compiler/compiler.gni") import("//build/config/coverage/coverage.gni") import("//build/config/dcheck_always_on.gni") import("//build/config/gclient_args.gni") import("//build/config/host_byteorder.gni") +import("//build/config/rust.gni") import("//build/config/sanitizers/sanitizers.gni") import("//build/config/ui.gni") import("//build/toolchain/cc_wrapper.gni") import("//build/toolchain/goma.gni") +import("//build/toolchain/rbe.gni") import("//build/toolchain/toolchain.gni") import("//build_overrides/build.gni") @@ -28,11 +30,8 @@ if (current_cpu == "mipsel" || current_cpu == "mips64el" || current_cpu == "mips" || current_cpu == "mips64") { import("//build/config/mips.gni") } -if (current_cpu == "x64") { - import("//build/config/x64.gni") -} if (is_mac) { - import("//build/config/mac/symbols.gni") + import("//build/config/apple/symbols.gni") } if (is_ios) { import("//build/config/ios/ios_sdk.gni") @@ -44,6 +43,17 @@ if (is_nacl) { import("//build/config/nacl/config.gni") } +lld_path = "" +if (!is_clang) { + declare_args() { + # This allows overriding the location of lld. + lld_path = rebase_path("$clang_base_path/bin", root_build_dir) + } +} else { + # clang looks for lld next to it, no need for -B. + lld_path = "" +} + declare_args() { # Normally, Android builds are lightly optimized, even for debug builds, to # keep binary size down. Setting this flag to true disables such optimization @@ -75,9 +85,6 @@ declare_args() { # the needed gcov profiling data. auto_profile_path = "" - # Allow projects that wish to stay on C++11 to override Chromium's default. - use_cxx11 = false - # Path to an AFDO profile to use while building with clang, if any. Empty # implies none. clang_sample_profile_path = "" @@ -90,7 +97,7 @@ declare_args() { # nonsensical for said projects. clang_use_default_sample_profile = chrome_pgo_phase == 0 && build_with_chromium && is_official_build && - (is_android || chromeos_is_browser_only || is_chromecast) + (is_android || chromeos_is_browser_only) # This configuration is used to select a default profile in Chrome OS based on # the microarchitectures we are using. This is only used if @@ -99,7 +106,8 @@ declare_args() { chromeos_afdo_platform = "atom" # Emit debug information for profiling wile building with clang. - clang_emit_debug_info_for_profiling = false + # Only enable this for ChromeOS official builds for AFDO. + clang_emit_debug_info_for_profiling = is_chromeos_device && is_official_build # Turn this on to have the compiler output extra timing information. compiler_timing = false @@ -116,7 +124,8 @@ declare_args() { # the space overhead is too great. We should use some mixture of profiles and # optimization settings to better tune the size increase. thin_lto_enable_optimizations = - (is_chromeos || is_android || is_win) && is_official_build + (is_chromeos || is_android || is_win || is_linux || is_mac || + (is_ios && use_lld)) && is_official_build # Initialize all local variables with a pattern. This flag will fill # uninitialized floating-point types (and 32-bit pointers) with 0xFF and the @@ -126,10 +135,7 @@ declare_args() { # # TODO(crbug.com/1131993): Enabling this when 'is_android' is true breaks # content_shell_test_apk on both ARM and x86. - # - # TODO(crbug.com/977230): Enabling this when 'use_xcode_clang' is true may - # call an old clang that doesn't support auto-init. - init_stack_vars = !is_android && !use_xcode_clang + init_stack_vars = !is_android # This argument is to control whether enabling text section splitting in the # final binary. When enabled, the separated text sections with prefix @@ -140,24 +146,28 @@ declare_args() { # The gold linker by default has text section splitting enabled. use_text_section_splitting = false - # Token limits may not be accurate for build configs not covered by the CQ, - # so only enable them by default for mainstream build configs. - enable_wmax_tokens = - !is_official_build && - ((is_mac && target_cpu == "x64" && !use_system_xcode) || - (is_linux && !is_chromeos && target_cpu == "x64") || - (is_win && target_cpu == "x86") || (is_win && target_cpu == "x64") || - (is_android && target_cpu == "arm") || - (is_android && target_cpu == "arm64")) - # Turn off the --call-graph-profile-sort flag for lld by default. Enable # selectively for targets where it's beneficial. enable_call_graph_profile_sort = chrome_pgo_phase == 2 -} -declare_args() { - # C++11 may not be an option if Android test infrastructure is used. - use_cxx11_on_android = use_cxx11 + # Enable DWARF v5. + use_dwarf5 = false + + # Override this to put full paths to PDBs in Windows PE files. This helps + # windbg and Windows Performance Analyzer with finding the PDBs in some local- + # build scenarios. This is never needed for bots or official builds. Because + # this puts the output directory in the DLLs/EXEs it breaks build determinism. + # Bugs have been reported to the windbg/WPA teams and this workaround will be + # removed when they are fixed. + use_full_pdb_paths = false + + # Enable -H, which prints the include tree during compilation. + # For use by tools/clang/scripts/analyze_includes.py + show_includes = false + + # If true, linker crashes will be rerun with `--reproduce` which causes + # a reproducer file to be saved. + save_reproducers_on_lld_crash = false } declare_args() { @@ -171,12 +181,13 @@ declare_args() { # # lld doesn't have the bug. use_icf = (is_posix || is_fuchsia) && !is_debug && !using_sanitizer && - !use_clang_coverage && !(is_android && use_order_profiling) && + !use_clang_coverage && current_os != "zos" && + !(is_android && use_order_profiling) && (use_lld || (use_gold && (is_chromeos || !(current_cpu == "x86" || current_cpu == "x64")))) } -if (is_win || is_android || (is_chromeos && is_chromeos_device)) { +if (is_android || (is_chromeos_ash && is_chromeos_device)) { # Set the path to use orderfile for linking Chrome # Note that this is for using only one orderfile for linking # the Chrome binary/library. @@ -187,9 +198,7 @@ if (is_win || is_android || (is_chromeos && is_chromeos_device)) { # Allow downstream tools to set orderfile path with # another variable. chrome_orderfile_path = default_chrome_orderfile - } else if (is_win && is_clang && is_official_build) { - chrome_orderfile_path = "//chrome/build/chrome.$target_cpu.orderfile" - } else if (is_chromeos && is_chromeos_device) { + } else if (is_chromeos_ash && is_chromeos_device) { chrome_orderfile_path = "//chromeos/profiles/chromeos.orderfile.txt" } } @@ -197,6 +206,8 @@ if (is_win || is_android || (is_chromeos && is_chromeos_device)) { assert(!(llvm_force_head_revision && use_goma), "can't use goma with trunk clang") +assert(!(llvm_force_head_revision && use_remoteexec), + "can't use rbe with trunk clang") # default_include_dirs --------------------------------------------------------- # @@ -210,6 +221,18 @@ config("default_include_dirs") { ] } +# Compiler instrumentation can introduce dependencies in DSOs to symbols in +# the executable they are loaded into, so they are unresolved at link-time. +config("no_unresolved_symbols") { + if (!using_sanitizer && + (is_linux || is_chromeos || is_android || is_fuchsia)) { + ldflags = [ + "-Wl,-z,defs", + "-Wl,--as-needed", + ] + } +} + # compiler --------------------------------------------------------------------- # # Base compiler configuration. @@ -237,9 +260,6 @@ config("compiler") { configs += [ "//build/config/android:compiler" ] } else if (is_linux || is_chromeos) { configs += [ "//build/config/linux:compiler" ] - if (is_chromeos) { - configs += [ "//build/config/chromeos:compiler" ] - } } else if (is_nacl) { configs += [ "//build/config/nacl:compiler" ] } else if (is_mac) { @@ -250,25 +270,47 @@ config("compiler") { configs += [ "//build/config/fuchsia:compiler" ] } else if (current_os == "aix") { configs += [ "//build/config/aix:compiler" ] + } else if (current_os == "zos") { + configs += [ "//build/config/zos:compiler" ] } configs += [ # See the definitions below. ":clang_revision", + ":rustc_revision", ":compiler_cpu_abi", ":compiler_codegen", ":compiler_deterministic", ] + # Here we enable -fno-delete-null-pointer-checks, which makes various nullptr + # operations (e.g. dereferencing) into defined behavior. This avoids deletion + # of some security-critical code: see https://crbug.com/1139129. + # Nacl does not support the flag. And, we still want UBSAN to catch undefined + # behavior related to nullptrs, so do not add this flag if UBSAN is enabled. + # GCC seems to have some bugs compiling constexpr code when this is defined, + # so only enable it if using_clang. See: https://gcc.gnu.org/PR97913 + # TODO(mpdenton): remove is_clang once GCC bug is fixed. + if (!is_nacl && !is_ubsan && is_clang) { + cflags += [ "-fno-delete-null-pointer-checks" ] + } + + # Don't emit the GCC version ident directives, they just end up in the + # .comment section or debug info taking up binary size, and makes comparing + # .o files built with different compiler versions harder. + if (!is_win || is_clang) { + cflags += [ "-fno-ident" ] + } + # In general, Windows is totally different, but all the other builds share - # some common GCC configuration. + # some common compiler and linker configuration. if (!is_win) { # Common POSIX compiler flags setup. # -------------------------------- cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204 # Stack protection. - if (is_mac) { + if (is_apple) { # The strong variant of the stack protector significantly increases # binary size, so only enable it in debug mode. if (is_debug) { @@ -279,7 +321,9 @@ config("compiler") { } 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 - cflags += [ "--param=ssp-buffer-size=4" ] + 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") { @@ -290,14 +334,21 @@ config("compiler") { } } + if (use_lld) { + ldflags += [ "-fuse-ld=lld" ] + if (lld_path != "") { + ldflags += [ "-B$lld_path" ] + } + } + # Linker warnings. - if (fatal_linker_warnings && !is_apple && current_os != "aix") { + if (fatal_linker_warnings && !is_apple && current_os != "aix" && + current_os != "zos") { ldflags += [ "-Wl,--fatal-warnings" ] } if (fatal_linker_warnings && is_apple) { ldflags += [ "-Wl,-fatal_warnings" ] } - } else { } if (is_clang && is_debug) { @@ -311,7 +362,7 @@ config("compiler") { ] } - # Non-Mac Posix and Fuchsia compiler flags setup. + # Non-Apple Posix and Fuchsia compiler flags setup. # ----------------------------------- if ((is_posix && !is_apple) || is_fuchsia) { if (enable_profiling) { @@ -335,7 +386,7 @@ config("compiler") { # compute, so only use it in the official build to avoid slowing down # links. ldflags += [ "-Wl,--build-id=sha1" ] - } else if (current_os != "aix") { + } else if (current_os != "aix" && current_os != "zos") { ldflags += [ "-Wl,--build-id" ] } @@ -363,6 +414,23 @@ config("compiler") { } } + # Apple compiler flags setup. + # --------------------------------- + if (is_apple) { + # On Intel, clang emits both Apple's "compact unwind" information and + # DWARF eh_frame unwind information by default, for compatibility reasons. + # This flag limits emission of eh_frame information to functions + # whose unwind information can't be expressed in the compact unwind format + # (which in practice means almost everything gets only compact unwind + # entries). This reduces object file size a bit and makes linking a bit + # faster. + # On arm64, this is already the default behavior. + if (current_cpu == "x64") { + asmflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] + cflags += [ "-femit-dwarf-unwind=no-compact-unwind" ] + } + } + # Linux/Android/Fuchsia common flags setup. # --------------------------------- if (is_linux || is_chromeos || is_android || is_fuchsia) { @@ -384,28 +452,11 @@ config("compiler") { if (!is_component_build) { ldflags += [ "-Wl,-z,now" ] } - - # Compiler instrumentation can introduce dependencies in DSOs to symbols in - # the executable they are loaded into, so they are unresolved at link-time. - if (!using_sanitizer) { - ldflags += [ - "-Wl,-z,defs", - "-Wl,--as-needed", - ] - } } # Linux-specific compiler flags setup. # ------------------------------------ - if ((is_posix || is_fuchsia) && use_lld) { - ldflags += [ "-fuse-ld=lld" ] - if (current_cpu == "arm64") { - # Reduce the page size from 65536 in order to reduce binary size slightly - # by shrinking the alignment gap between segments. This also causes all - # segments to be mapped adjacently, which breakpad relies on. - ldflags += [ "-Wl,-z,max-page-size=4096" ] - } - } else if (use_gold) { + if (use_gold) { ldflags += [ "-fuse-ld=gold" ] if (!is_android) { # On Android, this isn't needed. gcc in the NDK knows to look next to @@ -434,7 +485,7 @@ config("compiler") { #} } - if (use_icf) { + if (use_icf && (!is_apple || use_lld)) { ldflags += [ "-Wl,--icf=all" ] } @@ -478,27 +529,46 @@ config("compiler") { ldflags += [ "-Wl,-z,keep-text-section-prefix" ] } - if (is_clang && !is_nacl && !use_xcode_clang) { + if (is_clang && !is_nacl && current_os != "zos") { cflags += [ "-fcrash-diagnostics-dir=" + clang_diagnostic_dir ] + if (save_reproducers_on_lld_crash && use_lld) { + ldflags += [ + "-fcrash-diagnostics=all", + "-fcrash-diagnostics-dir=" + clang_diagnostic_dir, + ] + } + # TODO(hans): Remove this once Clang generates better optimized debug info + # by default. https://crbug.com/765793 cflags += [ - # TODO(hans): Remove this once Clang generates better optimized debug info - # by default. https://crbug.com/765793 "-mllvm", "-instcombine-lower-dbg-declare=0", ] + if (!is_debug && use_thin_lto && is_a_target_toolchain) { + if (is_win) { + ldflags += [ "-mllvm:-instcombine-lower-dbg-declare=0" ] + } else { + ldflags += [ "-Wl,-mllvm,-instcombine-lower-dbg-declare=0" ] + } + } + + # TODO(crbug.com/1235145): Investigate why/if this should be needed. + if (is_win) { + cflags += [ "/clang:-ffp-contract=off" ] + } else { + cflags += [ "-ffp-contract=off" ] + } + } + + # Rust compiler setup (for either clang or rustc). + if (enable_rust) { + defines += [ "RUST_ENABLED" ] } # C11/C++11 compiler flags setup. # --------------------------- if (is_linux || is_chromeos || is_android || (is_nacl && is_clang) || current_os == "aix") { - if (target_os == "android") { - cxx11_override = use_cxx11_on_android - } else { - cxx11_override = use_cxx11 - } - if (is_clang) { standard_prefix = "c" @@ -522,55 +592,56 @@ config("compiler") { } cflags_c += [ "-std=${standard_prefix}11" ] - if (cxx11_override) { - # Override Chromium's default for projects that wish to stay on C++11. - cflags_cc += [ "-std=${standard_prefix}++11" ] - } else { + if (is_nacl && !is_nacl_saigo) { + # This is for the pnacl_newlib toolchain. It's only used to build + # a few independent ppapi test files that don't pull in any other + # dependencies. cflags_cc += [ "-std=${standard_prefix}++14" ] - } - } else if (!is_win && !is_nacl) { - if (target_os == "android") { - cxx11_override = use_cxx11_on_android + if (is_clang) { + cflags_cc += [ "-fno-trigraphs" ] + } + } else if (is_clang) { + if (is_chromeos_device) { + # TODO(crbug.com/1392471): Support C++20 in CrOS toolchain. + cflags_cc += [ "-std=${standard_prefix}++17" ] + } else { + cflags_cc += [ "-std=${standard_prefix}++20" ] + } } else { - cxx11_override = use_cxx11 + # The gcc bots are currently using GCC 9, which is not new enough to + # support "c++20"/"gnu++20". + cflags_cc += [ "-std=${standard_prefix}++2a" ] } - - # TODO(mcgrathr) - the NaCl GCC toolchain doesn't support either gnu11/gnu++11 - # or c11/c++11; we technically don't need this toolchain any more, but there - # are still a few buildbots using it, so until those are turned off - # we need the !is_nacl clause and the (is_nacl && is_clang) clause, above. + } else if (is_win) { + cflags_c += [ "/std:c11" ] + if (!is_clang && defined(msvc_use_cxx17) && msvc_use_cxx17) { + cflags_cc += [ "/std:c++17" ] + } else { + cflags_cc += [ "/std:c++20" ] + } + } else if (!is_nacl) { + # TODO(mcgrathr) - the NaCl GCC toolchain doesn't support either + # gnu11/gnu++11 or c11/c++11; we technically don't need this toolchain any + # more, but there are still a few buildbots using it, so until those are + # turned off we need the !is_nacl clause and the (is_nacl && is_clang) + # clause, above. cflags_c += [ "-std=c11" ] - if (cxx11_override) { - cflags_cc += [ "-std=c++11" ] + + if (is_fuchsia) { + # TODO(crbug.com/fuchsia/108751): The FIDL compiler generates code that + # will not compile in C++20 mode. Switch to C++20 when this is resolved. + cflags_cc += [ "-std=c++17" ] } else { - cflags_cc += [ "-std=c++14" ] + cflags_cc += [ "-std=c++20" ] } } - # C++17 removes trigraph support, so preemptively disable trigraphs. This is - # especially useful given the collision with ecmascript's logical assignment - # operators: https://github.com/tc39/proposal-logical-assignment - if (is_clang) { - # clang-cl disables trigraphs by default - if (!is_win) { - # The gnu variants of C++11 and C++14 already disable trigraph support, - # but when building with clang, we use -std=c++11 / -std=c++14, which - # enables trigraph support: override that here. - cflags_cc += [ "-fno-trigraphs" ] - } - - # Don't warn that trigraphs are ignored, since trigraphs are disabled - # anyway. + if (is_clang && current_os != "zos") { + # C++17 removes trigraph support, but clang still warns that it ignores + # them when seeing them. Don't. cflags_cc += [ "-Wno-trigraphs" ] } - if (is_mac) { - # The system libc++ on Mac doesn't have aligned allocation in C++17. - defines += [ "_LIBCPP_HAS_NO_ALIGNED_ALLOCATION" ] - cflags_cc += [ "-stdlib=libc++" ] - ldflags += [ "-stdlib=libc++" ] - } - # 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 @@ -587,26 +658,25 @@ config("compiler") { "-fsplit-lto-unit", ] - if (thin_lto_enable_optimizations) { - lto_opt_level = 3 - } else { - lto_opt_level = 3 - } + # 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" + + # An import limit of 30 has better performance (per speedometer) and lower + # binary size than the default setting of 100. + # TODO(gbiv): We ideally shouldn't need to specify this; ThinLTO + # should be able to better manage binary size increases on its own. + import_instr_limit = 30 if (is_win) { - # This is a straight translation of the non-Windows flags below, - # except we do not use the ThinLTO cache, which leaks temporary - # files on Windows (https://crbug.com/871962). ldflags += [ - "/opt:lldlto=" + lto_opt_level, "/opt:lldltojobs=all", - - # Experimentally determined to yield a reasonable trade-off between - # build time, run-time performance, and binary size. - "-mllvm:-import-instr-limit=10", - - # TODO(https://crbug.com/1127713): Investigate, remove. - "-mllvm:-enable-dse-memoryssa=false", + "-mllvm:-import-instr-limit=$import_instr_limit", + "-mllvm:-import-hot-multiplier=15", + "-mllvm:-import-cold-multiplier=4", + # "/lldltocache:" + + # rebase_path("$root_out_dir/thinlto-cache", root_build_dir), + # "/lldltocachepolicy:$cache_policy", ] } else { ldflags += [ "-flto=thin" ] @@ -620,48 +690,42 @@ 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" ] - - # Limit the size of the ThinLTO cache to the lesser of 10% of - # available disk space, 10GB and 100000 files. - cache_policy = - "cache_size=10%:cache_size_bytes=10g:cache_size_files=100000" - ldflags += [ - "-Wl,--thinlto-cache-dir=" + - rebase_path("$root_out_dir/thinlto-cache", root_build_dir), - "-Wl,--thinlto-cache-policy,$cache_policy", - ] - - # TODO(https://crbug.com/1127713): Investigate, remove. - ldflags += [ "-Wl,-mllvm,-enable-dse-memoryssa=false" ] - - ldflags += [ "-Wl,--lto-O" + lto_opt_level ] - if (thin_lto_enable_optimizations) { - # TODO(gbiv): We ideally shouldn't need to specify this; ThinLTO - # should be able to better manage binary size increases on its own. - import_instr_limit = 30 - if (is_android) { - import_instr_limit = 30 - } else if (is_chromeos) { - # Not much performance difference was noted between the default (100) - # and these. ARM was originally set lower than x86 to keep the size - # bloat of ThinLTO to <10%, but that's potentially no longer true. - # FIXME(inglorion): maybe tune these? - if (target_cpu == "arm" || target_cpu == "arm64") { - import_instr_limit = 30 - } else { - import_instr_limit = 30 - } - } - - if (import_instr_limit != -1) { - ldflags += [ "-Wl,-mllvm,-import-instr-limit=$import_instr_limit" ] + if (is_apple) { + _object_path_suffix = "" + if (is_ios) { + _object_path_suffix = ",persist" } + ldflags += [ + "-Wl,-cache_path_lto," + + rebase_path("$root_out_dir/thinlto-cache", root_build_dir), + "-Wcrl,object_path_lto" + _object_path_suffix, + ] + } else { + ldflags += + [] } + + # ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ] + + if (is_chromeos) { + # ARM was originally set lower than x86 to keep the size + # bloat of ThinLTO to <10%, but that's potentially no longer true. + # FIXME(inglorion): maybe tune these? + if (target_cpu == "arm" || target_cpu == "arm64") { + import_instr_limit = 30 + } + } else if (is_android) { + # TODO(crbug.com/1308318): Investigate if we can get the > 6% perf win + # of import_instr_limit 30 with a binary size hit smaller than ~2 MiB. + import_instr_limit = 30 + } + + ldflags += [ "-Wl,-mllvm,-import-instr-limit=$import_instr_limit" ] } - # TODO(pcc): Re-enable this flag on Android. This will require libc++ to be - # built with ThinLTO (see https://crbug.com/767901) as well as the GVR shim. - if (!is_android) { + # TODO(https://crbug.com/1211155): investigate why this isn't effective on + # arm32. + if (!is_android || current_cpu == "arm64") { cflags += [ "-fwhole-program-vtables" ] if (!is_win) { ldflags += [ "-fwhole-program-vtables" ] @@ -680,11 +744,7 @@ config("compiler") { if (compiler_timing) { if (is_clang && !is_nacl) { - if (is_win) { - cflags += [ "/clang:-ftime-trace" ] - } else { - cflags += [ "-ftime-trace" ] - } + cflags += [ "-ftime-trace" ] } else if (is_win) { cflags += [ # "Documented" here: @@ -700,6 +760,12 @@ config("compiler") { ldflags += [ "-Wl,--no-rosegment" ] } + # TODO(crbug.com/1374347): Cleanup undefined symbol errors caught by + # --no-undefined-version. + if (use_lld && !is_win && !is_mac && !is_ios) { + ldflags += [ "-Wl,--undefined-version" ] + } + # LLD does call-graph-sorted binary layout by default when profile data is # present. On Android this increases binary size due to more thinks for long # jumps. Turn it off by default and enable selectively for targets where it's @@ -712,14 +778,59 @@ config("compiler") { } } + if (is_clang && !is_nacl && show_includes) { + if (is_win) { + # TODO(crbug.com/1223741): Goma mixes the -H and /showIncludes output. + assert(!use_goma, "show_includes on Windows is not reliable with goma") + cflags += [ + "/clang:-H", + "/clang:-fshow-skipped-includes", + ] + } else { + cflags += [ + "-H", + "-fshow-skipped-includes", + ] + } + } + # This flag enforces that member pointer base types are complete. It helps # prevent us from running into problems in the Microsoft C++ ABI (see # https://crbug.com/847724). - if (is_clang && !is_nacl && target_os != "chromeos" && !use_xcode_clang && + if (is_clang && !is_nacl && target_os != "chromeos" && (is_win || use_custom_libcxx)) { cflags += [ "-fcomplete-member-pointers" ] } + # Use DWARF simple template names, with the following exceptions: + # + # * Windows is not supported as it doesn't use DWARF. + # * Apple platforms (e.g. MacOS, iPhone, iPad) aren't supported because xcode + # lldb doesn't have the needed changes yet. + # * Fuchsia isn't supported as zxdb doesn't support simple template names yet. + # TODO(crbug.com/1379070): Remove if the upstream default ever changes. + if (is_clang && !is_nacl && !is_win && !is_apple && !is_fuchsia) { + cflags_cc += [ "-gsimple-template-names" ] + } + + # MLGO specific flags. These flags enable an ML-based inliner trained on + # Chrome on Android (arm32) with ThinLTO enabled, optimizing for size. + # The "release" ML model is embedded into clang as part of its build. + # Currently, the ML inliner is only enabled when targeting Android due to: + # a) Android is where size matters the most. + # b) MLGO presently has the limitation of only being able to embed one model + # at a time; It is unclear if the embedded model is beneficial for + # non-Android targets. + # MLGO is only officially supported on linux. + if (use_ml_inliner && is_a_target_toolchain) { + assert( + is_android && host_os == "linux", + "MLGO is currently only supported for targeting Android on a linux host") + if (use_thin_lto) { + ldflags += [ "-Wl,-mllvm,-enable-ml-inliner=release" ] + } + } + # Pass the same C/C++ flags to the objective C/C++ compiler. cflags_objc += cflags_c cflags_objcc += cflags_cc @@ -731,6 +842,92 @@ config("compiler") { asmflags += cflags asmflags += cflags_c } + + # Rust compiler flags setup. + # --------------------------- + 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 + # in safe Rust, they also can't provoke buffer overflows. + # As such these checks may be less important in Rust than C++. + # But in (simplistic) testing they have negligible performance + # overhead, and this helps to provide consistent behavior + # between different configurations, so we'll keep them on until + # we discover a reason to turn them off. + "-Coverflow-checks=on", + + # To make Rust .d files compatible with ninja + "-Zdep-info-omit-d-target", + + # If a macro panics during compilation, show which macro and where it is + # defined. + "-Zmacro-backtrace", + + # For deterministic builds, keep the local machine's current working + # directory from appearing in build outputs. + "-Zremap-cwd-prefix=.", + + # Full RUSTC optimizations. + "-Copt-level=3", "-Ctarget-feature=+sse2", + ] + if (rust_abi_target != "") { + rustflags += [ "--target=$rust_abi_target" ] + } + if (use_lto_in_rustc_linking) { + rustflags += [ "-Clinker-plugin-lto" ] + } + if (!use_thin_lto || !use_chromium_rust_toolchain) { + # Don't include bitcode if it won't be used, or can't be used. When + # use_thin_lto is true, we will try to apply LTO to any objects that have + # the appropriate bitcode. But we have to use Chromium's toolchain in order + # to use LTO with rust code. Chromium's rustc will have an LLVM backend that + # matches the C++ clang compiler. + rustflags += [ "-Cembed-bitcode=no" ] + } + if (is_official_build) { + rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+sse2", ] + } +} + +# The BUILDCONFIG file sets this config on targets by default, which means when +# building with ThinLTO, no optimization is performed in the link step. +config("thinlto_optimize_default") { + if (!is_debug && use_thin_lto && is_a_target_toolchain) { + lto_opt_level = 3 + + if (is_win) { + ldflags = [ "/opt:lldlto=" + lto_opt_level ] + ldflags += [ "-mllvm:-enable-pre=false", ] + } else { + ldflags = [ "-Wl,--lto-O" + lto_opt_level ] + } + } +} + +# Use this to enable optimization in the ThinLTO link step for select targets +# when thin_lto_enable_optimizations is set by doing: +# +# configs -= [ "//build/config/compiler:thinlto_optimize_default" ] +# configs += [ "//build/config/compiler:thinlto_optimize_max" ] +# +# Since it makes linking significantly slower and more resource intensive, only +# use it on important targets such as the main browser executable or dll. +config("thinlto_optimize_max") { + if (!is_debug && use_thin_lto && is_a_target_toolchain) { + if (thin_lto_enable_optimizations) { + lto_opt_level = 3 + } else { + lto_opt_level = 3 + } + + if (is_win) { + ldflags = [ "/opt:lldlto=" + lto_opt_level ] + ldflags += [ "-mllvm:-enable-pre=false", ] + } else { + ldflags = [ "-Wl,--lto-O" + lto_opt_level ] + } + } } # This provides the basic options to select the target CPU and ABI. @@ -739,34 +936,45 @@ config("compiler") { # tweak code generation for a particular CPU do not belong here! # See "compiler_codegen", below. config("compiler_cpu_abi") { - cflags = [] + cflags = [ "-O3", ] ldflags = [] defines = [] + configs = [] + if (is_chromeos) { + configs += [ "//build/config/chromeos:compiler_cpu_abi" ] + } + if ((is_posix && !is_apple) || is_fuchsia) { # CPU architecture. We may or may not be doing a cross compile now, so for # simplicity we always explicitly set the architecture. if (current_cpu == "x64") { cflags += [ "-m64", - "-march=$x64_arch", + "-O3", + "-msse2", ] - ldflags += [ "-m64" ] + ldflags += [ "-m64", "-Wl,-O3", "-msse2", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=4", ] } else if (current_cpu == "x86") { - cflags += [ "-m32", "-O3", ] - ldflags += [ "-m32", "-Wl,-O3", ] + cflags += [ "-m32" ] + ldflags += [ "-m32", "-Wl,-O3", "-msse2", ] if (!is_nacl) { cflags += [ - "-msse2", - "-O3", "-mfpmath=sse", - "-mmmx", + "-O3", + "-msse2", ] } + } else if (target_cpu == "arm64") { + if (!is_android && !is_nacl) { + cflags += [ "-O3", "-Wno-unused-command-line-argument", ] + ldflags += [ "-Wl,-O3", "-Wno-unused-command-line-argument", ] + } } else if (current_cpu == "arm") { - if (is_clang && !is_android && !is_nacl) { - cflags += [ "--target=arm-linux-gnueabihf" ] - ldflags += [ "--target=arm-linux-gnueabihf" ] + if (is_clang && !is_android && !is_nacl && + !(is_chromeos_lacros && is_chromeos_device)) { + cflags += [ "--target=arm-linux-gnueabihf", "-O3", "-Wno-unused-command-line-argument", ] + ldflags += [ "--target=arm-linux-gnueabihf", "-Wl,-O3", "-Wno-unused-command-line-argument", ] } if (!is_nacl) { cflags += [ @@ -778,19 +986,24 @@ config("compiler_cpu_abi") { cflags += [ "-mtune=$arm_tune" ] } } else if (current_cpu == "arm64") { - if (is_clang && !is_android && !is_nacl && !is_fuchsia) { - cflags += [ "--target=aarch64-linux-gnu" ] - ldflags += [ "--target=aarch64-linux-gnu" ] + if (is_clang && !is_android && !is_nacl && !is_fuchsia && + !(is_chromeos_lacros && is_chromeos_device)) { + cflags += [ "--target=aarch64-linux-gnu", "-O3", "-Wno-unused-command-line-argument", ] + ldflags += [ "--target=aarch64-linux-gnu", "-Wl,-O3", "-Wno-unused-command-line-argument", ] + } + if (is_android) { + cflags += [ "-O3", ] + ldflags += [ "-Wl,-O3", ] } } else if (current_cpu == "mipsel" && !is_nacl) { ldflags += [ "-Wl,--hash-style=sysv" ] if (custom_toolchain == "") { if (is_clang) { if (is_android) { - cflags += [ "--target=mipsel-linux-android" ] + cflags += [ "--target=mipsel-linux-android", "-O3", ] ldflags += [ "--target=mipsel-linux-android" ] } else { - cflags += [ "--target=mipsel-linux-gnu" ] + cflags += [ "--target=mipsel-linux-gnu", "-O3", ] ldflags += [ "--target=mipsel-linux-gnu" ] } } else { @@ -1014,33 +1227,6 @@ config("compiler_cpu_abi") { ] ldflags += [ "-mips64r2" ] } - } else if (current_cpu == "pnacl" && is_nacl_nonsfi) { - if (target_cpu == "x86" || target_cpu == "x64") { - cflags += [ - "-arch", - "x86-32-nonsfi", - "--pnacl-bias=x86-32-nonsfi", - "--target=i686-unknown-nacl", - ] - ldflags += [ - "-arch", - "x86-32-nonsfi", - "--target=i686-unknown-nacl", - ] - } else if (target_cpu == "arm") { - cflags += [ - "-arch", - "arm-nonsfi", - "-mfloat-abi=hard", - "--pnacl-bias=arm-nonsfi", - "--target=armv7-unknown-nacl-gnueabihf", - ] - ldflags += [ - "-arch", - "arm-nonsfi", - "--target=armv7-unknown-nacl-gnueabihf", - ] - } } else if (current_cpu == "ppc64") { if (current_os == "aix") { cflags += [ "-maix64" ] @@ -1049,6 +1235,21 @@ config("compiler_cpu_abi") { cflags += [ "-m64" ] ldflags += [ "-m64" ] } + } else if (current_cpu == "riscv64") { + if (is_clang) { + cflags += [ "--target=riscv64-linux-gnu" ] + ldflags += [ "--target=riscv64-linux-gnu" ] + } + cflags += [ "-mabi=lp64d" ] + } else if (current_cpu == "loong64") { + if (is_clang) { + cflags += [ "--target=loongarch64-linux-gnu" ] + ldflags += [ "--target=loongarch64-linux-gnu" ] + } + cflags += [ + "-mabi=lp64d", + "-mcmodel=medium", + ] } else if (current_cpu == "s390x") { cflags += [ "-m64" ] ldflags += [ "-m64" ] @@ -1094,6 +1295,7 @@ config("compiler_codegen") { config("compiler_deterministic") { cflags = [] ldflags = [] + swiftflags = [] # Eliminate build metadata (__DATE__, __TIME__ and __TIMESTAMP__) for # deterministic build. See https://crbug.com/314403 @@ -1122,12 +1324,20 @@ config("compiler_deterministic") { # different build directory like "out/feature_a" and "out/feature_b" if # we build same files with same compile flag. # Other paths are already given in relative, no need to normalize them. - cflags += [ - "-Xclang", - "-fdebug-compilation-dir", - "-Xclang", - ".", - ] + if (is_nacl) { + # TODO(https://crbug.com/1231236): Use -ffile-compilation-dir= here. + cflags += [ + "-Xclang", + "-fdebug-compilation-dir", + "-Xclang", + ".", + ] + } else { + # -ffile-compilation-dir is an alias for both -fdebug-compilation-dir= + # and -fcoverage-compilation-dir=. + cflags += [ "-ffile-compilation-dir=." ] + swiftflags += [ "-file-compilation-dir=." ] + } if (!is_win) { # We don't use clang -cc1as on Windows (yet? https://crbug.com/762167) asmflags = [ "-Wa,-fdebug-compilation-dir,." ] @@ -1150,8 +1360,18 @@ config("compiler_deterministic") { # Tells the compiler not to use absolute paths when passing the default # paths to the tools it invokes. We don't want this because we don't # really need it and it can mess up the goma cache entries. - if (is_clang && !is_nacl) { + if (is_clang && (!is_nacl || is_nacl_saigo)) { cflags += [ "-no-canonical-prefixes" ] + + # Same for links: Let the compiler driver invoke the linker + # with a relative path and pass relative paths to built-in + # libraries. Not needed on Windows because we call the linker + # directly there, not through the compiler driver. + # We don't link on goma, so this change is just for cleaner + # internal linker invocations, for people who work on the build. + if (!is_win) { + ldflags += [ "-no-canonical-prefixes" ] + } } } @@ -1176,6 +1396,21 @@ config("clang_revision") { } } +config("rustc_revision") { + if (enable_rust && defined(rustc_version)) { + # Similar to the above config, this is here so that all files get + # recompiled after a rustc roll. Nothing should ever read this cfg. + # $rustc_version is a gn arg set within //build/config/rust.gni + # so that users using a custom Rust toolchain can override it. + # Its accuracy is checked in //build/rust/std:find_stdlib, which + # most of our Rust targets depend upon. + rustflags = [ + "--cfg", + "rustc_version=\"$rustc_version\"", + ] + } +} + config("compiler_arm_fpu") { if (current_cpu == "arm" && !is_ios && !is_nacl) { cflags = [ "-mfpu=$arm_fpu" ] @@ -1235,6 +1470,9 @@ config("runtime_library") { configs += [ "//build/config/win:runtime_library" ] } else if (is_linux || is_chromeos) { configs += [ "//build/config/linux:runtime_library" ] + if (is_chromeos) { + configs += [ "//build/config/chromeos:runtime_library" ] + } } else if (is_ios) { configs += [ "//build/config/ios:runtime_library" ] } else if (is_mac) { @@ -1264,160 +1502,25 @@ config("default_warnings") { cflags += [ "/WX" ] } if (fatal_linker_warnings) { + arflags = [ "/WX" ] ldflags = [ "/WX" ] } + defines = [ + # Without this, Windows headers warn that functions like wcsnicmp + # should be spelled _wcsnicmp. But all other platforms keep spelling + # it wcsnicmp, making this warning unhelpful. We don't want it. + "_CRT_NONSTDC_NO_WARNINGS", - cflags += [ - # Warnings permanently disabled: - - # C4091: 'typedef ': ignored on left of 'X' when no variable is - # declared. - # This happens in a number of Windows headers. Dumb. - "/wd4091", - - # C4127: conditional expression is constant - # This warning can in theory catch dead code and other problems, but - # triggers in far too many desirable cases where the conditional - # expression is either set by macros or corresponds some legitimate - # compile-time constant expression (due to constant template args, - # conditionals comparing the sizes of different types, etc.). Some of - # these can be worked around, but it's not worth it. - "/wd4127", - - # C4251: 'identifier' : class 'type' needs to have dll-interface to be - # used by clients of class 'type2' - # This is necessary for the shared library build. - "/wd4251", - - # C4275: non dll-interface class used as base for dll-interface class - # This points out a potential (but rare) problem with referencing static - # fields of a non-exported base, through the base's non-exported inline - # functions, or directly. The warning is subtle enough that people just - # suppressed it when they saw it, so it's not worth it. - "/wd4275", - - # C4312 is a VS 2015 64-bit warning for integer to larger pointer. - # TODO(brucedawson): fix warnings, crbug.com/554200 - "/wd4312", - - # C4324 warns when padding is added to fulfill alignas requirements, - # but can trigger in benign cases that are difficult to individually - # suppress. - "/wd4324", - - # C4351: new behavior: elements of array 'array' will be default - # initialized - # This is a silly "warning" that basically just alerts you that the - # compiler is going to actually follow the language spec like it's - # supposed to, instead of not following it like old buggy versions did. - # There's absolutely no reason to turn this on. - "/wd4351", - - # C4355: 'this': used in base member initializer list - # It's commonly useful to pass |this| to objects in a class' initializer - # list. While this warning can catch real bugs, most of the time the - # constructors in question don't attempt to call methods on the passed-in - # pointer (until later), and annotating every legit usage of this is - # simply more hassle than the warning is worth. - "/wd4355", - - # C4503: 'identifier': decorated name length exceeded, name was - # truncated - # This only means that some long error messages might have truncated - # identifiers in the presence of lots of templates. It has no effect on - # program correctness and there's no real reason to waste time trying to - # prevent it. - "/wd4503", - - # Warning C4589 says: "Constructor of abstract class ignores - # initializer for virtual base class." Disable this warning because it - # is flaky in VS 2015 RTM. It triggers on compiler generated - # copy-constructors in some cases. - "/wd4589", - - # C4611: interaction between 'function' and C++ object destruction is - # non-portable - # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN - # suggests using exceptions instead of setjmp/longjmp for C++, but - # Chromium code compiles without exception support. We therefore have to - # use setjmp/longjmp for e.g. JPEG decode error handling, which means we - # have to turn off this warning (and be careful about how object - # destruction happens in such cases). - "/wd4611", - - # Warnings to evaluate and possibly fix/reenable later: - - "/wd4100", # Unreferenced formal function parameter. - "/wd4121", # Alignment of a member was sensitive to packing. - "/wd4244", # Conversion: possible loss of data. - "/wd4505", # Unreferenced local function has been removed. - "/wd4510", # Default constructor could not be generated. - "/wd4512", # Assignment operator could not be generated. - "/wd4610", # Class can never be instantiated, constructor required. - "/wd4838", # Narrowing conversion. Doesn't seem to be very useful. - "/wd4995", # 'X': name was marked as #pragma deprecated - "/wd4996", # Deprecated function warning. - - # These are variable shadowing warnings that are new in VS2015. We - # should work through these at some point -- they may be removed from - # the RTM release in the /W4 set. - "/wd4456", - "/wd4457", - "/wd4458", - "/wd4459", - - # All of our compilers support the extensions below. - "/wd4200", # nonstandard extension used: zero-sized array in struct/union - "/wd4201", # nonstandard extension used: nameless struct/union - "/wd4204", # nonstandard extension used : non-constant aggregate - # initializer - - "/wd4221", # nonstandard extension used : 'identifier' : cannot be - # initialized using address of automatic variable - - # http://crbug.com/588506 - Conversion suppressions waiting on Clang - # -Wconversion. - "/wd4245", # 'conversion' : conversion from 'type1' to 'type2', - # signed/unsigned mismatch - - "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of - # data - - "/wd4305", # 'identifier' : truncation from 'type1' to 'type2' - "/wd4389", # 'operator' : signed/unsigned mismatch - - "/wd4702", # unreachable code - - # http://crbug.com/848979 - MSVC is more conservative than Clang with - # regards to variables initialized and consumed in different branches. - "/wd4701", # Potentially uninitialized local variable 'name' used - "/wd4703", # Potentially uninitialized local pointer variable 'name' used - - # http://crbug.com/848979 - Remaining Clang permitted warnings. - "/wd4661", # 'identifier' : no suitable definition provided for explicit - # template instantiation request - - "/wd4706", # assignment within conditional expression - # MSVC is stricter and requires a boolean expression. - - "/wd4715", # 'function' : not all control paths return a value' - # MSVC does not analyze switch (enum) for completeness. + # TODO(thakis): winsock wants us to use getaddrinfo instead of + # gethostbyname. Fires mostly in non-Chromium code. We probably + # want to remove this define eventually. + "_WINSOCK_DEPRECATED_NO_WARNINGS", ] - - cflags_cc += [ - # Allow "noexcept" annotations even though we compile with exceptions - # disabled. - "/wd4577", - ] - - if (current_cpu == "x86") { - cflags += [ - # VC++ 2015 changes 32-bit size_t truncation warnings from 4244 to - # 4267. Example: short TruncTest(size_t x) { return x; } - # Since we disable 4244 we need to disable 4267 during migration. - # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. - "/wd4267", - ] + if (!is_clang) { + # TODO(thakis): Remove this once + # https://swiftshader-review.googlesource.com/c/SwiftShader/+/57968 has + # rolled into angle. + cflags += [ "/wd4244" ] } } else { if (is_apple && !is_nacl) { @@ -1478,18 +1581,20 @@ config("default_warnings") { "-Wno-missing-field-initializers", # "struct foo f = {0};" "-Wno-unused-parameter", # Unused function parameters. ] + + if (!is_nacl || is_nacl_saigo) { + cflags += [ + # An ABI compat warning we don't care about, https://crbug.com/1102157 + # TODO(thakis): Push this to the (few) targets that need it, + # instead of having a global flag. + "-Wno-psabi", + ] + } } if (is_clang) { cflags += [ - # TODO(thakis): Consider -Wloop-analysis (turns on - # -Wrange-loop-analysis too). - - # This warns on using ints as initializers for floats in - # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|), - # which happens in several places in chrome code. Not sure if - # this is worth fixing. - "-Wno-c++11-narrowing", + "-Wloop-analysis", # TODO(thakis): This used to be implied by -Wno-unused-function, # which we no longer use. Check if it makes sense to remove @@ -1497,70 +1602,75 @@ config("default_warnings") { "-Wno-unneeded-internal-declaration", ] - # use_xcode_clang only refers to the iOS toolchain, host binaries use - # chromium's clang always. - if (!is_nacl) { - cflags += [ - # TODO(thakis): https://crbug.com/604888 - "-Wno-undefined-var-template", - ] - + if (!is_nacl || is_nacl_saigo) { if (is_win) { # TODO(thakis): https://crbug.com/617318 # Currently goma can not handle case sensitiveness for windows well. cflags += [ "-Wno-nonportable-include-path" ] } - if (current_toolchain == host_toolchain || !use_xcode_clang) { - # Flags NaCl (Clang 3.7) and Xcode 9.2 (Clang clang-900.0.39.2) do not - # recognize. + cflags += [ + "-Wenum-compare-conditional", + + # Ignore warnings about MSVC optimization pragmas. + # TODO(thakis): Only for no_chromium_code? http://crbug.com/912662 + "-Wno-ignored-pragma-optimize", + ] + + if (!is_nacl) { cflags += [ - # An ABI compat warning we don't care about, https://crbug.com/1102157 - # TODO(thakis): Push this to the (few) targets that need it, - # instead of having a global flag. - "-Wno-psabi", + # TODO(crbug.com/1343975) Evaluate and possibly enable. + "-Wno-deprecated-builtins", - # Ignore warnings about MSVC optimization pragmas. - # TODO(thakis): Only for no_chromium_code? http://crbug.com/912662 - "-Wno-ignored-pragma-optimize", - - # TODO(https://crbug.com/989932): Evaluate and possibly enable. - "-Wno-implicit-int-float-conversion", - - # TODO(https://crbug.com/999886): Clean up, enable. - "-Wno-final-dtor-non-final-class", - - # TODO(https://crbug.com/1016945) Clean up, enable. - "-Wno-builtin-assume-aligned-alignment", - - # TODO(https://crbug.com/1028110): Evaluate and possible enable. - "-Wno-deprecated-copy", - - # TODO(https://crbug.com/1050281): Clean up, enable. - "-Wno-non-c-typedef-for-linkage", + # TODO(crbug.com/1352183) Evaluate and possibly enable. + "-Wno-bitfield-constant-conversion", ] - - cflags_c += [ - # TODO(https://crbug.com/995993): Clean up and enable. - "-Wno-implicit-fallthrough", - ] - - if (is_ios) { - # TODO(https://crbug.com/1143700): Clean up and re-enable. - cflags_objc = [ "-Wno-gnu-folding-constant" ] - } - - if (enable_wmax_tokens) { - cflags += [ "-Wmax-tokens" ] - } else { - # TODO(https://crbug.com/1049569): Remove after Clang 87b235db. - cflags += [ "-Wno-max-tokens" ] - } } } } } +# prevent_unsafe_narrowing ---------------------------------------------------- +# +# Warnings that prevent narrowing or comparisons of integer types that are +# likely to cause out-of-bound read/writes or Undefined Behaviour. In +# particular, size_t is used for memory sizes, allocation, indexing, and +# offsets. Using other integer types along with size_t produces risk of +# memory-safety bugs and thus security exploits. +# +# In order to prevent these bugs, allocation sizes were historically limited to +# sizes that can be represented within 31 bits of information, allowing `int` to +# be safely misused instead of `size_t` (https://crbug.com/169327). In order to +# support increasing the allocation limit we require strictly adherence to +# using the correct types, avoiding lossy conversions, and preventing overflow. +# To do so, enable this config and fix errors by converting types to be +# `size_t`, which is both large enough and unsigned, when dealing with memory +# sizes, allocations, indices, or offsets.In cases where type conversion is not +# possible or is superfluous, use base::strict_cast<> or base::checked_cast<> +# to convert to size_t as needed. +# See also: https://docs.google.com/document/d/14yKUwDaorqqNfgdGqHY_nck2nn02XBQcB5N0ue4fax8 +# +# To enable in a GN target, use: +# configs += [ "//build/config/compiler:prevent_unsafe_narrowing" ] + +config("prevent_unsafe_narrowing") { + if (is_clang) { + cflags = [ + "-Wshorten-64-to-32", + "-Wimplicit-int-conversion", + "-Wsign-compare", + "-Wsign-conversion", + ] + if (!is_nacl) { + cflags += [ + # Avoid bugs of the form `if (size_t i = size; i >= 0; --i)` while + # fixing types to be sign-correct. + "-Wtautological-unsigned-zero-compare", + ] + } + } +} + # chromium_code --------------------------------------------------------------- # # Toggles between higher and lower warnings for code that is (or isn't) @@ -1568,9 +1678,9 @@ config("default_warnings") { config("chromium_code") { if (is_win) { - cflags = [ "/W4" ] # Warning level 4. - if (is_clang) { + cflags = [ "/W4" ] # Warning level 4. + # Opt in to additional [[nodiscard]] on standard library methods. defines = [ "_HAS_NODISCARD" ] } @@ -1598,7 +1708,8 @@ config("chromium_code") { if (!is_debug && !using_sanitizer && current_cpu != "s390x" && current_cpu != "s390" && current_cpu != "ppc64" && - current_cpu != "mips" && current_cpu != "mips64") { + current_cpu != "mips" && current_cpu != "mips64" && + current_cpu != "riscv64" && current_cpu != "loong64") { # Non-chromium code is not guaranteed to compile cleanly with # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are # disabled, so only do that for Release build. @@ -1609,45 +1720,43 @@ config("chromium_code") { cflags_objc = [ "-Wobjc-missing-property-synthesis" ] cflags_objcc = [ "-Wobjc-missing-property-synthesis" ] } + + if (is_ios) { + cflags_objc = [ "-Wimplicit-retain-self" ] + cflags_objcc = cflags_objc + } } if (is_clang) { cflags += [ # Warn on missing break statements at the end of switch cases. - # For intentional fallthrough, use FALLTHROUGH; from - # base/compiler_specific.h + # For intentional fallthrough, use [[fallthrough]]. "-Wimplicit-fallthrough", + + # Warn on unnecessary extra semicolons outside of function definitions. + "-Wextra-semi", ] # TODO(thakis): Enable this more often, https://crbug.com/346399 # use_libfuzzer: https://crbug.com/1063180 - if (!is_nacl && !use_libfuzzer) { - cflags += [ "-Wunreachable-code" ] + if ((!is_nacl || is_nacl_saigo) && !use_libfuzzer) { + cflags += [ "-Wunreachable-code-aggressive" ] } # Thread safety analysis is broken under nacl: https://crbug.com/982423. - if (!is_nacl) { + if (!is_nacl || is_nacl_saigo) { cflags += [ # Thread safety analysis. See base/thread_annotations.h and # https://clang.llvm.org/docs/ThreadSafetyAnalysis.html "-Wthread-safety", ] } - - # TODO(thakis): Enable this for more platforms, https://crbug.com/926235 - # ChromeOS: http://crbug.com/940863 - # Chromecast: http://crbug.com/942554 - has_dchecks = is_debug || dcheck_always_on - if (!has_dchecks && is_chromeos && is_chrome_branded) { - # Temporarily disable -Wextra-semi for Chrome on Chrome OS. - } else if (is_chromecast && chromecast_branding != "public") { - # Temporarily disable -Wextra-semi for Chromecast. - } else { - cflags += [ "-Wextra-semi" ] - } } - configs = [ ":default_warnings" ] + configs = [ + ":default_warnings", + ":noshadowing", + ] } config("no_chromium_code") { @@ -1656,15 +1765,12 @@ config("no_chromium_code") { defines = [] if (is_win) { + if (is_clang) { + cflags += [ "/W3" ] # Warning level 3. + } cflags += [ - "/W3", # Warning level 3. "/wd4800", # Disable warning when forcing value to bool. "/wd4267", # TODO(jschuh): size_t to int. - "/wd4996", # Deprecated function warning. - ] - defines += [ - "_CRT_NONSTDC_NO_WARNINGS", - "_CRT_NONSTDC_NO_DEPRECATE", ] } else { # GCC may emit unsuppressible warnings so don't add -Werror for no chromium @@ -1685,15 +1791,54 @@ config("no_chromium_code") { # Lots of third-party libraries have unused variables. Instead of # suppressing them individually, we just blanket suppress them here. "-Wno-unused-variable", + + # Similarly, we're not going to fix all the C++11 narrowing issues in + # third-party libraries. + "-Wno-c++11-narrowing", ] - if (!is_nacl && (current_toolchain == host_toolchain || !use_xcode_clang)) { + if (!is_nacl) { cflags += [ - # TODO(https://crbug.com/1031169): Clean up and enable. + # Disabled for similar reasons as -Wunused-variable. + "-Wno-unused-but-set-variable", + + # TODO(https://crbug.com/1202159): Clean up and enable. "-Wno-misleading-indentation", ] } } + # Rust warnings to ignore in third party dependencies. This list is + # built from those warnings which are currently in our various Rust + # third party dependencies, but aren't serious (they're largely + # stylistic). + # An alternative policy would be to suppress all warnings in third + # party Rust code using "--cap-lints allow". This is what cargo does + # for code outside your own crate, so is worth considering if it + # turns out that maintaining this list is onerous. + # (https://doc.rust-lang.org/rustc/lints/levels.html#capping-lints) + rustflags = [ + "-A", + "unused_parens", + "-A", + "bare_trait_objects", + "-A", + "non_fmt_panics", + "-A", + "redundant_semicolons", + "-A", + "unused_parens", + "-A", + "anonymous_parameters", + "-A", + "bare_trait_objects", + "-A", + "deprecated", + "-A", + "non_camel_case_types", + "-A", + "unused_imports", + ] + configs = [ ":default_warnings" ] } @@ -1704,7 +1849,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) { + if (is_clang && (!is_nacl || is_nacl_saigo)) { cflags = [ "-Wshadow" ] } } @@ -1741,7 +1886,8 @@ config("no_rtti") { # (de)allocate memory on a different heap, which would spell trouble if pointers # to heap-allocated memory are passed over shared library boundaries. config("export_dynamic") { - if (is_linux || export_libcxxabi_from_executables) { + # TODO(crbug.com/1052397): Revisit after target_os flip is completed. + if (is_linux || is_chromeos_lacros || export_libcxxabi_from_executables) { ldflags = [ "-rdynamic" ] } } @@ -1761,9 +1907,10 @@ config("export_dynamic") { # 2. Remove the thin_archive config, so that the .a file actually contains all # .o files, instead of just references to .o files in the build directoy config("thin_archive") { - # Mac and iOS use the mac-specific "libtool" command, not ar, which doesn't - # have a "thin archive" mode (it does accept -T, but it means truncating - # archive names to 16 characters, which is not what we want). + # The macOS and iOS default linker ld64 does not support reading thin + # archives. + # TODO(crbug.com/1221615): Enable on is_apple if use_lld once that no longer + # confuses lldb. if ((is_posix && !is_nacl && !is_apple) || is_fuchsia) { arflags = [ "-T" ] } else if (is_win && use_lld) { @@ -1826,50 +1973,6 @@ config("wexit_time_destructors") { } } -# On Windows compiling on x64, VC will issue a warning when converting -# size_t to int because it will truncate the value. Our code should not have -# these warnings and one should use a static_cast or a checked_cast for the -# conversion depending on the case. However, a lot of code still needs to be -# fixed. Apply this config to such targets to disable the warning. -# -# Note that this can be applied regardless of platform and architecture to -# clean up the call sites. This will only apply the flag when necessary. -# -# This config is just an alias to no_shorten_64_warnings and will -# suppress a superset of warning 4267 and any 64-bit -> 32-bit implicit -# conversions. Having both for a time means not having to go through and -# update all references to no_size_t_to_int_warning throughout the codebase -# atomically. -# -# Any new warning suppressions should use the no_shorten_64_warnings -# config below and not this. -# -# TODO(jschuh): crbug.com/167187 fix this and delete this config. -config("no_size_t_to_int_warning") { - configs = [ ":no_shorten_64_warnings" ] -} - -# As part of re-enabling -Wconversion (see issue 588506) some code -# will continue to generate warnings. -# The first warning to be enabled will be -Wshorten-64-to-32. -# -# Code that currently generates warnings for this can include this -# config to disable them. -config("no_shorten_64_warnings") { - if (current_cpu == "x64" || current_cpu == "arm64") { - if (is_clang) { - cflags = [ "-Wno-shorten-64-to-32" ] - } else { - if (is_win) { - # MSVC does not have an explicit warning equivalent to - # -Wshorten-64-to-32 but 4267 warns for size_t -> int - # on 64-bit builds, so is the closest. - cflags = [ "/wd4267" ] - } - } - } -} - # Some code presumes that pointers to structures/objects are compatible # regardless of whether what they point to is already known to be valid. # gcc 4.9 and earlier had no way of suppressing this warning without @@ -1881,7 +1984,7 @@ config("no_incompatible_pointer_warnings") { cflags += [ "-Wno-incompatible-pointer-types" ] } else if (current_cpu == "mipsel" || current_cpu == "mips64el") { cflags += [ "-w" ] - } else if (is_chromeos && current_cpu == "arm") { + } else if (is_chromeos_ash && current_cpu == "arm") { cflags += [ "-w" ] } } @@ -1900,12 +2003,21 @@ config("no_incompatible_pointer_warnings") { # Shared settings for both "optimize" and "optimize_max" configs. # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags. + + common_optimize_on_cflags = [ "-O3", ] + common_optimize_on_ldflags = [ "-Wl,-O3", ] + if (is_win) { - common_optimize_on_cflags = [ + + common_optimize_on_cflags = [] + common_optimize_on_ldflags = [] + + common_optimize_on_cflags += [ "/Ob2", # Both explicit and auto inlining. "/Oy-", # Disable omitting frame pointers, must be after /O2. "/Zc:inline", # Remove unreferenced COMDAT (faster links). ] + common_optimize_on_ldflags += [] if (!is_asan) { common_optimize_on_cflags += [ # Put data in separate COMDATs. This allows the linker @@ -1916,8 +2028,39 @@ if (is_win) { "/Gw", ] } - common_optimize_on_ldflags = [] + common_optimize_on_cflags += [ + "-mllvm", "-extra-vectorizer-passes", + "-mllvm", "-enable-cond-stores-vec", + "-mllvm", "-slp-vectorize-hor-store", + "-mllvm", "-enable-loopinterchange", + "-mllvm", "-enable-loop-distribute", + "-mllvm", "-enable-unroll-and-jam", + "-mllvm", "-enable-loop-flatten", + "-mllvm", "-interleave-small-loop-scalar-reduction", + "-mllvm", "-unroll-runtime-multi-exit", + "-mllvm", "-aggressive-ext-opt", + "-mllvm", "-enable-interleaved-mem-accesses", + "/O3", + "/clang:-O3", + "/clang:-msse2", + "-Xclang", "-O3", + ] + + common_optimize_on_ldflags += [ + "-mllvm:-extra-vectorizer-passes", + "-mllvm:-enable-cond-stores-vec", + "-mllvm:-slp-vectorize-hor-store", + "-mllvm:-enable-loopinterchange", + "-mllvm:-enable-loop-distribute", + "-mllvm:-enable-unroll-and-jam", + "-mllvm:-enable-loop-flatten", + "-mllvm:-interleave-small-loop-scalar-reduction", + "-mllvm:-unroll-runtime-multi-exit", + "-mllvm:-aggressive-ext-opt", + "-mllvm:-enable-interleaved-mem-accesses", + ] + # /OPT:ICF is not desirable in Debug builds, since code-folding can result in # misleading symbols in stack traces. if (!is_debug && !is_component_build) { @@ -1927,11 +2070,43 @@ if (is_win) { if (is_official_build) { common_optimize_on_ldflags += [ "/OPT:REF" ] # Remove unreferenced data. # TODO(thakis): Add LTO/PGO clang flags eventually, https://crbug.com/598772 + common_optimize_on_cflags += [] } } else { + common_optimize_on_cflags = [] common_optimize_on_ldflags = [] + common_optimize_on_cflags += [ + "-mllvm", "-extra-vectorizer-passes", + "-mllvm", "-enable-cond-stores-vec", + "-mllvm", "-slp-vectorize-hor-store", + "-mllvm", "-enable-loopinterchange", + "-mllvm", "-enable-loop-distribute", + "-mllvm", "-enable-unroll-and-jam", + "-mllvm", "-enable-loop-flatten", + "-mllvm", "-interleave-small-loop-scalar-reduction", + "-mllvm", "-unroll-runtime-multi-exit", + "-mllvm", "-aggressive-ext-opt", + "-mllvm", "-enable-interleaved-mem-accesses", + "-O3", + ] + + common_optimize_on_ldflags += [ + "-Wl,-mllvm,-extra-vectorizer-passes", + "-Wl,-mllvm,-enable-cond-stores-vec", + "-Wl,-mllvm,-slp-vectorize-hor-store", + "-Wl,-mllvm,-enable-loopinterchange", + "-Wl,-mllvm,-enable-loop-distribute", + "-Wl,-mllvm,-enable-unroll-and-jam", + "-Wl,-mllvm,-enable-loop-flatten", + "-Wl,-mllvm,-interleave-small-loop-scalar-reduction", + "-Wl,-mllvm,-unroll-runtime-multi-exit", + "-Wl,-mllvm,-aggressive-ext-opt", + "-Wl,-mllvm,-enable-interleaved-mem-accesses", + "-Wl,-O3", + ] + if (is_android) { # TODO(jdduke) Re-enable on mips after resolving linking # issues with libc++ (crbug.com/456380). @@ -1944,10 +2119,7 @@ if (is_win) { } if (is_apple) { - if (symbol_level == 2) { - # Mac dead code stripping requires symbols. - common_optimize_on_ldflags += [ "-Wl,-dead_strip" ] - } + common_optimize_on_ldflags += [ "-Wl,-dead_strip" ] if (is_official_build) { common_optimize_on_ldflags += [ @@ -1955,20 +2127,22 @@ if (is_win) { "-Wl,-no_function_starts", ] } - } else if (current_os != "aix") { + } else if (current_os != "aix" && current_os != "zos") { # Non-Mac Posix flags. # Aix does not support these. common_optimize_on_cflags += [ - # Don't emit the GCC version ident directives, they just end up in the - # .comment section taking up binary size. - "-fno-ident", - # Put data and code in their own sections, so that unused symbols # can be removed at link time with --gc-sections. "-fdata-sections", "-ffunction-sections", + "-funique-section-names", ] + if ((!is_nacl || is_nacl_saigo) && is_clang) { + # We don't care about unique section names, this makes object files a bit + # smaller. + # common_optimize_on_cflags += [ "-fno-unique-section-names" ] + } common_optimize_on_ldflags += [ # Specifically tell the linker to perform optimizations. @@ -2012,18 +2186,23 @@ config("optimize") { if (chrome_pgo_phase != 2) { # Favor size over speed, /O1 must be before the common flags. # /O1 implies /Os and /GF. - cflags = [ "/O3" ] + common_optimize_on_cflags + [ "/Oi" ] + cflags = [ "/O2" ] + common_optimize_on_cflags + [ "/Oi" ] } else { # PGO requires all translation units to be compiled with /O2. The actual # optimization level will be decided based on the profiling data. - cflags = [ "/O3" ] + common_optimize_on_cflags + [ "/Oi" ] + cflags = [ "/O2" ] + common_optimize_on_cflags + [ "/Oi" ] } - } else if (optimize_for_size && !is_nacl) { + } else if (optimize_for_size) { # Favor size over speed. - # TODO(crbug.com/718650): Fix -Os in PNaCl compiler and remove the is_nacl - # guard above. if (is_clang) { cflags = [ "-O3" ] + common_optimize_on_cflags + + if (use_ml_inliner && is_a_target_toolchain) { + cflags += [ + "-mllvm", + "-enable-ml-inliner=release", + ] + } } else { cflags = [ "-O3" ] + common_optimize_on_cflags } @@ -2038,6 +2217,11 @@ config("optimize") { } else { cflags = [ "-O3" ] + common_optimize_on_cflags } + if (optimize_for_size) { + rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse2", ] + } else { + rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse2", ] + } ldflags = common_optimize_on_ldflags } @@ -2098,12 +2282,13 @@ config("optimize_max") { if (is_win) { # Favor speed over size, /O2 must be before the common flags. # /O2 implies /Ot, /Oi, and /GF. - cflags = [ "/O3" ] + common_optimize_on_cflags + cflags = [ "/O2", "-Xclang", "-O3", ] + common_optimize_on_cflags } else if (optimize_for_fuzzing) { cflags = [ "-O3" ] + common_optimize_on_cflags } else { cflags = [ "-O3" ] + common_optimize_on_cflags } + rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse2", ] } } @@ -2130,17 +2315,19 @@ config("optimize_speed") { if (is_win) { # Favor speed over size, /O2 must be before the common flags. # /O2 implies /Ot, /Oi, and /GF. - cflags = [ "/O3" ] + common_optimize_on_cflags + cflags = [ "/O2", "-Xclang", "-O3", ] + common_optimize_on_cflags } else if (optimize_for_fuzzing) { cflags = [ "-O3" ] + common_optimize_on_cflags } else { cflags = [ "-O3" ] + common_optimize_on_cflags } + rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse2", ] } } config("optimize_fuzzing") { cflags = [ "-O3" ] + common_optimize_on_cflags + rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse2", ] ldflags = common_optimize_on_ldflags visibility = [ ":default_optimization" ] } @@ -2175,21 +2362,15 @@ if (is_clang && is_a_target_toolchain) { } else if (clang_use_default_sample_profile) { assert(build_with_chromium, "Our default profiles currently only apply to Chromium") - assert( - is_android || chromeos_is_browser_only || is_chromeos || is_chromecast, - "The current platform has no default profile") - if (is_android || is_chromecast) { + assert(is_android || is_chromeos || is_castos, + "The current platform has no default profile") + if (is_android || is_castos) { _clang_sample_profile = "//chrome/android/profiles/afdo.prof" } else { - # TODO(crbug/1135245): Remove silvermont, airmont and broadwell after - # the change atom and bigcore reaches Chrome OS. - assert( - chromeos_afdo_platform == "silvermont" || - chromeos_afdo_platform == "airmont" || - chromeos_afdo_platform == "broadwell" || - chromeos_afdo_platform == "atom" || - chromeos_afdo_platform == "bigcore", - "Only silvermont, airmont and broadwell are valid Chrome OS profiles.") + assert(chromeos_afdo_platform == "atom" || + chromeos_afdo_platform == "bigcore" || + chromeos_afdo_platform == "arm", + "Only atom, bigcore and arm are valid Chrome OS profiles.") _clang_sample_profile = "//chromeos/profiles/${chromeos_afdo_platform}.afdo.prof" } @@ -2207,8 +2388,7 @@ config("afdo_optimize_size") { } # GCC and clang support a form of profile-guided optimization called AFDO. -# There are some targeted places that AFDO regresses (and an icky interaction -# between //base/allocator:tcmalloc and AFDO on GCC), so we provide a separate +# There are some targeted places that AFDO regresses, so we provide a separate # config to allow AFDO to be disabled per-target. config("afdo") { if (is_clang) { @@ -2256,14 +2436,11 @@ config("win_pdbaltpath") { # path to it in the executable file it generates. This flag turns that # absolute path into just the basename of the pdb file, which helps with # build reproducibility. Debuggers look for pdb files next to executables, - # so there's no downside to always using this. - ldflags = [ "/pdbaltpath:%_PDB%" ] - - if (enable_cet_shadow_stack && use_lld) { - # TODO(crbug.com/1136664): Investigate why Windows does not recognize - # CET in some binaries linked by LLD with /DEBUG. - # This is the best place for work around as it follows all /DEBUG uses. - ldflags += [ "/DEBUG:NONE" ] + # so there's minimal downside to always using this. However, post-mortem + # debugging of Chromium crash dumps and ETW tracing can be complicated by this + # switch so an option to omit it is important. + if (!use_full_pdb_paths) { + ldflags = [ "/pdbaltpath:%_PDB%" ] } } @@ -2285,16 +2462,6 @@ config("symbols") { # All configs using /DEBUG should include this: configs = [ ":win_pdbaltpath" ] - - if (is_clang) { - # Use constructor debug mode. This option reduces debug info more than - # -fno-standalone-debug by emitting class type information only when - # constructors are emitted. - cflags += [ - "-Xclang", - "-debug-info-kind=constructor", - ] - } } else { cflags = [] if (is_mac && enable_dsyms) { @@ -2304,11 +2471,18 @@ config("symbols") { # version 7 also produces debug data that is incompatible with Breakpad # dump_syms, so this is still required (https://crbug.com/622406). cflags += [ "-fno-standalone-debug" ] - } else if (is_mac) { - # clang defaults to DWARF2 on macOS unless mac_deployment_target is - # at least 10.11. - # TODO(thakis): Remove this once mac_deployment_target is 10.11. - cflags += [ "-gdwarf-4" ] + } + + # On aix -gdwarf causes linker failures due to thread_local variables. + if (!is_nacl && current_os != "aix") { + if (use_dwarf5) { + cflags += [ "-gdwarf-5" ] + } else if (!is_apple) { + # Recent clang versions default to DWARF5 on Linux, and Android is about + # to switch. TODO: Adopt that in controlled way. + # Apple platforms still default to 4, so the flag is not needed there. + cflags += [ "-gdwarf-4" ] + } } # The gcc-based nacl compilers don't support -fdebug-compilation-dir (see @@ -2317,16 +2491,18 @@ config("symbols") { # build-directory-independent output. pnacl and nacl-clang do support that # flag, so we can use use -g1 for pnacl and nacl-clang compiles. # gcc nacl is is_nacl && !is_clang, pnacl and nacl-clang are && is_clang. - if (!is_nacl || is_clang) { + if ((!is_nacl || is_clang) && current_os != "zos") { cflags += [ "-g2" ] } - # TODO(https://crbug.com/1050118): Investigate missing debug info on mac. - if (is_clang && !is_nacl && !use_xcode_clang && !is_apple) { - cflags += [ - "-Xclang", - "-debug-info-kind=constructor", - ] + if (!is_nacl && is_clang && !is_tsan && !is_asan) { + # gcc generates dwarf-aranges by default on -g1 and -g2. On clang it has + # to be manually enabled. + # + # It is skipped in tsan and asan because enabling it causes some + # formatting changes in the output which would require fixing bunches + # of expectation regexps. + cflags += [ "-gdwarf-aranges" ] } if (is_apple) { @@ -2339,8 +2515,9 @@ config("symbols") { asmflags = cflags ldflags = [] - # TODO(agrieve): Not sure why this is Android-specific. - if (use_debug_fission && use_thin_lto && is_android) { + # Split debug info with all thinlto builds except nacl and apple. + # thinlto requires -gsplit-dwarf in ldflags. + if (use_debug_fission && use_thin_lto && !is_nacl && !is_apple) { ldflags += [ "-gsplit-dwarf" ] } @@ -2349,8 +2526,14 @@ config("symbols") { # obj/native_client/src/trusted/service_runtime/sel_asm/nacl_switch_32.o: # DWARF info may be corrupt; offsets in a range list entry are in different # sections" there. Maybe just a bug in nacl_switch_32.S. - if (!is_apple && !is_nacl && current_cpu != "x86" && - (use_gold || use_lld)) { + _enable_gdb_index = + symbol_level == 2 && !is_apple && !is_nacl && current_cpu != "x86" && + current_os != "zos" && (use_gold || use_lld) && + # Disable on non-fission 32-bit Android because it pushes + # libcomponents_unittests over the 4gb size limit. + !(is_android && !use_debug_fission && current_cpu != "x64" && + current_cpu != "arm64") + if (_enable_gdb_index) { if (is_clang) { # This flag enables the GNU-format pubnames and pubtypes sections, # which lld needs in order to generate a correct GDB index. @@ -2361,6 +2544,34 @@ config("symbols") { ldflags += [ "-Wl,--gdb-index" ] } } + + configs = [] + + # Compress debug on 32-bit ARM to stay under 4GB for ChromeOS + # https://b/243982712. + if (symbol_level == 2 && is_chromeos_device && !use_debug_fission && + !is_nacl && current_cpu == "arm") { + configs += [ "//build/config:compress_debug_sections" ] + } + + if (is_clang && (!is_nacl || is_nacl_saigo) && current_os != "zos") { + if (is_apple) { + # TODO(https://crbug.com/1050118): Investigate missing debug info on mac. + # Make sure we don't use constructor homing on mac. + cflags += [ + "-Xclang", + "-debug-info-kind=limited", + ] + } else { + # Use constructor homing for debug info. This option reduces debug info + # by emitting class type info only when constructors are emitted. + cflags += [ + "-Xclang", + "-fuse-ctor-homing", + ] + } + } + rustflags = [ "-g", "-Copt-level=3", "-Ctarget-feature=+sse2", ] } # Minimal symbols. @@ -2370,7 +2581,13 @@ config("minimal_symbols") { if (is_win) { # Functions, files, and line tables only. cflags = [] - ldflags = [ "/DEBUG" ] + + if (is_clang && use_lld && use_ghash) { + cflags += [ "-gcodeview-ghash" ] + ldflags = [ "/DEBUG:GHASH" ] + } else { + ldflags = [ "/DEBUG" ] + } # All configs using /DEBUG should include this: configs = [ ":win_pdbaltpath" ] @@ -2383,11 +2600,20 @@ config("minimal_symbols") { } } else { cflags = [] - if (is_mac) { + if (is_mac && !use_dwarf5) { # clang defaults to DWARF2 on macOS unless mac_deployment_target is # at least 10.11. # TODO(thakis): Remove this once mac_deployment_target is 10.11. cflags += [ "-gdwarf-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" ] + } + + if (use_dwarf5 && !is_nacl) { + cflags += [ "-gdwarf-5" ] } # The gcc-based nacl compilers don't support -fdebug-compilation-dir (see @@ -2399,21 +2625,26 @@ config("minimal_symbols") { if (!is_nacl || is_clang) { cflags += [ "-g1" ] } + + if (!is_nacl && is_clang && !is_tsan && !is_asan) { + # See comment for -gdwarf-aranges in config("symbols"). + cflags += [ "-gdwarf-aranges" ] + } + ldflags = [] if (is_android && is_clang) { - # Android defaults to symbol_level=1 builds in production builds - # (https://crbug.com/648948), but clang, unlike gcc, doesn't emit - # DW_AT_linkage_name in -g1 builds. -fdebug-info-for-profiling enables - # that (and a bunch of other things we don't need), so that we get - # qualified names in stacks. + # Android defaults to symbol_level=1 builds, but clang, unlike gcc, + # doesn't emit DW_AT_linkage_name in -g1 builds. + # -fdebug-info-for-profiling enables that (and a bunch of other things we + # don't need), so that we get qualified names in stacks. # TODO(thakis): Consider making clang emit DW_AT_linkage_name in -g1 mode; # failing that consider doing this on non-Android too. cflags += [ "-fdebug-info-for-profiling" ] } - # Note: -gsplit-dwarf implicitly turns on -g2 with clang, so don't pass it. asmflags = cflags } + rustflags = [ "-Cdebuginfo=1", "-Copt-level=3", "-Ctarget-feature=+sse2", ] } # This configuration contains function names only. That is, the compiler is @@ -2421,7 +2652,7 @@ config("minimal_symbols") { # names in the final debug information. config("no_symbols") { if (is_win) { - ldflags = [ "/DEBUG" ] + ldflags = [ "/DEBUG:NONE" ] # All configs using /DEBUG should include this: configs = [ ":win_pdbaltpath" ] @@ -2466,7 +2697,7 @@ if (is_apple) { } } -if (is_chromeos && is_chromeos_device) { +if (is_chromeos_ash && is_chromeos_device) { # This config is intended to be a temporary to facilitate # the transition to use orderfile in Chrome OS. Once orderfile # use becomes a default in Chrome OS, this config should not @@ -2478,29 +2709,19 @@ if (is_chromeos && is_chromeos_device) { } } -if (is_win || is_android || (is_chromeos && is_chromeos_device)) { - # Use orderfile for linking Chrome on win, android, and Chrome OS. +if (is_android || (is_chromeos_ash && is_chromeos_device)) { + # Use orderfile for linking Chrome on Android and Chrome OS. # This config enables using an orderfile for linking in LLD. + # TODO: Consider using call graph sort instead, at least on Android. config("chrome_orderfile_config") { if (chrome_orderfile_path != "" && !enable_call_graph_profile_sort) { assert(use_lld) _rebased_orderfile = rebase_path(chrome_orderfile_path, root_build_dir) - if (is_android || (is_chromeos && is_chromeos_device)) { - ldflags = [ - "-Wl,--symbol-ordering-file", - "-Wl,$_rebased_orderfile", - "-Wl,--no-warn-symbol-ordering", - ] - } else { - ldflags = [ - "/order:@$_rebased_orderfile", - - # Ignore warnings about missing functions or functions not in their - # own section. - "/ignore:4037", - "/ignore:4065", - ] - } + ldflags = [ + "-Wl,--symbol-ordering-file", + "-Wl,$_rebased_orderfile", + "-Wl,--no-warn-symbol-ordering", + ] inputs = [ chrome_orderfile_path ] } } @@ -2517,7 +2738,10 @@ config("default_init_stack_vars") { buildflag_header("compiler_buildflags") { header = "compiler_buildflags.h" - flags = [ "CLANG_PGO=$chrome_pgo_phase" ] + flags = [ + "CLANG_PGO=$chrome_pgo_phase", + "SYMBOL_LEVEL=$symbol_level", + ] } config("cet_shadow_stack") {