Merge "Make apex_key HostAndDeviceDefault"
diff --git a/android/config.go b/android/config.go
index 0c9f957..ed05c72 100644
--- a/android/config.go
+++ b/android/config.go
@@ -1048,3 +1048,7 @@
 func (c *config) ProductHiddenAPIStubsTest() []string {
 	return c.productVariables.ProductHiddenAPIStubsTest
 }
+
+func (c *deviceConfig) TargetFSConfigGen() *string {
+	return c.config.productVariables.TargetFSConfigGen
+}
diff --git a/android/variable.go b/android/variable.go
index 16d7b13..666f29f 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -287,6 +287,8 @@
 	ProductHiddenAPIStubs       []string `json:",omitempty"`
 	ProductHiddenAPIStubsSystem []string `json:",omitempty"`
 	ProductHiddenAPIStubsTest   []string `json:",omitempty"`
+
+	TargetFSConfigGen *string `json:",omitempty"`
 }
 
 func boolPtr(v bool) *bool {
diff --git a/bpf/bpf.go b/bpf/bpf.go
index 073f62d..13468c7 100644
--- a/bpf/bpf.go
+++ b/bpf/bpf.go
@@ -91,7 +91,7 @@
 			},
 		})
 
-		bpf.objs = append(bpf.objs, obj)
+		bpf.objs = append(bpf.objs, obj.WithoutRel())
 	}
 }
 
diff --git a/cc/builder.go b/cc/builder.go
index e643584..65369d6 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -709,7 +709,7 @@
 }
 
 func SourceAbiDiff(ctx android.ModuleContext, inputDump android.Path, referenceDump android.Path,
-	baseName, exportedHeaderFlags string, isLlndk, isVndkExt bool) android.OptionalPath {
+	baseName, exportedHeaderFlags string, isLlndk, isNdk, isVndkExt bool) android.OptionalPath {
 
 	outputFile := android.PathForModuleOut(ctx, baseName+".abidiff")
 	libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
@@ -719,9 +719,14 @@
 	if exportedHeaderFlags == "" {
 		localAbiCheckAllowFlags = append(localAbiCheckAllowFlags, "-advice-only")
 	}
-	if isLlndk {
-		localAbiCheckAllowFlags = append(localAbiCheckAllowFlags, "-consider-opaque-types-different")
+	if isLlndk || isNdk {
 		createReferenceDumpFlags = "--llndk"
+		if isLlndk {
+			// TODO(b/130324828): "-consider-opaque-types-different" should apply to
+			// both LLNDK and NDK shared libs. However, a known issue in header-abi-diff
+			// breaks libaaudio. Remove the if-guard after the issue is fixed.
+			localAbiCheckAllowFlags = append(localAbiCheckAllowFlags, "-consider-opaque-types-different")
+		}
 	}
 	if isVndkExt {
 		localAbiCheckAllowFlags = append(localAbiCheckAllowFlags, "-allow-extensions")
diff --git a/cc/config/global.go b/cc/config/global.go
index 78f24f2..8fc9ff2 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -83,6 +83,7 @@
 		"-Wl,--warn-shared-textrel",
 		"-Wl,--fatal-warnings",
 		"-Wl,--no-undefined-version",
+		"-Wl,--exclude-libs,libgcc.a",
 	}
 
 	deviceGlobalLldflags = append(ClangFilterUnknownLldflags(deviceGlobalLdflags),
diff --git a/cc/library.go b/cc/library.go
index cf20747..a594b91 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -804,7 +804,7 @@
 		refAbiDumpFile := getRefAbiDumpFile(ctx, vndkVersion, fileName)
 		if refAbiDumpFile != nil {
 			library.sAbiDiff = SourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
-				refAbiDumpFile, fileName, exportedHeaderFlags, ctx.isLlndk(), ctx.isVndkExt())
+				refAbiDumpFile, fileName, exportedHeaderFlags, ctx.isLlndk(), ctx.isNdk(), ctx.isVndkExt())
 		}
 	}
 }
diff --git a/cc/stl.go b/cc/stl.go
index e59f677..1a5dd79 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -245,7 +245,10 @@
 		ndkSrcRoot := android.PathForSource(ctx, "prebuilts/ndk/current/sources/cxx-stl/system/include")
 		flags.CFlags = append(flags.CFlags, "-isystem "+ndkSrcRoot.String())
 	case "ndk_libc++_shared", "ndk_libc++_static":
-		// Nothing.
+		if ctx.Arch().ArchType == android.Arm {
+			// Make sure the _Unwind_XXX symbols are not re-exported.
+			flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,libunwind.a")
+		}
 	case "":
 		// None or error.
 		if !ctx.toolchain().Bionic() {
diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go
index a399b28..c2ad944 100644
--- a/cmd/pom2bp/pom2bp.go
+++ b/cmd/pom2bp/pom2bp.go
@@ -328,6 +328,9 @@
     {{- if .IsAar}}
     min_sdk_version: "{{.MinSdkVersion}}",
     static_libs: [
+        {{- range .BpJarDeps}}
+        "{{.}}",
+        {{- end}}
         {{- range .BpAarDeps}}
         "{{.}}",
         {{- end}}
@@ -349,7 +352,7 @@
     {{- end}}
     static_libs: [
         "{{.BpName}}-nodeps",
-         {{- range .BpJarDeps}}
+        {{- range .BpJarDeps}}
         "{{.}}",
         {{- end}}
         {{- range .BpAarDeps}}
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go
index a23b477..e857fe8 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -57,6 +57,7 @@
 	dir          android.OutputPath
 	symbolsDir   android.OutputPath
 	images       map[android.ArchType]android.OutputPath
+	zip          android.WritablePath
 }
 
 type bootImage struct {
@@ -187,6 +188,8 @@
 
 	profile := bootImageProfileRule(ctx, image, missingDeps)
 
+	var allFiles android.Paths
+
 	if !global.DisablePreopt {
 		targets := ctx.Config().Targets[android.Android]
 		if ctx.Config().SecondArchIsTranslated() {
@@ -194,15 +197,27 @@
 		}
 
 		for _, target := range targets {
-			buildBootImageRuleForArch(ctx, image, target.Arch.ArchType, profile, missingDeps)
+			files := buildBootImageRuleForArch(ctx, image, target.Arch.ArchType, profile, missingDeps)
+			allFiles = append(allFiles, files.Paths()...)
 		}
 	}
 
+	if image.zip != nil {
+		rule := android.NewRuleBuilder()
+		rule.Command().
+			Tool(ctx.Config().HostToolPath(ctx, "soong_zip")).
+			FlagWithOutput("-o ", image.zip).
+			FlagWithArg("-C ", image.dir.String()).
+			FlagWithInputList("-f ", allFiles, " -f ")
+
+		rule.Build(pctx, ctx, "zip_"+image.name, "zip "+image.name+" image")
+	}
+
 	return image
 }
 
 func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage,
-	arch android.ArchType, profile android.Path, missingDeps []string) {
+	arch android.ArchType, profile android.Path, missingDeps []string) android.WritablePaths {
 
 	global := dexpreoptGlobalConfig(ctx)
 
@@ -290,6 +305,8 @@
 	var vdexInstalls android.RuleBuilderInstalls
 	var unstrippedInstalls android.RuleBuilderInstalls
 
+	var zipFiles android.WritablePaths
+
 	// dex preopt on the bootclasspath produces multiple files.  The first dex file
 	// is converted into to 'name'.art (to match the legacy assumption that 'name'.art
 	// exists), and the rest are converted to 'name'-<jar>.art.
@@ -308,6 +325,8 @@
 
 		extraFiles = append(extraFiles, art, oat, vdex, unstrippedOat)
 
+		zipFiles = append(zipFiles, art, oat, vdex)
+
 		// Install the .oat and .art files.
 		rule.Install(art, filepath.Join(installDir, art.Base()))
 		rule.Install(oat, filepath.Join(installDir, oat.Base()))
@@ -331,6 +350,8 @@
 	image.installs[arch] = rule.Installs()
 	image.vdexInstalls[arch] = vdexInstalls
 	image.unstrippedInstalls[arch] = unstrippedInstalls
+
+	return zipFiles
 }
 
 const failureMessage = `ERROR: Dex2oat failed to compile a boot image.
@@ -443,6 +464,7 @@
 		ctx.Strict("DEXPREOPT_IMAGE_PROFILE_BUILT_INSTALLED", image.profileInstalls.String())
 		ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_FILES", strings.Join(image.dexPaths.Strings(), " "))
 		ctx.Strict("DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS", strings.Join(image.dexLocations, " "))
+		ctx.Strict("DEXPREOPT_IMAGE_ZIP_"+image.name, image.zip.String())
 
 		var imageNames []string
 		for _, current := range append(d.otherImages, image) {
@@ -452,6 +474,8 @@
 				ctx.Strict("DEXPREOPT_IMAGE_"+current.name+"_"+arch.String(), current.images[arch].String())
 				ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.installs[arch].String())
 				ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.unstrippedInstalls[arch].String())
+				if current.zip != nil {
+				}
 			}
 		}
 		ctx.Strict("DEXPREOPT_IMAGE_NAMES", strings.Join(imageNames, " "))
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go
index 409b4b1..b30bd00 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -111,6 +111,7 @@
 		dir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_bootjars")
 		symbolsDir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_bootjars_unstripped")
 		images := make(map[android.ArchType]android.OutputPath)
+		zip := dir.Join(ctx, "boot.zip")
 
 		for _, target := range ctx.Config().Targets[android.Android] {
 			images[target.Arch.ArchType] = dir.Join(ctx,
@@ -125,6 +126,7 @@
 			dir:          dir,
 			symbolsDir:   symbolsDir,
 			images:       images,
+			zip:          zip,
 		}
 	}).(bootImageConfig)
 }
diff --git a/java/kotlin.go b/java/kotlin.go
index 054998f..54c6b0e 100644
--- a/java/kotlin.go
+++ b/java/kotlin.go
@@ -27,11 +27,12 @@
 
 var kotlinc = pctx.AndroidGomaStaticRule("kotlinc",
 	blueprint.RuleParams{
-		Command: `rm -rf "$classesDir" "$srcJarDir" "$kotlinBuildFile" && mkdir -p "$classesDir" "$srcJarDir" && ` +
+		Command: `rm -rf "$classesDir" "$srcJarDir" "$kotlinBuildFile" "$emptyDir" && ` +
+			`mkdir -p "$classesDir" "$srcJarDir" "$emptyDir" && ` +
 			`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
 			`${config.GenKotlinBuildFileCmd} $classpath $classesDir $out.rsp $srcJarDir/list > $kotlinBuildFile &&` +
 			`${config.KotlincCmd} ${config.JavacHeapFlags} $kotlincFlags ` +
-			`-jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile && ` +
+			`-jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile -kotlin-home $emptyDir && ` +
 			`${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir && ` +
 			`rm -rf "$srcJarDir"`,
 		CommandDeps: []string{
@@ -49,7 +50,7 @@
 		Rspfile:        "$out.rsp",
 		RspfileContent: `$in`,
 	},
-	"kotlincFlags", "classpath", "srcJars", "srcJarDir", "classesDir", "kotlinJvmTarget", "kotlinBuildFile")
+	"kotlincFlags", "classpath", "srcJars", "srcJarDir", "classesDir", "kotlinJvmTarget", "kotlinBuildFile", "emptyDir")
 
 // kotlinCompile takes .java and .kt sources and srcJars, and compiles the .kt sources into a classes jar in outputFile.
 func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath,
@@ -73,6 +74,7 @@
 			"classesDir":      android.PathForModuleOut(ctx, "kotlinc", "classes").String(),
 			"srcJarDir":       android.PathForModuleOut(ctx, "kotlinc", "srcJars").String(),
 			"kotlinBuildFile": android.PathForModuleOut(ctx, "kotlinc-build.xml").String(),
+			"emptyDir":        android.PathForModuleOut(ctx, "kotlinc", "empty").String(),
 			// http://b/69160377 kotlinc only supports -jvm-target 1.6 and 1.8
 			"kotlinJvmTarget": "1.8",
 		},