From f734f00898685a2c16a1ebffd3f3439bd0a48139 Mon Sep 17 00:00:00 2001 From: Tomislav Novak Date: Tue, 22 Aug 2023 10:51:44 -0700 Subject: [PATCH] soong: HWASan exclude path support Adds the ability to centrally disable HWASan for multiple modules when building with SANITIZE_TARGET=hwaddress. Soong version of the patchset. HWASan takes precedence over CFI and several other sanitizers that it's incompatible with[1], which can be problematic for modules that require those sanitizers (e.g. those that depend on vendor prebuilts where only sanitized variants are provided). This patch adds an easy way to disable HWASan for such modules while still keeping it globally enabled. Test: build with HWASAN_EXCLUDE_PATHS set and verify with readelf that relevant modules have no references to __hwasan symbols [1] https://android.googlesource.com/platform/build/+/bb31ca1168df6326d6f8eee7a834a974aafed6ed/core/config_sanitizers.mk#236 Change-Id: I5824f71f2a400c64cde29e2c7afdd167d851d337 --- android/config.go | 9 ++++++++- android/variable.go | 1 + cc/sanitize.go | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/android/config.go b/android/config.go index 3e7bb1426..9d387fcba 100644 --- a/android/config.go +++ b/android/config.go @@ -1662,11 +1662,18 @@ func (c *config) MemtagHeapSyncEnabledForPath(path string) bool { return HasAnyPrefix(path, c.productVariables.MemtagHeapSyncIncludePaths) && !c.MemtagHeapDisabledForPath(path) } +func (c *config) HWASanDisabledForPath(path string) bool { + if len(c.productVariables.HWASanExcludePaths) == 0 { + return false + } + return HasAnyPrefix(path, c.productVariables.HWASanExcludePaths) +} + func (c *config) HWASanEnabledForPath(path string) bool { if len(c.productVariables.HWASanIncludePaths) == 0 { return false } - return HasAnyPrefix(path, c.productVariables.HWASanIncludePaths) + return HasAnyPrefix(path, c.productVariables.HWASanIncludePaths) && !c.HWASanDisabledForPath(path) } func (c *config) VendorConfig(name string) VendorConfig { diff --git a/android/variable.go b/android/variable.go index ca9a221b1..ef8857add 100644 --- a/android/variable.go +++ b/android/variable.go @@ -315,6 +315,7 @@ type ProductVariables struct { MemtagHeapSyncIncludePaths []string `json:",omitempty"` HWASanIncludePaths []string `json:",omitempty"` + HWASanExcludePaths []string `json:",omitempty"` VendorPath *string `json:",omitempty"` OdmPath *string `json:",omitempty"` diff --git a/cc/sanitize.go b/cc/sanitize.go index 30bce9bff..68ac78e95 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -553,7 +553,9 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) { } if found, globalSanitizers = removeFromList("hwaddress", globalSanitizers); found && s.Hwaddress == nil { - s.Hwaddress = proptools.BoolPtr(true) + if !ctx.Config().HWASanDisabledForPath(ctx.ModuleDir()) { + s.Hwaddress = proptools.BoolPtr(true) + } } if found, globalSanitizers = removeFromList("writeonly", globalSanitizers); found && s.Writeonly == nil {