Add handling for libc_hwasan to Soong

libc_hwasan is a new library in the runtime apex that lives in
bionic/hwasan/libc.so and is symlinked to /system/lib64/hwasan/libc.so.
This is chosen by the linker if an app or binary requires HWASan
support.

Bug: 276930343
Change-Id: If331744ad84241ad99a41805ea3110d37cf9b0af
diff --git a/cc/cc.go b/cc/cc.go
index 9c555a1..10f5668 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1475,7 +1475,7 @@
 func InstallToBootstrap(name string, config android.Config) bool {
 	// NOTE: also update //build/bazel/rules/apex/cc.bzl#_installed_to_bootstrap
 	// if this list is updated.
-	if name == "libclang_rt.hwasan" {
+	if name == "libclang_rt.hwasan" || name == "libc_hwasan" {
 		return true
 	}
 	return isBionic(name)
diff --git a/cc/library.go b/cc/library.go
index 7504302..172ca64 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -2193,7 +2193,16 @@
 func (library *libraryDecorator) installSymlinkToRuntimeApex(ctx ModuleContext, file android.Path) {
 	dir := library.baseInstaller.installDir(ctx)
 	dirOnDevice := android.InstallPathToOnDevicePath(ctx, dir)
-	target := "/" + filepath.Join("apex", "com.android.runtime", dir.Base(), "bionic", file.Base())
+	// libc_hwasan has relative_install_dir set, which would mess up the dir.Base() logic.
+	// hardcode here because it's the only target, if we have other targets that use this
+	// we can generalise this.
+	var target string
+	if ctx.baseModuleName() == "libc_hwasan" {
+		target = "/" + filepath.Join("apex", "com.android.runtime", "lib64", "bionic", "hwasan", file.Base())
+	} else {
+		base := dir.Base()
+		target = "/" + filepath.Join("apex", "com.android.runtime", base, "bionic", file.Base())
+	}
 	ctx.InstallAbsoluteSymlink(dir, file.Base(), target)
 	library.postInstallCmds = append(library.postInstallCmds, makeSymlinkCmd(dirOnDevice, file.Base(), target))
 }
diff --git a/cc/sanitize.go b/cc/sanitize.go
index f19659c..f34c631 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -785,6 +785,13 @@
 		if Bool(sanProps.Writeonly) {
 			flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm", "-hwasan-instrument-reads=0")
 		}
+		if !ctx.staticBinary() && !ctx.Host() {
+			if ctx.bootstrap() {
+				flags.DynamicLinker = "/system/bin/bootstrap/linker_hwasan64"
+			} else {
+				flags.DynamicLinker = "/system/bin/linker_hwasan64"
+			}
+		}
 	}
 
 	if Bool(sanProps.Fuzzer) {