Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 408d3731 authored by Ivan Lozano's avatar Ivan Lozano
Browse files

rust: Pass ASAN/HWASAN flags alongside fuzzers

'-Z sanitizer={hw}address' was not being passed if the fuzzer sanitizer
property was also set. Additionally, trying to use the fuzzer sanitizer
with the address sanitizer incorrectly linked in the hwasan runtime.

Bug: 293466009
Test: SANITIZE_TARGET="fuzzer address" m android_logger_fuzzer
Test: SANITIZE_TARGET="fuzzer hwaddress" m android_logger_fuzzer
Test: ldd <fuzzer_on_device> # ensure correct libraries linked
Test: Check build flags
Change-Id: I6b01c8808af07c642217b642af128ebf934f4bc6
parent f7bd2592
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -223,11 +223,16 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags, deps PathDeps) (
	if !sanitize.Properties.SanitizerEnabled {
		return flags, deps
	}

	if Bool(sanitize.Properties.Sanitize.Fuzzer) {
		flags.RustFlags = append(flags.RustFlags, fuzzerFlags...)
	} else if Bool(sanitize.Properties.Sanitize.Hwaddress) {
	}

	if Bool(sanitize.Properties.Sanitize.Hwaddress) {
		flags.RustFlags = append(flags.RustFlags, hwasanFlags...)
	} else if Bool(sanitize.Properties.Sanitize.Address) {
	}

	if Bool(sanitize.Properties.Sanitize.Address) {
		flags.RustFlags = append(flags.RustFlags, asanFlags...)
	}
	return flags, deps
@@ -267,14 +272,12 @@ func rustSanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
		var depTag blueprint.DependencyTag
		var deps []string

		if mod.IsSanitizerEnabled(cc.Asan) ||
			(mod.IsSanitizerEnabled(cc.Fuzzer) && (mctx.Arch().ArchType != android.Arm64 || !mctx.Os().Bionic())) {
		if mod.IsSanitizerEnabled(cc.Asan) {
			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) ||
			(mod.IsSanitizerEnabled(cc.Fuzzer) && mctx.Arch().ArchType == android.Arm64 && mctx.Os().Bionic()) {
		} else if mod.IsSanitizerEnabled(cc.Hwasan) {
			// TODO(b/204776996): HWASan for static Rust binaries isn't supported yet.
			if binary, ok := mod.compiler.(binaryInterface); ok {
				if binary.staticallyLinked() {