rust: Switch rust_fuzz to HWASan

Bug: 180495975
Test: example_rust_fuzzer
Change-Id: I26e6f15136ee2d5f4ed1167be5c1c6a14b19421a
This commit is contained in:
Tri Vo
2021-04-08 15:50:48 -07:00
parent c8ae73e678
commit 505b0e8991
3 changed files with 16 additions and 18 deletions

View File

@@ -46,7 +46,6 @@ var fuzzerFlags = []string{
"-C llvm-args=-sanitizer-coverage-inline-8bit-counters",
"-C llvm-args=-sanitizer-coverage-trace-geps",
"-C llvm-args=-sanitizer-coverage-prune-blocks=0",
"-Z sanitizer=address",
// Sancov breaks with lto
// TODO: Remove when https://bugs.llvm.org/show_bug.cgi?id=41734 is resolved and sancov works with LTO
@@ -109,6 +108,11 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags, deps PathDeps) (
}
if Bool(sanitize.Properties.Sanitize.Fuzzer) {
flags.RustFlags = append(flags.RustFlags, fuzzerFlags...)
if ctx.Arch().ArchType == android.Arm64 {
flags.RustFlags = append(flags.RustFlags, hwasanFlags...)
} else {
flags.RustFlags = append(flags.RustFlags, asanFlags...)
}
}
if Bool(sanitize.Properties.Sanitize.Address) {
flags.RustFlags = append(flags.RustFlags, asanFlags...)
@@ -133,12 +137,14 @@ func rustSanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
var depTag blueprint.DependencyTag
var deps []string
if Bool(mod.sanitize.Properties.Sanitize.Fuzzer) || Bool(mod.sanitize.Properties.Sanitize.Address) {
if mod.IsSanitizerEnabled(cc.Asan) ||
(mod.IsSanitizerEnabled(cc.Fuzzer) && mctx.Arch().ArchType != android.Arm64) {
variations = append(variations,
blueprint.Variation{Mutator: "link", Variation: "shared"})
depTag = cc.SharedDepTag()
deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "asan")}
} else if mod.IsSanitizerEnabled(cc.Hwasan) {
} else if mod.IsSanitizerEnabled(cc.Hwasan) ||
(mod.IsSanitizerEnabled(cc.Fuzzer) && mctx.Arch().ArchType == android.Arm64) {
// TODO(b/180495975): HWASan for static Rust binaries isn't supported yet.
if binary, ok := mod.compiler.(*binaryDecorator); ok {
if Bool(binary.Properties.Static_executable) {
@@ -285,11 +291,9 @@ func (mod *Module) SetSanitizeDep(b bool) {
func (mod *Module) StaticallyLinked() bool {
if lib, ok := mod.compiler.(libraryInterface); ok {
if lib.rlib() || lib.static() {
return true
}
} else if Bool(mod.compiler.(*binaryDecorator).Properties.Static_executable) {
return true
return lib.rlib() || lib.static()
} else if binary, ok := mod.compiler.(*binaryDecorator); ok {
return Bool(binary.Properties.Static_executable)
}
return false
}