VSDK: capture hwasan static libs for vsdk snapshot build

When generating vsdk snapshot with SANITIZE_TARGET=hwaddress option,
include hwasan static libraries to the vendor snapshot.

Bug: 234772527
Test: build against the vsdk with SANITIZE_TARGET=hwaddress
Change-Id: I6fdecefaa8557b5c968745487a3ed7c959e682f9
diff --git a/cc/sanitize.go b/cc/sanitize.go
index eba709b..dc07381 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -1067,6 +1067,11 @@
 // as vendor snapshot. Such modules must create both cfi and non-cfi variants,
 // except for ones which explicitly disable cfi.
 func needsCfiForVendorSnapshot(mctx android.BaseModuleContext) bool {
+	if inList("hwaddress", mctx.Config().SanitizeDevice()) {
+		// cfi will not be built if SANITIZE_TARGET=hwaddress is set
+		return false
+	}
+
 	if snapshot.IsVendorProprietaryModule(mctx) {
 		return false
 	}
diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go
index 2dcf26e..9b12bfa 100644
--- a/cc/vendor_snapshot.go
+++ b/cc/vendor_snapshot.go
@@ -93,17 +93,18 @@
 	// Libraries
 	if sanitizable, ok := m.(PlatformSanitizeable); ok && sanitizable.IsSnapshotLibrary() {
 		if sanitizable.SanitizePropDefined() {
-			// scs and hwasan export both sanitized and unsanitized variants for static and header
-			// Always use unsanitized variants of them.
-			for _, t := range []SanitizerType{scs, Hwasan} {
-				if !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(t) {
-					return false
-				}
+			// scs exports both sanitized and unsanitized variants for static and header
+			// Always use unsanitized variant of it.
+			if !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(scs) {
+				return false
 			}
-			// cfi also exports both variants. But for static, we capture both.
+			// cfi and hwasan also export both variants. But for static, we capture both.
 			// This is because cfi static libraries can't be linked from non-cfi modules,
-			// and vice versa. This isn't the case for scs and hwasan sanitizers.
-			if !sanitizable.Static() && !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(cfi) {
+			// and vice versa.
+			// hwasan is captured as well to support hwasan build.
+			if !sanitizable.Static() &&
+				!sanitizable.Shared() &&
+				(sanitizable.IsSanitizerEnabled(cfi) || sanitizable.IsSanitizerEnabled(Hwasan)) {
 				return false
 			}
 		}
@@ -303,14 +304,22 @@
 				libPath := m.OutputFile().Path()
 				stem = libPath.Base()
 				if sanitizable, ok := m.(PlatformSanitizeable); ok {
-					if (sanitizable.Static() || sanitizable.Rlib()) && sanitizable.SanitizePropDefined() && sanitizable.IsSanitizerEnabled(cfi) {
-						// both cfi and non-cfi variant for static libraries can exist.
-						// attach .cfi to distinguish between cfi and non-cfi.
-						// e.g. libbase.a -> libbase.cfi.a
-						ext := filepath.Ext(stem)
-						stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
-						prop.Sanitize = "cfi"
-						prop.ModuleName += ".cfi"
+					if (sanitizable.Static() || sanitizable.Rlib()) && sanitizable.SanitizePropDefined() {
+						if sanitizable.IsSanitizerEnabled(cfi) {
+							// both cfi and non-cfi variant for static libraries can exist.
+							// attach .cfi to distinguish between cfi and non-cfi.
+							// e.g. libbase.a -> libbase.cfi.a
+							ext := filepath.Ext(stem)
+							stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
+							prop.Sanitize = "cfi"
+							prop.ModuleName += ".cfi"
+						} else if sanitizable.IsSanitizerEnabled(Hwasan) {
+							// Same for the hwasan
+							ext := filepath.Ext(stem)
+							stem = strings.TrimSuffix(stem, ext) + ".hwasan" + ext
+							prop.Sanitize = "hwasan"
+							prop.ModuleName += ".hwasan"
+						}
 					}
 				}
 				snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem)