Added write only sanitizer for ASAN and HWASAN
Bug: 162024969
Test: Successfully builds targets for both host and device
"writeonly" flag in SANITIZE_(HOST|TARGET) enables it with "address"
and "hwaddress"
Change-Id: Ia89d43230deef15a67dee09ed015fea14f0717ff
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 72ad6d7..136a510 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -158,6 +158,9 @@
Scudo *bool `android:"arch_variant"`
Scs *bool `android:"arch_variant"`
+ // A modifier for ASAN and HWASAN for write only instrumentation
+ Writeonly *bool `android:"arch_variant"`
+
// Sanitizers to run in the diagnostic mode (as opposed to the release mode).
// Replaces abort() on error with a human-readable error message.
// Address and Thread sanitizers always run in diagnostic mode.
@@ -279,6 +282,15 @@
s.Hwaddress = boolPtr(true)
}
+ if found, globalSanitizers = removeFromList("writeonly", globalSanitizers); found && s.Writeonly == nil {
+ // Hwaddress and Address are set before, so we can check them here
+ // If they aren't explicitly set in the blueprint/SANITIZE_(HOST|TARGET), they would be nil instead of false
+ if s.Address == nil && s.Hwaddress == nil {
+ ctx.ModuleErrorf("writeonly modifier cannot be used without 'address' or 'hwaddress'")
+ }
+ s.Writeonly = boolPtr(true)
+ }
+
if len(globalSanitizers) > 0 {
ctx.ModuleErrorf("unknown global sanitizer option %s", globalSanitizers[0])
}
@@ -456,6 +468,10 @@
flags.Local.CFlags = append(flags.Local.CFlags, asanCflags...)
flags.Local.LdFlags = append(flags.Local.LdFlags, asanLdflags...)
+ if Bool(sanitize.Properties.Sanitize.Writeonly) {
+ flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm", "-asan-instrument-reads=0")
+ }
+
if ctx.Host() {
// -nodefaultlibs (provided with libc++) prevents the driver from linking
// libraries needed with -fsanitize=address. http://b/18650275 (WAI)
@@ -475,6 +491,9 @@
if Bool(sanitize.Properties.Sanitize.Hwaddress) {
flags.Local.CFlags = append(flags.Local.CFlags, hwasanCflags...)
+ if Bool(sanitize.Properties.Sanitize.Writeonly) {
+ flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm", "-hwasan-instrument-reads=0")
+ }
}
if Bool(sanitize.Properties.Sanitize.Fuzzer) {