Merge "Add dont_merge_manifests attribute to android_test"
diff --git a/apex/apex.go b/apex/apex.go
index 629cbbf..a421850 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1374,6 +1374,8 @@
 			copyCommands = append(copyCommands, "ln -s "+filepath.Base(dest)+" "+symlinkDest)
 		}
 	}
+	emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String())
+
 	implicitInputs := append(android.Paths(nil), filesToCopy...)
 	implicitInputs = append(implicitInputs, a.manifestOut)
 
diff --git a/cc/androidmk.go b/cc/androidmk.go
index a978cb9..f278d6f 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -93,11 +93,6 @@
 					fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
 					if c.isVndk() && !c.static() {
 						fmt.Fprintln(w, "LOCAL_SOONG_VNDK_VERSION := "+c.vndkVersion())
-						// VNDK libraries available to vendor are not installed because
-						// they are packaged in VNDK APEX and installed by APEX packages (apex/apex.go)
-						if !c.isVndkExt() {
-							fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
-						}
 					}
 				}
 			},
@@ -322,6 +317,11 @@
 			filepath.Dir(fuzz.dictionary.String())+":"+fuzz.dictionary.Base())
 	}
 
+	if fuzz.config != nil {
+		fuzzFiles = append(fuzzFiles,
+			filepath.Dir(fuzz.config.String())+":config.json")
+	}
+
 	if len(fuzzFiles) > 0 {
 		ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
 			fmt.Fprintln(w, "LOCAL_TEST_DATA := "+strings.Join(fuzzFiles, " "))
diff --git a/cc/binary.go b/cc/binary.go
index 9f18d6c..b27142c 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -158,7 +158,7 @@
 
 		if binary.static() {
 			if ctx.selectedStl() == "libc++_static" {
-				deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", "libdl")
+				deps.StaticLibs = append(deps.StaticLibs, "libm", "libc")
 			}
 			// static libraries libcompiler_rt, libc and libc_nomalloc need to be linked with
 			// --start-group/--end-group along with libgcc.  If they are in deps.StaticLibs,
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 8418ec7..635e7d0 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -2309,7 +2309,7 @@
 	variant := "android_arm64_armv8-a_core"
 	binModuleRule := ctx.ModuleForTests("static_test", variant).Rule("ld")
 	libFlags := binModuleRule.Args["libFlags"]
-	systemStaticLibs := []string{"libc.a", "libm.a", "libdl.a"}
+	systemStaticLibs := []string{"libc.a", "libm.a"}
 	for _, lib := range systemStaticLibs {
 		if !strings.Contains(libFlags, lib) {
 			t.Errorf("Static lib %q was not found in %q", lib, libFlags)
diff --git a/cc/fuzz.go b/cc/fuzz.go
index a99b0bb..4d38526 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -15,6 +15,7 @@
 package cc
 
 import (
+	"encoding/json"
 	"path/filepath"
 	"strings"
 
@@ -24,12 +25,35 @@
 	"android/soong/cc/config"
 )
 
+type FuzzConfig struct {
+	// Email address of people to CC on bugs or contact about this fuzz target.
+	Cc []string `json:"cc,omitempty"`
+	// Boolean specifying whether to disable the fuzz target from running
+	// automatically in continuous fuzzing infrastructure.
+	Disable *bool `json:"disable,omitempty"`
+	// Component in Google's bug tracking system that bugs should be filed to.
+	Componentid *int64 `json:"componentid,omitempty"`
+	// Hotlists in Google's bug tracking system that bugs should be marked with.
+	Hotlists []string `json:"hotlists,omitempty"`
+}
+
+func (f *FuzzConfig) String() string {
+	b, err := json.Marshal(f)
+	if err != nil {
+		panic(err)
+	}
+
+	return string(b)
+}
+
 type FuzzProperties struct {
 	// Optional list of seed files to be installed to the fuzz target's output
 	// directory.
 	Corpus []string `android:"path"`
 	// Optional dictionary to be installed to the fuzz target's output directory.
 	Dictionary *string `android:"path"`
+	// Config for running the target on fuzzing infrastructure.
+	Fuzz_config *FuzzConfig
 }
 
 func init() {
@@ -57,6 +81,7 @@
 	dictionary            android.Path
 	corpus                android.Paths
 	corpusIntermediateDir android.Path
+	config                android.Path
 }
 
 func (fuzz *fuzzBinary) linkerProps() []interface{} {
@@ -122,6 +147,19 @@
 				fuzz.dictionary.String())
 		}
 	}
+
+	if fuzz.Properties.Fuzz_config != nil {
+		configPath := android.PathForModuleOut(ctx, "config").Join(ctx, "config.txt")
+		ctx.Build(pctx, android.BuildParams{
+			Rule:        android.WriteFile,
+			Description: "fuzzer infrastructure configuration",
+			Output:      configPath,
+			Args: map[string]string{
+				"content": fuzz.Properties.Fuzz_config.String(),
+			},
+		})
+		fuzz.config = configPath
+	}
 }
 
 func NewFuzz(hod android.HostOrDeviceSupported) *Module {
@@ -234,6 +272,12 @@
 			archDirs[archDir] = append(archDirs[archDir],
 				fileToZip{fuzzModule.dictionary, ccModule.Name()})
 		}
+
+		// Additional fuzz config.
+		if fuzzModule.config != nil {
+			archDirs[archDir] = append(archDirs[archDir],
+				fileToZip{fuzzModule.config, ccModule.Name()})
+		}
 	})
 
 	for archDir, filesToZip := range archDirs {
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 5172fc8..3f0f0f4 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -848,12 +848,14 @@
 
 		// Determine the runtime library required
 		runtimeLibrary := ""
+		var extraStaticDeps []string
 		toolchain := c.toolchain(mctx)
 		if Bool(c.sanitize.Properties.Sanitize.Address) {
 			runtimeLibrary = config.AddressSanitizerRuntimeLibrary(toolchain)
 		} else if Bool(c.sanitize.Properties.Sanitize.Hwaddress) {
 			if c.staticBinary() {
 				runtimeLibrary = config.HWAddressSanitizerStaticLibrary(toolchain)
+				extraStaticDeps = []string{"libdl"}
 			} else {
 				runtimeLibrary = config.HWAddressSanitizerRuntimeLibrary(toolchain)
 			}
@@ -887,7 +889,7 @@
 				mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
 					{Mutator: "link", Variation: "static"},
 					{Mutator: "image", Variation: c.imageVariation()},
-				}...), staticDepTag, runtimeLibrary)
+				}...), staticDepTag, append([]string{runtimeLibrary}, extraStaticDeps...)...)
 			} else if !c.static() && !c.header() {
 				// dynamic executable and shared libs get shared runtime libs
 				mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
diff --git a/cc/stl.go b/cc/stl.go
index aa34240..f9273e1 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -175,7 +175,7 @@
 				deps.StaticLibs = append(deps.StaticLibs, "libunwind_llvm")
 			}
 			if ctx.staticBinary() {
-				deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", "libdl")
+				deps.StaticLibs = append(deps.StaticLibs, "libm", "libc")
 			}
 		}
 	case "":
diff --git a/cc/vndk.go b/cc/vndk.go
index 46fd7b1..2997204 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -301,7 +301,7 @@
 	if inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
 		m.Properties.MustUseVendorVariant = true
 	}
-	if mctx.DeviceConfig().VndkUseCoreVariant() && !m.mustUseVendorVariant() {
+	if mctx.DeviceConfig().VndkUseCoreVariant() && !inList(name, vndkMustUseVendorVariantList(mctx.Config())) {
 		vndkUsingCoreVariantLibraries := vndkUsingCoreVariantLibraries(mctx.Config())
 		if !inList(name, *vndkUsingCoreVariantLibraries) {
 			*vndkUsingCoreVariantLibraries = append(*vndkUsingCoreVariantLibraries, name)