update main build.gns

This commit is contained in:
Alexander Frick 2024-04-17 00:14:35 -05:00
parent 325d802c3f
commit cb9f493e07
7 changed files with 536 additions and 360 deletions

View file

@ -386,12 +386,7 @@ config("compiler") {
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
# The x86 toolchain currently has problems with stack-protector.
if (is_android && current_cpu == "x86") {
cflags += [ "-fno-stack-protector" ]
} else if (current_os != "aix") {
if (current_os != "aix") {
# Not available on aix.
cflags += [ "-fstack-protector" ]
}
@ -787,8 +782,6 @@ config("compiler") {
ldflags += [
"/opt:lldltojobs=all",
"-mllvm:-import-instr-limit=$import_instr_limit",
"-mllvm:-import-hot-multiplier=15",
"-mllvm:-import-cold-multiplier=2",
"-mllvm:-disable-auto-upgrade-debug-info",
]
} else {
@ -1062,9 +1055,14 @@ config("compiler") {
if (rust_abi_target != "") {
rustflags += [ "--target=$rust_abi_target" ]
}
if (!use_thin_lto) {
if (!use_thin_lto || !toolchain_supports_rust_thin_lto) {
# Don't include bitcode if it won't be used.
rustflags += [ "-Cembed-bitcode=no" ]
# Disable "automatic" ThinLTO between codegen units. The weak symbol
# resolution across units can have surprising effects on linking, see
# crbug.com/324126269 and github.com/rust-lang/rust/issues/120842.
rustflags += [ "-Clto=no" ]
}
if (is_official_build) {
rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", ]
@ -1113,8 +1111,8 @@ config("thinlto_optimize_default") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1151,8 +1149,8 @@ config("thinlto_optimize_max") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1194,11 +1192,11 @@ config("compiler_cpu_abi") {
"-msse4",
"-msse4.1",
"-msse4.2",
"-mavx",
"-maes",
"-mpclmul",
"-maes",
"-mavx",
]
ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-mssse3", "-msse4", "-msse4.1", "-msse4.2", "-mavx", "-maes", "-mpclmul", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2", ]
ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-mssse3", "-msse4", "-msse4.1", "-msse4.2", "-mpclmul", "-maes", "-mavx", "-Wl,-mllvm,-import-instr-limit=30", ]
} else if (current_cpu == "x86") {
cflags += [ "-m32" ]
ldflags += [ "-m32", "-Wl,-O3", "-msse3", ]
@ -1206,8 +1204,8 @@ config("compiler_cpu_abi") {
cflags += [
"-mfpmath=sse",
"-O3",
"-msse3",
"-mmmx",
"-msse3",
]
}
} else if (current_cpu == "arm") {
@ -1891,6 +1889,9 @@ config("default_warnings") {
cflags_cc += [
# TODO(https://crbug.com/1474434): fix and reenable
"-Wno-missing-field-initializers",
# TODO(https://crbug.com/324953188): fix and reenable
"-Wno-extra-qualification",
]
}
@ -1935,6 +1936,7 @@ config("default_warnings") {
cflags += [
"-Wno-error=unknown-warning-option",
"-Wno-error=unused-command-line-argument",
"-Wno-error=unknown-pragmas",
]
}
}
@ -1988,6 +1990,35 @@ config("prevent_unsafe_narrowing") {
}
}
# unsafe_buffer_warning -------------------------------------------------------
# Paths of third-party headers that violate Wunsafe-buffer-usage, but which we
# have been unable to fix yet. We use this list to be able to make progress and
# enable the warning on code that we do control/own.
#
# WARNING: This will disable all warnings in the files. ONLY USE THIS for
# third-party code which we do not control/own. Fix the warnings instead in
# our own code.
if (is_clang) {
unsafe_buffer_warning_header_allowlist =
[ "third_party/googletest/src/googletest/include/gtest" ]
}
# Enables warnings on pointer arithmetic/indexing or calls to functions
# annotated with `UNSAFE_BUFFER_USAGE`.
config("unsafe_buffer_warning") {
if (is_clang) {
cflags = [ "-Wunsafe-buffer-usage" ]
foreach(h, unsafe_buffer_warning_header_allowlist) {
if (is_win) {
cflags += [ "/clang:--system-header-prefix=$h" ]
} else {
cflags += [ "--system-header-prefix=$h" ]
}
}
}
}
# chromium_code ---------------------------------------------------------------
#
# Toggles between higher and lower warnings for code that is (or isn't)
@ -2330,7 +2361,11 @@ if (is_win) {
"-Xclang", "-O3",
]
common_optimize_on_ldflags += [ "-mllvm:-enable-interleaved-mem-accesses" ]
common_optimize_on_ldflags += [
"-mllvm:-enable-interleaved-mem-accesses",
"-mllvm:-aggressive-ext-opt",
"-mllvm:-enable-gvn-hoist",
]
if (use_polly == true) {
common_optimize_on_ldflags += [
@ -2372,6 +2407,9 @@ if (is_win) {
}
common_optimize_on_cflags += [
"-mllvm", "-enable-interleaved-mem-accesses",
"-mllvm", "-aggressive-ext-opt",
"-mllvm", "-enable-gvn-hoist",
"-O3",
]
@ -2383,6 +2421,9 @@ if (is_win) {
}
common_optimize_on_ldflags += [
"-Wl,-mllvm,-enable-interleaved-mem-accesses",
"-Wl,-mllvm,-aggressive-ext-opt",
"-Wl,-mllvm,-enable-gvn-hoist",
"-Wl,-O3",
]
@ -2537,32 +2578,22 @@ config("optimize") {
# to optimize for performance like `/O2` for clang.
rustflags = [ "-Copt-level=3" ]
}
} else if (optimize_for_size) {
} else if (optimize_for_size || is_chromeos) {
# Favor size over speed.
if (is_clang) {
cflags = [ "-O3" ] + common_optimize_on_cflags
# -Os in clang is more of a size-conscious -O2 than "size at any cost" (AKA -Oz).
if (use_ml_inliner && is_a_target_toolchain) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
if (is_fuchsia) {
cflags = [ "-O3" ] + common_optimize_on_cflags
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
# Like with `-Oz` on Clang, `-Copt-level=z` will also turn off loop
# vectorization.
rustflags = [ "-Copt-level=3" ]
} else if (is_chromeos) {
# TODO(gbiv): This is partially favoring size over speed. CrOS exclusively
# uses clang, and -Os in clang is more of a size-conscious -O2 than "size at
# any cost" (AKA -Oz). It'd be nice to:
# - Make `optimize_for_size` apply to all platforms where we're optimizing
# for size by default (so, also Windows)
# - Investigate -Oz here, maybe just for ARM?
cflags = [ "-O3" ] + common_optimize_on_cflags
if (is_clang && use_ml_inliner && is_a_target_toolchain && !is_chromeos) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
# Similar to clang, we optimize with `-Copt-level=s` to keep loop
# vectorization while otherwise optimizing for size.

View file

@ -383,12 +383,7 @@ config("compiler") {
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
# The x86 toolchain currently has problems with stack-protector.
if (is_android && current_cpu == "x86") {
cflags += [ "-fno-stack-protector" ]
} else if (current_os != "aix") {
if (current_os != "aix") {
# Not available on aix.
cflags += [ "-fstack-protector" ]
}
@ -507,10 +502,10 @@ config("compiler") {
# Linux/Android/Fuchsia common flags setup.
# ---------------------------------
if (is_linux || is_chromeos || is_android || is_fuchsia) {
asmflags += [ "-fPIC" ]
cflags += [ "-fPIC" ]
ldflags += [ "-fPIC" ]
rustflags += [ "-Crelocation-model=pic" ]
asmflags += [ "-fPIC", "-fno-emulated-tls", "-w", ]
cflags += [ "-fPIC","-fno-emulated-tls", "-w", ]
ldflags += [ "-fPIC", "-Wl,-plugin-opt=-emulated-tls=0", "-w", ]
rustflags += [ "-Crelocation-model=pic", "-Awarnings", ]
if (is_clang && chrome_pgo_phase == 2 && !is_android) {
asmflags += [ "-fbasic-block-sections=labels" ]
@ -784,8 +779,6 @@ config("compiler") {
ldflags += [
"/opt:lldltojobs=all",
"-mllvm:-import-instr-limit=$import_instr_limit",
"-mllvm:-import-hot-multiplier=15",
"-mllvm:-import-cold-multiplier=2",
"-mllvm:-disable-auto-upgrade-debug-info",
]
} else {
@ -1039,7 +1032,7 @@ config("compiler") {
"-Zremap-cwd-prefix=.",
# Full RUSTC optimizations.
"-Copt-level=3", "-Ctarget-feature=+aes,+avx,+avx2,+fma",
"-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+avx2,+fma,+f16c,+aes",
"-Cllvm-args=-fp-contract=fast",
]
@ -1052,12 +1045,17 @@ config("compiler") {
if (rust_abi_target != "") {
rustflags += [ "--target=$rust_abi_target" ]
}
if (!use_thin_lto) {
if (!use_thin_lto || !toolchain_supports_rust_thin_lto) {
# Don't include bitcode if it won't be used.
rustflags += [ "-Cembed-bitcode=no" ]
# Disable "automatic" ThinLTO between codegen units. The weak symbol
# resolution across units can have surprising effects on linking, see
# crbug.com/324126269 and github.com/rust-lang/rust/issues/120842.
rustflags += [ "-Clto=no" ]
}
if (is_official_build) {
rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+aes,+avx,+avx2,+fma", ]
rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+avx2,+fma,+f16c,+aes", ]
}
if (!rust_prebuilt_stdlib) {
# When building against the Chromium Rust stdlib (which we compile) always
@ -1103,8 +1101,8 @@ config("thinlto_optimize_default") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1141,8 +1139,8 @@ config("thinlto_optimize_max") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1181,6 +1179,7 @@ config("compiler_cpu_abi") {
"-O3",
"-msse3",
"-mssse3",
"-msse4",
"-msse4.1",
"-msse4.2",
"-mpclmul",
@ -1194,7 +1193,7 @@ config("compiler_cpu_abi") {
"-mtune=haswell",
"-ffp-contract=fast",
]
ldflags += [ "-m64", "-Wl,-O3", "-Wl,-mllvm,-march=haswell", "-Wl,-mllvm,-fp-contract=fast", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2", ]
ldflags += [ "-m64", "-Wl,-O3", "-Wl,-mllvm,-march=haswell", "-Wl,-mllvm,-fp-contract=fast", "-Wl,-mllvm,-import-instr-limit=30", ]
} else if (current_cpu == "x86") {
cflags += [ "-m32" ]
ldflags += [ "-m32", "-Wl,-O3", "-msse3", ]
@ -1202,20 +1201,20 @@ config("compiler_cpu_abi") {
cflags += [
"-mfpmath=sse",
"-O3",
"-msse3",
"-mmmx",
"-msse3",
]
}
} 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", ]
cflags += [ "-O3", ]
ldflags += [ "-Wl,-O3", ]
}
} else if (current_cpu == "arm") {
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", ]
cflags += [ "--target=arm-linux-gnueabihf", "-O3", ]
ldflags += [ "--target=arm-linux-gnueabihf", "-Wl,-O3", ]
}
if (!is_nacl) {
cflags += [
@ -1229,12 +1228,8 @@ config("compiler_cpu_abi") {
} else if (current_cpu == "arm64") {
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", ]
cflags += [ "--target=aarch64-linux-gnu", "-O3", ]
ldflags += [ "--target=aarch64-linux-gnu", "-Wl,-O3", ]
}
} else if (current_cpu == "mipsel" && !is_nacl) {
ldflags += [ "-Wl,--hash-style=sysv" ]
@ -1892,6 +1887,9 @@ config("default_warnings") {
cflags_cc += [
# TODO(https://crbug.com/1474434): fix and reenable
"-Wno-missing-field-initializers",
# TODO(https://crbug.com/324953188): fix and reenable
"-Wno-extra-qualification",
]
}
@ -1936,6 +1934,7 @@ config("default_warnings") {
cflags += [
"-Wno-error=unknown-warning-option",
"-Wno-error=unused-command-line-argument",
"-Wno-error=unknown-pragmas",
]
}
}
@ -1989,6 +1988,35 @@ config("prevent_unsafe_narrowing") {
}
}
# unsafe_buffer_warning -------------------------------------------------------
# Paths of third-party headers that violate Wunsafe-buffer-usage, but which we
# have been unable to fix yet. We use this list to be able to make progress and
# enable the warning on code that we do control/own.
#
# WARNING: This will disable all warnings in the files. ONLY USE THIS for
# third-party code which we do not control/own. Fix the warnings instead in
# our own code.
if (is_clang) {
unsafe_buffer_warning_header_allowlist =
[ "third_party/googletest/src/googletest/include/gtest" ]
}
# Enables warnings on pointer arithmetic/indexing or calls to functions
# annotated with `UNSAFE_BUFFER_USAGE`.
config("unsafe_buffer_warning") {
if (is_clang) {
cflags = [ "-Wunsafe-buffer-usage" ]
foreach(h, unsafe_buffer_warning_header_allowlist) {
if (is_win) {
cflags += [ "/clang:--system-header-prefix=$h" ]
} else {
cflags += [ "--system-header-prefix=$h" ]
}
}
}
}
# chromium_code ---------------------------------------------------------------
#
# Toggles between higher and lower warnings for code that is (or isn't)
@ -2528,7 +2556,7 @@ config("optimize") {
# Favor size over speed, /O1 must be before the common flags.
# /O1 implies /Os and /GF.
cflags = [ "/O2", "-Xclang", "-O3", ] + common_optimize_on_cflags
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx,+avx2,+fma" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+avx2,+fma,+f16c,+aes" ]
} else {
# PGO requires all translation units to be compiled with /O2. The actual
# optimization level will be decided based on the profiling data.
@ -2537,45 +2565,35 @@ config("optimize") {
# https://doc.rust-lang.org/rustc/profile-guided-optimization.html#usage
# suggests not using an explicit `-Copt-level` at all, and the default is
# to optimize for performance like `/O2` for clang.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx,+avx2,+fma" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+avx2,+fma,+f16c,+aes" ]
}
} else if (optimize_for_size) {
} else if (optimize_for_size || is_chromeos) {
# Favor size over speed.
if (is_clang) {
cflags = [ "-O3" ] + common_optimize_on_cflags
# -Os in clang is more of a size-conscious -O2 than "size at any cost" (AKA -Oz).
if (use_ml_inliner && is_a_target_toolchain) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
if (is_fuchsia) {
cflags = [ "-O3" ] + common_optimize_on_cflags
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
# Like with `-Oz` on Clang, `-Copt-level=z` will also turn off loop
# vectorization.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx,+avx2,+fma" ]
} else if (is_chromeos) {
# TODO(gbiv): This is partially favoring size over speed. CrOS exclusively
# uses clang, and -Os in clang is more of a size-conscious -O2 than "size at
# any cost" (AKA -Oz). It'd be nice to:
# - Make `optimize_for_size` apply to all platforms where we're optimizing
# for size by default (so, also Windows)
# - Investigate -Oz here, maybe just for ARM?
cflags = [ "-O3" ] + common_optimize_on_cflags
if (is_clang && use_ml_inliner && is_a_target_toolchain && !is_chromeos) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
# Similar to clang, we optimize with `-Copt-level=s` to keep loop
# vectorization while otherwise optimizing for size.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx,+avx2,+fma" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+avx2,+fma,+f16c,+aes" ]
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
# The `-O3` for clang turns on extra optimizations compared to the standard
# `-O2`. But for rust, `-Copt-level=3` is the default and is thus reliable
# to use.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx,+avx2,+fma" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+avx2,+fma,+f16c,+aes" ]
}
ldflags = common_optimize_on_ldflags
}
@ -2643,7 +2661,7 @@ config("optimize_max") {
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx,+avx2,+fma", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+avx2,+fma,+f16c,+aes", ]
}
}
@ -2676,13 +2694,13 @@ config("optimize_speed") {
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx,+avx2,+fma", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+avx2,+fma,+f16c,+aes", ]
}
}
config("optimize_fuzzing") {
cflags = [ "-O3" ] + common_optimize_on_cflags
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx,+avx2,+fma", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+avx2,+fma,+f16c,+aes", ]
ldflags = common_optimize_on_ldflags
visibility = [ ":default_optimization" ]
}
@ -3041,7 +3059,7 @@ config("minimal_symbols") {
asmflags = cflags
}
rustflags += [ "-Cdebuginfo=1", "-Copt-level=3", "-Ctarget-feature=+aes,+avx,+avx2,+fma", ]
rustflags += [ "-Cdebuginfo=1", "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+avx2,+fma,+f16c,+aes", ]
}
# This configuration contains function names only. That is, the compiler is

View file

@ -383,12 +383,7 @@ config("compiler") {
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
# The x86 toolchain currently has problems with stack-protector.
if (is_android && current_cpu == "x86") {
cflags += [ "-fno-stack-protector" ]
} else if (current_os != "aix") {
if (current_os != "aix") {
# Not available on aix.
cflags += [ "-fstack-protector" ]
}
@ -507,10 +502,10 @@ config("compiler") {
# Linux/Android/Fuchsia common flags setup.
# ---------------------------------
if (is_linux || is_chromeos || is_android || is_fuchsia) {
asmflags += [ "-fPIC" ]
cflags += [ "-fPIC" ]
ldflags += [ "-fPIC" ]
rustflags += [ "-Crelocation-model=pic" ]
asmflags += [ "-fPIC", "-fno-emulated-tls", "-w", ]
cflags += [ "-fPIC","-fno-emulated-tls", "-w", ]
ldflags += [ "-fPIC", "-Wl,-plugin-opt=-emulated-tls=0", "-w", ]
rustflags += [ "-Crelocation-model=pic", "-Awarnings", ]
if (is_clang && chrome_pgo_phase == 2 && !is_android) {
asmflags += [ "-fbasic-block-sections=labels" ]
@ -784,8 +779,6 @@ config("compiler") {
ldflags += [
"/opt:lldltojobs=all",
"-mllvm:-import-instr-limit=$import_instr_limit",
"-mllvm:-import-hot-multiplier=15",
"-mllvm:-import-cold-multiplier=2",
"-mllvm:-disable-auto-upgrade-debug-info",
]
} else {
@ -1039,7 +1032,7 @@ config("compiler") {
"-Zremap-cwd-prefix=.",
# Full RUSTC optimizations.
"-Copt-level=3", "-Ctarget-feature=+sse4.1",
"-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1",
]
if (!is_win || force_rustc_color_output) {
@ -1051,12 +1044,17 @@ config("compiler") {
if (rust_abi_target != "") {
rustflags += [ "--target=$rust_abi_target" ]
}
if (!use_thin_lto) {
if (!use_thin_lto || !toolchain_supports_rust_thin_lto) {
# Don't include bitcode if it won't be used.
rustflags += [ "-Cembed-bitcode=no" ]
# Disable "automatic" ThinLTO between codegen units. The weak symbol
# resolution across units can have surprising effects on linking, see
# crbug.com/324126269 and github.com/rust-lang/rust/issues/120842.
rustflags += [ "-Clto=no" ]
}
if (is_official_build) {
rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+sse4.1", ]
rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1", ]
}
if (!rust_prebuilt_stdlib) {
# When building against the Chromium Rust stdlib (which we compile) always
@ -1102,8 +1100,8 @@ config("thinlto_optimize_default") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1140,8 +1138,8 @@ config("thinlto_optimize_max") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1191,20 +1189,20 @@ config("compiler_cpu_abi") {
cflags += [
"-mfpmath=sse",
"-O3",
"-msse3",
"-mmmx",
"-msse3",
]
}
} 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", ]
cflags += [ "-O3", ]
ldflags += [ "-Wl,-O3", ]
}
} else if (current_cpu == "arm") {
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", ]
cflags += [ "--target=arm-linux-gnueabihf", "-O3", ]
ldflags += [ "--target=arm-linux-gnueabihf", "-Wl,-O3", ]
}
if (!is_nacl) {
cflags += [
@ -1218,12 +1216,8 @@ config("compiler_cpu_abi") {
} else if (current_cpu == "arm64") {
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", ]
cflags += [ "--target=aarch64-linux-gnu", "-O3", ]
ldflags += [ "--target=aarch64-linux-gnu", "-Wl,-O3", ]
}
} else if (current_cpu == "mipsel" && !is_nacl) {
ldflags += [ "-Wl,--hash-style=sysv" ]
@ -1881,6 +1875,9 @@ config("default_warnings") {
cflags_cc += [
# TODO(https://crbug.com/1474434): fix and reenable
"-Wno-missing-field-initializers",
# TODO(https://crbug.com/324953188): fix and reenable
"-Wno-extra-qualification",
]
}
@ -1925,6 +1922,7 @@ config("default_warnings") {
cflags += [
"-Wno-error=unknown-warning-option",
"-Wno-error=unused-command-line-argument",
"-Wno-error=unknown-pragmas",
]
}
}
@ -1978,6 +1976,35 @@ config("prevent_unsafe_narrowing") {
}
}
# unsafe_buffer_warning -------------------------------------------------------
# Paths of third-party headers that violate Wunsafe-buffer-usage, but which we
# have been unable to fix yet. We use this list to be able to make progress and
# enable the warning on code that we do control/own.
#
# WARNING: This will disable all warnings in the files. ONLY USE THIS for
# third-party code which we do not control/own. Fix the warnings instead in
# our own code.
if (is_clang) {
unsafe_buffer_warning_header_allowlist =
[ "third_party/googletest/src/googletest/include/gtest" ]
}
# Enables warnings on pointer arithmetic/indexing or calls to functions
# annotated with `UNSAFE_BUFFER_USAGE`.
config("unsafe_buffer_warning") {
if (is_clang) {
cflags = [ "-Wunsafe-buffer-usage" ]
foreach(h, unsafe_buffer_warning_header_allowlist) {
if (is_win) {
cflags += [ "/clang:--system-header-prefix=$h" ]
} else {
cflags += [ "--system-header-prefix=$h" ]
}
}
}
}
# chromium_code ---------------------------------------------------------------
#
# Toggles between higher and lower warnings for code that is (or isn't)
@ -2317,7 +2344,6 @@ if (is_win) {
"/clang:-O3",
"/clang:-msse3",
"/clang:-mssse3",
"/clang:-msse4",
"/clang:-msse4.1",
"-Xclang", "-O3",
]
@ -2365,7 +2391,7 @@ if (is_win) {
common_optimize_on_ldflags += [
"-Wl,-mllvm,-aggressive-ext-opt",
"-Wl,-mllvm,-enable-gvn-hoist",
"-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2",
"-Wl,-mllvm,-import-instr-limit=30",
"-Wl,-O3",
]
@ -2434,6 +2460,48 @@ if (is_win) {
common_optimize_on_cflags += [ "-fno-math-errno" ]
}
config("march_crc") {
if (!is_win || is_clang) {
cflags = [ "-march=armv8-a+crc" ]
asmflags = cflags
}
}
config("march_dotprod") {
if (!is_win || is_clang) {
cflags = [ "-march=armv8.2-a+dotprod" ]
asmflags = cflags
}
}
config("march_fp16") {
if (!is_win || is_clang) {
cflags = [ "-march=armv8.2-a+fp16" ]
asmflags = cflags
}
}
config("march_dotprod_fp16") {
if (!is_win || is_clang) {
cflags = [ "-march=armv8.2-a+fp16+dotprod" ]
asmflags = cflags
}
}
config("march_i8mm") {
if (!is_win || is_clang) {
cflags = [ "-march=armv8.2-a+i8mm" ]
asmflags = cflags
}
}
config("march_i8mm_f16") {
if (!is_win || is_clang) {
cflags = [ "-march=armv8.2-a+i8mm+fp16" ]
asmflags = cflags
}
}
config("default_stack_frames") {
if (!is_win) {
if (enable_frame_pointers) {
@ -2466,55 +2534,45 @@ config("optimize") {
if (chrome_pgo_phase != 2) {
# Favor size over speed, /O1 must be before the common flags.
# /O1 implies /Os and /GF.
cflags = [ "/O2", "-Xclang", "-O3", ] + common_optimize_on_cflags + [ "/Oi" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1" ]
cflags = [ "/O2", "-Xclang", "-O3", ] + common_optimize_on_cflags
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1" ]
} else {
# PGO requires all translation units to be compiled with /O2. The actual
# optimization level will be decided based on the profiling data.
cflags = [ "/O2", "-Xclang", "-O3", ] + common_optimize_on_cflags + [ "/Oi" ]
cflags = [ "/O2", "-Xclang", "-O3", ] + common_optimize_on_cflags
# https://doc.rust-lang.org/rustc/profile-guided-optimization.html#usage
# suggests not using an explicit `-Copt-level` at all, and the default is
# to optimize for performance like `/O2` for clang.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1" ]
}
} else if (optimize_for_size) {
} else if (optimize_for_size || is_chromeos) {
# Favor size over speed.
if (is_clang) {
cflags = [ "-O3" ] + common_optimize_on_cflags
# -Os in clang is more of a size-conscious -O2 than "size at any cost" (AKA -Oz).
if (use_ml_inliner && is_a_target_toolchain) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
if (is_fuchsia) {
cflags = [ "-O3" ] + common_optimize_on_cflags
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
# Like with `-Oz` on Clang, `-Copt-level=z` will also turn off loop
# vectorization.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1" ]
} else if (is_chromeos) {
# TODO(gbiv): This is partially favoring size over speed. CrOS exclusively
# uses clang, and -Os in clang is more of a size-conscious -O2 than "size at
# any cost" (AKA -Oz). It'd be nice to:
# - Make `optimize_for_size` apply to all platforms where we're optimizing
# for size by default (so, also Windows)
# - Investigate -Oz here, maybe just for ARM?
cflags = [ "-O3" ] + common_optimize_on_cflags
if (is_clang && use_ml_inliner && is_a_target_toolchain && !is_chromeos) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
# Similar to clang, we optimize with `-Copt-level=s` to keep loop
# vectorization while otherwise optimizing for size.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1" ]
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
# The `-O3` for clang turns on extra optimizations compared to the standard
# `-O2`. But for rust, `-Copt-level=3` is the default and is thus reliable
# to use.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1" ]
}
ldflags = common_optimize_on_ldflags
}
@ -2582,7 +2640,7 @@ config("optimize_max") {
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1", ]
}
}
@ -2615,13 +2673,13 @@ config("optimize_speed") {
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1", ]
}
}
config("optimize_fuzzing") {
cflags = [ "-O3" ] + common_optimize_on_cflags
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1", ]
ldflags = common_optimize_on_ldflags
visibility = [ ":default_optimization" ]
}
@ -2980,7 +3038,7 @@ config("minimal_symbols") {
asmflags = cflags
}
rustflags += [ "-Cdebuginfo=1", "-Copt-level=3", "-Ctarget-feature=+sse4.1", ]
rustflags += [ "-Cdebuginfo=1", "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1", ]
}
# This configuration contains function names only. That is, the compiler is

View file

@ -383,12 +383,7 @@ config("compiler") {
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
# The x86 toolchain currently has problems with stack-protector.
if (is_android && current_cpu == "x86") {
cflags += [ "-fno-stack-protector" ]
} else if (current_os != "aix") {
if (current_os != "aix") {
# Not available on aix.
cflags += [ "-fstack-protector" ]
}
@ -507,10 +502,10 @@ config("compiler") {
# Linux/Android/Fuchsia common flags setup.
# ---------------------------------
if (is_linux || is_chromeos || is_android || is_fuchsia) {
asmflags += [ "-fPIC" ]
cflags += [ "-fPIC" ]
ldflags += [ "-fPIC" ]
rustflags += [ "-Crelocation-model=pic" ]
asmflags += [ "-fPIC", "-fno-emulated-tls", "-w", ]
cflags += [ "-fPIC","-fno-emulated-tls", "-w", ]
ldflags += [ "-fPIC", "-Wl,-plugin-opt=-emulated-tls=0", "-w", ]
rustflags += [ "-Crelocation-model=pic", "-Awarnings", ]
if (is_clang && chrome_pgo_phase == 2 && !is_android) {
asmflags += [ "-fbasic-block-sections=labels" ]
@ -784,8 +779,6 @@ config("compiler") {
ldflags += [
"/opt:lldltojobs=all",
"-mllvm:-import-instr-limit=$import_instr_limit",
"-mllvm:-import-hot-multiplier=15",
"-mllvm:-import-cold-multiplier=2",
"-mllvm:-disable-auto-upgrade-debug-info",
]
} else {
@ -1051,9 +1044,14 @@ config("compiler") {
if (rust_abi_target != "") {
rustflags += [ "--target=$rust_abi_target" ]
}
if (!use_thin_lto) {
if (!use_thin_lto || !toolchain_supports_rust_thin_lto) {
# Don't include bitcode if it won't be used.
rustflags += [ "-Cembed-bitcode=no" ]
# Disable "automatic" ThinLTO between codegen units. The weak symbol
# resolution across units can have surprising effects on linking, see
# crbug.com/324126269 and github.com/rust-lang/rust/issues/120842.
rustflags += [ "-Clto=no" ]
}
if (is_official_build) {
rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+sse2", ]
@ -1102,8 +1100,8 @@ config("thinlto_optimize_default") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1140,8 +1138,8 @@ config("thinlto_optimize_max") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1183,7 +1181,7 @@ config("compiler_cpu_abi") {
"-msse",
"-msse2",
]
ldflags += [ "-m64", "-Wl,-O3", "-mmmx", "-mfxsr", "-msse", "-msse2", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2", ]
ldflags += [ "-m64", "-Wl,-O3", "-mmmx", "-mfxsr", "-msse", "-msse2", "-Wl,-mllvm,-import-instr-limit=30", ]
} else if (current_cpu == "x86") {
cflags += [ "-m32" ]
ldflags += [ "-m32", "-Wl,-O3", "-mmmx", "-mfxsr", "-msse", "-msse2", ]
@ -1199,14 +1197,14 @@ config("compiler_cpu_abi") {
}
} 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", ]
cflags += [ "-O3", ]
ldflags += [ "-Wl,-O3", ]
}
} else if (current_cpu == "arm") {
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", ]
cflags += [ "--target=arm-linux-gnueabihf", "-O3", ]
ldflags += [ "--target=arm-linux-gnueabihf", "-Wl,-O3", ]
}
if (!is_nacl) {
cflags += [
@ -1220,12 +1218,8 @@ config("compiler_cpu_abi") {
} else if (current_cpu == "arm64") {
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", ]
cflags += [ "--target=aarch64-linux-gnu", "-O3", ]
ldflags += [ "--target=aarch64-linux-gnu", "-Wl,-O3", ]
}
} else if (current_cpu == "mipsel" && !is_nacl) {
ldflags += [ "-Wl,--hash-style=sysv" ]
@ -1883,6 +1877,9 @@ config("default_warnings") {
cflags_cc += [
# TODO(https://crbug.com/1474434): fix and reenable
"-Wno-missing-field-initializers",
# TODO(https://crbug.com/324953188): fix and reenable
"-Wno-extra-qualification",
]
}
@ -1927,6 +1924,7 @@ config("default_warnings") {
cflags += [
"-Wno-error=unknown-warning-option",
"-Wno-error=unused-command-line-argument",
"-Wno-error=unknown-pragmas",
]
}
}
@ -1980,6 +1978,35 @@ config("prevent_unsafe_narrowing") {
}
}
# unsafe_buffer_warning -------------------------------------------------------
# Paths of third-party headers that violate Wunsafe-buffer-usage, but which we
# have been unable to fix yet. We use this list to be able to make progress and
# enable the warning on code that we do control/own.
#
# WARNING: This will disable all warnings in the files. ONLY USE THIS for
# third-party code which we do not control/own. Fix the warnings instead in
# our own code.
if (is_clang) {
unsafe_buffer_warning_header_allowlist =
[ "third_party/googletest/src/googletest/include/gtest" ]
}
# Enables warnings on pointer arithmetic/indexing or calls to functions
# annotated with `UNSAFE_BUFFER_USAGE`.
config("unsafe_buffer_warning") {
if (is_clang) {
cflags = [ "-Wunsafe-buffer-usage" ]
foreach(h, unsafe_buffer_warning_header_allowlist) {
if (is_win) {
cflags += [ "/clang:--system-header-prefix=$h" ]
} else {
cflags += [ "--system-header-prefix=$h" ]
}
}
}
}
# chromium_code ---------------------------------------------------------------
#
# Toggles between higher and lower warnings for code that is (or isn't)
@ -2479,32 +2506,22 @@ config("optimize") {
# to optimize for performance like `/O2` for clang.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse2" ]
}
} else if (optimize_for_size) {
} else if (optimize_for_size || is_chromeos) {
# Favor size over speed.
if (is_clang) {
cflags = [ "-O3" ] + common_optimize_on_cflags
# -Os in clang is more of a size-conscious -O2 than "size at any cost" (AKA -Oz).
if (use_ml_inliner && is_a_target_toolchain) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
if (is_fuchsia) {
cflags = [ "-O3" ] + common_optimize_on_cflags
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
# Like with `-Oz` on Clang, `-Copt-level=z` will also turn off loop
# vectorization.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse2" ]
} else if (is_chromeos) {
# TODO(gbiv): This is partially favoring size over speed. CrOS exclusively
# uses clang, and -Os in clang is more of a size-conscious -O2 than "size at
# any cost" (AKA -Oz). It'd be nice to:
# - Make `optimize_for_size` apply to all platforms where we're optimizing
# for size by default (so, also Windows)
# - Investigate -Oz here, maybe just for ARM?
cflags = [ "-O3" ] + common_optimize_on_cflags
if (is_clang && use_ml_inliner && is_a_target_toolchain && !is_chromeos) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
# Similar to clang, we optimize with `-Copt-level=s` to keep loop
# vectorization while otherwise optimizing for size.

View file

@ -383,12 +383,7 @@ config("compiler") {
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
# The x86 toolchain currently has problems with stack-protector.
if (is_android && current_cpu == "x86") {
cflags += [ "-fno-stack-protector" ]
} else if (current_os != "aix") {
if (current_os != "aix") {
# Not available on aix.
cflags += [ "-fstack-protector" ]
}
@ -507,10 +502,10 @@ config("compiler") {
# Linux/Android/Fuchsia common flags setup.
# ---------------------------------
if (is_linux || is_chromeos || is_android || is_fuchsia) {
asmflags += [ "-fPIC" ]
cflags += [ "-fPIC" ]
ldflags += [ "-fPIC" ]
rustflags += [ "-Crelocation-model=pic" ]
asmflags += [ "-fPIC", "-fno-emulated-tls", "-w", ]
cflags += [ "-fPIC","-fno-emulated-tls", "-w", ]
ldflags += [ "-fPIC", "-Wl,-plugin-opt=-emulated-tls=0", "-w", ]
rustflags += [ "-Crelocation-model=pic", "-Awarnings", ]
if (is_clang && chrome_pgo_phase == 2 && !is_android) {
asmflags += [ "-fbasic-block-sections=labels" ]
@ -784,8 +779,6 @@ config("compiler") {
ldflags += [
"/opt:lldltojobs=all",
"-mllvm:-import-instr-limit=$import_instr_limit",
"-mllvm:-import-hot-multiplier=15",
"-mllvm:-import-cold-multiplier=2",
"-mllvm:-disable-auto-upgrade-debug-info",
]
} else {
@ -1051,9 +1044,14 @@ config("compiler") {
if (rust_abi_target != "") {
rustflags += [ "--target=$rust_abi_target" ]
}
if (!use_thin_lto) {
if (!use_thin_lto || !toolchain_supports_rust_thin_lto) {
# Don't include bitcode if it won't be used.
rustflags += [ "-Cembed-bitcode=no" ]
# Disable "automatic" ThinLTO between codegen units. The weak symbol
# resolution across units can have surprising effects on linking, see
# crbug.com/324126269 and github.com/rust-lang/rust/issues/120842.
rustflags += [ "-Clto=no" ]
}
if (is_official_build) {
rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+sse3", ]
@ -1102,8 +1100,8 @@ config("thinlto_optimize_default") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1140,8 +1138,8 @@ config("thinlto_optimize_max") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1180,7 +1178,7 @@ config("compiler_cpu_abi") {
"-O3",
"-msse3",
]
ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2", ]
ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-Wl,-mllvm,-import-instr-limit=30", ]
} else if (current_cpu == "x86") {
cflags += [ "-m32" ]
ldflags += [ "-m32", "-Wl,-O3", "-msse3", ]
@ -1188,20 +1186,20 @@ config("compiler_cpu_abi") {
cflags += [
"-mfpmath=sse",
"-O3",
"-msse3",
"-mmmx",
"-msse3",
]
}
} 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", ]
cflags += [ "-O3", ]
ldflags += [ "-Wl,-O3", ]
}
} else if (current_cpu == "arm") {
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", ]
cflags += [ "--target=arm-linux-gnueabihf", "-O3", ]
ldflags += [ "--target=arm-linux-gnueabihf", "-Wl,-O3", ]
}
if (!is_nacl) {
cflags += [
@ -1215,12 +1213,8 @@ config("compiler_cpu_abi") {
} else if (current_cpu == "arm64") {
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", ]
cflags += [ "--target=aarch64-linux-gnu", "-O3", ]
ldflags += [ "--target=aarch64-linux-gnu", "-Wl,-O3", ]
}
} else if (current_cpu == "mipsel" && !is_nacl) {
ldflags += [ "-Wl,--hash-style=sysv" ]
@ -1878,6 +1872,9 @@ config("default_warnings") {
cflags_cc += [
# TODO(https://crbug.com/1474434): fix and reenable
"-Wno-missing-field-initializers",
# TODO(https://crbug.com/324953188): fix and reenable
"-Wno-extra-qualification",
]
}
@ -1922,6 +1919,7 @@ config("default_warnings") {
cflags += [
"-Wno-error=unknown-warning-option",
"-Wno-error=unused-command-line-argument",
"-Wno-error=unknown-pragmas",
]
}
}
@ -1975,6 +1973,35 @@ config("prevent_unsafe_narrowing") {
}
}
# unsafe_buffer_warning -------------------------------------------------------
# Paths of third-party headers that violate Wunsafe-buffer-usage, but which we
# have been unable to fix yet. We use this list to be able to make progress and
# enable the warning on code that we do control/own.
#
# WARNING: This will disable all warnings in the files. ONLY USE THIS for
# third-party code which we do not control/own. Fix the warnings instead in
# our own code.
if (is_clang) {
unsafe_buffer_warning_header_allowlist =
[ "third_party/googletest/src/googletest/include/gtest" ]
}
# Enables warnings on pointer arithmetic/indexing or calls to functions
# annotated with `UNSAFE_BUFFER_USAGE`.
config("unsafe_buffer_warning") {
if (is_clang) {
cflags = [ "-Wunsafe-buffer-usage" ]
foreach(h, unsafe_buffer_warning_header_allowlist) {
if (is_win) {
cflags += [ "/clang:--system-header-prefix=$h" ]
} else {
cflags += [ "--system-header-prefix=$h" ]
}
}
}
}
# chromium_code ---------------------------------------------------------------
#
# Toggles between higher and lower warnings for code that is (or isn't)
@ -2471,32 +2498,22 @@ config("optimize") {
# to optimize for performance like `/O2` for clang.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3" ]
}
} else if (optimize_for_size) {
} else if (optimize_for_size || is_chromeos) {
# Favor size over speed.
if (is_clang) {
cflags = [ "-O3" ] + common_optimize_on_cflags
# -Os in clang is more of a size-conscious -O2 than "size at any cost" (AKA -Oz).
if (use_ml_inliner && is_a_target_toolchain) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
if (is_fuchsia) {
cflags = [ "-O3" ] + common_optimize_on_cflags
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
# Like with `-Oz` on Clang, `-Copt-level=z` will also turn off loop
# vectorization.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3" ]
} else if (is_chromeos) {
# TODO(gbiv): This is partially favoring size over speed. CrOS exclusively
# uses clang, and -Os in clang is more of a size-conscious -O2 than "size at
# any cost" (AKA -Oz). It'd be nice to:
# - Make `optimize_for_size` apply to all platforms where we're optimizing
# for size by default (so, also Windows)
# - Investigate -Oz here, maybe just for ARM?
cflags = [ "-O3" ] + common_optimize_on_cflags
if (is_clang && use_ml_inliner && is_a_target_toolchain && !is_chromeos) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
# Similar to clang, we optimize with `-Copt-level=s` to keep loop
# vectorization while otherwise optimizing for size.

View file

@ -383,12 +383,7 @@ config("compiler") {
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
# The x86 toolchain currently has problems with stack-protector.
if (is_android && current_cpu == "x86") {
cflags += [ "-fno-stack-protector" ]
} else if (current_os != "aix") {
if (current_os != "aix") {
# Not available on aix.
cflags += [ "-fstack-protector" ]
}
@ -507,10 +502,10 @@ config("compiler") {
# Linux/Android/Fuchsia common flags setup.
# ---------------------------------
if (is_linux || is_chromeos || is_android || is_fuchsia) {
asmflags += [ "-fPIC" ]
cflags += [ "-fPIC" ]
ldflags += [ "-fPIC" ]
rustflags += [ "-Crelocation-model=pic" ]
asmflags += [ "-fPIC", "-fno-emulated-tls", "-w", ]
cflags += [ "-fPIC","-fno-emulated-tls", "-w", ]
ldflags += [ "-fPIC", "-Wl,-plugin-opt=-emulated-tls=0", "-w", ]
rustflags += [ "-Crelocation-model=pic", "-Awarnings", ]
if (is_clang && chrome_pgo_phase == 2 && !is_android) {
asmflags += [ "-fbasic-block-sections=labels" ]
@ -784,8 +779,6 @@ config("compiler") {
ldflags += [
"/opt:lldltojobs=all",
"-mllvm:-import-instr-limit=$import_instr_limit",
"-mllvm:-import-hot-multiplier=15",
"-mllvm:-import-cold-multiplier=2",
"-mllvm:-disable-auto-upgrade-debug-info",
]
} else {
@ -1039,7 +1032,7 @@ config("compiler") {
"-Zremap-cwd-prefix=.",
# Full RUSTC optimizations.
"-Copt-level=3", "-Ctarget-feature=+sse4.1",
"-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1",
]
if (!is_win || force_rustc_color_output) {
@ -1051,12 +1044,17 @@ config("compiler") {
if (rust_abi_target != "") {
rustflags += [ "--target=$rust_abi_target" ]
}
if (!use_thin_lto) {
if (!use_thin_lto || !toolchain_supports_rust_thin_lto) {
# Don't include bitcode if it won't be used.
rustflags += [ "-Cembed-bitcode=no" ]
# Disable "automatic" ThinLTO between codegen units. The weak symbol
# resolution across units can have surprising effects on linking, see
# crbug.com/324126269 and github.com/rust-lang/rust/issues/120842.
rustflags += [ "-Clto=no" ]
}
if (is_official_build) {
rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+sse4.1", ]
rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1", ]
}
if (!rust_prebuilt_stdlib) {
# When building against the Chromium Rust stdlib (which we compile) always
@ -1102,8 +1100,8 @@ config("thinlto_optimize_default") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1140,8 +1138,8 @@ config("thinlto_optimize_max") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1180,9 +1178,10 @@ config("compiler_cpu_abi") {
"-O3",
"-msse3",
"-mssse3",
"-msse4",
"-msse4.1",
]
ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-mssse3", "-msse4.1", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2", ]
ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-mssse3", "-msse4", "-msse4.1", "-Wl,-mllvm,-import-instr-limit=30", ]
} else if (current_cpu == "x86") {
cflags += [ "-m32" ]
ldflags += [ "-m32", "-Wl,-O3", "-msse3", ]
@ -1190,20 +1189,20 @@ config("compiler_cpu_abi") {
cflags += [
"-mfpmath=sse",
"-O3",
"-msse3",
"-mmmx",
"-msse3",
]
}
} 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", ]
cflags += [ "-O3", ]
ldflags += [ "-Wl,-O3", ]
}
} else if (current_cpu == "arm") {
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", ]
cflags += [ "--target=arm-linux-gnueabihf", "-O3", ]
ldflags += [ "--target=arm-linux-gnueabihf", "-Wl,-O3", ]
}
if (!is_nacl) {
cflags += [
@ -1217,12 +1216,8 @@ config("compiler_cpu_abi") {
} else if (current_cpu == "arm64") {
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", ]
cflags += [ "--target=aarch64-linux-gnu", "-O3", ]
ldflags += [ "--target=aarch64-linux-gnu", "-Wl,-O3", ]
}
} else if (current_cpu == "mipsel" && !is_nacl) {
ldflags += [ "-Wl,--hash-style=sysv" ]
@ -1880,6 +1875,9 @@ config("default_warnings") {
cflags_cc += [
# TODO(https://crbug.com/1474434): fix and reenable
"-Wno-missing-field-initializers",
# TODO(https://crbug.com/324953188): fix and reenable
"-Wno-extra-qualification",
]
}
@ -1924,6 +1922,7 @@ config("default_warnings") {
cflags += [
"-Wno-error=unknown-warning-option",
"-Wno-error=unused-command-line-argument",
"-Wno-error=unknown-pragmas",
]
}
}
@ -1977,6 +1976,35 @@ config("prevent_unsafe_narrowing") {
}
}
# unsafe_buffer_warning -------------------------------------------------------
# Paths of third-party headers that violate Wunsafe-buffer-usage, but which we
# have been unable to fix yet. We use this list to be able to make progress and
# enable the warning on code that we do control/own.
#
# WARNING: This will disable all warnings in the files. ONLY USE THIS for
# third-party code which we do not control/own. Fix the warnings instead in
# our own code.
if (is_clang) {
unsafe_buffer_warning_header_allowlist =
[ "third_party/googletest/src/googletest/include/gtest" ]
}
# Enables warnings on pointer arithmetic/indexing or calls to functions
# annotated with `UNSAFE_BUFFER_USAGE`.
config("unsafe_buffer_warning") {
if (is_clang) {
cflags = [ "-Wunsafe-buffer-usage" ]
foreach(h, unsafe_buffer_warning_header_allowlist) {
if (is_win) {
cflags += [ "/clang:--system-header-prefix=$h" ]
} else {
cflags += [ "--system-header-prefix=$h" ]
}
}
}
}
# chromium_code ---------------------------------------------------------------
#
# Toggles between higher and lower warnings for code that is (or isn't)
@ -2464,7 +2492,7 @@ config("optimize") {
# Favor size over speed, /O1 must be before the common flags.
# /O1 implies /Os and /GF.
cflags = [ "/O2", "-Xclang", "-O3", ] + common_optimize_on_cflags
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1" ]
} else {
# PGO requires all translation units to be compiled with /O2. The actual
# optimization level will be decided based on the profiling data.
@ -2473,45 +2501,35 @@ config("optimize") {
# https://doc.rust-lang.org/rustc/profile-guided-optimization.html#usage
# suggests not using an explicit `-Copt-level` at all, and the default is
# to optimize for performance like `/O2` for clang.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1" ]
}
} else if (optimize_for_size) {
} else if (optimize_for_size || is_chromeos) {
# Favor size over speed.
if (is_clang) {
cflags = [ "-O3" ] + common_optimize_on_cflags
# -Os in clang is more of a size-conscious -O2 than "size at any cost" (AKA -Oz).
if (use_ml_inliner && is_a_target_toolchain) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
if (is_fuchsia) {
cflags = [ "-O3" ] + common_optimize_on_cflags
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
# Like with `-Oz` on Clang, `-Copt-level=z` will also turn off loop
# vectorization.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1" ]
} else if (is_chromeos) {
# TODO(gbiv): This is partially favoring size over speed. CrOS exclusively
# uses clang, and -Os in clang is more of a size-conscious -O2 than "size at
# any cost" (AKA -Oz). It'd be nice to:
# - Make `optimize_for_size` apply to all platforms where we're optimizing
# for size by default (so, also Windows)
# - Investigate -Oz here, maybe just for ARM?
cflags = [ "-O3" ] + common_optimize_on_cflags
if (is_clang && use_ml_inliner && is_a_target_toolchain && !is_chromeos) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
# Similar to clang, we optimize with `-Copt-level=s` to keep loop
# vectorization while otherwise optimizing for size.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1" ]
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
# The `-O3` for clang turns on extra optimizations compared to the standard
# `-O2`. But for rust, `-Copt-level=3` is the default and is thus reliable
# to use.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1" ]
}
ldflags = common_optimize_on_ldflags
}
@ -2579,7 +2597,7 @@ config("optimize_max") {
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1", ]
}
}
@ -2612,13 +2630,13 @@ config("optimize_speed") {
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1", ]
}
}
config("optimize_fuzzing") {
cflags = [ "-O3" ] + common_optimize_on_cflags
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse4.1", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1", ]
ldflags = common_optimize_on_ldflags
visibility = [ ":default_optimization" ]
}
@ -2977,7 +2995,7 @@ config("minimal_symbols") {
asmflags = cflags
}
rustflags += [ "-Cdebuginfo=1", "-Copt-level=3", "-Ctarget-feature=+sse4.1", ]
rustflags += [ "-Cdebuginfo=1", "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1", ]
}
# This configuration contains function names only. That is, the compiler is

View file

@ -383,12 +383,7 @@ config("compiler") {
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
# The x86 toolchain currently has problems with stack-protector.
if (is_android && current_cpu == "x86") {
cflags += [ "-fno-stack-protector" ]
} else if (current_os != "aix") {
if (current_os != "aix") {
# Not available on aix.
cflags += [ "-fstack-protector" ]
}
@ -507,10 +502,10 @@ config("compiler") {
# Linux/Android/Fuchsia common flags setup.
# ---------------------------------
if (is_linux || is_chromeos || is_android || is_fuchsia) {
asmflags += [ "-fPIC" ]
cflags += [ "-fPIC" ]
ldflags += [ "-fPIC" ]
rustflags += [ "-Crelocation-model=pic" ]
asmflags += [ "-fPIC", "-fno-emulated-tls", "-w", ]
cflags += [ "-fPIC","-fno-emulated-tls", "-w", ]
ldflags += [ "-fPIC", "-Wl,-plugin-opt=-emulated-tls=0", "-w", ]
rustflags += [ "-Crelocation-model=pic", "-Awarnings", ]
if (is_clang && chrome_pgo_phase == 2 && !is_android) {
asmflags += [ "-fbasic-block-sections=labels" ]
@ -784,8 +779,6 @@ config("compiler") {
ldflags += [
"/opt:lldltojobs=all",
"-mllvm:-import-instr-limit=$import_instr_limit",
"-mllvm:-import-hot-multiplier=15",
"-mllvm:-import-cold-multiplier=2",
"-mllvm:-disable-auto-upgrade-debug-info",
]
} else {
@ -1039,7 +1032,7 @@ config("compiler") {
"-Zremap-cwd-prefix=.",
# Full RUSTC optimizations.
"-Copt-level=3", "-Ctarget-feature=+aes,+avx",
"-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+aes",
]
if (!is_win || force_rustc_color_output) {
@ -1051,12 +1044,17 @@ config("compiler") {
if (rust_abi_target != "") {
rustflags += [ "--target=$rust_abi_target" ]
}
if (!use_thin_lto) {
if (!use_thin_lto || !toolchain_supports_rust_thin_lto) {
# Don't include bitcode if it won't be used.
rustflags += [ "-Cembed-bitcode=no" ]
# Disable "automatic" ThinLTO between codegen units. The weak symbol
# resolution across units can have surprising effects on linking, see
# crbug.com/324126269 and github.com/rust-lang/rust/issues/120842.
rustflags += [ "-Clto=no" ]
}
if (is_official_build) {
rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+aes,+avx", ]
rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+aes", ]
}
if (!rust_prebuilt_stdlib) {
# When building against the Chromium Rust stdlib (which we compile) always
@ -1102,8 +1100,8 @@ config("thinlto_optimize_default") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1140,8 +1138,8 @@ config("thinlto_optimize_max") {
ldflags += [ "-opt:lldltocgo=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
ldflags += [ "-Wl,-mllvm,-enable-pre=false", ]
ldflags += [ "-Wl,--lto-CGO" + lto_opt_level ]
}
if (toolchain_supports_rust_thin_lto) {
@ -1187,7 +1185,7 @@ config("compiler_cpu_abi") {
"-maes",
"-mavx",
]
ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-mssse3", "-msse4", "-msse4.1", "-msse4.2", "-mpclmul", "-maes", "-mavx", "-Wl,-mllvm,-import-instr-limit=30", "-Wl,-mllvm,-import-hot-multiplier=15", "-Wl,-mllvm,-import-cold-multiplier=2", ]
ldflags += [ "-m64", "-Wl,-O3", "-msse3", "-mssse3", "-msse4", "-msse4.1", "-msse4.2", "-mpclmul", "-maes", "-mavx", "-Wl,-mllvm,-import-instr-limit=30", ]
} else if (current_cpu == "x86") {
cflags += [ "-m32" ]
ldflags += [ "-m32", "-Wl,-O3", "-msse3", ]
@ -1195,20 +1193,20 @@ config("compiler_cpu_abi") {
cflags += [
"-mfpmath=sse",
"-O3",
"-msse3",
"-mmmx",
"-msse3",
]
}
} 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", ]
cflags += [ "-O3", ]
ldflags += [ "-Wl,-O3", ]
}
} else if (current_cpu == "arm") {
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", ]
cflags += [ "--target=arm-linux-gnueabihf", "-O3", ]
ldflags += [ "--target=arm-linux-gnueabihf", "-Wl,-O3", ]
}
if (!is_nacl) {
cflags += [
@ -1222,12 +1220,8 @@ config("compiler_cpu_abi") {
} else if (current_cpu == "arm64") {
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", ]
cflags += [ "--target=aarch64-linux-gnu", "-O3", ]
ldflags += [ "--target=aarch64-linux-gnu", "-Wl,-O3", ]
}
} else if (current_cpu == "mipsel" && !is_nacl) {
ldflags += [ "-Wl,--hash-style=sysv" ]
@ -1885,6 +1879,9 @@ config("default_warnings") {
cflags_cc += [
# TODO(https://crbug.com/1474434): fix and reenable
"-Wno-missing-field-initializers",
# TODO(https://crbug.com/324953188): fix and reenable
"-Wno-extra-qualification",
]
}
@ -1929,6 +1926,7 @@ config("default_warnings") {
cflags += [
"-Wno-error=unknown-warning-option",
"-Wno-error=unused-command-line-argument",
"-Wno-error=unknown-pragmas",
]
}
}
@ -1982,6 +1980,35 @@ config("prevent_unsafe_narrowing") {
}
}
# unsafe_buffer_warning -------------------------------------------------------
# Paths of third-party headers that violate Wunsafe-buffer-usage, but which we
# have been unable to fix yet. We use this list to be able to make progress and
# enable the warning on code that we do control/own.
#
# WARNING: This will disable all warnings in the files. ONLY USE THIS for
# third-party code which we do not control/own. Fix the warnings instead in
# our own code.
if (is_clang) {
unsafe_buffer_warning_header_allowlist =
[ "third_party/googletest/src/googletest/include/gtest" ]
}
# Enables warnings on pointer arithmetic/indexing or calls to functions
# annotated with `UNSAFE_BUFFER_USAGE`.
config("unsafe_buffer_warning") {
if (is_clang) {
cflags = [ "-Wunsafe-buffer-usage" ]
foreach(h, unsafe_buffer_warning_header_allowlist) {
if (is_win) {
cflags += [ "/clang:--system-header-prefix=$h" ]
} else {
cflags += [ "--system-header-prefix=$h" ]
}
}
}
}
# chromium_code ---------------------------------------------------------------
#
# Toggles between higher and lower warnings for code that is (or isn't)
@ -2515,7 +2542,7 @@ config("optimize") {
# Favor size over speed, /O1 must be before the common flags.
# /O1 implies /Os and /GF.
cflags = [ "/O2", "-Xclang", "-O3", ] + common_optimize_on_cflags
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+aes" ]
} else {
# PGO requires all translation units to be compiled with /O2. The actual
# optimization level will be decided based on the profiling data.
@ -2524,45 +2551,35 @@ config("optimize") {
# https://doc.rust-lang.org/rustc/profile-guided-optimization.html#usage
# suggests not using an explicit `-Copt-level` at all, and the default is
# to optimize for performance like `/O2` for clang.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+aes" ]
}
} else if (optimize_for_size) {
} else if (optimize_for_size || is_chromeos) {
# Favor size over speed.
if (is_clang) {
cflags = [ "-O3" ] + common_optimize_on_cflags
# -Os in clang is more of a size-conscious -O2 than "size at any cost" (AKA -Oz).
if (use_ml_inliner && is_a_target_toolchain) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
if (is_fuchsia) {
cflags = [ "-O3" ] + common_optimize_on_cflags
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
# Like with `-Oz` on Clang, `-Copt-level=z` will also turn off loop
# vectorization.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx" ]
} else if (is_chromeos) {
# TODO(gbiv): This is partially favoring size over speed. CrOS exclusively
# uses clang, and -Os in clang is more of a size-conscious -O2 than "size at
# any cost" (AKA -Oz). It'd be nice to:
# - Make `optimize_for_size` apply to all platforms where we're optimizing
# for size by default (so, also Windows)
# - Investigate -Oz here, maybe just for ARM?
cflags = [ "-O3" ] + common_optimize_on_cflags
if (is_clang && use_ml_inliner && is_a_target_toolchain && !is_chromeos) {
cflags += [
"-mllvm",
"-enable-ml-inliner=release",
]
}
# Similar to clang, we optimize with `-Copt-level=s` to keep loop
# vectorization while otherwise optimizing for size.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+aes" ]
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
# The `-O3` for clang turns on extra optimizations compared to the standard
# `-O2`. But for rust, `-Copt-level=3` is the default and is thus reliable
# to use.
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx" ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+aes" ]
}
ldflags = common_optimize_on_ldflags
}
@ -2630,7 +2647,7 @@ config("optimize_max") {
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+aes", ]
}
}
@ -2663,13 +2680,13 @@ config("optimize_speed") {
} else {
cflags = [ "-O3" ] + common_optimize_on_cflags
}
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+aes", ]
}
}
config("optimize_fuzzing") {
cflags = [ "-O3" ] + common_optimize_on_cflags
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+aes,+avx", ]
rustflags = [ "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+aes", ]
ldflags = common_optimize_on_ldflags
visibility = [ ":default_optimization" ]
}
@ -3028,7 +3045,7 @@ config("minimal_symbols") {
asmflags = cflags
}
rustflags += [ "-Cdebuginfo=1", "-Copt-level=3", "-Ctarget-feature=+aes,+avx", ]
rustflags += [ "-Cdebuginfo=1", "-Copt-level=3", "-Ctarget-feature=+sse3,+ssse3,+sse4.1,+sse4.2,+avx,+aes", ]
}
# This configuration contains function names only. That is, the compiler is