Merge changes I46e851c8,I2c9eb248
* changes: rust: Add HWASan build support Export CC HWASan sanitizer type
This commit is contained in:
4
cc/cc.go
4
cc/cc.go
@@ -56,8 +56,8 @@ func RegisterCCBuildComponents(ctx android.RegistrationContext) {
|
|||||||
ctx.TopDown("asan_deps", sanitizerDepsMutator(Asan))
|
ctx.TopDown("asan_deps", sanitizerDepsMutator(Asan))
|
||||||
ctx.BottomUp("asan", sanitizerMutator(Asan)).Parallel()
|
ctx.BottomUp("asan", sanitizerMutator(Asan)).Parallel()
|
||||||
|
|
||||||
ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
|
ctx.TopDown("hwasan_deps", sanitizerDepsMutator(Hwasan))
|
||||||
ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
|
ctx.BottomUp("hwasan", sanitizerMutator(Hwasan)).Parallel()
|
||||||
|
|
||||||
ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(Fuzzer))
|
ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(Fuzzer))
|
||||||
ctx.BottomUp("fuzzer", sanitizerMutator(Fuzzer)).Parallel()
|
ctx.BottomUp("fuzzer", sanitizerMutator(Fuzzer)).Parallel()
|
||||||
|
@@ -83,7 +83,7 @@ func boolPtr(v bool) *bool {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
Asan SanitizerType = iota + 1
|
Asan SanitizerType = iota + 1
|
||||||
hwasan
|
Hwasan
|
||||||
tsan
|
tsan
|
||||||
intOverflow
|
intOverflow
|
||||||
cfi
|
cfi
|
||||||
@@ -97,7 +97,7 @@ func (t SanitizerType) variationName() string {
|
|||||||
switch t {
|
switch t {
|
||||||
case Asan:
|
case Asan:
|
||||||
return "asan"
|
return "asan"
|
||||||
case hwasan:
|
case Hwasan:
|
||||||
return "hwasan"
|
return "hwasan"
|
||||||
case tsan:
|
case tsan:
|
||||||
return "tsan"
|
return "tsan"
|
||||||
@@ -121,7 +121,7 @@ func (t SanitizerType) name() string {
|
|||||||
switch t {
|
switch t {
|
||||||
case Asan:
|
case Asan:
|
||||||
return "address"
|
return "address"
|
||||||
case hwasan:
|
case Hwasan:
|
||||||
return "hwaddress"
|
return "hwaddress"
|
||||||
case memtag_heap:
|
case memtag_heap:
|
||||||
return "memtag_heap"
|
return "memtag_heap"
|
||||||
@@ -144,7 +144,7 @@ func (*Module) SanitizerSupported(t SanitizerType) bool {
|
|||||||
switch t {
|
switch t {
|
||||||
case Asan:
|
case Asan:
|
||||||
return true
|
return true
|
||||||
case hwasan:
|
case Hwasan:
|
||||||
return true
|
return true
|
||||||
case tsan:
|
case tsan:
|
||||||
return true
|
return true
|
||||||
@@ -163,7 +163,7 @@ func (*Module) SanitizerSupported(t SanitizerType) bool {
|
|||||||
|
|
||||||
// incompatibleWithCfi returns true if a sanitizer is incompatible with CFI.
|
// incompatibleWithCfi returns true if a sanitizer is incompatible with CFI.
|
||||||
func (t SanitizerType) incompatibleWithCfi() bool {
|
func (t SanitizerType) incompatibleWithCfi() bool {
|
||||||
return t == Asan || t == Fuzzer || t == hwasan
|
return t == Asan || t == Fuzzer || t == Hwasan
|
||||||
}
|
}
|
||||||
|
|
||||||
type SanitizeUserProps struct {
|
type SanitizeUserProps struct {
|
||||||
@@ -745,7 +745,7 @@ func (sanitize *sanitize) getSanitizerBoolPtr(t SanitizerType) *bool {
|
|||||||
switch t {
|
switch t {
|
||||||
case Asan:
|
case Asan:
|
||||||
return sanitize.Properties.Sanitize.Address
|
return sanitize.Properties.Sanitize.Address
|
||||||
case hwasan:
|
case Hwasan:
|
||||||
return sanitize.Properties.Sanitize.Hwaddress
|
return sanitize.Properties.Sanitize.Hwaddress
|
||||||
case tsan:
|
case tsan:
|
||||||
return sanitize.Properties.Sanitize.Thread
|
return sanitize.Properties.Sanitize.Thread
|
||||||
@@ -767,7 +767,7 @@ func (sanitize *sanitize) getSanitizerBoolPtr(t SanitizerType) *bool {
|
|||||||
// isUnsanitizedVariant returns true if no sanitizers are enabled.
|
// isUnsanitizedVariant returns true if no sanitizers are enabled.
|
||||||
func (sanitize *sanitize) isUnsanitizedVariant() bool {
|
func (sanitize *sanitize) isUnsanitizedVariant() bool {
|
||||||
return !sanitize.isSanitizerEnabled(Asan) &&
|
return !sanitize.isSanitizerEnabled(Asan) &&
|
||||||
!sanitize.isSanitizerEnabled(hwasan) &&
|
!sanitize.isSanitizerEnabled(Hwasan) &&
|
||||||
!sanitize.isSanitizerEnabled(tsan) &&
|
!sanitize.isSanitizerEnabled(tsan) &&
|
||||||
!sanitize.isSanitizerEnabled(cfi) &&
|
!sanitize.isSanitizerEnabled(cfi) &&
|
||||||
!sanitize.isSanitizerEnabled(scs) &&
|
!sanitize.isSanitizerEnabled(scs) &&
|
||||||
@@ -778,7 +778,7 @@ func (sanitize *sanitize) isUnsanitizedVariant() bool {
|
|||||||
// isVariantOnProductionDevice returns true if variant is for production devices (no non-production sanitizers enabled).
|
// isVariantOnProductionDevice returns true if variant is for production devices (no non-production sanitizers enabled).
|
||||||
func (sanitize *sanitize) isVariantOnProductionDevice() bool {
|
func (sanitize *sanitize) isVariantOnProductionDevice() bool {
|
||||||
return !sanitize.isSanitizerEnabled(Asan) &&
|
return !sanitize.isSanitizerEnabled(Asan) &&
|
||||||
!sanitize.isSanitizerEnabled(hwasan) &&
|
!sanitize.isSanitizerEnabled(Hwasan) &&
|
||||||
!sanitize.isSanitizerEnabled(tsan) &&
|
!sanitize.isSanitizerEnabled(tsan) &&
|
||||||
!sanitize.isSanitizerEnabled(Fuzzer)
|
!sanitize.isSanitizerEnabled(Fuzzer)
|
||||||
}
|
}
|
||||||
@@ -787,7 +787,7 @@ func (sanitize *sanitize) SetSanitizer(t SanitizerType, b bool) {
|
|||||||
switch t {
|
switch t {
|
||||||
case Asan:
|
case Asan:
|
||||||
sanitize.Properties.Sanitize.Address = boolPtr(b)
|
sanitize.Properties.Sanitize.Address = boolPtr(b)
|
||||||
case hwasan:
|
case Hwasan:
|
||||||
sanitize.Properties.Sanitize.Hwaddress = boolPtr(b)
|
sanitize.Properties.Sanitize.Hwaddress = boolPtr(b)
|
||||||
case tsan:
|
case tsan:
|
||||||
sanitize.Properties.Sanitize.Thread = boolPtr(b)
|
sanitize.Properties.Sanitize.Thread = boolPtr(b)
|
||||||
@@ -902,7 +902,7 @@ func sanitizerDepsMutator(t SanitizerType) func(android.TopDownMutatorContext) {
|
|||||||
if d, ok := child.(PlatformSanitizeable); ok && d.SanitizePropDefined() &&
|
if d, ok := child.(PlatformSanitizeable); ok && d.SanitizePropDefined() &&
|
||||||
!d.SanitizeNever() &&
|
!d.SanitizeNever() &&
|
||||||
!d.IsSanitizerExplicitlyDisabled(t) {
|
!d.IsSanitizerExplicitlyDisabled(t) {
|
||||||
if t == cfi || t == hwasan || t == scs {
|
if t == cfi || t == Hwasan || t == scs {
|
||||||
if d.StaticallyLinked() && d.SanitizerSupported(t) {
|
if d.StaticallyLinked() && d.SanitizerSupported(t) {
|
||||||
// Rust does not support some of these sanitizers, so we need to check if it's
|
// Rust does not support some of these sanitizers, so we need to check if it's
|
||||||
// supported before setting this true.
|
// supported before setting this true.
|
||||||
@@ -1286,7 +1286,7 @@ func sanitizerMutator(t SanitizerType) func(android.BottomUpMutatorContext) {
|
|||||||
// For cfi/scs/hwasan, we can export both sanitized and un-sanitized variants
|
// For cfi/scs/hwasan, we can export both sanitized and un-sanitized variants
|
||||||
// to Make, because the sanitized version has a different suffix in name.
|
// to Make, because the sanitized version has a different suffix in name.
|
||||||
// For other types of sanitizers, suppress the variation that is disabled.
|
// For other types of sanitizers, suppress the variation that is disabled.
|
||||||
if t != cfi && t != scs && t != hwasan {
|
if t != cfi && t != scs && t != Hwasan {
|
||||||
if isSanitizerEnabled {
|
if isSanitizerEnabled {
|
||||||
modules[0].(PlatformSanitizeable).SetPreventInstall()
|
modules[0].(PlatformSanitizeable).SetPreventInstall()
|
||||||
modules[0].(PlatformSanitizeable).SetHideFromMake()
|
modules[0].(PlatformSanitizeable).SetHideFromMake()
|
||||||
@@ -1300,7 +1300,7 @@ func sanitizerMutator(t SanitizerType) func(android.BottomUpMutatorContext) {
|
|||||||
if c.StaticallyLinked() && c.ExportedToMake() {
|
if c.StaticallyLinked() && c.ExportedToMake() {
|
||||||
if t == cfi {
|
if t == cfi {
|
||||||
cfiStaticLibs(mctx.Config()).add(c, c.Module().Name())
|
cfiStaticLibs(mctx.Config()).add(c, c.Module().Name())
|
||||||
} else if t == hwasan {
|
} else if t == Hwasan {
|
||||||
hwasanStaticLibs(mctx.Config()).add(c, c.Module().Name())
|
hwasanStaticLibs(mctx.Config()).add(c, c.Module().Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1417,7 +1417,7 @@ var hwasanStaticLibsKey = android.NewOnceKey("hwasanStaticLibs")
|
|||||||
|
|
||||||
func hwasanStaticLibs(config android.Config) *sanitizerStaticLibsMap {
|
func hwasanStaticLibs(config android.Config) *sanitizerStaticLibsMap {
|
||||||
return config.Once(hwasanStaticLibsKey, func() interface{} {
|
return config.Once(hwasanStaticLibsKey, func() interface{} {
|
||||||
return newSanitizerStaticLibsMap(hwasan)
|
return newSanitizerStaticLibsMap(Hwasan)
|
||||||
}).(*sanitizerStaticLibsMap)
|
}).(*sanitizerStaticLibsMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -196,7 +196,7 @@ func isSnapshotAware(cfg android.DeviceConfig, m *Module, inProprietaryPath bool
|
|||||||
if m.sanitize != nil {
|
if m.sanitize != nil {
|
||||||
// scs and hwasan export both sanitized and unsanitized variants for static and header
|
// scs and hwasan export both sanitized and unsanitized variants for static and header
|
||||||
// Always use unsanitized variants of them.
|
// Always use unsanitized variants of them.
|
||||||
for _, t := range []SanitizerType{scs, hwasan} {
|
for _, t := range []SanitizerType{scs, Hwasan} {
|
||||||
if !l.shared() && m.sanitize.isSanitizerEnabled(t) {
|
if !l.shared() && m.sanitize.isSanitizerEnabled(t) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@@ -70,6 +70,11 @@ func (mod *Module) AndroidMkEntries() []android.AndroidMkEntries {
|
|||||||
// If the compiler is disabled, this is a SourceProvider.
|
// If the compiler is disabled, this is a SourceProvider.
|
||||||
mod.SubAndroidMk(&ret, mod.sourceProvider)
|
mod.SubAndroidMk(&ret, mod.sourceProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if mod.sanitize != nil {
|
||||||
|
mod.SubAndroidMk(&ret, mod.sanitize)
|
||||||
|
}
|
||||||
|
|
||||||
ret.SubName += mod.Properties.SubName
|
ret.SubName += mod.Properties.SubName
|
||||||
|
|
||||||
return []android.AndroidMkEntries{ret}
|
return []android.AndroidMkEntries{ret}
|
||||||
|
@@ -23,11 +23,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SanitizeProperties struct {
|
type SanitizeProperties struct {
|
||||||
// enable AddressSanitizer, ThreadSanitizer, or UndefinedBehaviorSanitizer
|
// enable AddressSanitizer, HWAddressSanitizer, and others.
|
||||||
Sanitize struct {
|
Sanitize struct {
|
||||||
Address *bool `android:"arch_variant"`
|
Address *bool `android:"arch_variant"`
|
||||||
Fuzzer *bool `android:"arch_variant"`
|
Hwaddress *bool `android:"arch_variant"`
|
||||||
Never *bool `android:"arch_variant"`
|
Fuzzer *bool `android:"arch_variant"`
|
||||||
|
Never *bool `android:"arch_variant"`
|
||||||
}
|
}
|
||||||
SanitizerEnabled bool `blueprint:"mutated"`
|
SanitizerEnabled bool `blueprint:"mutated"`
|
||||||
SanitizeDep bool `blueprint:"mutated"`
|
SanitizeDep bool `blueprint:"mutated"`
|
||||||
@@ -56,6 +57,11 @@ var asanFlags = []string{
|
|||||||
"-Z sanitizer=address",
|
"-Z sanitizer=address",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hwasanFlags = []string{
|
||||||
|
"-Z sanitizer=hwaddress",
|
||||||
|
"-C target-feature=+tagged-globals",
|
||||||
|
}
|
||||||
|
|
||||||
func boolPtr(v bool) *bool {
|
func boolPtr(v bool) *bool {
|
||||||
if v {
|
if v {
|
||||||
return &v
|
return &v
|
||||||
@@ -82,6 +88,15 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
|
|||||||
if ctx.Os() == android.Android && Bool(s.Address) {
|
if ctx.Os() == android.Android && Bool(s.Address) {
|
||||||
sanitize.Properties.SanitizerEnabled = true
|
sanitize.Properties.SanitizerEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HWASan requires AArch64 hardware feature (top-byte-ignore).
|
||||||
|
if ctx.Arch().ArchType != android.Arm64 {
|
||||||
|
s.Hwaddress = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctx.Os() == android.Android && Bool(s.Hwaddress) {
|
||||||
|
sanitize.Properties.SanitizerEnabled = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type sanitize struct {
|
type sanitize struct {
|
||||||
@@ -98,6 +113,9 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags, deps PathDeps) (
|
|||||||
if Bool(sanitize.Properties.Sanitize.Address) {
|
if Bool(sanitize.Properties.Sanitize.Address) {
|
||||||
flags.RustFlags = append(flags.RustFlags, asanFlags...)
|
flags.RustFlags = append(flags.RustFlags, asanFlags...)
|
||||||
}
|
}
|
||||||
|
if Bool(sanitize.Properties.Sanitize.Hwaddress) {
|
||||||
|
flags.RustFlags = append(flags.RustFlags, hwasanFlags...)
|
||||||
|
}
|
||||||
return flags, deps
|
return flags, deps
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,11 +128,38 @@ func rustSanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
if !mod.Enabled() {
|
if !mod.Enabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variations := mctx.Target().Variations()
|
||||||
|
var depTag blueprint.DependencyTag
|
||||||
|
var deps []string
|
||||||
|
|
||||||
if Bool(mod.sanitize.Properties.Sanitize.Fuzzer) || Bool(mod.sanitize.Properties.Sanitize.Address) {
|
if Bool(mod.sanitize.Properties.Sanitize.Fuzzer) || Bool(mod.sanitize.Properties.Sanitize.Address) {
|
||||||
mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
|
variations = append(variations,
|
||||||
{Mutator: "link", Variation: "shared"},
|
blueprint.Variation{Mutator: "link", Variation: "shared"})
|
||||||
}...), cc.SharedDepTag(), config.LibclangRuntimeLibrary(mod.toolchain(mctx), "asan"))
|
depTag = cc.SharedDepTag()
|
||||||
|
deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "asan")}
|
||||||
|
} else if mod.IsSanitizerEnabled(cc.Hwasan) {
|
||||||
|
// 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) {
|
||||||
|
mctx.ModuleErrorf("HWASan is not supported for static Rust executables yet.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if mod.StaticallyLinked() {
|
||||||
|
variations = append(variations,
|
||||||
|
blueprint.Variation{Mutator: "link", Variation: "static"})
|
||||||
|
depTag = cc.StaticDepTag(false)
|
||||||
|
deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "hwasan_static")}
|
||||||
|
} else {
|
||||||
|
variations = append(variations,
|
||||||
|
blueprint.Variation{Mutator: "link", Variation: "shared"})
|
||||||
|
depTag = cc.SharedDepTag()
|
||||||
|
deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "hwasan")}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mctx.AddFarVariationDependencies(variations, depTag, deps...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +172,9 @@ func (sanitize *sanitize) SetSanitizer(t cc.SanitizerType, b bool) {
|
|||||||
case cc.Asan:
|
case cc.Asan:
|
||||||
sanitize.Properties.Sanitize.Address = boolPtr(b)
|
sanitize.Properties.Sanitize.Address = boolPtr(b)
|
||||||
sanitizerSet = true
|
sanitizerSet = true
|
||||||
|
case cc.Hwasan:
|
||||||
|
sanitize.Properties.Sanitize.Hwaddress = boolPtr(b)
|
||||||
|
sanitizerSet = true
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("setting unsupported sanitizerType %d", t))
|
panic(fmt.Errorf("setting unsupported sanitizerType %d", t))
|
||||||
}
|
}
|
||||||
@@ -168,11 +216,23 @@ func (sanitize *sanitize) getSanitizerBoolPtr(t cc.SanitizerType) *bool {
|
|||||||
return sanitize.Properties.Sanitize.Fuzzer
|
return sanitize.Properties.Sanitize.Fuzzer
|
||||||
case cc.Asan:
|
case cc.Asan:
|
||||||
return sanitize.Properties.Sanitize.Address
|
return sanitize.Properties.Sanitize.Address
|
||||||
|
case cc.Hwasan:
|
||||||
|
return sanitize.Properties.Sanitize.Hwaddress
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
||||||
|
// Add a suffix for hwasan rlib libraries to allow surfacing both the sanitized and
|
||||||
|
// non-sanitized variants to make without a name conflict.
|
||||||
|
if entries.Class == "RLIB_LIBRARIES" || entries.Class == "STATIC_LIBRARIES" {
|
||||||
|
if sanitize.isSanitizerEnabled(cc.Hwasan) {
|
||||||
|
entries.SubName += ".hwasan"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (mod *Module) SanitizerSupported(t cc.SanitizerType) bool {
|
func (mod *Module) SanitizerSupported(t cc.SanitizerType) bool {
|
||||||
if mod.Host() {
|
if mod.Host() {
|
||||||
return false
|
return false
|
||||||
@@ -182,6 +242,8 @@ func (mod *Module) SanitizerSupported(t cc.SanitizerType) bool {
|
|||||||
return true
|
return true
|
||||||
case cc.Asan:
|
case cc.Asan:
|
||||||
return true
|
return true
|
||||||
|
case cc.Hwasan:
|
||||||
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user