From 5f59553bca49ad4acd00625633c2a6fd5c4eb2c5 Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Thu, 13 Jul 2017 14:46:05 -0700 Subject: [PATCH] Allow integer_overflow sanitizer path exclusion. Add support for excluding paths from having integer_overflow applied to them when using SANITIZE_TARGET=integer_overflow via an INTEGER_OVERFLOW_EXCLUDE_PATHS make variable. This covers the soong side of the change. Bug: 30969751 Test: Build with SANITIZE_TARGET=integer_overflow SANITIZE_TARGET_DIAG=integer_overflow INTEGER_OVERFLOW_EXCLUDE_PATHS= and confirmed this was no longer being applied to binaries in that path. Change-Id: I298b772f5425da28dff1cf007825be19558db3a8 --- android/config.go | 21 +++++++++++---------- android/util.go | 9 +++++++++ android/variable.go | 2 ++ cc/sanitize.go | 4 +++- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/android/config.go b/android/config.go index 661e333d2..5dcc59bef 100644 --- a/android/config.go +++ b/android/config.go @@ -530,20 +530,21 @@ func (c *deviceConfig) NativeCoverageEnabled() bool { func (c *deviceConfig) CoverageEnabledForPath(path string) bool { coverage := false if c.config.ProductVariables.CoveragePaths != nil { - for _, prefix := range *c.config.ProductVariables.CoveragePaths { - if strings.HasPrefix(path, prefix) { - coverage = true - break - } + if prefixInList(path, *c.config.ProductVariables.CoveragePaths) { + coverage = true } } if coverage && c.config.ProductVariables.CoverageExcludePaths != nil { - for _, prefix := range *c.config.ProductVariables.CoverageExcludePaths { - if strings.HasPrefix(path, prefix) { - coverage = false - break - } + if prefixInList(path, *c.config.ProductVariables.CoverageExcludePaths) { + coverage = false } } return coverage } + +func (c *config) IntegerOverflowDisabledForPath(path string) bool { + if c.ProductVariables.IntegerOverflowExcludePaths == nil { + return false + } + return prefixInList(path, *c.ProductVariables.IntegerOverflowExcludePaths) +} diff --git a/android/util.go b/android/util.go index 8cee256c9..80c7870a0 100644 --- a/android/util.go +++ b/android/util.go @@ -68,6 +68,15 @@ func inList(s string, list []string) bool { return indexList(s, list) != -1 } +func prefixInList(s string, list []string) bool { + for _, prefix := range list { + if strings.HasPrefix(s, prefix) { + return true + } + } + return false +} + // checkCalledFromInit panics if a Go package's init function is not on the // call stack. func checkCalledFromInit() { diff --git a/android/variable.go b/android/variable.go index 7ca7a55a2..8462d0d58 100644 --- a/android/variable.go +++ b/android/variable.go @@ -140,6 +140,8 @@ type productVariables struct { Treble *bool `json:",omitempty"` Pdk *bool `json:",omitempty"` + IntegerOverflowExcludePaths *[]string `json:",omitempty"` + VendorPath *string `json:",omitempty"` ClangTidy *bool `json:",omitempty"` diff --git a/cc/sanitize.go b/cc/sanitize.go index 49bd0f310..eccd25587 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -188,7 +188,9 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) { } if found, globalSanitizers = removeFromList("integer_overflow", globalSanitizers); found && s.Integer_overflow == nil { - s.Integer_overflow = boolPtr(true) + if !ctx.AConfig().IntegerOverflowDisabledForPath(ctx.ModuleDir()) { + s.Integer_overflow = boolPtr(true) + } } if len(globalSanitizers) > 0 {