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

Commit 3968d8f6 authored by Ivan Lozano's avatar Ivan Lozano
Browse files

Refactor CC to prep for Rust sanitizable modules.

Adds a PlatformSanitizable interface which both CC and Rust can
implement so that the sanitizer mutators in CC can sanitize Rust
shared/static libraries appropriately.

Bug: 147140513
Test: m nothing
Change-Id: Ib31103b6c4902a4d5df2565c0d7c981298d100a3
parent c7ca43ec
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -57,14 +57,14 @@ func RegisterCCBuildComponents(ctx android.RegistrationContext) {
	})

	ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
		ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
		ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
		ctx.TopDown("asan_deps", sanitizerDepsMutator(Asan))
		ctx.BottomUp("asan", sanitizerMutator(Asan)).Parallel()

		ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
		ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()

		ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
		ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
		ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(Fuzzer))
		ctx.BottomUp("fuzzer", sanitizerMutator(Fuzzer)).Parallel()

		// cfi mutator shouldn't run before sanitizers that return true for
		// incompatibleWithCfi()
@@ -785,6 +785,14 @@ type Module struct {
	hideApexVariantFromMake bool
}

func (c *Module) SetPreventInstall() {
	c.Properties.PreventInstall = true
}

func (c *Module) SetHideFromMake() {
	c.Properties.HideFromMake = true
}

func (c *Module) Toc() android.OptionalPath {
	if c.linker != nil {
		if library, ok := c.linker.(libraryInterface); ok {
@@ -1026,7 +1034,7 @@ func (c *Module) Init() android.Module {

// Returns true for dependency roots (binaries)
// TODO(ccross): also handle dlopenable libraries
func (c *Module) isDependencyRoot() bool {
func (c *Module) IsDependencyRoot() bool {
	if root, ok := c.linker.(interface {
		isDependencyRoot() bool
	}); ok {
@@ -1264,7 +1272,7 @@ func (ctx *moduleContextImpl) staticBinary() bool {
}

func (ctx *moduleContextImpl) header() bool {
	return ctx.mod.header()
	return ctx.mod.Header()
}

func (ctx *moduleContextImpl) binary() bool {
@@ -1421,6 +1429,10 @@ func (c *Module) Prebuilt() *android.Prebuilt {
	return nil
}

func (c *Module) IsPrebuilt() bool {
	return c.Prebuilt() != nil
}

func (c *Module) Name() string {
	name := c.ModuleBase.Name()
	if p, ok := c.linker.(interface {
@@ -2847,7 +2859,7 @@ func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface,
				return baseName + ".vendor"
			}

			if c.inVendor() && vendorSuffixModules[baseName] {
			if c.InVendor() && vendorSuffixModules[baseName] {
				return baseName + ".vendor"
			} else if c.InRecovery() && recoverySuffixModules[baseName] {
				return baseName + ".recovery"
@@ -2959,7 +2971,8 @@ func (c *Module) staticBinary() bool {
	return false
}

func (c *Module) header() bool {
// Header returns true if the module is a header-only variant. (See cc/library.go header()).
func (c *Module) Header() bool {
	if h, ok := c.linker.(interface {
		header() bool
	}); ok {
+1 −1
Original line number Diff line number Diff line
@@ -315,7 +315,7 @@ func NewFuzz(hod android.HostOrDeviceSupported) *Module {
	module, binary := NewBinary(hod)

	binary.baseInstaller = NewFuzzInstaller()
	module.sanitize.SetSanitizer(fuzzer, true)
	module.sanitize.SetSanitizer(Fuzzer, true)

	fuzz := &fuzzBinary{
		binaryDecorator: binary,
+11 −29
Original line number Diff line number Diff line
@@ -26,36 +26,18 @@ import (

var _ android.ImageInterface = (*Module)(nil)

type imageVariantType string
type ImageVariantType string

const (
	coreImageVariant          imageVariantType = "core"
	vendorImageVariant        imageVariantType = "vendor"
	productImageVariant       imageVariantType = "product"
	ramdiskImageVariant       imageVariantType = "ramdisk"
	vendorRamdiskImageVariant imageVariantType = "vendor_ramdisk"
	recoveryImageVariant      imageVariantType = "recovery"
	hostImageVariant          imageVariantType = "host"
	coreImageVariant          ImageVariantType = "core"
	vendorImageVariant        ImageVariantType = "vendor"
	productImageVariant       ImageVariantType = "product"
	ramdiskImageVariant       ImageVariantType = "ramdisk"
	vendorRamdiskImageVariant ImageVariantType = "vendor_ramdisk"
	recoveryImageVariant      ImageVariantType = "recovery"
	hostImageVariant          ImageVariantType = "host"
)

func (c *Module) getImageVariantType() imageVariantType {
	if c.Host() {
		return hostImageVariant
	} else if c.inVendor() {
		return vendorImageVariant
	} else if c.InProduct() {
		return productImageVariant
	} else if c.InRamdisk() {
		return ramdiskImageVariant
	} else if c.InVendorRamdisk() {
		return vendorRamdiskImageVariant
	} else if c.InRecovery() {
		return recoveryImageVariant
	} else {
		return coreImageVariant
	}
}

const (
	// VendorVariationPrefix is the variant prefix used for /vendor code that compiles
	// against the VNDK.
@@ -75,7 +57,7 @@ func (ctx *moduleContext) ProductSpecific() bool {
func (ctx *moduleContext) SocSpecific() bool {
	// Additionally check if this module is inVendor() that means it is a "vendor" variant of a
	// module. As well as SoC specific modules, vendor variants must be installed to /vendor.
	return ctx.ModuleContext.SocSpecific() || ctx.mod.inVendor()
	return ctx.ModuleContext.SocSpecific() || ctx.mod.InVendor()
}

func (ctx *moduleContextImpl) inProduct() bool {
@@ -83,7 +65,7 @@ func (ctx *moduleContextImpl) inProduct() bool {
}

func (ctx *moduleContextImpl) inVendor() bool {
	return ctx.mod.inVendor()
	return ctx.mod.InVendor()
}

func (ctx *moduleContextImpl) inRamdisk() bool {
@@ -119,7 +101,7 @@ func (c *Module) InProduct() bool {
}

// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
func (c *Module) inVendor() bool {
func (c *Module) InVendor() bool {
	return c.Properties.ImageVariationPrefix == VendorVariationPrefix
}

+82 −0
Original line number Diff line number Diff line
@@ -6,6 +6,59 @@ import (
	"github.com/google/blueprint"
)

// PlatformSanitizeable is an interface for sanitizing platform modules.
type PlatformSanitizeable interface {
	LinkableInterface

	// SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
	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(t SanitizerType) bool

	// IsSanitizerExplicitlyDisabled returns whether a sanitizer has been explicitly disabled (set to false) rather
	// than left undefined.
	IsSanitizerExplicitlyDisabled(t SanitizerType) bool

	// SanitizeDep returns the value of the SanitizeDep flag, which is set if a module is a dependency of a
	// sanitized module.
	SanitizeDep() bool

	// SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
	SetSanitizer(t SanitizerType, b bool)

	// SetSanitizerDep returns true if the module is statically linked.
	SetSanitizeDep(b bool)

	// StaticallyLinked returns true if the module is statically linked.
	StaticallyLinked() bool

	// SetInSanitizerDir sets the module installation to the sanitizer directory.
	SetInSanitizerDir()

	// SanitizeNever returns true if this module should never be sanitized.
	SanitizeNever() bool

	// SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
	SanitizerSupported(t SanitizerType) bool

	// SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
	SanitizableDepTagChecker() SantizableDependencyTagChecker
}

// SantizableDependencyTagChecker functions check whether or not a dependency
// tag can be sanitized. These functions should return true if the tag can be
// sanitized, otherwise they should return false. These functions should also
// handle all possible dependency tags in the dependency tree. For example,
// Rust modules can depend on both Rust and CC libraries, so the Rust module
// implementation should handle tags from both.
type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool

// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
type LinkableInterface interface {
	android.Module
@@ -27,6 +80,8 @@ type LinkableInterface interface {
	SetShared()
	Static() bool
	Shared() bool
	Header() bool
	IsPrebuilt() bool
	Toc() android.OptionalPath

	Host() bool
@@ -40,6 +95,8 @@ type LinkableInterface interface {
	InRecovery() bool
	OnlyInRecovery() bool

	InVendor() bool

	UseSdk() bool
	UseVndk() bool
	MustUseVendorVariant() bool
@@ -56,6 +113,11 @@ type LinkableInterface interface {
	IsSdkVariant() bool

	SplitPerApiLevel() bool

	// SetPreventInstall sets the PreventInstall property to 'true' for this module.
	SetPreventInstall()
	// SetHideFromMake sets the HideFromMake property to 'true' for this module.
	SetHideFromMake()
}

var (
@@ -67,6 +129,26 @@ var (
	CoverageDepTag = dependencyTag{name: "coverage"}
)

// GetImageVariantType returns the ImageVariantType string value for the given module
// (these are defined in cc/image.go).
func GetImageVariantType(c LinkableInterface) ImageVariantType {
	if c.Host() {
		return hostImageVariant
	} else if c.InVendor() {
		return vendorImageVariant
	} else if c.InProduct() {
		return productImageVariant
	} else if c.InRamdisk() {
		return ramdiskImageVariant
	} else if c.InVendorRamdisk() {
		return vendorRamdiskImageVariant
	} else if c.InRecovery() {
		return recoveryImageVariant
	} else {
		return coreImageVariant
	}
}

// SharedDepTag returns the dependency tag for any C++ shared libraries.
func SharedDepTag() blueprint.DependencyTag {
	return libraryDependencyTag{Kind: sharedLibraryDependency}
+168 −80

File changed.

Preview size limit exceeded, changes collapsed.

Loading