Merge "Allow hwasan variant for vendor_snapshot_static modules"
This commit is contained in:
@@ -530,8 +530,10 @@ func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entrie
|
|||||||
|
|
||||||
entries.SubName = ""
|
entries.SubName = ""
|
||||||
|
|
||||||
if c.sanitizerProperties.CfiEnabled {
|
if c.isSanitizerEnabled(cfi) {
|
||||||
entries.SubName += ".cfi"
|
entries.SubName += ".cfi"
|
||||||
|
} else if c.isSanitizerEnabled(Hwasan) {
|
||||||
|
entries.SubName += ".hwasan"
|
||||||
}
|
}
|
||||||
|
|
||||||
entries.SubName += c.baseProperties.Androidmk_suffix
|
entries.SubName += c.baseProperties.Androidmk_suffix
|
||||||
|
@@ -1171,7 +1171,7 @@ func (s *sanitizerSplitMutator) Split(ctx android.BaseModuleContext) []string {
|
|||||||
//TODO: When Rust modules have vendor support, enable this path for PlatformSanitizeable
|
//TODO: When Rust modules have vendor support, enable this path for PlatformSanitizeable
|
||||||
|
|
||||||
// Check if it's a snapshot module supporting sanitizer
|
// Check if it's a snapshot module supporting sanitizer
|
||||||
if ss, ok := c.linker.(snapshotSanitizer); ok && ss.isSanitizerEnabled(s.sanitizer) {
|
if ss, ok := c.linker.(snapshotSanitizer); ok && ss.isSanitizerAvailable(s.sanitizer) {
|
||||||
return []string{"", s.sanitizer.variationName()}
|
return []string{"", s.sanitizer.variationName()}
|
||||||
} else {
|
} else {
|
||||||
return []string{""}
|
return []string{""}
|
||||||
@@ -1203,7 +1203,7 @@ func (s *sanitizerSplitMutator) OutgoingTransition(ctx android.OutgoingTransitio
|
|||||||
func (s *sanitizerSplitMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string {
|
func (s *sanitizerSplitMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string {
|
||||||
if d, ok := ctx.Module().(PlatformSanitizeable); ok {
|
if d, ok := ctx.Module().(PlatformSanitizeable); ok {
|
||||||
if dm, ok := ctx.Module().(*Module); ok {
|
if dm, ok := ctx.Module().(*Module); ok {
|
||||||
if ss, ok := dm.linker.(snapshotSanitizer); ok && ss.isSanitizerEnabled(s.sanitizer) {
|
if ss, ok := dm.linker.(snapshotSanitizer); ok && ss.isSanitizerAvailable(s.sanitizer) {
|
||||||
return incomingVariation
|
return incomingVariation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1319,14 +1319,23 @@ func (s *sanitizerSplitMutator) Mutate(mctx android.BottomUpMutatorContext, vari
|
|||||||
sanitizeable.AddSanitizerDependencies(mctx, s.sanitizer.name())
|
sanitizeable.AddSanitizerDependencies(mctx, s.sanitizer.name())
|
||||||
}
|
}
|
||||||
} else if c, ok := mctx.Module().(*Module); ok {
|
} else if c, ok := mctx.Module().(*Module); ok {
|
||||||
if ss, ok := c.linker.(snapshotSanitizer); ok && ss.isSanitizerEnabled(s.sanitizer) {
|
if ss, ok := c.linker.(snapshotSanitizer); ok && ss.isSanitizerAvailable(s.sanitizer) {
|
||||||
|
if !ss.isUnsanitizedVariant() {
|
||||||
|
// Snapshot sanitizer may have only one variantion.
|
||||||
|
// Skip exporting the module if it already has a sanitizer variation.
|
||||||
|
c.SetPreventInstall()
|
||||||
|
c.SetHideFromMake()
|
||||||
|
return
|
||||||
|
}
|
||||||
c.linker.(snapshotSanitizer).setSanitizerVariation(s.sanitizer, sanitizerVariation)
|
c.linker.(snapshotSanitizer).setSanitizerVariation(s.sanitizer, sanitizerVariation)
|
||||||
|
|
||||||
// Export the static lib name to make
|
// Export the static lib name to make
|
||||||
if c.static() && c.ExportedToMake() {
|
if c.static() && c.ExportedToMake() {
|
||||||
|
// use BaseModuleName which is the name for Make.
|
||||||
if s.sanitizer == cfi {
|
if s.sanitizer == cfi {
|
||||||
// use BaseModuleName which is the name for Make.
|
|
||||||
cfiStaticLibs(mctx.Config()).add(c, c.BaseModuleName())
|
cfiStaticLibs(mctx.Config()).add(c, c.BaseModuleName())
|
||||||
|
} else if s.sanitizer == Hwasan {
|
||||||
|
hwasanStaticLibs(mctx.Config()).add(c, c.BaseModuleName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ package cc
|
|||||||
// snapshot mutators and snapshot information maps which are also defined in this file.
|
// snapshot mutators and snapshot information maps which are also defined in this file.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
@@ -399,8 +400,10 @@ type SnapshotLibraryProperties struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type snapshotSanitizer interface {
|
type snapshotSanitizer interface {
|
||||||
isSanitizerEnabled(t SanitizerType) bool
|
isSanitizerAvailable(t SanitizerType) bool
|
||||||
setSanitizerVariation(t SanitizerType, enabled bool)
|
setSanitizerVariation(t SanitizerType, enabled bool)
|
||||||
|
isSanitizerEnabled(t SanitizerType) bool
|
||||||
|
isUnsanitizedVariant() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type snapshotLibraryDecorator struct {
|
type snapshotLibraryDecorator struct {
|
||||||
@@ -408,10 +411,13 @@ type snapshotLibraryDecorator struct {
|
|||||||
*libraryDecorator
|
*libraryDecorator
|
||||||
properties SnapshotLibraryProperties
|
properties SnapshotLibraryProperties
|
||||||
sanitizerProperties struct {
|
sanitizerProperties struct {
|
||||||
CfiEnabled bool `blueprint:"mutated"`
|
SanitizerVariation SanitizerType `blueprint:"mutated"`
|
||||||
|
|
||||||
// Library flags for cfi variant.
|
// Library flags for cfi variant.
|
||||||
Cfi SnapshotLibraryProperties `android:"arch_variant"`
|
Cfi SnapshotLibraryProperties `android:"arch_variant"`
|
||||||
|
|
||||||
|
// Library flags for hwasan variant.
|
||||||
|
Hwasan SnapshotLibraryProperties `android:"arch_variant"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,8 +456,10 @@ func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps Pat
|
|||||||
return p.libraryDecorator.link(ctx, flags, deps, objs)
|
return p.libraryDecorator.link(ctx, flags, deps, objs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.sanitizerProperties.CfiEnabled {
|
if p.isSanitizerEnabled(cfi) {
|
||||||
p.properties = p.sanitizerProperties.Cfi
|
p.properties = p.sanitizerProperties.Cfi
|
||||||
|
} else if p.isSanitizerEnabled(Hwasan) {
|
||||||
|
p.properties = p.sanitizerProperties.Hwasan
|
||||||
}
|
}
|
||||||
|
|
||||||
if !p.MatchesWithDevice(ctx.DeviceConfig()) {
|
if !p.MatchesWithDevice(ctx.DeviceConfig()) {
|
||||||
@@ -514,25 +522,34 @@ func (p *snapshotLibraryDecorator) nativeCoverage() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *snapshotLibraryDecorator) isSanitizerEnabled(t SanitizerType) bool {
|
func (p *snapshotLibraryDecorator) isSanitizerAvailable(t SanitizerType) bool {
|
||||||
switch t {
|
switch t {
|
||||||
case cfi:
|
case cfi:
|
||||||
return p.sanitizerProperties.Cfi.Src != nil
|
return p.sanitizerProperties.Cfi.Src != nil
|
||||||
|
case Hwasan:
|
||||||
|
return p.sanitizerProperties.Hwasan.Src != nil
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *snapshotLibraryDecorator) setSanitizerVariation(t SanitizerType, enabled bool) {
|
func (p *snapshotLibraryDecorator) setSanitizerVariation(t SanitizerType, enabled bool) {
|
||||||
if !enabled {
|
if !enabled || p.isSanitizerEnabled(t) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch t {
|
if !p.isUnsanitizedVariant() {
|
||||||
case cfi:
|
panic(fmt.Errorf("snapshot Sanitizer must be one of Cfi or Hwasan but not both"))
|
||||||
p.sanitizerProperties.CfiEnabled = true
|
|
||||||
default:
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
p.sanitizerProperties.SanitizerVariation = t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *snapshotLibraryDecorator) isSanitizerEnabled(t SanitizerType) bool {
|
||||||
|
return p.sanitizerProperties.SanitizerVariation == t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *snapshotLibraryDecorator) isUnsanitizedVariant() bool {
|
||||||
|
return !p.isSanitizerEnabled(Asan) &&
|
||||||
|
!p.isSanitizerEnabled(Hwasan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func snapshotLibraryFactory(image SnapshotImage, moduleSuffix string) (*Module, *snapshotLibraryDecorator) {
|
func snapshotLibraryFactory(image SnapshotImage, moduleSuffix string) (*Module, *snapshotLibraryDecorator) {
|
||||||
|
@@ -1053,6 +1053,7 @@ func TestVendorSnapshotSanitizer(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
vendor_snapshot_static {
|
vendor_snapshot_static {
|
||||||
name: "libsnapshot",
|
name: "libsnapshot",
|
||||||
vendor: true,
|
vendor: true,
|
||||||
@@ -1063,7 +1064,10 @@ func TestVendorSnapshotSanitizer(t *testing.T) {
|
|||||||
src: "libsnapshot.a",
|
src: "libsnapshot.a",
|
||||||
cfi: {
|
cfi: {
|
||||||
src: "libsnapshot.cfi.a",
|
src: "libsnapshot.cfi.a",
|
||||||
}
|
},
|
||||||
|
hwasan: {
|
||||||
|
src: "libsnapshot.hwasan.a",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1098,6 +1102,7 @@ func TestVendorSnapshotSanitizer(t *testing.T) {
|
|||||||
"vendor/libc++demangle.a": nil,
|
"vendor/libc++demangle.a": nil,
|
||||||
"vendor/libsnapshot.a": nil,
|
"vendor/libsnapshot.a": nil,
|
||||||
"vendor/libsnapshot.cfi.a": nil,
|
"vendor/libsnapshot.cfi.a": nil,
|
||||||
|
"vendor/libsnapshot.hwasan.a": nil,
|
||||||
"vendor/note_memtag_heap_sync.a": nil,
|
"vendor/note_memtag_heap_sync.a": nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1106,15 +1111,25 @@ func TestVendorSnapshotSanitizer(t *testing.T) {
|
|||||||
config.TestProductVariables.Platform_vndk_version = StringPtr("29")
|
config.TestProductVariables.Platform_vndk_version = StringPtr("29")
|
||||||
ctx := testCcWithConfig(t, config)
|
ctx := testCcWithConfig(t, config)
|
||||||
|
|
||||||
// Check non-cfi and cfi variant.
|
// Check non-cfi, cfi and hwasan variant.
|
||||||
staticVariant := "android_vendor.28_arm64_armv8-a_static"
|
staticVariant := "android_vendor.28_arm64_armv8-a_static"
|
||||||
staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
|
staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
|
||||||
|
staticHwasanVariant := "android_vendor.28_arm64_armv8-a_static_hwasan"
|
||||||
|
staticHwasanCfiVariant := "android_vendor.28_arm64_armv8-a_static_hwasan_cfi"
|
||||||
|
|
||||||
staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
|
staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
|
||||||
assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
|
assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
|
||||||
|
|
||||||
staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
|
staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
|
||||||
assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
|
assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
|
||||||
|
|
||||||
|
staticHwasanModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanVariant).Module().(*Module)
|
||||||
|
assertString(t, staticHwasanModule.outputFile.Path().Base(), "libsnapshot.hwasan.a")
|
||||||
|
|
||||||
|
staticHwasanCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanCfiVariant).Module().(*Module)
|
||||||
|
if !staticHwasanCfiModule.HiddenFromMake() || !staticHwasanCfiModule.PreventInstall() {
|
||||||
|
t.Errorf("Hwasan and Cfi cannot enabled at the same time.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVendorSnapshotExclude(t *testing.T) {
|
func TestVendorSnapshotExclude(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user