.vendor suffix is added only for libs having core/vendor variants

When the lib is vendor-only, then .vendor suffix is not added.
Furthermore, this change correctly adds .vendor suffix even to the names
listed in LOCAL_SHARED_LIBRARIES so that we don't need to add the suffix
in the make world.

This also allows us to use the original name (without the .vendor
suffix) of the vendor-only modules in make (e.g. in PRODUCT_PACKAGES or
as a make target).

Bug: 37480243
Test: BOARD_VNDK_VERSION=current m -j <name> is successful, where <name>
is one of the vendor-only libraries in Soong. (i.e.
android.hardware.renderscript@1.0-impl)
Test: m -j does not break anything

Change-Id: I203e546ff941878a40c5e7cfbb9f70b617df272d
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 385b565..1fcb32c 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -116,7 +116,8 @@
 type sanitize struct {
 	Properties SanitizeProperties
 
-	runtimeLibrary string
+	runtimeLibrary          string
+	androidMkRuntimeLibrary string
 }
 
 func (sanitize *sanitize) props() []interface{} {
@@ -419,12 +420,18 @@
 		runtimeLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(ctx.toolchain())
 	}
 
-	// ASan runtime library must be the first in the link order.
 	if runtimeLibrary != "" {
+		// ASan runtime library must be the first in the link order.
 		flags.libFlags = append([]string{
 			"${config.ClangAsanLibDir}/" + runtimeLibrary + ctx.toolchain().ShlibSuffix(),
 		}, flags.libFlags...)
 		sanitize.runtimeLibrary = runtimeLibrary
+
+		// When linking against VNDK, use the vendor variant of the runtime lib
+		sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary
+		if ctx.vndk() {
+			sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary + vendorSuffix
+		}
 	}
 
 	blacklist := android.OptionalPathForModuleSrc(ctx, sanitize.Properties.Sanitize.Blacklist)
@@ -438,8 +445,8 @@
 
 func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
 	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
-		if sanitize.runtimeLibrary != "" {
-			fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES += "+sanitize.runtimeLibrary)
+		if sanitize.androidMkRuntimeLibrary != "" {
+			fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES += "+sanitize.androidMkRuntimeLibrary)
 		}
 
 		return nil