diff --git a/android/arch.go b/android/arch.go index f0f0ea364..b653ce6bc 100644 --- a/android/arch.go +++ b/android/arch.go @@ -274,6 +274,7 @@ func ArchMutator(mctx BottomUpMutatorContext) { } var moduleTargets []Target + primaryModules := make(map[int]bool) for _, class := range osClasses { targets := mctx.AConfig().Targets[class] @@ -293,11 +294,18 @@ func ArchMutator(mctx BottomUpMutatorContext) { if multilib == "" { multilib = module.base().commonProperties.Default_multilib } - targets, err := decodeMultilib(multilib, targets) + prefer32 := false + if class == Device { + prefer32 = mctx.AConfig().DevicePrefer32BitExecutables() + } + targets, err := decodeMultilib(multilib, targets, prefer32) if err != nil { mctx.ModuleErrorf("%s", err.Error()) } - moduleTargets = append(moduleTargets, targets...) + if len(targets) > 0 { + primaryModules[len(moduleTargets)] = true + moduleTargets = append(moduleTargets, targets...) + } } if len(moduleTargets) == 0 { @@ -313,7 +321,7 @@ func ArchMutator(mctx BottomUpMutatorContext) { modules := mctx.CreateVariations(targetNames...) for i, m := range modules { - m.(Module).base().SetTarget(moduleTargets[i]) + m.(Module).base().SetTarget(moduleTargets[i], primaryModules[i]) m.(Module).base().setArchProperties(mctx) } } @@ -915,15 +923,26 @@ func filterMultilibTargets(targets []Target, multilib string) []Target { } // Use the module multilib setting to select one or more targets from a target list -func decodeMultilib(multilib string, targets []Target) ([]Target, error) { +func decodeMultilib(multilib string, targets []Target, prefer32 bool) ([]Target, error) { buildTargets := []Target{} + if multilib == "first" { + if prefer32 { + multilib = "prefer32" + } else { + multilib = "prefer64" + } + } switch multilib { case "common": buildTargets = append(buildTargets, commonTarget) case "both": - buildTargets = append(buildTargets, targets...) - case "first": - buildTargets = append(buildTargets, targets[0]) + if prefer32 { + buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) + buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) + } else { + buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) + buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) + } case "32": buildTargets = filterMultilibTargets(targets, "lib32") case "64": @@ -933,6 +952,11 @@ func decodeMultilib(multilib string, targets []Target) ([]Target, error) { if len(buildTargets) == 0 { buildTargets = filterMultilibTargets(targets, "lib64") } + case "prefer64": + buildTargets = filterMultilibTargets(targets, "lib64") + if len(buildTargets) == 0 { + buildTargets = filterMultilibTargets(targets, "lib32") + } default: return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", or "prefer32" found %q`, multilib) diff --git a/android/module.go b/android/module.go index 8c48bd3a3..d3f238387 100644 --- a/android/module.go +++ b/android/module.go @@ -57,6 +57,7 @@ type ModuleBuildParams struct { type androidBaseContext interface { Target() Target + TargetPrimary() bool Arch() Arch Os() OsType Host() bool @@ -145,7 +146,8 @@ type commonProperties struct { Required []string // Set by TargetMutator - CompileTarget Target `blueprint:"mutated"` + CompileTarget Target `blueprint:"mutated"` + CompilePrimary bool `blueprint:"mutated"` // Set by InitAndroidModule HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"` @@ -282,14 +284,19 @@ func (a *ModuleBase) base() *ModuleBase { return a } -func (a *ModuleBase) SetTarget(target Target) { +func (a *ModuleBase) SetTarget(target Target, primary bool) { a.commonProperties.CompileTarget = target + a.commonProperties.CompilePrimary = primary } func (a *ModuleBase) Target() Target { return a.commonProperties.CompileTarget } +func (a *ModuleBase) TargetPrimary() bool { + return a.commonProperties.CompilePrimary +} + func (a *ModuleBase) Os() OsType { return a.Target().Os } @@ -420,8 +427,9 @@ func (a *ModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) { func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl { return androidBaseContextImpl{ - target: a.commonProperties.CompileTarget, - config: ctx.Config().(Config), + target: a.commonProperties.CompileTarget, + targetPrimary: a.commonProperties.CompilePrimary, + config: ctx.Config().(Config), } } @@ -454,9 +462,10 @@ func (a *ModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) { } type androidBaseContextImpl struct { - target Target - debug bool - config Config + target Target + targetPrimary bool + debug bool + config Config } type androidModuleContext struct { @@ -536,6 +545,10 @@ func (a *androidBaseContextImpl) Target() Target { return a.target } +func (a *androidBaseContextImpl) TargetPrimary() bool { + return a.targetPrimary +} + func (a *androidBaseContextImpl) Arch() Arch { return a.target.Arch } diff --git a/cc/binary.go b/cc/binary.go index d31cfd68e..6ad71c624 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -170,11 +170,7 @@ func (binary *binaryDecorator) linkerInit(ctx BaseModuleContext) { if binary.Properties.Stem == "" && binary.Properties.Suffix == "" { ctx.PropertyErrorf("symlink_preferred_arch", "must also specify stem or suffix") } - prefer32 := false - if ctx.Device() { - prefer32 = ctx.AConfig().DevicePrefer32BitExecutables() - } - if ctx.PrimaryArch() != prefer32 { + if ctx.TargetPrimary() { binary.baseInstaller.Properties.Symlinks = append(binary.baseInstaller.Properties.Symlinks, ctx.ModuleName()) }