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

Commit 4aa48b03 authored by Liz Kammer's avatar Liz Kammer Committed by Gerrit Code Review
Browse files

Merge changes I770f5ce7,I32d4417d

* changes:
  Remove IsDependencyRoot from interface
  Delete local boolPtr function
parents af60f411 187d5445
Loading
Loading
Loading
Loading
+0 −5
Original line number Original line Diff line number Diff line
@@ -183,11 +183,6 @@ func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
	return deps
	return deps
}
}


func (binary *binaryDecorator) isDependencyRoot() bool {
	// Binaries are always the dependency root.
	return true
}

// NewBinary builds and returns a new Module corresponding to a C++ binary.
// NewBinary builds and returns a new Module corresponding to a C++ binary.
// Individual module implementations which comprise a C++ binary should call this function,
// Individual module implementations which comprise a C++ binary should call this function,
// set some fields on the result, and then call the Init function.
// set some fields on the result, and then call the Init function.
+0 −11
Original line number Original line Diff line number Diff line
@@ -1119,17 +1119,6 @@ func (c *Module) Init() android.Module {
	return c
	return c
}
}


// Returns true for dependency roots (binaries)
// TODO(ccross): also handle dlopenable libraries
func (c *Module) IsDependencyRoot() bool {
	if root, ok := c.linker.(interface {
		isDependencyRoot() bool
	}); ok {
		return root.isDependencyRoot()
	}
	return false
}

func (c *Module) UseVndk() bool {
func (c *Module) UseVndk() bool {
	return c.Properties.VndkVersion != ""
	return c.Properties.VndkVersion != ""
}
}
+0 −5
Original line number Original line Diff line number Diff line
@@ -14,11 +14,6 @@ type PlatformSanitizeable interface {
	// SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
	// SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
	SanitizePropDefined() bool
	SanitizePropDefined() bool


	// IsDependencyRoot returns whether a module is of a type which cannot be a linkage dependency
	// of another module. For example, cc_binary and rust_binary represent dependency roots as other
	// modules cannot have linkage dependencies against these types.
	IsDependencyRoot() bool

	// IsSanitizerEnabled returns whether a sanitizer is enabled.
	// IsSanitizerEnabled returns whether a sanitizer is enabled.
	IsSanitizerEnabled(t SanitizerType) bool
	IsSanitizerEnabled(t SanitizerType) bool


+8 −6
Original line number Original line Diff line number Diff line
@@ -15,6 +15,8 @@
package cc
package cc


import (
import (
	"github.com/google/blueprint/proptools"

	"android/soong/android"
	"android/soong/android"
)
)


@@ -67,14 +69,14 @@ func (lto *lto) props() []interface{} {


func (lto *lto) begin(ctx BaseModuleContext) {
func (lto *lto) begin(ctx BaseModuleContext) {
	if ctx.Config().IsEnvTrue("DISABLE_LTO") {
	if ctx.Config().IsEnvTrue("DISABLE_LTO") {
		lto.Properties.Lto.Never = boolPtr(true)
		lto.Properties.Lto.Never = proptools.BoolPtr(true)
	} else if ctx.Config().IsEnvTrue("GLOBAL_THINLTO") {
	} else if ctx.Config().IsEnvTrue("GLOBAL_THINLTO") {
		staticLib := ctx.static() && !ctx.staticBinary()
		staticLib := ctx.static() && !ctx.staticBinary()
		hostBin := ctx.Host()
		hostBin := ctx.Host()
		vndk := ctx.isVndk() // b/169217596
		vndk := ctx.isVndk() // b/169217596
		if !staticLib && !hostBin && !vndk {
		if !staticLib && !hostBin && !vndk {
			if !lto.Never() && !lto.FullLTO() {
			if !lto.Never() && !lto.FullLTO() {
				lto.Properties.Lto.Thin = boolPtr(true)
				lto.Properties.Lto.Thin = proptools.BoolPtr(true)
			}
			}
		}
		}
	}
	}
@@ -229,12 +231,12 @@ func ltoMutator(mctx android.BottomUpMutatorContext) {


				// LTO properties for dependencies
				// LTO properties for dependencies
				if name == "lto-full" {
				if name == "lto-full" {
					variation.lto.Properties.Lto.Full = boolPtr(true)
					variation.lto.Properties.Lto.Full = proptools.BoolPtr(true)
					variation.lto.Properties.Lto.Thin = boolPtr(false)
					variation.lto.Properties.Lto.Thin = proptools.BoolPtr(false)
				}
				}
				if name == "lto-thin" {
				if name == "lto-thin" {
					variation.lto.Properties.Lto.Full = boolPtr(false)
					variation.lto.Properties.Lto.Full = proptools.BoolPtr(false)
					variation.lto.Properties.Lto.Thin = boolPtr(true)
					variation.lto.Properties.Lto.Thin = proptools.BoolPtr(true)
				}
				}
				variation.Properties.PreventInstall = true
				variation.Properties.PreventInstall = true
				variation.Properties.HideFromMake = true
				variation.Properties.HideFromMake = true
+45 −48
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import (
	"sync"
	"sync"


	"github.com/google/blueprint"
	"github.com/google/blueprint"
	"github.com/google/blueprint/proptools"


	"android/soong/android"
	"android/soong/android"
	"android/soong/cc/config"
	"android/soong/cc/config"
@@ -73,14 +74,6 @@ var (


type SanitizerType int
type SanitizerType int


func boolPtr(v bool) *bool {
	if v {
		return &v
	} else {
		return nil
	}
}

const (
const (
	Asan SanitizerType = iota + 1
	Asan SanitizerType = iota + 1
	Hwasan
	Hwasan
@@ -269,8 +262,8 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {


	// cc_test targets default to SYNC MemTag unless explicitly set to ASYNC (via diag: {memtag_heap}).
	// cc_test targets default to SYNC MemTag unless explicitly set to ASYNC (via diag: {memtag_heap}).
	if ctx.testBinary() && s.Memtag_heap == nil {
	if ctx.testBinary() && s.Memtag_heap == nil {
		s.Memtag_heap = boolPtr(true)
		s.Memtag_heap = proptools.BoolPtr(true)
		s.Diag.Memtag_heap = boolPtr(true)
		s.Diag.Memtag_heap = proptools.BoolPtr(true)
	}
	}


	var globalSanitizers []string
	var globalSanitizers []string
@@ -291,48 +284,48 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
	if len(globalSanitizers) > 0 {
	if len(globalSanitizers) > 0 {
		var found bool
		var found bool
		if found, globalSanitizers = removeFromList("undefined", globalSanitizers); found && s.All_undefined == nil {
		if found, globalSanitizers = removeFromList("undefined", globalSanitizers); found && s.All_undefined == nil {
			s.All_undefined = boolPtr(true)
			s.All_undefined = proptools.BoolPtr(true)
		}
		}


		if found, globalSanitizers = removeFromList("default-ub", globalSanitizers); found && s.Undefined == nil {
		if found, globalSanitizers = removeFromList("default-ub", globalSanitizers); found && s.Undefined == nil {
			s.Undefined = boolPtr(true)
			s.Undefined = proptools.BoolPtr(true)
		}
		}


		if found, globalSanitizers = removeFromList("address", globalSanitizers); found && s.Address == nil {
		if found, globalSanitizers = removeFromList("address", globalSanitizers); found && s.Address == nil {
			s.Address = boolPtr(true)
			s.Address = proptools.BoolPtr(true)
		}
		}


		if found, globalSanitizers = removeFromList("thread", globalSanitizers); found && s.Thread == nil {
		if found, globalSanitizers = removeFromList("thread", globalSanitizers); found && s.Thread == nil {
			s.Thread = boolPtr(true)
			s.Thread = proptools.BoolPtr(true)
		}
		}


		if found, globalSanitizers = removeFromList("fuzzer", globalSanitizers); found && s.Fuzzer == nil {
		if found, globalSanitizers = removeFromList("fuzzer", globalSanitizers); found && s.Fuzzer == nil {
			s.Fuzzer = boolPtr(true)
			s.Fuzzer = proptools.BoolPtr(true)
		}
		}


		if found, globalSanitizers = removeFromList("safe-stack", globalSanitizers); found && s.Safestack == nil {
		if found, globalSanitizers = removeFromList("safe-stack", globalSanitizers); found && s.Safestack == nil {
			s.Safestack = boolPtr(true)
			s.Safestack = proptools.BoolPtr(true)
		}
		}


		if found, globalSanitizers = removeFromList("cfi", globalSanitizers); found && s.Cfi == nil {
		if found, globalSanitizers = removeFromList("cfi", globalSanitizers); found && s.Cfi == nil {
			if !ctx.Config().CFIDisabledForPath(ctx.ModuleDir()) {
			if !ctx.Config().CFIDisabledForPath(ctx.ModuleDir()) {
				s.Cfi = boolPtr(true)
				s.Cfi = proptools.BoolPtr(true)
			}
			}
		}
		}


		// Global integer_overflow builds do not support static libraries.
		// Global integer_overflow builds do not support static libraries.
		if found, globalSanitizers = removeFromList("integer_overflow", globalSanitizers); found && s.Integer_overflow == nil {
		if found, globalSanitizers = removeFromList("integer_overflow", globalSanitizers); found && s.Integer_overflow == nil {
			if !ctx.Config().IntegerOverflowDisabledForPath(ctx.ModuleDir()) && !ctx.static() {
			if !ctx.Config().IntegerOverflowDisabledForPath(ctx.ModuleDir()) && !ctx.static() {
				s.Integer_overflow = boolPtr(true)
				s.Integer_overflow = proptools.BoolPtr(true)
			}
			}
		}
		}


		if found, globalSanitizers = removeFromList("scudo", globalSanitizers); found && s.Scudo == nil {
		if found, globalSanitizers = removeFromList("scudo", globalSanitizers); found && s.Scudo == nil {
			s.Scudo = boolPtr(true)
			s.Scudo = proptools.BoolPtr(true)
		}
		}


		if found, globalSanitizers = removeFromList("hwaddress", globalSanitizers); found && s.Hwaddress == nil {
		if found, globalSanitizers = removeFromList("hwaddress", globalSanitizers); found && s.Hwaddress == nil {
			s.Hwaddress = boolPtr(true)
			s.Hwaddress = proptools.BoolPtr(true)
		}
		}


		if found, globalSanitizers = removeFromList("writeonly", globalSanitizers); found && s.Writeonly == nil {
		if found, globalSanitizers = removeFromList("writeonly", globalSanitizers); found && s.Writeonly == nil {
@@ -341,11 +334,11 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
			if s.Address == nil && s.Hwaddress == nil {
			if s.Address == nil && s.Hwaddress == nil {
				ctx.ModuleErrorf("writeonly modifier cannot be used without 'address' or 'hwaddress'")
				ctx.ModuleErrorf("writeonly modifier cannot be used without 'address' or 'hwaddress'")
			}
			}
			s.Writeonly = boolPtr(true)
			s.Writeonly = proptools.BoolPtr(true)
		}
		}
		if found, globalSanitizers = removeFromList("memtag_heap", globalSanitizers); found && s.Memtag_heap == nil {
		if found, globalSanitizers = removeFromList("memtag_heap", globalSanitizers); found && s.Memtag_heap == nil {
			if !ctx.Config().MemtagHeapDisabledForPath(ctx.ModuleDir()) {
			if !ctx.Config().MemtagHeapDisabledForPath(ctx.ModuleDir()) {
				s.Memtag_heap = boolPtr(true)
				s.Memtag_heap = proptools.BoolPtr(true)
			}
			}
		}
		}


@@ -356,17 +349,17 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
		// Global integer_overflow builds do not support static library diagnostics.
		// Global integer_overflow builds do not support static library diagnostics.
		if found, globalSanitizersDiag = removeFromList("integer_overflow", globalSanitizersDiag); found &&
		if found, globalSanitizersDiag = removeFromList("integer_overflow", globalSanitizersDiag); found &&
			s.Diag.Integer_overflow == nil && Bool(s.Integer_overflow) && !ctx.static() {
			s.Diag.Integer_overflow == nil && Bool(s.Integer_overflow) && !ctx.static() {
			s.Diag.Integer_overflow = boolPtr(true)
			s.Diag.Integer_overflow = proptools.BoolPtr(true)
		}
		}


		if found, globalSanitizersDiag = removeFromList("cfi", globalSanitizersDiag); found &&
		if found, globalSanitizersDiag = removeFromList("cfi", globalSanitizersDiag); found &&
			s.Diag.Cfi == nil && Bool(s.Cfi) {
			s.Diag.Cfi == nil && Bool(s.Cfi) {
			s.Diag.Cfi = boolPtr(true)
			s.Diag.Cfi = proptools.BoolPtr(true)
		}
		}


		if found, globalSanitizersDiag = removeFromList("memtag_heap", globalSanitizersDiag); found &&
		if found, globalSanitizersDiag = removeFromList("memtag_heap", globalSanitizersDiag); found &&
			s.Diag.Memtag_heap == nil && Bool(s.Memtag_heap) {
			s.Diag.Memtag_heap == nil && Bool(s.Memtag_heap) {
			s.Diag.Memtag_heap = boolPtr(true)
			s.Diag.Memtag_heap = proptools.BoolPtr(true)
		}
		}


		if len(globalSanitizersDiag) > 0 {
		if len(globalSanitizersDiag) > 0 {
@@ -378,30 +371,30 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
	if ctx.Arch().ArchType == android.Arm64 {
	if ctx.Arch().ArchType == android.Arm64 {
		if ctx.Config().MemtagHeapSyncEnabledForPath(ctx.ModuleDir()) {
		if ctx.Config().MemtagHeapSyncEnabledForPath(ctx.ModuleDir()) {
			if s.Memtag_heap == nil {
			if s.Memtag_heap == nil {
				s.Memtag_heap = boolPtr(true)
				s.Memtag_heap = proptools.BoolPtr(true)
			}
			}
			if s.Diag.Memtag_heap == nil {
			if s.Diag.Memtag_heap == nil {
				s.Diag.Memtag_heap = boolPtr(true)
				s.Diag.Memtag_heap = proptools.BoolPtr(true)
			}
			}
		} else if ctx.Config().MemtagHeapAsyncEnabledForPath(ctx.ModuleDir()) {
		} else if ctx.Config().MemtagHeapAsyncEnabledForPath(ctx.ModuleDir()) {
			if s.Memtag_heap == nil {
			if s.Memtag_heap == nil {
				s.Memtag_heap = boolPtr(true)
				s.Memtag_heap = proptools.BoolPtr(true)
			}
			}
		}
		}
	}
	}


	// Enable CFI for all components in the include paths (for Aarch64 only)
	// Enable CFI for all components in the include paths (for Aarch64 only)
	if s.Cfi == nil && ctx.Config().CFIEnabledForPath(ctx.ModuleDir()) && ctx.Arch().ArchType == android.Arm64 {
	if s.Cfi == nil && ctx.Config().CFIEnabledForPath(ctx.ModuleDir()) && ctx.Arch().ArchType == android.Arm64 {
		s.Cfi = boolPtr(true)
		s.Cfi = proptools.BoolPtr(true)
		if inList("cfi", ctx.Config().SanitizeDeviceDiag()) {
		if inList("cfi", ctx.Config().SanitizeDeviceDiag()) {
			s.Diag.Cfi = boolPtr(true)
			s.Diag.Cfi = proptools.BoolPtr(true)
		}
		}
	}
	}


	// Is CFI actually enabled?
	// Is CFI actually enabled?
	if !ctx.Config().EnableCFI() {
	if !ctx.Config().EnableCFI() {
		s.Cfi = boolPtr(false)
		s.Cfi = nil
		s.Diag.Cfi = boolPtr(false)
		s.Diag.Cfi = nil
	}
	}


	// HWASan requires AArch64 hardware feature (top-byte-ignore).
	// HWASan requires AArch64 hardware feature (top-byte-ignore).
@@ -421,14 +414,14 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {


	// Also disable CFI if ASAN is enabled.
	// Also disable CFI if ASAN is enabled.
	if Bool(s.Address) || Bool(s.Hwaddress) {
	if Bool(s.Address) || Bool(s.Hwaddress) {
		s.Cfi = boolPtr(false)
		s.Cfi = nil
		s.Diag.Cfi = boolPtr(false)
		s.Diag.Cfi = nil
	}
	}


	// Disable sanitizers that depend on the UBSan runtime for windows/darwin builds.
	// Disable sanitizers that depend on the UBSan runtime for windows/darwin builds.
	if !ctx.Os().Linux() {
	if !ctx.Os().Linux() {
		s.Cfi = boolPtr(false)
		s.Cfi = nil
		s.Diag.Cfi = boolPtr(false)
		s.Diag.Cfi = nil
		s.Misc_undefined = nil
		s.Misc_undefined = nil
		s.Undefined = nil
		s.Undefined = nil
		s.All_undefined = nil
		s.All_undefined = nil
@@ -443,8 +436,8 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
			s.Cfi = nil
			s.Cfi = nil
			s.Diag.Cfi = nil
			s.Diag.Cfi = nil
		} else {
		} else {
			s.Cfi = boolPtr(false)
			s.Cfi = nil
			s.Diag.Cfi = boolPtr(false)
			s.Diag.Cfi = nil
		}
		}
	}
	}


@@ -495,7 +488,7 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
	// TODO(b/131771163): CFI transiently depends on LTO, and thus Fuzzer is
	// TODO(b/131771163): CFI transiently depends on LTO, and thus Fuzzer is
	// mutually incompatible.
	// mutually incompatible.
	if Bool(s.Fuzzer) {
	if Bool(s.Fuzzer) {
		s.Cfi = boolPtr(false)
		s.Cfi = nil
	}
	}
}
}


@@ -781,23 +774,27 @@ func (sanitize *sanitize) isVariantOnProductionDevice() bool {
}
}


func (sanitize *sanitize) SetSanitizer(t SanitizerType, b bool) {
func (sanitize *sanitize) SetSanitizer(t SanitizerType, b bool) {
	bPtr := proptools.BoolPtr(b)
	if !b {
		bPtr = nil
	}
	switch t {
	switch t {
	case Asan:
	case Asan:
		sanitize.Properties.Sanitize.Address = boolPtr(b)
		sanitize.Properties.Sanitize.Address = bPtr
	case Hwasan:
	case Hwasan:
		sanitize.Properties.Sanitize.Hwaddress = boolPtr(b)
		sanitize.Properties.Sanitize.Hwaddress = bPtr
	case tsan:
	case tsan:
		sanitize.Properties.Sanitize.Thread = boolPtr(b)
		sanitize.Properties.Sanitize.Thread = bPtr
	case intOverflow:
	case intOverflow:
		sanitize.Properties.Sanitize.Integer_overflow = boolPtr(b)
		sanitize.Properties.Sanitize.Integer_overflow = bPtr
	case cfi:
	case cfi:
		sanitize.Properties.Sanitize.Cfi = boolPtr(b)
		sanitize.Properties.Sanitize.Cfi = bPtr
	case scs:
	case scs:
		sanitize.Properties.Sanitize.Scs = boolPtr(b)
		sanitize.Properties.Sanitize.Scs = bPtr
	case memtag_heap:
	case memtag_heap:
		sanitize.Properties.Sanitize.Memtag_heap = boolPtr(b)
		sanitize.Properties.Sanitize.Memtag_heap = bPtr
	case Fuzzer:
	case Fuzzer:
		sanitize.Properties.Sanitize.Fuzzer = boolPtr(b)
		sanitize.Properties.Sanitize.Fuzzer = bPtr
	default:
	default:
		panic(fmt.Errorf("unknown SanitizerType %d", t))
		panic(fmt.Errorf("unknown SanitizerType %d", t))
	}
	}
@@ -1253,7 +1250,7 @@ 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() {
			if c.IsDependencyRoot() && 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)
			} else if c.IsSanitizerEnabled(t) || c.SanitizeDep() {
			} else if c.IsSanitizerEnabled(t) || c.SanitizeDep() {
Loading