LTO Bp2build

Bug: 261733821
Test: Unit Tests
Change-Id: I8c3721d35c464e296012145b2e95a7f0866aac37
This commit is contained in:
Trevor Radcliffe
2023-02-06 21:58:30 +00:00
parent 7720f5704c
commit 56b1a2b575
6 changed files with 636 additions and 0 deletions

View File

@@ -817,6 +817,7 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
compilerAttrs.hdrs.Prepend = true
features := compilerAttrs.features.Clone().Append(linkerAttrs.features).Append(bp2buildSanitizerFeatures(ctx, module))
features = features.Append(bp2buildLtoFeatures(ctx, module))
features.DeduplicateAxesFromBase()
addMuslSystemDynamicDeps(ctx, linkerAttrs)
@@ -1459,3 +1460,49 @@ func bp2buildSanitizerFeatures(ctx android.BazelConversionPathContext, m *Module
})
return sanitizerFeatures
}
func bp2buildLtoFeatures(ctx android.BazelConversionPathContext, m *Module) bazel.StringListAttribute {
lto_feature_name := "android_thin_lto"
ltoBoolFeatures := bazel.BoolAttribute{}
bp2BuildPropParseHelper(ctx, m, &LTOProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
if ltoProps, ok := props.(*LTOProperties); ok {
thinProp := ltoProps.Lto.Thin != nil && *ltoProps.Lto.Thin
thinPropSetToFalse := ltoProps.Lto.Thin != nil && !*ltoProps.Lto.Thin
neverProp := ltoProps.Lto.Never != nil && *ltoProps.Lto.Never
if thinProp {
ltoBoolFeatures.SetSelectValue(axis, config, BoolPtr(true))
return
}
if neverProp || thinPropSetToFalse {
if thinProp {
ctx.ModuleErrorf("lto.thin and lto.never are mutually exclusive but were specified together")
} else {
ltoBoolFeatures.SetSelectValue(axis, config, BoolPtr(false))
}
return
}
}
ltoBoolFeatures.SetSelectValue(axis, config, nil)
})
props := m.GetArchVariantProperties(ctx, &LTOProperties{})
ltoStringFeatures, err := ltoBoolFeatures.ToStringListAttribute(func(boolPtr *bool, axis bazel.ConfigurationAxis, config string) []string {
if boolPtr == nil {
return []string{}
}
if !*boolPtr {
return []string{"-" + lto_feature_name}
}
features := []string{lto_feature_name}
if ltoProps, ok := props[axis][config].(*LTOProperties); ok {
if ltoProps.Whole_program_vtables != nil && *ltoProps.Whole_program_vtables {
features = append(features, "android_thin_lto_whole_program_vtables")
}
}
return features
})
if err != nil {
ctx.ModuleErrorf("Error processing LTO attributes: %s", err)
}
return ltoStringFeatures
}