Merge "More documentation for C++ global config." into main
This commit is contained in:
@@ -29,83 +29,112 @@ var (
|
|||||||
// Flags used by lots of devices. Putting them in package static variables
|
// Flags used by lots of devices. Putting them in package static variables
|
||||||
// will save bytes in build.ninja so they aren't repeated for every file
|
// will save bytes in build.ninja so they aren't repeated for every file
|
||||||
commonGlobalCflags = []string{
|
commonGlobalCflags = []string{
|
||||||
"-DANDROID",
|
// Enable some optimization by default.
|
||||||
"-fmessage-length=0",
|
"-O2",
|
||||||
"-W",
|
|
||||||
|
// Warnings enabled by default. Reference:
|
||||||
|
// https://clang.llvm.org/docs/DiagnosticsReference.html
|
||||||
"-Wall",
|
"-Wall",
|
||||||
"-Wno-unused",
|
"-Wextra",
|
||||||
"-Winit-self",
|
"-Winit-self",
|
||||||
"-Wpointer-arith",
|
"-Wpointer-arith",
|
||||||
"-Wunreachable-code-loop-increment",
|
"-Wunguarded-availability",
|
||||||
|
|
||||||
// Make paths in deps files relative
|
// Warnings treated as errors by default.
|
||||||
"-no-canonical-prefixes",
|
// See also noOverrideGlobalCflags for errors that cannot be disabled
|
||||||
|
// from Android.bp files.
|
||||||
"-DNDEBUG",
|
|
||||||
"-UDEBUG",
|
|
||||||
|
|
||||||
"-fno-exceptions",
|
|
||||||
|
|
||||||
"-O2",
|
|
||||||
"-fdebug-default-version=5",
|
|
||||||
|
|
||||||
"-fno-strict-aliasing",
|
|
||||||
|
|
||||||
|
// Using __DATE__/__TIME__ causes build nondeterminism.
|
||||||
"-Werror=date-time",
|
"-Werror=date-time",
|
||||||
|
// Detects forgotten */& that usually cause a crash
|
||||||
|
"-Werror=int-conversion",
|
||||||
|
// Detects unterminated alignment modification pragmas, which often lead
|
||||||
|
// to ABI mismatch between modules and hard-to-debug crashes.
|
||||||
"-Werror=pragma-pack",
|
"-Werror=pragma-pack",
|
||||||
|
// Same as above, but detects alignment pragmas around a header
|
||||||
|
// inclusion.
|
||||||
"-Werror=pragma-pack-suspicious-include",
|
"-Werror=pragma-pack-suspicious-include",
|
||||||
|
// Detects dividing an array size by itself, which is a common typo that
|
||||||
|
// leads to bugs.
|
||||||
|
"-Werror=sizeof-array-div",
|
||||||
|
// Detects a typo that cuts off a prefix from a string literal.
|
||||||
"-Werror=string-plus-int",
|
"-Werror=string-plus-int",
|
||||||
|
// Detects for loops that will never execute more than once (for example
|
||||||
|
// due to unconditional break), but have a non-empty loop increment
|
||||||
|
// clause. Often a mistake/bug.
|
||||||
"-Werror=unreachable-code-loop-increment",
|
"-Werror=unreachable-code-loop-increment",
|
||||||
|
|
||||||
// Force deprecation warnings to be warnings for code that compiles with -Werror.
|
// Warnings that should not be errors even for modules with -Werror.
|
||||||
// Making deprecated usages an error causes extreme pain when trying to deprecate anything.
|
|
||||||
"-Wno-error=deprecated-declarations",
|
|
||||||
|
|
||||||
|
// Making deprecated usages an error causes extreme pain when trying to
|
||||||
|
// deprecate anything.
|
||||||
|
"-Wno-error=deprecated-declarations",
|
||||||
|
// This rarely indicates a bug. http://b/145210666
|
||||||
|
"-Wno-error=reorder-init-list",
|
||||||
|
|
||||||
|
// Warnings disabled by default.
|
||||||
|
|
||||||
|
// Designated initializer syntax is recommended by the Google C++ style
|
||||||
|
// and is OK to use even if not formally supported by the chosen C++
|
||||||
|
// version.
|
||||||
|
"-Wno-c99-designator",
|
||||||
|
// Detects uses of a GNU C extension equivalent to a limited form of
|
||||||
|
// constexpr. Enabling this would require replacing many constants with
|
||||||
|
// macros, which is not a good trade-off.
|
||||||
|
"-Wno-gnu-folding-constant",
|
||||||
|
// AIDL generated code redeclares pure virtual methods in each
|
||||||
|
// subsequent version of an interface, so this warning is currently
|
||||||
|
// infeasible to enable.
|
||||||
|
"-Wno-inconsistent-missing-override",
|
||||||
|
// Incompatible with the Google C++ style guidance to use 'int' for loop
|
||||||
|
// indices; poor signal to noise ratio.
|
||||||
|
"-Wno-sign-compare",
|
||||||
|
// Poor signal to noise ratio.
|
||||||
|
"-Wno-unused",
|
||||||
|
|
||||||
|
// Global preprocessor constants.
|
||||||
|
|
||||||
|
"-DANDROID",
|
||||||
|
"-DNDEBUG",
|
||||||
|
"-UDEBUG",
|
||||||
"-D__compiler_offsetof=__builtin_offsetof",
|
"-D__compiler_offsetof=__builtin_offsetof",
|
||||||
|
// Allows the bionic versioning.h to indirectly determine whether the
|
||||||
|
// option -Wunguarded-availability is on or not.
|
||||||
|
"-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__",
|
||||||
|
|
||||||
|
// -f and -g options.
|
||||||
|
|
||||||
// Emit address-significance table which allows linker to perform safe ICF. Clang does
|
// Emit address-significance table which allows linker to perform safe ICF. Clang does
|
||||||
// not emit the table by default on Android since NDK still uses GNU binutils.
|
// not emit the table by default on Android since NDK still uses GNU binutils.
|
||||||
"-faddrsig",
|
"-faddrsig",
|
||||||
|
|
||||||
// Help catch common 32/64-bit errors.
|
// Emit debugging data in a modern format (DWARF v5).
|
||||||
"-Werror=int-conversion",
|
"-fdebug-default-version=5",
|
||||||
|
|
||||||
// Force clang to always output color diagnostics. Ninja will strip the ANSI
|
// Force clang to always output color diagnostics. Ninja will strip the ANSI
|
||||||
// color codes if it is not running in a terminal.
|
// color codes if it is not running in a terminal.
|
||||||
"-fcolor-diagnostics",
|
"-fcolor-diagnostics",
|
||||||
|
|
||||||
// -Wno-sign-compare is incompatible with the Google C++ style guidance
|
|
||||||
// to use 'int' for loop indices, and the signal to noise ratio is poor
|
|
||||||
// anyway.
|
|
||||||
"-Wno-sign-compare",
|
|
||||||
|
|
||||||
// AIDL generated code redeclares pure virtual methods in each
|
|
||||||
// subsequent version of an interface, so this is currently infeasible
|
|
||||||
// to enable.
|
|
||||||
"-Wno-inconsistent-missing-override",
|
|
||||||
|
|
||||||
// Designated initializer syntax is recommended by the Google C++ style
|
|
||||||
// guide and should not be a warning, at least by default.
|
|
||||||
"-Wno-c99-designator",
|
|
||||||
|
|
||||||
// Warnings from clang-12
|
|
||||||
"-Wno-gnu-folding-constant",
|
|
||||||
|
|
||||||
// http://b/145210666
|
|
||||||
"-Wno-error=reorder-init-list",
|
|
||||||
|
|
||||||
// Calls to the APIs that are newer than the min sdk version of the caller should be
|
|
||||||
// guarded with __builtin_available.
|
|
||||||
"-Wunguarded-availability",
|
|
||||||
// This macro allows the bionic versioning.h to indirectly determine whether the
|
|
||||||
// option -Wunguarded-availability is on or not.
|
|
||||||
"-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__",
|
|
||||||
|
|
||||||
// Turn off FMA which got enabled by default in clang-r445002 (http://b/218805949)
|
// Turn off FMA which got enabled by default in clang-r445002 (http://b/218805949)
|
||||||
"-ffp-contract=off",
|
"-ffp-contract=off",
|
||||||
|
|
||||||
|
// Google C++ style does not allow exceptions, turn them off by default.
|
||||||
|
"-fno-exceptions",
|
||||||
|
|
||||||
|
// Disable optimizations based on strict aliasing by default.
|
||||||
|
// The performance benefit of enabling them currently does not outweigh
|
||||||
|
// the risk of hard-to-reproduce bugs.
|
||||||
|
"-fno-strict-aliasing",
|
||||||
|
|
||||||
|
// Disable line wrapping for error messages - it interferes with
|
||||||
|
// displaying logs in web browsers.
|
||||||
|
"-fmessage-length=0",
|
||||||
|
|
||||||
// Using simple template names reduces the size of debug builds.
|
// Using simple template names reduces the size of debug builds.
|
||||||
"-gsimple-template-names",
|
"-gsimple-template-names",
|
||||||
|
|
||||||
|
// Make paths in deps files relative.
|
||||||
|
"-no-canonical-prefixes",
|
||||||
}
|
}
|
||||||
|
|
||||||
commonGlobalConlyflags = []string{}
|
commonGlobalConlyflags = []string{}
|
||||||
@@ -117,6 +146,7 @@ var (
|
|||||||
"-fdebug-default-version=4",
|
"-fdebug-default-version=4",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compilation flags for device code; not applied to host code.
|
||||||
deviceGlobalCflags = []string{
|
deviceGlobalCflags = []string{
|
||||||
"-ffunction-sections",
|
"-ffunction-sections",
|
||||||
"-fdata-sections",
|
"-fdata-sections",
|
||||||
@@ -152,6 +182,7 @@ var (
|
|||||||
"-fvisibility-inlines-hidden",
|
"-fvisibility-inlines-hidden",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Linking flags for device code; not applied to host binaries.
|
||||||
deviceGlobalLdflags = []string{
|
deviceGlobalLdflags = []string{
|
||||||
"-Wl,-z,noexecstack",
|
"-Wl,-z,noexecstack",
|
||||||
"-Wl,-z,relro",
|
"-Wl,-z,relro",
|
||||||
@@ -194,6 +225,14 @@ var (
|
|||||||
|
|
||||||
// These flags are appended after the module's cflags, so they cannot be
|
// These flags are appended after the module's cflags, so they cannot be
|
||||||
// overridden from Android.bp files.
|
// overridden from Android.bp files.
|
||||||
|
//
|
||||||
|
// NOTE: if you need to disable a warning to unblock a compiler upgrade
|
||||||
|
// and it is only triggered by third party code, add it to
|
||||||
|
// extraExternalCflags (if possible) or noOverrideExternalGlobalCflags
|
||||||
|
// (if the former doesn't work). If the new warning also occurs in first
|
||||||
|
// party code, try adding it to commonGlobalCflags first. Adding it here
|
||||||
|
// should be the last resort, because it prevents all code in Android from
|
||||||
|
// opting into the warning.
|
||||||
noOverrideGlobalCflags = []string{
|
noOverrideGlobalCflags = []string{
|
||||||
"-Werror=bool-operation",
|
"-Werror=bool-operation",
|
||||||
"-Werror=format-insufficient-args",
|
"-Werror=format-insufficient-args",
|
||||||
@@ -245,35 +284,9 @@ var (
|
|||||||
|
|
||||||
noOverride64GlobalCflags = []string{}
|
noOverride64GlobalCflags = []string{}
|
||||||
|
|
||||||
// Similar to noOverrideGlobalCflags, but applies only to third-party code
|
// Extra cflags applied to third-party code (anything for which
|
||||||
// (anything for which IsThirdPartyPath() in build/soong/android/paths.go
|
// IsThirdPartyPath() in build/soong/android/paths.go returns true;
|
||||||
// returns true - includes external/, most of vendor/ and most of hardware/)
|
// includes external/, most of vendor/ and most of hardware/)
|
||||||
noOverrideExternalGlobalCflags = []string{
|
|
||||||
// http://b/151457797
|
|
||||||
"-fcommon",
|
|
||||||
// http://b/191699019
|
|
||||||
"-Wno-format-insufficient-args",
|
|
||||||
// http://b/296321145
|
|
||||||
// Indicates potential memory or stack corruption, so should be changed
|
|
||||||
// to a hard error. Currently triggered by some vendor code.
|
|
||||||
"-Wno-incompatible-function-pointer-types",
|
|
||||||
// http://b/296321508
|
|
||||||
// Introduced in response to a critical security vulnerability and
|
|
||||||
// should be a hard error - it requires only whitespace changes to fix.
|
|
||||||
"-Wno-misleading-indentation",
|
|
||||||
// Triggered by old LLVM code in external/llvm. Likely not worth
|
|
||||||
// enabling since it's a cosmetic issue.
|
|
||||||
"-Wno-bitwise-instead-of-logical",
|
|
||||||
|
|
||||||
"-Wno-unused-but-set-variable",
|
|
||||||
"-Wno-unused-but-set-parameter",
|
|
||||||
"-Wno-unqualified-std-cast-call",
|
|
||||||
"-Wno-array-parameter",
|
|
||||||
"-Wno-gnu-offsetof-extensions",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extra cflags for external third-party projects to disable warnings that
|
|
||||||
// are infeasible to fix in all the external projects and their upstream repos.
|
|
||||||
extraExternalCflags = []string{
|
extraExternalCflags = []string{
|
||||||
"-Wno-enum-compare",
|
"-Wno-enum-compare",
|
||||||
"-Wno-enum-compare-switch",
|
"-Wno-enum-compare-switch",
|
||||||
@@ -303,11 +316,41 @@ var (
|
|||||||
"-Wno-deprecated-non-prototype",
|
"-Wno-deprecated-non-prototype",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Similar to noOverrideGlobalCflags, but applies only to third-party code
|
||||||
|
// (see extraExternalCflags).
|
||||||
|
// This section can unblock compiler upgrades when a third party module that
|
||||||
|
// enables -Werror and some group of warnings explicitly triggers newly
|
||||||
|
// added warnings.
|
||||||
|
noOverrideExternalGlobalCflags = []string{
|
||||||
|
// http://b/151457797
|
||||||
|
"-fcommon",
|
||||||
|
// http://b/191699019
|
||||||
|
"-Wno-format-insufficient-args",
|
||||||
|
// http://b/296321145
|
||||||
|
// Indicates potential memory or stack corruption, so should be changed
|
||||||
|
// to a hard error. Currently triggered by some vendor code.
|
||||||
|
"-Wno-incompatible-function-pointer-types",
|
||||||
|
// http://b/296321508
|
||||||
|
// Introduced in response to a critical security vulnerability and
|
||||||
|
// should be a hard error - it requires only whitespace changes to fix.
|
||||||
|
"-Wno-misleading-indentation",
|
||||||
|
// Triggered by old LLVM code in external/llvm. Likely not worth
|
||||||
|
// enabling since it's a cosmetic issue.
|
||||||
|
"-Wno-bitwise-instead-of-logical",
|
||||||
|
|
||||||
|
"-Wno-unused-but-set-variable",
|
||||||
|
"-Wno-unused-but-set-parameter",
|
||||||
|
"-Wno-unqualified-std-cast-call",
|
||||||
|
"-Wno-array-parameter",
|
||||||
|
"-Wno-gnu-offsetof-extensions",
|
||||||
|
}
|
||||||
|
|
||||||
llvmNextExtraCommonGlobalCflags = []string{
|
llvmNextExtraCommonGlobalCflags = []string{
|
||||||
// Do not report warnings when testing with the top of trunk LLVM.
|
// Do not report warnings when testing with the top of trunk LLVM.
|
||||||
"-Wno-error",
|
"-Wno-error",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flags that must not appear in any command line.
|
||||||
IllegalFlags = []string{
|
IllegalFlags = []string{
|
||||||
"-w",
|
"-w",
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user