Enable HWASan for multiple modules in one place(Soong)
Environment variables HWASAN_INCLUDE_PATHS and
PRODUCT_HWASAN_INCLUDE_PATHS can be used to enable HWASan for multiple
modules, by just adding the module directory to the env variable.
Bug: b/271948407
Test: Set specific module directory to above env variable and check the
assembly codes of output elf files after building, finding hwasan
related symbols inside.
Merged-In: Ic49b515830c4469ca5fa94f547b26c0fb602fc54
Change-Id: Ic49b515830c4469ca5fa94f547b26c0fb602fc54
(cherry picked from commit a98aab98c45aa7245cd235b8822de35aa6eb4fd6)
diff --git a/android/config.go b/android/config.go
index 9920fe4..980460a 100644
--- a/android/config.go
+++ b/android/config.go
@@ -1564,6 +1564,13 @@
return HasAnyPrefix(path, c.productVariables.MemtagHeapSyncIncludePaths) && !c.MemtagHeapDisabledForPath(path)
}
+func (c *config) HWASanEnabledForPath(path string) bool {
+ if len(c.productVariables.HWASanIncludePaths) == 0 {
+ return false
+ }
+ return HasAnyPrefix(path, c.productVariables.HWASanIncludePaths)
+}
+
func (c *config) VendorConfig(name string) VendorConfig {
return soongconfig.Config(c.productVariables.VendorVars[name])
}
diff --git a/android/variable.go b/android/variable.go
index d7152b3..496f523 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -307,6 +307,8 @@
MemtagHeapAsyncIncludePaths []string `json:",omitempty"`
MemtagHeapSyncIncludePaths []string `json:",omitempty"`
+ HWASanIncludePaths []string `json:",omitempty"`
+
VendorPath *string `json:",omitempty"`
OdmPath *string `json:",omitempty"`
ProductPath *string `json:",omitempty"`
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 45d7fab..7fddc1b 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -593,6 +593,12 @@
}
}
+ // Enable HWASan for all components in the include paths (for Aarch64 only)
+ if s.Hwaddress == nil && ctx.Config().HWASanEnabledForPath(ctx.ModuleDir()) &&
+ ctx.Arch().ArchType == android.Arm64 && ctx.toolchain().Bionic() {
+ s.Hwaddress = proptools.BoolPtr(true)
+ }
+
// Enable CFI for non-host components in the include paths
if s.Cfi == nil && ctx.Config().CFIEnabledForPath(ctx.ModuleDir()) && !ctx.Host() {
s.Cfi = proptools.BoolPtr(true)