Merge "For JIT-zygote config, add "apex" boot image files to the ART apex."
diff --git a/android/config.go b/android/config.go
index 1cb543d..5c4f0a8 100644
--- a/android/config.go
+++ b/android/config.go
@@ -1027,6 +1027,10 @@
 	return Bool(c.config.productVariables.NativeCoverage)
 }
 
+func (c *deviceConfig) ClangCoverageEnabled() bool {
+	return Bool(c.config.productVariables.ClangCoverage)
+}
+
 func (c *deviceConfig) CoverageEnabledForPath(path string) bool {
 	coverage := false
 	if c.config.productVariables.CoveragePaths != nil {
diff --git a/android/variable.go b/android/variable.go
index 2bf84dd..c588672 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -243,6 +243,7 @@
 	TidyChecks *string `json:",omitempty"`
 
 	NativeCoverage       *bool    `json:",omitempty"`
+	ClangCoverage        *bool    `json:",omitempty"`
 	CoveragePaths        []string `json:",omitempty"`
 	CoverageExcludePaths []string `json:",omitempty"`
 
diff --git a/apex/apex.go b/apex/apex.go
index d908cd3..cfd417d 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1084,7 +1084,7 @@
 }
 
 func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
-	return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled()
+	return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled())
 }
 
 func (a *apexBundle) PreventInstall() {
diff --git a/build_kzip.bash b/build_kzip.bash
index 329825a..008030f 100755
--- a/build_kzip.bash
+++ b/build_kzip.bash
@@ -14,6 +14,7 @@
 
 : ${BUILD_NUMBER:=$(uuidgen)}
 : ${KYTHE_KZIP_ENCODING:=proto}
+export KYTHE_KZIP_ENCODING
 
 # The extraction might fail for some source files, so run with -k and then check that
 # sufficiently many files were generated.
diff --git a/cc/config/global.go b/cc/config/global.go
index 1ce29b9..87314dc 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -166,9 +166,6 @@
 			flags = append(flags, "-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang")
 		} else if ctx.Config().IsEnvTrue("AUTO_PATTERN_INITIALIZE") {
 			flags = append(flags, "-ftrivial-auto-var-init=pattern")
-		} else {
-			// Default to pattern initialization.
-			flags = append(flags, "-ftrivial-auto-var-init=pattern")
 		}
 
 		return strings.Join(flags, " ")
diff --git a/cc/config/vndk.go b/cc/config/vndk.go
index 3b16c78..52bd9f0 100644
--- a/cc/config/vndk.go
+++ b/cc/config/vndk.go
@@ -18,56 +18,20 @@
 // For these libraries, the vendor variants must be installed even if the device
 // has VndkUseCoreVariant set.
 var VndkMustUseVendorVariantList = []string{
-	"android.frameworks.sensorservice@1.0",
-	"android.hardware.atrace@1.0",
-	"android.hardware.audio.common@5.0",
-	"android.hardware.audio.effect@2.0",
-	"android.hardware.audio.effect@4.0",
-	"android.hardware.audio.effect@5.0",
-	"android.hardware.audio@2.0",
-	"android.hardware.audio@4.0",
-	"android.hardware.audio@5.0",
 	"android.hardware.automotive.evs@1.0",
 	"android.hardware.automotive.vehicle@2.0",
-	"android.hardware.bluetooth.audio@2.0",
-	"android.hardware.boot@1.0",
-	"android.hardware.broadcastradio@1.0",
-	"android.hardware.broadcastradio@1.1",
 	"android.hardware.broadcastradio@2.0",
 	"android.hardware.camera.device@1.0",
 	"android.hardware.camera.device@3.2",
 	"android.hardware.camera.device@3.3",
 	"android.hardware.camera.device@3.4",
 	"android.hardware.camera.provider@2.4",
-	"android.hardware.cas.native@1.0",
-	"android.hardware.cas@1.0",
-	"android.hardware.configstore@1.0",
-	"android.hardware.configstore@1.1",
-	"android.hardware.contexthub@1.0",
-	"android.hardware.drm@1.0",
-	"android.hardware.drm@1.1",
 	"android.hardware.fastboot@1.0",
-	"android.hardware.gatekeeper@1.0",
-	"android.hardware.gnss@1.0",
-	"android.hardware.graphics.allocator@2.0",
-	"android.hardware.graphics.bufferqueue@1.0",
-	"android.hardware.graphics.composer@2.1",
-	"android.hardware.graphics.composer@2.2",
-	"android.hardware.health@1.0",
-	"android.hardware.health@2.0",
-	"android.hardware.ir@1.0",
-	"android.hardware.keymaster@3.0",
-	"android.hardware.keymaster@4.0",
-	"android.hardware.light@2.0",
 	"android.hardware.media.bufferpool@1.0",
-	"android.hardware.media.omx@1.0",
-	"android.hardware.memtrack@1.0",
 	"android.hardware.neuralnetworks@1.0",
 	"android.hardware.neuralnetworks@1.1",
 	"android.hardware.neuralnetworks@1.2",
 	"android.hardware.neuralnetworks@1.3",
-	"android.hardware.nfc@1.0",
-	"android.hardware.nfc@1.1",
 	"android.hardware.nfc@1.2",
 	"android.hardware.oemlock@1.0",
 	"android.hardware.power.stats@1.0",
@@ -82,51 +46,31 @@
 	"android.hardware.soundtrigger@2.1",
 	"android.hardware.tetheroffload.config@1.0",
 	"android.hardware.tetheroffload.control@1.0",
-	"android.hardware.thermal@1.0",
-	"android.hardware.tv.cec@1.0",
-	"android.hardware.tv.input@1.0",
 	"android.hardware.vibrator-ndk_platform",
-	"android.hardware.vibrator@1.0",
-	"android.hardware.vibrator@1.1",
-	"android.hardware.vibrator@1.2",
 	"android.hardware.weaver@1.0",
 	"android.hardware.wifi.hostapd@1.0",
 	"android.hardware.wifi.offload@1.0",
 	"android.hardware.wifi.supplicant@1.0",
 	"android.hardware.wifi.supplicant@1.1",
-	"android.hardware.wifi@1.0",
 	"android.hardware.wifi@1.1",
 	"android.hardware.wifi@1.2",
 	"android.hardwareundtrigger@2.0",
 	"android.hardwareundtrigger@2.0-core",
 	"android.hardwareundtrigger@2.1",
-	"android.hidl.allocator@1.0",
-	"android.hidl.token@1.0",
-	"android.hidl.token@1.0-utils",
-	"android.system.net.netd@1.0",
-	"android.system.wifi.keystore@1.0",
 	"libaudioroute",
-	"libaudioutils",
 	"libbinder",
 	"libcamera_metadata",
 	"libcrypto",
-	"libdiskconfig",
-	"libdumpstateutil",
 	"libexpat",
-	"libfmq",
 	"libgatekeeper",
 	"libgui",
 	"libhidlcache",
 	"libkeymaster_messages",
 	"libkeymaster_portable",
-	"libmedia_helper",
 	"libmedia_omx",
-	"libmemtrack",
-	"libnetutils",
 	"libprotobuf-cpp-full",
 	"libprotobuf-cpp-lite",
 	"libpuresoftkeymasterdevice",
-	"libradio_metadata",
 	"libselinux",
 	"libsoftkeymasterdevice",
 	"libsqlite",
@@ -161,11 +105,8 @@
 	"libstagefright_soft_vpxdec",
 	"libstagefright_soft_vpxenc",
 	"libstagefright_xmlparser",
-	"libsysutils",
-	"libtinyxml2",
 	"libui",
 	"libvorbisidec",
 	"libxml2",
 	"libyuv",
-	"libziparchive",
 }
diff --git a/cc/coverage.go b/cc/coverage.go
index b6451ee..b94b628 100644
--- a/cc/coverage.go
+++ b/cc/coverage.go
@@ -43,7 +43,7 @@
 	return []interface{}{&cov.Properties}
 }
 
-func getProfileLibraryName(ctx ModuleContextIntf) string {
+func getGcovProfileLibraryName(ctx ModuleContextIntf) string {
 	// This function should only ever be called for a cc.Module, so the
 	// following statement should always succeed.
 	if ctx.useSdk() {
@@ -53,28 +53,47 @@
 	}
 }
 
+func getClangProfileLibraryName(ctx ModuleContextIntf) string {
+	if ctx.useSdk() {
+		return "libprofile-clang-extras_ndk"
+	} else {
+		return "libprofile-clang-extras"
+	}
+}
+
 func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps {
 	if cov.Properties.NeedCoverageVariant {
 		ctx.AddVariationDependencies([]blueprint.Variation{
 			{Mutator: "link", Variation: "static"},
-		}, coverageDepTag, getProfileLibraryName(ctx))
+		}, coverageDepTag, getGcovProfileLibraryName(ctx))
+		ctx.AddVariationDependencies([]blueprint.Variation{
+			{Mutator: "link", Variation: "static"},
+		}, coverageDepTag, getClangProfileLibraryName(ctx))
 	}
 	return deps
 }
 
 func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
-	if !ctx.DeviceConfig().NativeCoverageEnabled() {
+	gcovCoverage := ctx.DeviceConfig().NativeCoverageEnabled()
+	clangCoverage := ctx.DeviceConfig().ClangCoverageEnabled()
+
+	if !gcovCoverage && !clangCoverage {
 		return flags, deps
 	}
 
 	if cov.Properties.CoverageEnabled {
 		flags.Coverage = true
-		flags.Local.CommonFlags = append(flags.Local.CommonFlags, "--coverage", "-O0")
 		cov.linkCoverage = true
 
-		// Override -Wframe-larger-than and non-default optimization
-		// flags that the module may use.
-		flags.Local.CFlags = append(flags.Local.CFlags, "-Wno-frame-larger-than=", "-O0")
+		if gcovCoverage {
+			flags.Local.CommonFlags = append(flags.Local.CommonFlags, "--coverage", "-O0")
+
+			// Override -Wframe-larger-than and non-default optimization
+			// flags that the module may use.
+			flags.Local.CFlags = append(flags.Local.CFlags, "-Wno-frame-larger-than=", "-O0")
+		} else if clangCoverage {
+			flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-fprofile-instr-generate", "-fcoverage-mapping")
+		}
 	}
 
 	// Even if we don't have coverage enabled, if any of our object files were compiled
@@ -112,12 +131,19 @@
 	}
 
 	if cov.linkCoverage {
-		flags.Local.LdFlags = append(flags.Local.LdFlags, "--coverage")
+		if gcovCoverage {
+			flags.Local.LdFlags = append(flags.Local.LdFlags, "--coverage")
 
-		coverage := ctx.GetDirectDepWithTag(getProfileLibraryName(ctx), coverageDepTag).(*Module)
-		deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
+			coverage := ctx.GetDirectDepWithTag(getGcovProfileLibraryName(ctx), coverageDepTag).(*Module)
+			deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
 
-		flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,getenv")
+			flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,getenv")
+		} else if clangCoverage {
+			flags.Local.LdFlags = append(flags.Local.LdFlags, "-fprofile-instr-generate")
+
+			coverage := ctx.GetDirectDepWithTag(getClangProfileLibraryName(ctx), coverageDepTag).(*Module)
+			deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
+		}
 	}
 
 	return flags, deps
@@ -125,7 +151,7 @@
 
 func (cov *coverage) begin(ctx BaseModuleContext) {
 	// Coverage is disabled globally
-	if !ctx.DeviceConfig().NativeCoverageEnabled() {
+	if !ctx.DeviceConfig().NativeCoverageEnabled() && !ctx.DeviceConfig().ClangCoverageEnabled() {
 		return
 	}