diff --git a/android/arch.go b/android/arch.go index b0389560b..907c58b82 100644 --- a/android/arch.go +++ b/android/arch.go @@ -527,6 +527,7 @@ type Arch struct { CpuVariant string Abi []string ArchFeatures []string + Native bool } func (a Arch) String() string { @@ -1481,6 +1482,11 @@ func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { addTarget(Android, *variables.DeviceSecondaryArch, variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, variables.DeviceSecondaryAbi, NativeBridgeDisabled, nil, nil) + + deviceArches := targets[Android] + if deviceArches[0].Arch.ArchType.Multilib == deviceArches[1].Arch.ArchType.Multilib { + deviceArches[1].Arch.Native = false + } } if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" { @@ -1628,7 +1634,7 @@ func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) { if err != nil { return nil, err } - + arch.Native = false ret = append(ret, Target{ Os: Android, Arch: arch, @@ -1657,6 +1663,7 @@ func decodeArch(os OsType, arch string, archVariant, cpuVariant *string, abi []s ArchVariant: stringPtr(archVariant), CpuVariant: stringPtr(cpuVariant), Abi: abi, + Native: true, } if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" { diff --git a/android/config.go b/android/config.go index 3006064af..cb1bdf52d 100644 --- a/android/config.go +++ b/android/config.go @@ -240,10 +240,10 @@ func TestArchConfigNativeBridge(buildDir string, env map[string]string) Config { config := testConfig.config config.Targets[Android] = []Target{ - {Android, Arch{ArchType: X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", ""}, - {Android, Arch{ArchType: X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", ""}, - {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeEnabled, "x86_64", "arm64"}, - {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeEnabled, "x86", "arm"}, + {Android, Arch{ArchType: X86_64, ArchVariant: "silvermont", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", ""}, + {Android, Arch{ArchType: X86, ArchVariant: "silvermont", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", ""}, + {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridgeEnabled, "x86_64", "arm64"}, + {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridgeEnabled, "x86", "arm"}, } return testConfig @@ -255,7 +255,7 @@ func TestArchConfigFuchsia(buildDir string, env map[string]string) Config { config.Targets = map[OsType][]Target{ Fuchsia: []Target{ - {Fuchsia, Arch{ArchType: Arm64, ArchVariant: ""}, NativeBridgeDisabled, "", ""}, + {Fuchsia, Arch{ArchType: Arm64, ArchVariant: "", Native: true}, NativeBridgeDisabled, "", ""}, }, BuildOs: []Target{ {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", ""}, @@ -272,8 +272,8 @@ func TestArchConfig(buildDir string, env map[string]string) Config { config.Targets = map[OsType][]Target{ Android: []Target{ - {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", ""}, - {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", ""}, + {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", ""}, + {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", ""}, }, BuildOs: []Target{ {BuildOs, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", ""}, @@ -1009,6 +1009,19 @@ func findOverrideValue(overrides []string, name string, errorMsg string) (newVal return "", false } +// SecondArchIsTranslated returns true if the primary device arch is X86 or X86_64 and the device also has an arch +// that is Arm or Arm64. +func (c *config) SecondArchIsTranslated() bool { + deviceTargets := c.Targets[Android] + if len(deviceTargets) < 2 { + return false + } + + arch := deviceTargets[0].Arch + + return (arch.ArchType == X86 || arch.ArchType == X86_64) && hasArmAndroidArch(deviceTargets) +} + func (c *config) IntegerOverflowDisabledForPath(path string) bool { if c.productVariables.IntegerOverflowExcludePaths == nil { return false diff --git a/apex/apex.go b/apex/apex.go index 23f6d3729..4f79c4227 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -829,7 +829,9 @@ func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, ha dirInApex = "lib64" } dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath()) - if ccMod.Target().NativeBridge == android.NativeBridgeEnabled { + if !ccMod.Arch().Native { + dirInApex = filepath.Join(dirInApex, ccMod.Arch().ArchType.String()) + } else if ccMod.Target().NativeBridge == android.NativeBridgeEnabled { dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath) } if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), config) { @@ -852,7 +854,9 @@ func getCopyManifestForNativeLibrary(ccMod *cc.Module, config android.Config, ha func getCopyManifestForExecutable(cc *cc.Module) (fileToCopy android.Path, dirInApex string) { dirInApex = filepath.Join("bin", cc.RelativeInstallPath()) - if cc.Target().NativeBridge == android.NativeBridgeEnabled { + if !cc.Arch().Native { + dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String()) + } else if cc.Target().NativeBridge == android.NativeBridgeEnabled { dirInApex = filepath.Join(dirInApex, cc.Target().NativeBridgeRelativePath) } fileToCopy = cc.OutputFile().Path() diff --git a/apex/apex_test.go b/apex/apex_test.go index 577cf8fe1..7f36f51e1 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -1467,10 +1467,10 @@ func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { } `, withTargets(map[android.OsType][]android.Target{ android.Android: []android.Target{ - {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, - {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, - {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"}, - {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"}, + {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, + {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, + {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Native: true, Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm64", NativeBridgeRelativePath: "x86_64"}, + {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Native: true, Abi: []string{"armeabi-v7a"}}, NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "arm", NativeBridgeRelativePath: "x86"}, }, })) diff --git a/cc/binary.go b/cc/binary.go index 9f18d6c8a..0d6940511 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -453,7 +453,7 @@ func (binary *binaryDecorator) install(ctx ModuleContext, file android.Path) { // Bionic binaries (e.g. linker) is installed to the bootstrap subdirectory. // The original path becomes a symlink to the corresponding file in the // runtime APEX. - translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled + translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled || !ctx.Arch().Native if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !translatedArch && ctx.apexName() == "" && !ctx.inRecovery() { if ctx.Device() && isBionic(ctx.baseModuleName()) { binary.installSymlinkToRuntimeApex(ctx, file) diff --git a/cc/installer.go b/cc/installer.go index 96a113828..a52ccf1fe 100644 --- a/cc/installer.go +++ b/cc/installer.go @@ -66,6 +66,9 @@ func (installer *baseInstaller) installDir(ctx ModuleContext) android.OutputPath if ctx.toolchain().Is64Bit() && installer.dir64 != "" { dir = installer.dir64 } + if !ctx.Host() && !ctx.Arch().Native { + dir = filepath.Join(dir, ctx.Arch().ArchType.String()) + } if ctx.Target().NativeBridge == android.NativeBridgeEnabled { dir = filepath.Join(dir, ctx.Target().NativeBridgeRelativePath) } diff --git a/cc/library.go b/cc/library.go index 43bb1315d..c402ea0c9 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1032,7 +1032,7 @@ func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) { // Bionic libraries (e.g. libc.so) is installed to the bootstrap subdirectory. // The original path becomes a symlink to the corresponding file in the // runtime APEX. - translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled + translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled || !ctx.Arch().Native if InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !library.buildStubs() && !translatedArch && !ctx.inRecovery() { if ctx.Device() { library.installSymlinkToRuntimeApex(ctx, file) diff --git a/java/dexpreopt.go b/java/dexpreopt.go index 8bc9b19ad..6214dac44 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -126,6 +126,10 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo archs = archs[:1] } } + if ctx.Config().SecondArchIsTranslated() { + // Only preopt primary arch for translated arch since there is only an image there. + archs = archs[:1] + } var images android.Paths var imagesDeps []android.Paths diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go index 043f9daed..8c699b83a 100644 --- a/java/dexpreopt_config.go +++ b/java/dexpreopt_config.go @@ -87,7 +87,11 @@ var systemServerClasspathKey = android.NewOnceKey("systemServerClasspath") // supported through native bridge. func dexpreoptTargets(ctx android.PathContext) []android.Target { var targets []android.Target - for _, target := range ctx.Config().Targets[android.Android] { + for i, target := range ctx.Config().Targets[android.Android] { + if ctx.Config().SecondArchIsTranslated() && i > 0 { + break + } + if target.NativeBridge == android.NativeBridgeDisabled { targets = append(targets, target) } diff --git a/python/installer.go b/python/installer.go index 22c06c24d..62f36f4b5 100644 --- a/python/installer.go +++ b/python/installer.go @@ -15,6 +15,8 @@ package python import ( + "path/filepath" + "android/soong/android" ) @@ -50,6 +52,9 @@ func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android. if ctx.Arch().ArchType.Multilib == "lib64" && installer.dir64 != "" { dir = installer.dir64 } + if !ctx.Host() && !ctx.Arch().Native { + dir = filepath.Join(dir, ctx.Arch().ArchType.String()) + } return android.PathForModuleInstall(ctx, dir, installer.relative) } diff --git a/rust/compiler.go b/rust/compiler.go index 4e0118325..87cf08b40 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -157,7 +157,7 @@ func (compiler *baseCompiler) installDir(ctx ModuleContext) android.OutputPath { if ctx.toolchain().Is64Bit() && compiler.dir64 != "" { dir = compiler.dir64 } - if !ctx.Host() || ctx.Target().NativeBridge == android.NativeBridgeEnabled { + if (!ctx.Host() && !ctx.Arch().Native) || ctx.Target().NativeBridge == android.NativeBridgeEnabled { dir = filepath.Join(dir, ctx.Arch().ArchType.String()) } return android.PathForModuleInstall(ctx, dir, compiler.subDir,