Fix -fsanitize=integer not passed for soong builds.
Also filter out -Wl,--no-undefined for all host sanitizers, not just ASan.
UBSan on host defaults to no-trap (i.e. diagnostic mode), and that requires
the runtime library and runs into the same problem with undefined symbols as ASan.
Bug: 34719251
Test: Misc_undefined: ["integer"] on a soong target
Change-Id: I1fb4781f663a11f5f427d50c0bf9beb8e181cd5e
Merged-In: I1fb4781f663a11f5f427d50c0bf9beb8e181cd5e
(cherry picked from commit fe9bc1dccb6cb8a92d5442c8a93a8f4dc30c2453)
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 8900ee8..fcb3289 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -212,8 +212,8 @@
// TODO(ccross): error for compile_multilib = "32"?
}
- if Bool(s.All_undefined) || Bool(s.Undefined) || Bool(s.Address) ||
- Bool(s.Thread) || Bool(s.Coverage) || Bool(s.Safestack) || Bool(s.Cfi) {
+ if ctx.Os() != android.Windows && (Bool(s.All_undefined) || Bool(s.Undefined) || Bool(s.Address) || Bool(s.Thread) ||
+ Bool(s.Coverage) || Bool(s.Safestack) || Bool(s.Cfi) || len(s.Misc_undefined) > 0) {
sanitize.Properties.SanitizerEnabled = true
}
@@ -308,9 +308,6 @@
// libraries needed with -fsanitize=address. http://b/18650275 (WAI)
flags.LdFlags = append(flags.LdFlags, "-lm", "-lpthread")
flags.LdFlags = append(flags.LdFlags, "-Wl,--no-as-needed")
- // Host ASAN only links symbols in the final executable, so
- // there will always be undefined symbols in intermediate libraries.
- _, flags.LdFlags = removeFromList("-Wl,--no-undefined", flags.LdFlags)
} else {
flags.CFlags = append(flags.CFlags, "-mllvm", "-asan-globals=0")
flags.DynamicLinker = "/system/bin/linker_asan"
@@ -355,6 +352,9 @@
flags.CFlags = append(flags.CFlags, "-fno-sanitize-recover=all")
flags.LdFlags = append(flags.LdFlags, sanitizeArg)
flags.LdFlags = append(flags.LdFlags, "-lrt", "-ldl")
+ // Host sanitizers only link symbols in the final executable, so
+ // there will always be undefined symbols in intermediate libraries.
+ _, flags.LdFlags = removeFromList("-Wl,--no-undefined", flags.LdFlags)
} else {
flags.CFlags = append(flags.CFlags, "-fsanitize-trap=all", "-ftrap-function=abort")
}