Merge "Remove Full LTO support"

This commit is contained in:
Yi Kong
2023-06-01 22:46:23 +00:00
committed by Gerrit Code Review

View File

@@ -43,16 +43,13 @@ type LTOProperties struct {
// referred to in blueprint files as "lto" // referred to in blueprint files as "lto"
Lto struct { Lto struct {
Never *bool `android:"arch_variant"` Never *bool `android:"arch_variant"`
Full *bool `android:"arch_variant"`
Thin *bool `android:"arch_variant"` Thin *bool `android:"arch_variant"`
} `android:"arch_variant"` } `android:"arch_variant"`
// Dep properties indicate that this module needs to be built with LTO // Dep properties indicate that this module needs to be built with LTO
// since it is an object dependency of an LTO module. // since it is an object dependency of an LTO module.
FullEnabled bool `blueprint:"mutated"`
ThinEnabled bool `blueprint:"mutated"` ThinEnabled bool `blueprint:"mutated"`
NoLtoEnabled bool `blueprint:"mutated"` NoLtoEnabled bool `blueprint:"mutated"`
FullDep bool `blueprint:"mutated"`
ThinDep bool `blueprint:"mutated"` ThinDep bool `blueprint:"mutated"`
NoLtoDep bool `blueprint:"mutated"` NoLtoDep bool `blueprint:"mutated"`
@@ -86,8 +83,6 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
var ltoLdFlag string var ltoLdFlag string
if lto.ThinLTO() { if lto.ThinLTO() {
ltoCFlag = "-flto=thin -fsplit-lto-unit" ltoCFlag = "-flto=thin -fsplit-lto-unit"
} else if lto.FullLTO() {
ltoCFlag = "-flto"
} else { } else {
ltoCFlag = "-flto=thin -fsplit-lto-unit" ltoCFlag = "-flto=thin -fsplit-lto-unit"
ltoLdFlag = "-Wl,--lto-O0" ltoLdFlag = "-Wl,--lto-O0"
@@ -126,13 +121,13 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
} }
func (lto *lto) LTO(ctx BaseModuleContext) bool { func (lto *lto) LTO(ctx BaseModuleContext) bool {
return lto.ThinLTO() || lto.FullLTO() || lto.DefaultThinLTO(ctx) return lto.ThinLTO() || lto.DefaultThinLTO(ctx)
} }
func (lto *lto) DefaultThinLTO(ctx BaseModuleContext) bool { func (lto *lto) DefaultThinLTO(ctx BaseModuleContext) bool {
// LP32 has many subtle issues and less test coverage. // LP32 has many subtle issues and less test coverage.
lib32 := ctx.Arch().ArchType.Multilib == "lib32" lib32 := ctx.Arch().ArchType.Multilib == "lib32"
// CFI enables full LTO. // CFI adds LTO flags by itself.
cfi := ctx.isCfi() cfi := ctx.isCfi()
// Performance and binary size are less important for host binaries and tests. // Performance and binary size are less important for host binaries and tests.
host := ctx.Host() host := ctx.Host()
@@ -143,10 +138,6 @@ func (lto *lto) DefaultThinLTO(ctx BaseModuleContext) bool {
return GlobalThinLTO(ctx) && !lto.Never() && !lib32 && !cfi && !host && !test && !vndk return GlobalThinLTO(ctx) && !lto.Never() && !lib32 && !cfi && !host && !test && !vndk
} }
func (lto *lto) FullLTO() bool {
return lto != nil && (proptools.Bool(lto.Properties.Lto.Full) || lto.Properties.FullEnabled)
}
func (lto *lto) ThinLTO() bool { func (lto *lto) ThinLTO() bool {
return lto != nil && (proptools.Bool(lto.Properties.Lto.Thin) || lto.Properties.ThinEnabled) return lto != nil && (proptools.Bool(lto.Properties.Lto.Thin) || lto.Properties.ThinEnabled)
} }
@@ -164,12 +155,8 @@ func ltoDepsMutator(mctx android.TopDownMutatorContext) {
globalThinLTO := GlobalThinLTO(mctx) globalThinLTO := GlobalThinLTO(mctx)
if m, ok := mctx.Module().(*Module); ok { if m, ok := mctx.Module().(*Module); ok {
full := m.lto.FullLTO()
thin := m.lto.ThinLTO() thin := m.lto.ThinLTO()
never := m.lto.Never() never := m.lto.Never()
if full && thin {
mctx.PropertyErrorf("LTO", "FullLTO and ThinLTO are mutually exclusive")
}
mctx.WalkDeps(func(dep android.Module, parent android.Module) bool { mctx.WalkDeps(func(dep android.Module, parent android.Module) bool {
tag := mctx.OtherModuleDependencyTag(dep) tag := mctx.OtherModuleDependencyTag(dep)
@@ -187,9 +174,6 @@ func ltoDepsMutator(mctx android.TopDownMutatorContext) {
} }
if dep, ok := dep.(*Module); ok { if dep, ok := dep.(*Module); ok {
if full && !dep.lto.FullLTO() {
dep.lto.Properties.FullDep = true
}
if !globalThinLTO && thin && !dep.lto.ThinLTO() { if !globalThinLTO && thin && !dep.lto.ThinLTO() {
dep.lto.Properties.ThinDep = true dep.lto.Properties.ThinDep = true
} }
@@ -212,9 +196,6 @@ func ltoMutator(mctx android.BottomUpMutatorContext) {
// Create variations for LTO types required as static // Create variations for LTO types required as static
// dependencies // dependencies
variationNames := []string{""} variationNames := []string{""}
if m.lto.Properties.FullDep && !m.lto.FullLTO() {
variationNames = append(variationNames, "lto-full")
}
if !globalThinLTO && m.lto.Properties.ThinDep && !m.lto.ThinLTO() { if !globalThinLTO && m.lto.Properties.ThinDep && !m.lto.ThinLTO() {
variationNames = append(variationNames, "lto-thin") variationNames = append(variationNames, "lto-thin")
} }
@@ -224,13 +205,10 @@ func ltoMutator(mctx android.BottomUpMutatorContext) {
// Use correct dependencies if LTO property is explicitly set // Use correct dependencies if LTO property is explicitly set
// (mutually exclusive) // (mutually exclusive)
if m.lto.FullLTO() {
mctx.SetDependencyVariation("lto-full")
}
if !globalThinLTO && m.lto.ThinLTO() { if !globalThinLTO && m.lto.ThinLTO() {
mctx.SetDependencyVariation("lto-thin") mctx.SetDependencyVariation("lto-thin")
} }
// Never must be the last, it overrides Thin or Full. // Never must be the last, it overrides Thin.
if globalThinLTO && m.lto.Never() { if globalThinLTO && m.lto.Never() {
mctx.SetDependencyVariation("lto-none") mctx.SetDependencyVariation("lto-none")
} }
@@ -247,9 +225,6 @@ func ltoMutator(mctx android.BottomUpMutatorContext) {
} }
// LTO properties for dependencies // LTO properties for dependencies
if name == "lto-full" {
variation.lto.Properties.FullEnabled = true
}
if name == "lto-thin" { if name == "lto-thin" {
variation.lto.Properties.ThinEnabled = true variation.lto.Properties.ThinEnabled = true
} }
@@ -258,7 +233,6 @@ func ltoMutator(mctx android.BottomUpMutatorContext) {
} }
variation.Properties.PreventInstall = true variation.Properties.PreventInstall = true
variation.Properties.HideFromMake = true variation.Properties.HideFromMake = true
variation.lto.Properties.FullDep = false
variation.lto.Properties.ThinDep = false variation.lto.Properties.ThinDep = false
variation.lto.Properties.NoLtoDep = false variation.lto.Properties.NoLtoDep = false
} }