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

Commit 94e8a651 authored by Ivan Lozano's avatar Ivan Lozano Committed by Gerrit Code Review
Browse files

Merge changes I26198187,Ia904d07b

* changes:
  rust: Support MTE memtag_heap sanitizer
  rust: Support global sanitizers
parents 4220a613 62cd0388
Loading
Loading
Loading
Loading
+17 −12
Original line number Original line Diff line number Diff line
@@ -88,7 +88,7 @@ const (
	intOverflow
	intOverflow
	scs
	scs
	Fuzzer
	Fuzzer
	memtag_heap
	Memtag_heap
	cfi // cfi is last to prevent it running before incompatible mutators
	cfi // cfi is last to prevent it running before incompatible mutators
)
)


@@ -99,7 +99,7 @@ var Sanitizers = []SanitizerType{
	intOverflow,
	intOverflow,
	scs,
	scs,
	Fuzzer,
	Fuzzer,
	memtag_heap,
	Memtag_heap,
	cfi, // cfi is last to prevent it running before incompatible mutators
	cfi, // cfi is last to prevent it running before incompatible mutators
}
}


@@ -118,7 +118,7 @@ func (t SanitizerType) variationName() string {
		return "cfi"
		return "cfi"
	case scs:
	case scs:
		return "scs"
		return "scs"
	case memtag_heap:
	case Memtag_heap:
		return "memtag_heap"
		return "memtag_heap"
	case Fuzzer:
	case Fuzzer:
		return "fuzzer"
		return "fuzzer"
@@ -134,7 +134,7 @@ func (t SanitizerType) name() string {
		return "address"
		return "address"
	case Hwasan:
	case Hwasan:
		return "hwaddress"
		return "hwaddress"
	case memtag_heap:
	case Memtag_heap:
		return "memtag_heap"
		return "memtag_heap"
	case tsan:
	case tsan:
		return "thread"
		return "thread"
@@ -156,7 +156,7 @@ func (t SanitizerType) registerMutators(ctx android.RegisterMutatorsContext) {
	case Asan, Hwasan, Fuzzer, scs, tsan, cfi:
	case Asan, Hwasan, Fuzzer, scs, tsan, cfi:
		ctx.TopDown(t.variationName()+"_deps", sanitizerDepsMutator(t))
		ctx.TopDown(t.variationName()+"_deps", sanitizerDepsMutator(t))
		ctx.BottomUp(t.variationName(), sanitizerMutator(t))
		ctx.BottomUp(t.variationName(), sanitizerMutator(t))
	case memtag_heap, intOverflow:
	case Memtag_heap, intOverflow:
		// do nothing
		// do nothing
	default:
	default:
		panic(fmt.Errorf("unknown SanitizerType %d", t))
		panic(fmt.Errorf("unknown SanitizerType %d", t))
@@ -179,6 +179,8 @@ func (*Module) SanitizerSupported(t SanitizerType) bool {
		return true
		return true
	case Fuzzer:
	case Fuzzer:
		return true
		return true
	case Memtag_heap:
		return true
	default:
	default:
		return false
		return false
	}
	}
@@ -467,7 +469,7 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
		s.Scs = nil
		s.Scs = nil
	}
	}


	// memtag_heap is only implemented on AArch64.
	// Memtag_heap is only implemented on AArch64.
	if ctx.Arch().ArchType != android.Arm64 {
	if ctx.Arch().ArchType != android.Arm64 {
		s.Memtag_heap = nil
		s.Memtag_heap = nil
	}
	}
@@ -813,7 +815,7 @@ func (sanitize *sanitize) getSanitizerBoolPtr(t SanitizerType) *bool {
		return sanitize.Properties.Sanitize.Cfi
		return sanitize.Properties.Sanitize.Cfi
	case scs:
	case scs:
		return sanitize.Properties.Sanitize.Scs
		return sanitize.Properties.Sanitize.Scs
	case memtag_heap:
	case Memtag_heap:
		return sanitize.Properties.Sanitize.Memtag_heap
		return sanitize.Properties.Sanitize.Memtag_heap
	case Fuzzer:
	case Fuzzer:
		return sanitize.Properties.Sanitize.Fuzzer
		return sanitize.Properties.Sanitize.Fuzzer
@@ -829,7 +831,7 @@ func (sanitize *sanitize) isUnsanitizedVariant() bool {
		!sanitize.isSanitizerEnabled(tsan) &&
		!sanitize.isSanitizerEnabled(tsan) &&
		!sanitize.isSanitizerEnabled(cfi) &&
		!sanitize.isSanitizerEnabled(cfi) &&
		!sanitize.isSanitizerEnabled(scs) &&
		!sanitize.isSanitizerEnabled(scs) &&
		!sanitize.isSanitizerEnabled(memtag_heap) &&
		!sanitize.isSanitizerEnabled(Memtag_heap) &&
		!sanitize.isSanitizerEnabled(Fuzzer)
		!sanitize.isSanitizerEnabled(Fuzzer)
}
}


@@ -859,7 +861,7 @@ func (sanitize *sanitize) SetSanitizer(t SanitizerType, b bool) {
		sanitize.Properties.Sanitize.Cfi = bPtr
		sanitize.Properties.Sanitize.Cfi = bPtr
	case scs:
	case scs:
		sanitize.Properties.Sanitize.Scs = bPtr
		sanitize.Properties.Sanitize.Scs = bPtr
	case memtag_heap:
	case Memtag_heap:
		sanitize.Properties.Sanitize.Memtag_heap = bPtr
		sanitize.Properties.Sanitize.Memtag_heap = bPtr
	case Fuzzer:
	case Fuzzer:
		sanitize.Properties.Sanitize.Fuzzer = bPtr
		sanitize.Properties.Sanitize.Fuzzer = bPtr
@@ -1148,7 +1150,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
			if lib, ok := snapshot.StaticLibs[noteDep]; ok {
			if lib, ok := snapshot.StaticLibs[noteDep]; ok {
				noteDep = lib
				noteDep = lib
			}
			}
			depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true}
			depTag := StaticDepTag(true)
			variations := append(mctx.Target().Variations(),
			variations := append(mctx.Target().Variations(),
				blueprint.Variation{Mutator: "link", Variation: "static"})
				blueprint.Variation{Mutator: "link", Variation: "static"})
			if c.Device() {
			if c.Device() {
@@ -1318,6 +1320,10 @@ var _ PlatformSanitizeable = (*Module)(nil)
func sanitizerMutator(t SanitizerType) func(android.BottomUpMutatorContext) {
func sanitizerMutator(t SanitizerType) func(android.BottomUpMutatorContext) {
	return func(mctx android.BottomUpMutatorContext) {
	return func(mctx android.BottomUpMutatorContext) {
		if c, ok := mctx.Module().(PlatformSanitizeable); ok && c.SanitizePropDefined() {
		if c, ok := mctx.Module().(PlatformSanitizeable); ok && c.SanitizePropDefined() {

			// Make sure we're not setting CFI to any value if it's not supported.
			cfiSupported := mctx.Module().(PlatformSanitizeable).SanitizerSupported(cfi)

			if c.Binary() && c.IsSanitizerEnabled(t) {
			if c.Binary() && c.IsSanitizerEnabled(t) {
				modules := mctx.CreateVariations(t.variationName())
				modules := mctx.CreateVariations(t.variationName())
				modules[0].(PlatformSanitizeable).SetSanitizer(t, true)
				modules[0].(PlatformSanitizeable).SetSanitizer(t, true)
@@ -1338,7 +1344,6 @@ func sanitizerMutator(t SanitizerType) func(android.BottomUpMutatorContext) {
					// is redirected to the sanitized variant of the dependent module.
					// is redirected to the sanitized variant of the dependent module.
					defaultVariation := t.variationName()
					defaultVariation := t.variationName()
					// Not all PlatformSanitizeable modules support the CFI sanitizer
					// Not all PlatformSanitizeable modules support the CFI sanitizer
					cfiSupported := mctx.Module().(PlatformSanitizeable).SanitizerSupported(cfi)
					mctx.SetDefaultDependencyVariation(&defaultVariation)
					mctx.SetDefaultDependencyVariation(&defaultVariation)


					modules := mctx.CreateVariations("", t.variationName())
					modules := mctx.CreateVariations("", t.variationName())
@@ -1385,7 +1390,7 @@ func sanitizerMutator(t SanitizerType) func(android.BottomUpMutatorContext) {
						modules[0].(PlatformSanitizeable).SetInSanitizerDir()
						modules[0].(PlatformSanitizeable).SetInSanitizerDir()
					}
					}


					if mctx.Device() && t.incompatibleWithCfi() {
					if mctx.Device() && t.incompatibleWithCfi() && cfiSupported {
						// TODO: Make sure that cfi mutator runs "after" any of the sanitizers that
						// TODO: Make sure that cfi mutator runs "after" any of the sanitizers that
						// are incompatible with cfi
						// are incompatible with cfi
						modules[0].(PlatformSanitizeable).SetSanitizer(cfi, false)
						modules[0].(PlatformSanitizeable).SetSanitizer(cfi, false)
+1 −0
Original line number Original line Diff line number Diff line
@@ -54,6 +54,7 @@ bootstrap_go_package {
        "project_json_test.go",
        "project_json_test.go",
        "protobuf_test.go",
        "protobuf_test.go",
        "rust_test.go",
        "rust_test.go",
        "sanitize_test.go",
        "source_provider_test.go",
        "source_provider_test.go",
        "test_test.go",
        "test_test.go",
        "vendor_snapshot_test.go",
        "vendor_snapshot_test.go",
+5 −0
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ type BinaryCompilerProperties struct {
type binaryInterface interface {
type binaryInterface interface {
	binary() bool
	binary() bool
	staticallyLinked() bool
	staticallyLinked() bool
	testBinary() bool
}
}


type binaryDecorator struct {
type binaryDecorator struct {
@@ -172,3 +173,7 @@ func (binary *binaryDecorator) binary() bool {
func (binary *binaryDecorator) staticallyLinked() bool {
func (binary *binaryDecorator) staticallyLinked() bool {
	return Bool(binary.Properties.Static_executable)
	return Bool(binary.Properties.Static_executable)
}
}

func (binary *binaryDecorator) testBinary() bool {
	return false
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -36,7 +36,7 @@ type fuzzDecorator struct {
	fuzzPackagedModule fuzz.FuzzPackagedModule
	fuzzPackagedModule fuzz.FuzzPackagedModule
}
}


var _ compiler = (*binaryDecorator)(nil)
var _ compiler = (*fuzzDecorator)(nil)


// rust_binary produces a binary that is runnable on a device.
// rust_binary produces a binary that is runnable on a device.
func RustFuzzFactory() android.Module {
func RustFuzzFactory() android.Module {
+7 −0
Original line number Original line Diff line number Diff line
@@ -442,3 +442,10 @@ func TestLibrarySizes(t *testing.T) {
	m.Output("unstripped/libwaldo.dylib.so.bloaty.csv")
	m.Output("unstripped/libwaldo.dylib.so.bloaty.csv")
	m.Output("libwaldo.dylib.so.bloaty.csv")
	m.Output("libwaldo.dylib.so.bloaty.csv")
}
}

func assertString(t *testing.T, got, expected string) {
	t.Helper()
	if got != expected {
		t.Errorf("expected %q got %q", expected, got)
	}
}
Loading