2016-07-29 21:48:20 +02:00
|
|
|
// 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.
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
package config
|
2016-07-29 21:48:20 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2020-04-13 19:21:23 +02:00
|
|
|
"android/soong/remoteexec"
|
2016-07-29 21:48:20 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-05-23 01:11:34 +02:00
|
|
|
// 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
|
2016-07-29 21:48:20 +02:00
|
|
|
commonGlobalCflags = []string{
|
|
|
|
"-DANDROID",
|
|
|
|
"-fmessage-length=0",
|
|
|
|
"-W",
|
|
|
|
"-Wall",
|
|
|
|
"-Wno-unused",
|
|
|
|
"-Winit-self",
|
|
|
|
"-Wpointer-arith",
|
|
|
|
|
2017-11-03 06:38:32 +01:00
|
|
|
// Make paths in deps files relative
|
|
|
|
"-no-canonical-prefixes",
|
2017-11-06 21:53:30 +01:00
|
|
|
"-fno-canonical-system-headers",
|
2017-11-03 06:38:32 +01:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
"-DNDEBUG",
|
|
|
|
"-UDEBUG",
|
2017-11-03 06:38:32 +01:00
|
|
|
|
|
|
|
"-fno-exceptions",
|
|
|
|
"-Wno-multichar",
|
|
|
|
|
|
|
|
"-O2",
|
|
|
|
"-g",
|
|
|
|
|
|
|
|
"-fno-strict-aliasing",
|
2019-08-28 04:37:10 +02:00
|
|
|
|
|
|
|
"-Werror=date-time",
|
2019-12-04 03:13:00 +01:00
|
|
|
"-Werror=pragma-pack",
|
|
|
|
"-Werror=pragma-pack-suspicious-include",
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-10-17 23:19:06 +02:00
|
|
|
commonGlobalConlyflags = []string{}
|
2016-10-07 22:12:58 +02:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
deviceGlobalCflags = []string{
|
|
|
|
"-fdiagnostics-color",
|
|
|
|
|
2017-11-03 06:55:19 +01:00
|
|
|
"-ffunction-sections",
|
2017-11-06 23:02:02 +01:00
|
|
|
"-fdata-sections",
|
|
|
|
"-fno-short-enums",
|
2017-11-03 06:55:19 +01:00
|
|
|
"-funwind-tables",
|
|
|
|
"-fstack-protector-strong",
|
|
|
|
"-Wa,--noexecstack",
|
|
|
|
"-D_FORTIFY_SOURCE=2",
|
|
|
|
|
|
|
|
"-Wstrict-aliasing=2",
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
"-Werror=return-type",
|
|
|
|
"-Werror=non-virtual-dtor",
|
|
|
|
"-Werror=address",
|
|
|
|
"-Werror=sequence-point",
|
2017-11-03 06:55:19 +01:00
|
|
|
"-Werror=format-security",
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2017-11-06 22:59:48 +01:00
|
|
|
deviceGlobalCppflags = []string{
|
|
|
|
"-fvisibility-inlines-hidden",
|
|
|
|
}
|
|
|
|
|
Consolidate ldflags that are used on all devices
Move ldflags that are specified for all devices into
deviceGlobalLdflags, and add them to linker.go:
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-Wl,--build-id=md5
-Wl,--warn-shared-textrel
-Wl,--fatal-warnings
-Wl,--no-undefined-version
Bug: 68855788
Test: m checkbuild
Change-Id: I82561b4189287d7638006f9e298c5151f9930c5e
2017-11-03 07:09:41 +01:00
|
|
|
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",
|
2019-04-11 02:57:50 +02:00
|
|
|
"-Wl,--exclude-libs,libgcc.a",
|
2019-05-07 01:18:33 +02:00
|
|
|
"-Wl,--exclude-libs,libgcc_stripped.a",
|
2019-12-11 03:37:45 +01:00
|
|
|
"-Wl,--exclude-libs,libunwind_llvm.a",
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2018-04-03 20:33:34 +02:00
|
|
|
deviceGlobalLldflags = append(ClangFilterUnknownLldflags(deviceGlobalLdflags),
|
|
|
|
[]string{
|
|
|
|
"-fuse-ld=lld",
|
|
|
|
}...)
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
hostGlobalCflags = []string{}
|
|
|
|
|
2017-11-06 22:59:48 +01:00
|
|
|
hostGlobalCppflags = []string{}
|
|
|
|
|
Consolidate ldflags that are used on all devices
Move ldflags that are specified for all devices into
deviceGlobalLdflags, and add them to linker.go:
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-Wl,--build-id=md5
-Wl,--warn-shared-textrel
-Wl,--fatal-warnings
-Wl,--no-undefined-version
Bug: 68855788
Test: m checkbuild
Change-Id: I82561b4189287d7638006f9e298c5151f9930c5e
2017-11-03 07:09:41 +01:00
|
|
|
hostGlobalLdflags = []string{}
|
|
|
|
|
2018-04-17 23:16:05 +02:00
|
|
|
hostGlobalLldflags = []string{"-fuse-ld=lld"}
|
2018-04-03 20:33:34 +02:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
commonGlobalCppflags = []string{
|
|
|
|
"-Wsign-promo",
|
|
|
|
}
|
|
|
|
|
|
|
|
noOverrideGlobalCflags = []string{
|
|
|
|
"-Werror=int-to-pointer-cast",
|
|
|
|
"-Werror=pointer-to-int-cast",
|
2019-09-19 02:52:05 +02:00
|
|
|
"-Werror=fortify-source",
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
IllegalFlags = []string{
|
2016-07-29 21:48:20 +02:00
|
|
|
"-w",
|
|
|
|
}
|
2016-10-17 23:19:06 +02:00
|
|
|
|
2017-02-04 01:13:38 +01:00
|
|
|
CStdVersion = "gnu99"
|
2018-11-30 17:03:06 +01:00
|
|
|
CppStdVersion = "gnu++17"
|
2017-02-04 01:13:38 +01:00
|
|
|
ExperimentalCStdVersion = "gnu11"
|
2018-11-28 23:16:39 +01:00
|
|
|
ExperimentalCppStdVersion = "gnu++2a"
|
2017-05-09 19:21:52 +02:00
|
|
|
|
2018-01-17 01:21:06 +01:00
|
|
|
NdkMaxPrebuiltVersionInt = 27
|
2017-05-23 01:11:34 +02:00
|
|
|
|
|
|
|
// prebuilts/clang default settings.
|
|
|
|
ClangDefaultBase = "prebuilts/clang/host"
|
2020-04-10 22:36:41 +02:00
|
|
|
ClangDefaultVersion = "clang-r383902"
|
|
|
|
ClangDefaultShortVersion = "11.0.1"
|
2017-11-14 23:09:14 +01:00
|
|
|
|
2017-12-25 07:24:47 +01:00
|
|
|
// Directories with warnings from Android.bp files.
|
2017-11-14 23:09:14 +01:00
|
|
|
WarningAllowedProjects = []string{
|
|
|
|
"device/",
|
|
|
|
"vendor/",
|
|
|
|
}
|
|
|
|
|
2017-12-25 07:24:47 +01:00
|
|
|
// Directories with warnings from Android.mk files.
|
|
|
|
WarningAllowedOldProjects = []string{}
|
2016-07-29 21:48:20 +02:00
|
|
|
)
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
var pctx = android.NewPackageContext("android/soong/cc/config")
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func init() {
|
|
|
|
if android.BuildOs == android.Linux {
|
|
|
|
commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
|
|
|
|
}
|
|
|
|
|
2016-10-07 22:12:58 +02:00
|
|
|
pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
|
2017-11-06 22:59:48 +01:00
|
|
|
pctx.StaticVariable("DeviceGlobalCppflags", strings.Join(deviceGlobalCppflags, " "))
|
Consolidate ldflags that are used on all devices
Move ldflags that are specified for all devices into
deviceGlobalLdflags, and add them to linker.go:
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-Wl,--build-id=md5
-Wl,--warn-shared-textrel
-Wl,--fatal-warnings
-Wl,--no-undefined-version
Bug: 68855788
Test: m checkbuild
Change-Id: I82561b4189287d7638006f9e298c5151f9930c5e
2017-11-03 07:09:41 +01:00
|
|
|
pctx.StaticVariable("DeviceGlobalLdflags", strings.Join(deviceGlobalLdflags, " "))
|
2018-04-03 20:33:34 +02:00
|
|
|
pctx.StaticVariable("DeviceGlobalLldflags", strings.Join(deviceGlobalLldflags, " "))
|
2017-11-06 22:59:48 +01:00
|
|
|
pctx.StaticVariable("HostGlobalCppflags", strings.Join(hostGlobalCppflags, " "))
|
Consolidate ldflags that are used on all devices
Move ldflags that are specified for all devices into
deviceGlobalLdflags, and add them to linker.go:
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-Wl,--build-id=md5
-Wl,--warn-shared-textrel
-Wl,--fatal-warnings
-Wl,--no-undefined-version
Bug: 68855788
Test: m checkbuild
Change-Id: I82561b4189287d7638006f9e298c5151f9930c5e
2017-11-03 07:09:41 +01:00
|
|
|
pctx.StaticVariable("HostGlobalLdflags", strings.Join(hostGlobalLdflags, " "))
|
2018-04-03 20:33:34 +02:00
|
|
|
pctx.StaticVariable("HostGlobalLldflags", strings.Join(hostGlobalLldflags, " "))
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2019-06-11 02:40:12 +02:00
|
|
|
pctx.VariableFunc("CommonClangGlobalCflags", func(ctx android.PackageVarContext) string {
|
|
|
|
flags := ClangFilterUnknownCflags(commonGlobalCflags)
|
|
|
|
flags = append(flags, "${ClangExtraCflags}")
|
|
|
|
|
|
|
|
// http://b/131390872
|
|
|
|
// Automatically initialize any uninitialized stack variables.
|
|
|
|
// Prefer zero-init if both 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")
|
2020-01-28 23:43:11 +01:00
|
|
|
} else if ctx.Config().IsEnvTrue("AUTO_UNINITIALIZE") {
|
|
|
|
flags = append(flags, "-ftrivial-auto-var-init=uninitialized")
|
2020-01-31 00:06:00 +01:00
|
|
|
} else {
|
|
|
|
// Default to pattern initialization.
|
|
|
|
flags = append(flags, "-ftrivial-auto-var-init=pattern")
|
2019-06-11 02:40:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Join(flags, " ")
|
|
|
|
})
|
|
|
|
|
2019-01-17 23:44:05 +01:00
|
|
|
pctx.VariableFunc("DeviceClangGlobalCflags", func(ctx android.PackageVarContext) string {
|
|
|
|
if ctx.Config().Fuchsia() {
|
|
|
|
return strings.Join(ClangFilterUnknownCflags(deviceGlobalCflags), " ")
|
|
|
|
} else {
|
|
|
|
return strings.Join(append(ClangFilterUnknownCflags(deviceGlobalCflags), "${ClangExtraTargetCflags}"), " ")
|
|
|
|
}
|
|
|
|
})
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("HostClangGlobalCflags",
|
|
|
|
strings.Join(ClangFilterUnknownCflags(hostGlobalCflags), " "))
|
|
|
|
pctx.StaticVariable("NoOverrideClangGlobalCflags",
|
|
|
|
strings.Join(append(ClangFilterUnknownCflags(noOverrideGlobalCflags), "${ClangExtraNoOverrideCflags}"), " "))
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("CommonClangGlobalCppflags",
|
|
|
|
strings.Join(append(ClangFilterUnknownCflags(commonGlobalCppflags), "${ClangExtraCppflags}"), " "))
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2018-06-06 23:42:44 +02:00
|
|
|
pctx.StaticVariable("ClangExternalCflags", "${ClangExtraExternalCflags}")
|
|
|
|
|
2016-09-15 18:30:46 +02:00
|
|
|
// Everything in these lists is a crime against abstraction and dependency tracking.
|
2016-07-29 21:48:20 +02:00
|
|
|
// Do not add anything to this list.
|
2017-04-11 00:47:24 +02:00
|
|
|
pctx.PrefixedExistentPathsForSourcesVariable("CommonGlobalIncludes", "-I",
|
2016-09-23 00:29:50 +02:00
|
|
|
[]string{
|
2016-09-23 17:48:51 +02:00
|
|
|
"system/core/include",
|
2016-10-05 21:36:42 +02:00
|
|
|
"system/media/audio/include",
|
2016-10-05 21:36:42 +02:00
|
|
|
"hardware/libhardware/include",
|
2016-11-03 23:45:34 +01:00
|
|
|
"hardware/libhardware_legacy/include",
|
|
|
|
"hardware/ril/include",
|
2016-10-05 21:36:42 +02:00
|
|
|
"frameworks/native/include",
|
2016-12-14 20:13:16 +01:00
|
|
|
"frameworks/native/opengl/include",
|
2016-07-29 21:48:20 +02:00
|
|
|
"frameworks/av/include",
|
|
|
|
})
|
|
|
|
// This is used by non-NDK modules to get jni.h. export_include_dirs doesn't help
|
|
|
|
// with this, since there is no associated library.
|
2017-04-11 00:47:24 +02:00
|
|
|
pctx.PrefixedExistentPathsForSourcesVariable("CommonNativehelperInclude", "-I",
|
2017-09-25 20:22:02 +02:00
|
|
|
[]string{"libnativehelper/include_jni"})
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2017-05-23 01:11:34 +02:00
|
|
|
pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
|
2018-03-12 21:24:09 +01:00
|
|
|
pctx.VariableFunc("ClangBase", func(ctx android.PackageVarContext) string {
|
|
|
|
if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
|
|
|
|
return override
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
2018-03-12 21:24:09 +01:00
|
|
|
return "${ClangDefaultBase}"
|
2016-07-29 21:48:20 +02:00
|
|
|
})
|
2018-03-12 21:24:09 +01:00
|
|
|
pctx.VariableFunc("ClangVersion", func(ctx android.PackageVarContext) string {
|
|
|
|
if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
|
|
|
|
return override
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
2018-03-12 21:24:09 +01:00
|
|
|
return ClangDefaultVersion
|
2016-07-29 21:48:20 +02:00
|
|
|
})
|
2016-07-29 22:44:28 +02:00
|
|
|
pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
|
|
|
|
pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
|
|
|
|
|
2018-03-12 21:24:09 +01:00
|
|
|
pctx.VariableFunc("ClangShortVersion", func(ctx android.PackageVarContext) string {
|
|
|
|
if override := ctx.Config().Getenv("LLVM_RELEASE_VERSION"); override != "" {
|
|
|
|
return override
|
2016-11-19 02:12:38 +01:00
|
|
|
}
|
2018-03-12 21:24:09 +01:00
|
|
|
return ClangDefaultShortVersion
|
2016-11-19 02:12:38 +01:00
|
|
|
})
|
2018-01-25 04:58:36 +01:00
|
|
|
pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
|
2016-08-26 21:55:49 +02:00
|
|
|
|
2017-02-02 04:19:52 +01:00
|
|
|
// 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")
|
|
|
|
|
2017-04-11 00:47:24 +02:00
|
|
|
pctx.PrefixedExistentPathsForSourcesVariable("RsGlobalIncludes", "-I",
|
2017-05-02 02:37:24 +02:00
|
|
|
[]string{
|
|
|
|
"external/clang/lib/Headers",
|
|
|
|
"frameworks/rs/script_api/include",
|
|
|
|
})
|
|
|
|
|
2018-03-12 21:24:09 +01:00
|
|
|
pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string {
|
|
|
|
if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" {
|
|
|
|
return override + " "
|
2016-08-26 21:55:49 +02:00
|
|
|
}
|
2018-03-12 21:24:09 +01:00
|
|
|
return ""
|
2016-08-26 21:55:49 +02:00
|
|
|
})
|
2020-04-13 19:21:23 +02:00
|
|
|
|
2020-04-22 03:36:23 +02:00
|
|
|
pctx.VariableFunc("RECXXPool", remoteexec.EnvOverrideFunc("RBE_CXX_POOL", remoteexec.DefaultPool))
|
|
|
|
pctx.VariableFunc("RECXXLinksPool", remoteexec.EnvOverrideFunc("RBE_CXX_LINKS_POOL", remoteexec.DefaultPool))
|
|
|
|
pctx.VariableFunc("RECXXLinksExecStrategy", remoteexec.EnvOverrideFunc("RBE_CXX_LINKS_EXEC_STRATEGY", remoteexec.LocalExecStrategy))
|
|
|
|
pctx.VariableFunc("REAbiDumperExecStrategy", remoteexec.EnvOverrideFunc("RBE_ABI_DUMPER_EXEC_STRATEGY", remoteexec.LocalExecStrategy))
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
|
|
|
|
|
2017-10-12 18:07:53 +02:00
|
|
|
func bionicHeaders(kernelArch string) string {
|
2016-07-29 21:48:20 +02:00
|
|
|
return strings.Join([]string{
|
|
|
|
"-isystem bionic/libc/include",
|
|
|
|
"-isystem bionic/libc/kernel/uapi",
|
|
|
|
"-isystem bionic/libc/kernel/uapi/asm-" + kernelArch,
|
2017-05-26 02:16:10 +02:00
|
|
|
"-isystem bionic/libc/kernel/android/scsi",
|
2016-07-29 21:48:20 +02:00
|
|
|
"-isystem bionic/libc/kernel/android/uapi",
|
|
|
|
}, " ")
|
|
|
|
}
|
2020-04-13 19:21:23 +02:00
|
|
|
|
|
|
|
func envOverrideFunc(envVar, defaultVal string) func(ctx android.PackageVarContext) string {
|
|
|
|
return func(ctx android.PackageVarContext) string {
|
|
|
|
if override := ctx.Config().Getenv(envVar); override != "" {
|
|
|
|
return override
|
|
|
|
}
|
|
|
|
return defaultVal
|
|
|
|
}
|
|
|
|
}
|