Fix: deps to sanitizer runtime libs are with correct 'image' variant

This change fixes a bug that sanitizer runtime libs for non-core variant
(e.g. recovery, vendor, etc.) are not installed. It happened because the
dependency to the sanitizer runtime lib was without 'image' variant,
which in most case caused only the core variant - which is the first in
the image variants - of the lib to be installed.

Fixing the issue by correctly selecting image variant depending on the
location of the lib having dependency to the runtime lib.

Bug: 123525879
Test: SANITIZE_TARGET=hwaddress m out/target/product/blueline/boot.img
Test: SANITIZE_TARGET=address m out/target/product/blueline/boot.img
libclang_rt.*.so is under
out/target/product/blueline/root/recovery/system/lib64

Change-Id: Iea7d718d4971e36521f0a3f712a454de944cd7ac
diff --git a/cc/cc.go b/cc/cc.go
index ded89d4..062e6d9 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1175,15 +1175,9 @@
 			depTag = headerExportDepTag
 		}
 		if buildStubs {
-			imageVariation := "core"
-			if c.useVndk() {
-				imageVariation = "vendor"
-			} else if c.inRecovery() {
-				imageVariation = "recovery"
-			}
 			actx.AddFarVariationDependencies([]blueprint.Variation{
 				{Mutator: "arch", Variation: ctx.Target().String()},
-				{Mutator: "image", Variation: imageVariation},
+				{Mutator: "image", Variation: c.imageVariation()},
 			}, depTag, lib)
 		} else {
 			actx.AddVariationDependencies(nil, depTag, lib)
@@ -1845,6 +1839,16 @@
 	return false
 }
 
+func (c *Module) imageVariation() string {
+	variation := "core"
+	if c.useVndk() {
+		variation = "vendor"
+	} else if c.inRecovery() {
+		variation = "recovery"
+	}
+	return variation
+}
+
 //
 // Defaults
 //
diff --git a/cc/sanitize.go b/cc/sanitize.go
index b95e2a8..4576aa1 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -787,7 +787,7 @@
 		}
 
 		if mctx.Device() && runtimeLibrary != "" {
-			if inList(runtimeLibrary, llndkLibraries) && !c.static() {
+			if inList(runtimeLibrary, llndkLibraries) && !c.static() && c.useVndk() {
 				runtimeLibrary = runtimeLibrary + llndkLibrarySuffix
 			}
 
@@ -802,12 +802,14 @@
 				// static executable gets static runtime libs
 				mctx.AddFarVariationDependencies([]blueprint.Variation{
 					{Mutator: "link", Variation: "static"},
+					{Mutator: "image", Variation: c.imageVariation()},
 					{Mutator: "arch", Variation: mctx.Target().String()},
 				}, staticDepTag, runtimeLibrary)
 			} else if !c.static() {
-				// dynamic executable andshared libs get shared runtime libs
+				// dynamic executable and shared libs get shared runtime libs
 				mctx.AddFarVariationDependencies([]blueprint.Variation{
 					{Mutator: "link", Variation: "shared"},
+					{Mutator: "image", Variation: c.imageVariation()},
 					{Mutator: "arch", Variation: mctx.Target().String()},
 				}, earlySharedDepTag, runtimeLibrary)
 			}