From 84e2d003a247a3e8de2cba2237711954d6acaf11 Mon Sep 17 00:00:00 2001 From: Alexander David Frick Date: Thu, 13 Jan 2022 06:58:34 -0600 Subject: [PATCH] Update BUILD.gn --- build/config/compiler/BUILD.gn | 36 +++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index d39181b6..b08c5933 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -702,7 +702,7 @@ config("compiler") { # 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 = 20 + import_instr_limit = 30 } else { import_instr_limit = 30 } @@ -1538,6 +1538,40 @@ config("default_warnings") { } } +# 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", + ] + } +} + # chromium_code --------------------------------------------------------------- # # Toggles between higher and lower warnings for code that is (or isn't)