Scudo minimal runtime support for Soong

Scudo is now compatible with the -fsanitize-minimal-runtime, and offers a new
dynamic library that doesn't bundle UBSan.

This patch adds support for this new library in Soong, preferring it over the
full one, unless a UBSan or diagnostic dependency is found.

Test: aosp compiled with m -j
Test: local test enabling Scudo for tombstoned
Change-Id: I17794131db148b33f8a8710ac43302cadf1af314
diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go
index 997bca6..d5e9d01 100644
--- a/cc/config/toolchain.go
+++ b/cc/config/toolchain.go
@@ -220,6 +220,10 @@
 	return LibclangRuntimeLibrary(t, "scudo")
 }
 
+func ScudoMinimalRuntimeLibrary(t Toolchain) string {
+	return LibclangRuntimeLibrary(t, "scudo_minimal")
+}
+
 func ToolPath(t Toolchain) string {
 	if p := t.ToolPath(); p != "" {
 		return p
diff --git a/cc/makevars.go b/cc/makevars.go
index 47e5491..993b2a8 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -281,6 +281,7 @@
 		ctx.Strict(secondPrefix+"UBSAN_MINIMAL_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(toolchain), ".a"))
 		ctx.Strict(secondPrefix+"TSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.ThreadSanitizerRuntimeLibrary(toolchain), ".so"))
 		ctx.Strict(secondPrefix+"SCUDO_RUNTIME_LIBRARY", strings.TrimSuffix(config.ScudoRuntimeLibrary(toolchain), ".so"))
+		ctx.Strict(secondPrefix+"SCUDO_MINIMAL_RUNTIME_LIBRARY", strings.TrimSuffix(config.ScudoMinimalRuntimeLibrary(toolchain), ".so"))
 	}
 
 	// This is used by external/gentoo/...
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 8262a68..3fef6a8 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -531,7 +531,11 @@
 	} else if Bool(sanitize.Properties.Sanitize.Thread) {
 		runtimeLibrary = config.ThreadSanitizerRuntimeLibrary(ctx.toolchain())
 	} else if Bool(sanitize.Properties.Sanitize.Scudo) {
-		runtimeLibrary = config.ScudoRuntimeLibrary(ctx.toolchain())
+		if len(diagSanitizers) == 0 && !sanitize.Properties.UbsanRuntimeDep {
+			runtimeLibrary = config.ScudoMinimalRuntimeLibrary(ctx.toolchain())
+		} else {
+			runtimeLibrary = config.ScudoRuntimeLibrary(ctx.toolchain())
+		}
 	} else if len(diagSanitizers) > 0 || sanitize.Properties.UbsanRuntimeDep {
 		runtimeLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(ctx.toolchain())
 	}
@@ -831,7 +835,6 @@
 func enableMinimalRuntime(sanitize *sanitize) bool {
 	if !Bool(sanitize.Properties.Sanitize.Address) &&
 		!Bool(sanitize.Properties.Sanitize.Hwaddress) &&
-		!Bool(sanitize.Properties.Sanitize.Scudo) &&
 		(Bool(sanitize.Properties.Sanitize.Integer_overflow) ||
 			len(sanitize.Properties.Sanitize.Misc_undefined) > 0) &&
 		!(Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) ||