123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- // Copyright 2016 Google Inc. All rights reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package config
- import (
- "runtime"
- "strings"
- "android/soong/android"
- "android/soong/remoteexec"
- )
- var (
- // 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
- commonGlobalCflags = []string{
- "-DANDROID",
- "-fmessage-length=0",
- "-W",
- "-Wall",
- "-Wno-unused",
- "-Winit-self",
- "-Wpointer-arith",
- "-Wunreachable-code-loop-increment",
- // Make paths in deps files relative
- "-no-canonical-prefixes",
- "-DNDEBUG",
- "-UDEBUG",
- "-fno-exceptions",
- "-Wno-multichar",
- "-O2",
- "-g",
- "-fdebug-info-for-profiling",
- "-fno-strict-aliasing",
- "-Werror=date-time",
- "-Werror=pragma-pack",
- "-Werror=pragma-pack-suspicious-include",
- "-Werror=string-plus-int",
- "-Werror=unreachable-code-loop-increment",
- "-D__compiler_offsetof=__builtin_offsetof",
- // 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.
- "-faddrsig",
- // Turn on -fcommon explicitly, since Clang now defaults to -fno-common. The cleanup bug
- // tracking this is http://b/151457797.
- "-fcommon",
- // Help catch common 32/64-bit errors.
- "-Werror=int-conversion",
- // Enable the new pass manager.
- "-fexperimental-new-pass-manager",
- // Disable overly aggressive warning for macros defined with a leading underscore
- // This happens in AndroidConfig.h, which is included nearly everywhere.
- // TODO: can we remove this now?
- "-Wno-reserved-id-macro",
- // Force clang to always output color diagnostics. Ninja will strip the ANSI
- // color codes if it is not running in a terminal.
- "-fcolor-diagnostics",
- // Warnings from clang-7.0
- "-Wno-sign-compare",
- // Warnings from clang-8.0
- "-Wno-defaulted-function-deleted",
- // Disable -Winconsistent-missing-override until we can clean up the existing
- // codebase for it.
- "-Wno-inconsistent-missing-override",
- // Warnings from clang-10
- // Nested and array designated initialization is nice to have.
- "-Wno-c99-designator",
- // Warnings from clang-12
- "-Wno-gnu-folding-constant",
- // 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__",
- }
- commonGlobalConlyflags = []string{}
- deviceGlobalCflags = []string{
- "-ffunction-sections",
- "-fdata-sections",
- "-fno-short-enums",
- "-funwind-tables",
- "-fstack-protector-strong",
- "-Wa,--noexecstack",
- "-D_FORTIFY_SOURCE=2",
- "-Wstrict-aliasing=2",
- "-Werror=return-type",
- "-Werror=non-virtual-dtor",
- "-Werror=address",
- "-Werror=sequence-point",
- "-Werror=format-security",
- "-nostdlibinc",
- }
- deviceGlobalCppflags = []string{
- "-fvisibility-inlines-hidden",
- }
- deviceGlobalLdflags = []string{
- "-Wl,-z,noexecstack",
- "-Wl,-z,relro",
- "-Wl,-z,now",
- "-Wl,--build-id=md5",
- "-Wl,--warn-shared-textrel",
- "-Wl,--fatal-warnings",
- "-Wl,--no-undefined-version",
- // TODO: Eventually we should link against a libunwind.a with hidden symbols, and then these
- // --exclude-libs arguments can be removed.
- "-Wl,--exclude-libs,libgcc.a",
- "-Wl,--exclude-libs,libgcc_stripped.a",
- "-Wl,--exclude-libs,libunwind_llvm.a",
- "-Wl,--exclude-libs,libunwind.a",
- "-Wl,--icf=safe",
- }
- deviceGlobalLldflags = append(deviceGlobalLdflags,
- []string{
- "-fuse-ld=lld",
- }...)
- hostGlobalCflags = []string{}
- hostGlobalCppflags = []string{}
- hostGlobalLdflags = []string{}
- hostGlobalLldflags = []string{"-fuse-ld=lld"}
- commonGlobalCppflags = []string{
- "-Wsign-promo",
- // -Wimplicit-fallthrough is not enabled by -Wall.
- "-Wimplicit-fallthrough",
- // Enable clang's thread-safety annotations in libcxx.
- "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
- // libc++'s math.h has an #include_next outside of system_headers.
- "-Wno-gnu-include-next",
- }
- noOverrideGlobalCflags = []string{
- "-Werror=bool-operation",
- "-Werror=implicit-int-float-conversion",
- "-Werror=int-in-bool-context",
- "-Werror=int-to-pointer-cast",
- "-Werror=pointer-to-int-cast",
- "-Werror=string-compare",
- "-Werror=xor-used-as-pow",
- // http://b/161386391 for -Wno-void-pointer-to-enum-cast
- "-Wno-void-pointer-to-enum-cast",
- // http://b/161386391 for -Wno-void-pointer-to-int-cast
- "-Wno-void-pointer-to-int-cast",
- // http://b/161386391 for -Wno-pointer-to-int-cast
- "-Wno-pointer-to-int-cast",
- "-Werror=fortify-source",
- "-Werror=address-of-temporary",
- // Bug: http://b/29823425 Disable -Wnull-dereference until the
- // new cases detected by this warning in Clang r271374 are
- // fixed.
- //"-Werror=null-dereference",
- "-Werror=return-type",
- // http://b/72331526 Disable -Wtautological-* until the instances detected by these
- // new warnings are fixed.
- "-Wno-tautological-constant-compare",
- "-Wno-tautological-type-limit-compare",
- // http://b/145210666
- "-Wno-reorder-init-list",
- // http://b/145211066
- "-Wno-implicit-int-float-conversion",
- // New warnings to be fixed after clang-r377782.
- "-Wno-int-in-bool-context", // http://b/148287349
- "-Wno-sizeof-array-div", // http://b/148815709
- "-Wno-tautological-overlap-compare", // http://b/148815696
- // New warnings to be fixed after clang-r383902.
- "-Wno-deprecated-copy", // http://b/153746672
- "-Wno-range-loop-construct", // http://b/153747076
- "-Wno-misleading-indentation", // http://b/153746954
- "-Wno-zero-as-null-pointer-constant", // http://b/68236239
- "-Wno-deprecated-anon-enum-enum-conversion", // http://b/153746485
- "-Wno-deprecated-enum-enum-conversion", // http://b/153746563
- "-Wno-string-compare", // http://b/153764102
- "-Wno-enum-enum-conversion", // http://b/154138986
- "-Wno-enum-float-conversion", // http://b/154255917
- "-Wno-pessimizing-move", // http://b/154270751
- // New warnings to be fixed after clang-r399163
- "-Wno-non-c-typedef-for-linkage", // http://b/161304145
- // New warnings to be fixed after clang-r407598
- "-Wno-string-concatenation", // http://b/175068488
- // New warnings to be fixed after clang-r428724
- "-Wno-align-mismatch", // http://b/193679946
- // New warnings to be fixed after clang-r433403
- "-Wno-error=unused-but-set-variable", // http://b/197240255
- "-Wno-error=unused-but-set-parameter", // http://b/197240255
- }
- // 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{
- "-Wno-enum-compare",
- "-Wno-enum-compare-switch",
- // http://b/72331524 Allow null pointer arithmetic until the instances detected by
- // this new warning are fixed.
- "-Wno-null-pointer-arithmetic",
- // Bug: http://b/29823425 Disable -Wnull-dereference until the
- // new instances detected by this warning are fixed.
- "-Wno-null-dereference",
- // http://b/145211477
- "-Wno-pointer-compare",
- // http://b/145211022
- "-Wno-xor-used-as-pow",
- // http://b/145211022
- "-Wno-final-dtor-non-final-class",
- // http://b/165945989
- "-Wno-psabi",
- // http://b/199369603
- "-Wno-null-pointer-subtraction",
- }
- IllegalFlags = []string{
- "-w",
- }
- CStdVersion = "gnu99"
- CppStdVersion = "gnu++17"
- ExperimentalCStdVersion = "gnu11"
- ExperimentalCppStdVersion = "gnu++2a"
- // prebuilts/clang default settings.
- ClangDefaultBase = "prebuilts/clang/host"
- ClangDefaultVersion = "clang-r433403"
- ClangDefaultShortVersion = "13.0.2"
- // Directories with warnings from Android.bp files.
- WarningAllowedProjects = []string{
- "device/",
- "vendor/",
- }
- // Directories with warnings from Android.mk files.
- WarningAllowedOldProjects = []string{}
- )
- var pctx = android.NewPackageContext("android/soong/cc/config")
- func init() {
- if runtime.GOOS == "linux" {
- commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
- }
- exportStringListStaticVariable("CommonGlobalConlyflags", commonGlobalConlyflags)
- exportStringListStaticVariable("DeviceGlobalCppflags", deviceGlobalCppflags)
- exportStringListStaticVariable("DeviceGlobalLdflags", deviceGlobalLdflags)
- exportStringListStaticVariable("DeviceGlobalLldflags", deviceGlobalLldflags)
- exportStringListStaticVariable("HostGlobalCppflags", hostGlobalCppflags)
- exportStringListStaticVariable("HostGlobalLdflags", hostGlobalLdflags)
- exportStringListStaticVariable("HostGlobalLldflags", hostGlobalLldflags)
- // Export the static default CommonGlobalCflags to Bazel.
- // TODO(187086342): handle cflags that are set in VariableFuncs.
- bazelCommonGlobalCflags := append(
- commonGlobalCflags,
- []string{
- // Default to zero initialization.
- "-ftrivial-auto-var-init=zero",
- "-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang",
- }...)
- exportedStringListVars.Set("CommonGlobalCflags", bazelCommonGlobalCflags)
- pctx.VariableFunc("CommonGlobalCflags", func(ctx android.PackageVarContext) string {
- flags := commonGlobalCflags
- // http://b/131390872
- // Automatically initialize any uninitialized stack variables.
- // Prefer zero-init if multiple options are set.
- if ctx.Config().IsEnvTrue("AUTO_ZERO_INITIALIZE") {
- flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang")
- } else if ctx.Config().IsEnvTrue("AUTO_PATTERN_INITIALIZE") {
- flags = append(flags, "-ftrivial-auto-var-init=pattern")
- } else if ctx.Config().IsEnvTrue("AUTO_UNINITIALIZE") {
- flags = append(flags, "-ftrivial-auto-var-init=uninitialized")
- } else {
- // Default to zero initialization.
- flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang")
- }
- // Workaround for ccache with clang.
- // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
- if ctx.Config().IsEnvTrue("USE_CCACHE") {
- flags = append(flags, "-Wno-unused-command-line-argument")
- }
- return strings.Join(flags, " ")
- })
- // Export the static default DeviceGlobalCflags to Bazel.
- // TODO(187086342): handle cflags that are set in VariableFuncs.
- exportedStringListVars.Set("DeviceGlobalCflags", deviceGlobalCflags)
- pctx.VariableFunc("DeviceGlobalCflags", func(ctx android.PackageVarContext) string {
- return strings.Join(deviceGlobalCflags, " ")
- })
- exportStringListStaticVariable("HostGlobalCflags", hostGlobalCflags)
- exportStringListStaticVariable("NoOverrideGlobalCflags", noOverrideGlobalCflags)
- exportStringListStaticVariable("CommonGlobalCppflags", commonGlobalCppflags)
- exportStringListStaticVariable("ExternalCflags", extraExternalCflags)
- // Everything in these lists is a crime against abstraction and dependency tracking.
- // Do not add anything to this list.
- commonGlobalIncludes := []string{
- "system/core/include",
- "system/logging/liblog/include",
- "system/media/audio/include",
- "hardware/libhardware/include",
- "hardware/libhardware_legacy/include",
- "hardware/ril/include",
- "frameworks/native/include",
- "frameworks/native/opengl/include",
- "frameworks/av/include",
- }
- exportedStringListVars.Set("CommonGlobalIncludes", commonGlobalIncludes)
- pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I", commonGlobalIncludes)
- exportStringStaticVariable("CLANG_DEFAULT_VERSION", ClangDefaultVersion)
- exportStringStaticVariable("CLANG_DEFAULT_SHORT_VERSION", ClangDefaultShortVersion)
- pctx.StaticVariableWithEnvOverride("ClangBase", "LLVM_PREBUILTS_BASE", ClangDefaultBase)
- pctx.StaticVariableWithEnvOverride("ClangVersion", "LLVM_PREBUILTS_VERSION", ClangDefaultVersion)
- pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
- pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
- pctx.StaticVariableWithEnvOverride("ClangShortVersion", "LLVM_RELEASE_VERSION", ClangDefaultShortVersion)
- pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
- // These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
- // being used for the rest of the build process.
- pctx.SourcePathVariable("RSClangBase", "prebuilts/clang/host")
- pctx.SourcePathVariable("RSClangVersion", "clang-3289846")
- pctx.SourcePathVariable("RSReleaseVersion", "3.8")
- pctx.StaticVariable("RSLLVMPrebuiltsPath", "${RSClangBase}/${HostPrebuiltTag}/${RSClangVersion}/bin")
- pctx.StaticVariable("RSIncludePath", "${RSLLVMPrebuiltsPath}/../lib64/clang/${RSReleaseVersion}/include")
- pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
- []string{
- "external/clang/lib/Headers",
- "frameworks/rs/script_api/include",
- })
- pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string {
- if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" {
- return override + " "
- }
- return ""
- })
- pctx.StaticVariableWithEnvOverride("RECXXPool", "RBE_CXX_POOL", remoteexec.DefaultPool)
- pctx.StaticVariableWithEnvOverride("RECXXLinksPool", "RBE_CXX_LINKS_POOL", remoteexec.DefaultPool)
- pctx.StaticVariableWithEnvOverride("REClangTidyPool", "RBE_CLANG_TIDY_POOL", remoteexec.DefaultPool)
- pctx.StaticVariableWithEnvOverride("RECXXLinksExecStrategy", "RBE_CXX_LINKS_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
- pctx.StaticVariableWithEnvOverride("REClangTidyExecStrategy", "RBE_CLANG_TIDY_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
- pctx.StaticVariableWithEnvOverride("REAbiDumperExecStrategy", "RBE_ABI_DUMPER_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
- pctx.StaticVariableWithEnvOverride("REAbiLinkerExecStrategy", "RBE_ABI_LINKER_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
- }
- var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
- func ClangPath(ctx android.PathContext, file string) android.SourcePath {
- type clangToolKey string
- key := android.NewCustomOnceKey(clangToolKey(file))
- return ctx.Config().OnceSourcePath(key, func() android.SourcePath {
- return clangPath(ctx).Join(ctx, file)
- })
- }
- var clangPathKey = android.NewOnceKey("clangPath")
- func clangPath(ctx android.PathContext) android.SourcePath {
- return ctx.Config().OnceSourcePath(clangPathKey, func() android.SourcePath {
- clangBase := ClangDefaultBase
- if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
- clangBase = override
- }
- clangVersion := ClangDefaultVersion
- if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
- clangVersion = override
- }
- return android.PathForSource(ctx, clangBase, ctx.Config().PrebuiltOS(), clangVersion)
- })
- }
|