Split local and global cflags

Native compiler flags are currently applied in approximately:
global cflags
local cflags
local include dirs
global include dirs
global conlyflags
local conlyflags
global cppflags
local cppflags

This means that a flag that is enabled in the global cppflags
cannot be disabled in the local cflags, and an Android.bp author
must know to disable it in the local cppflags.  A better order
would be:
global cflags
global conlyflags
global cppflags
local cflags
local conlyflags
local cppflags
local include dirs
global include dirs

We are mixing both the global and local cflags into a single
variable, and similar for conlyflags and cppflags, which
prevents reordering them.  This CL prepares to reorder them
by splitting the global and local cflags into separate variables.

Bug: 143713277
Test: m native
Change-Id: Ic55a8c3516c331dc5f2af9d00e59ceca9d3e6c15
This commit is contained in:
Colin Cross
2019-11-04 09:37:55 -08:00
parent 1f056cd69d
commit 4af21ed26f
26 changed files with 286 additions and 259 deletions

View File

@@ -82,7 +82,7 @@ func (lto *lto) useClangLld(ctx BaseModuleContext) bool {
func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
// TODO(b/131771163): Disable LTO when using explicit fuzzing configurations.
// LTO breaks fuzzer builds.
if inList("-fsanitize=fuzzer-no-link", flags.CFlags) {
if inList("-fsanitize=fuzzer-no-link", flags.Local.CFlags) {
return flags
}
@@ -94,27 +94,28 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
ltoFlag = "-flto"
}
flags.CFlags = append(flags.CFlags, ltoFlag)
flags.LdFlags = append(flags.LdFlags, ltoFlag)
flags.Local.CFlags = append(flags.Local.CFlags, ltoFlag)
flags.Local.LdFlags = append(flags.Local.LdFlags, ltoFlag)
if ctx.Config().IsEnvTrue("USE_THINLTO_CACHE") && Bool(lto.Properties.Lto.Thin) && lto.useClangLld(ctx) {
// Set appropriate ThinLTO cache policy
cacheDirFormat := "-Wl,--thinlto-cache-dir="
cacheDir := android.PathForOutput(ctx, "thinlto-cache").String()
flags.LdFlags = append(flags.LdFlags, cacheDirFormat+cacheDir)
flags.Local.LdFlags = append(flags.Local.LdFlags, cacheDirFormat+cacheDir)
// Limit the size of the ThinLTO cache to the lesser of 10% of available
// disk space and 10GB.
cachePolicyFormat := "-Wl,--thinlto-cache-policy="
policy := "cache_size=10%:cache_size_bytes=10g"
flags.LdFlags = append(flags.LdFlags, cachePolicyFormat+policy)
flags.Local.LdFlags = append(flags.Local.LdFlags, cachePolicyFormat+policy)
}
// If the module does not have a profile, be conservative and do not inline
// or unroll loops during LTO, in order to prevent significant size bloat.
if !ctx.isPgoCompile() {
flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-inline-threshold=0")
flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-unroll-threshold=0")
flags.Local.LdFlags = append(flags.Local.LdFlags,
"-Wl,-plugin-opt,-inline-threshold=0",
"-Wl,-plugin-opt,-unroll-threshold=0")
}
}
return flags