rust: Add SCS sanitizer option for AArch64

SCS has been supported in Rust since 1.64.0.

This adds SCS as a sanitizer option in Rust.

Bug: 168914033
Test: Built module with sanitize: { scs: true }
Change-Id: Ie54ac4693286878b98704cf052649a267777d764
diff --git a/rust/sanitize.go b/rust/sanitize.go
index 0f7cf6e..e232b53 100644
--- a/rust/sanitize.go
+++ b/rust/sanitize.go
@@ -32,6 +32,7 @@
 	Sanitize struct {
 		Address   *bool `android:"arch_variant"`
 		Hwaddress *bool `android:"arch_variant"`
+		Scs       *bool `android:"arch_variant"`
 
 		// Memory-tagging, only available on arm64
 		// if diag.memtag unset or false, enables async memory tagging
@@ -75,6 +76,9 @@
 var asanFlags = []string{
 	"-Z sanitizer=address",
 }
+var scsFlags = []string{
+	"-Z sanitizer=shadow-call-stack",
+}
 
 // See cc/sanitize.go's hwasanGlobalOptions for global hwasan options.
 var hwasanFlags = []string{
@@ -208,9 +212,15 @@
 		s.Memtag_heap = nil
 	}
 
+	// SCS is only supported on AArch64 in Rust.
+	// TODO: Add riscv when riscv supported.
+	if (ctx.Arch().ArchType != android.Arm64) || !ctx.toolchain().Bionic() {
+		s.Scs = nil
+	}
+
 	// TODO:(b/178369775)
 	// For now sanitizing is only supported on devices
-	if ctx.Os() == android.Android && (Bool(s.Hwaddress) || Bool(s.Address) || Bool(s.Memtag_heap) || Bool(s.Fuzzer)) {
+	if ctx.Os() == android.Android && (Bool(s.Hwaddress) || Bool(s.Address) || Bool(s.Memtag_heap) || Bool(s.Fuzzer) || Bool(s.Scs)) {
 		sanitize.Properties.SanitizerEnabled = true
 	}
 }
@@ -229,7 +239,10 @@
 		flags.RustFlags = append(flags.RustFlags, hwasanFlags...)
 	} else if Bool(sanitize.Properties.Sanitize.Address) {
 		flags.RustFlags = append(flags.RustFlags, asanFlags...)
+	} else if Bool(sanitize.Properties.Sanitize.Scs) {
+		flags.RustFlags = append(flags.RustFlags, scsFlags...)
 	}
+
 	return flags, deps
 }
 
@@ -311,6 +324,9 @@
 	case cc.Memtag_heap:
 		sanitize.Properties.Sanitize.Memtag_heap = boolPtr(b)
 		sanitizerSet = true
+	case cc.Scs:
+		sanitize.Properties.Sanitize.Scs = boolPtr(b)
+		sanitizerSet = true
 	default:
 		panic(fmt.Errorf("setting unsupported sanitizerType %d", t))
 	}
@@ -372,6 +388,8 @@
 		return sanitize.Properties.Sanitize.Hwaddress
 	case cc.Memtag_heap:
 		return sanitize.Properties.Sanitize.Memtag_heap
+	case cc.Scs:
+		return sanitize.Properties.Sanitize.Scs
 	default:
 		return nil
 	}
@@ -384,6 +402,10 @@
 		if sanitize.isSanitizerEnabled(cc.Hwasan) {
 			entries.SubName += ".hwasan"
 		}
+		if sanitize.isSanitizerEnabled(cc.Scs) {
+			entries.SubName += ".scs"
+		}
+
 	}
 }
 
@@ -404,6 +426,13 @@
 		return true
 	case cc.Memtag_heap:
 		return true
+	case cc.Scs:
+		// SCS is only supported on AArch64 in Rust.
+		// TODO: Add riscv when riscv supported.
+		if mod.Target().Arch.ArchType == android.Arm64 {
+			return true
+		}
+		return false
 	default:
 		return false
 	}