Merge "Allow java_host_binary to be used with genrule."
diff --git a/android/register.go b/android/register.go
index 226e790..51089f7 100644
--- a/android/register.go
+++ b/android/register.go
@@ -43,7 +43,7 @@
 
 type ModuleFactory func() Module
 
-// ModuleFactoryAdapter Wraps a ModuleFactory into a blueprint.ModuleFactory by converting an Module
+// ModuleFactoryAdaptor Wraps a ModuleFactory into a blueprint.ModuleFactory by converting an Module
 // into a blueprint.Module and a list of property structs
 func ModuleFactoryAdaptor(factory ModuleFactory) blueprint.ModuleFactory {
 	return func() (blueprint.Module, []interface{}) {
diff --git a/cc/config/clang.go b/cc/config/clang.go
index 977afe1..64bb96e 100644
--- a/cc/config/clang.go
+++ b/cc/config/clang.go
@@ -66,7 +66,7 @@
 })
 
 var ClangLibToolingUnknownCflags = []string{
-	"-flto",
+	"-flto*",
 	"-fsanitize*",
 }
 
diff --git a/cc/library.go b/cc/library.go
index 1434f2c..25872c6 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -70,6 +70,8 @@
 			Version_script *string `android:"arch_variant"`
 		}
 	}
+
+	Static_ndk_lib bool
 }
 
 type LibraryMutatedProperties struct {
@@ -83,6 +85,9 @@
 	VariantIsShared bool `blueprint:"mutated"`
 	// This variant is static
 	VariantIsStatic bool `blueprint:"mutated"`
+	// Location of the static library in the sysroot. Empty if the library is
+	// not included in the NDK.
+	NdkSysrootPath string `blueprint:"mutated"`
 }
 
 type FlagExporterProperties struct {
@@ -721,6 +726,20 @@
 		}
 		library.baseInstaller.install(ctx, file)
 	}
+
+	if library.Properties.Static_ndk_lib && library.static() {
+		installPath := getNdkSysrootBase(ctx).Join(
+			ctx, "usr/lib", ctx.toolchain().ClangTriple(), file.Base())
+
+		ctx.ModuleBuild(pctx, android.ModuleBuildParams{
+			Rule:        android.Cp,
+			Description: "install " + installPath.Base(),
+			Output:      installPath,
+			Input:       file,
+		})
+
+		library.MutatedProperties.NdkSysrootPath = installPath.String()
+	}
 }
 
 func (library *libraryDecorator) static() bool {
diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go
index 5b4cfbe..e213965 100644
--- a/cc/ndk_sysroot.go
+++ b/cc/ndk_sysroot.go
@@ -108,6 +108,12 @@
 			if installer, ok := m.installer.(*stubDecorator); ok {
 				installPaths = append(installPaths, installer.installPath)
 			}
+
+			if library, ok := m.linker.(*libraryDecorator); ok {
+				if library.MutatedProperties.NdkSysrootPath != "" {
+					installPaths = append(installPaths, library.MutatedProperties.NdkSysrootPath)
+				}
+			}
 		}
 	})
 
diff --git a/java/config/config.go b/java/config/config.go
index 85a753c..c19a705 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -80,9 +80,9 @@
 	pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
 	pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips")
 	pctx.VariableFunc("DxCmd", func(config interface{}) (string, error) {
-		dexer := "dx"
-		if config.(android.Config).Getenv("USE_D8") == "true" {
-			dexer = "d8"
+		dexer := "d8"
+		if config.(android.Config).IsEnvFalse("USE_D8") {
+			dexer = "dx"
 		}
 		if config.(android.Config).UnbundledBuild() || config.(android.Config).IsPdkBuild() {
 			return "prebuilts/build-tools/common/bin/" + dexer, nil