Merge "Fix sanitizer dep"
am: e49256e564
Change-Id: I2199bff441c53410030ccf7f48fc386a7e123c4f
This commit is contained in:
@@ -143,6 +143,7 @@ type BottomUpMutatorContext interface {
|
|||||||
CreateVariations(...string) []blueprint.Module
|
CreateVariations(...string) []blueprint.Module
|
||||||
CreateLocalVariations(...string) []blueprint.Module
|
CreateLocalVariations(...string) []blueprint.Module
|
||||||
SetDependencyVariation(string)
|
SetDependencyVariation(string)
|
||||||
|
SetDefaultDependencyVariation(*string)
|
||||||
AddVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string)
|
AddVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string)
|
||||||
AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string)
|
AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string)
|
||||||
AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module)
|
AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module)
|
||||||
@@ -292,6 +293,10 @@ func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) {
|
|||||||
b.bp.SetDependencyVariation(variation)
|
b.bp.SetDependencyVariation(variation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *bottomUpMutatorContext) SetDefaultDependencyVariation(variation *string) {
|
||||||
|
b.bp.SetDefaultDependencyVariation(variation)
|
||||||
|
}
|
||||||
|
|
||||||
func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag,
|
func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag,
|
||||||
names ...string) {
|
names ...string) {
|
||||||
|
|
||||||
|
16
cc/cc.go
16
cc/cc.go
@@ -56,6 +56,8 @@ func init() {
|
|||||||
ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
|
ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
|
||||||
ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
|
ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
|
||||||
|
|
||||||
|
// cfi mutator shouldn't run before sanitizers that return true for
|
||||||
|
// incompatibleWithCfi()
|
||||||
ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
|
ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
|
||||||
ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
|
ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
|
||||||
|
|
||||||
@@ -255,6 +257,7 @@ type VendorProperties struct {
|
|||||||
type ModuleContextIntf interface {
|
type ModuleContextIntf interface {
|
||||||
static() bool
|
static() bool
|
||||||
staticBinary() bool
|
staticBinary() bool
|
||||||
|
header() bool
|
||||||
toolchain() config.Toolchain
|
toolchain() config.Toolchain
|
||||||
useSdk() bool
|
useSdk() bool
|
||||||
sdkVersion() string
|
sdkVersion() string
|
||||||
@@ -715,6 +718,10 @@ func (ctx *moduleContextImpl) staticBinary() bool {
|
|||||||
return ctx.mod.staticBinary()
|
return ctx.mod.staticBinary()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *moduleContextImpl) header() bool {
|
||||||
|
return ctx.mod.header()
|
||||||
|
}
|
||||||
|
|
||||||
func (ctx *moduleContextImpl) useSdk() bool {
|
func (ctx *moduleContextImpl) useSdk() bool {
|
||||||
if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
|
if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
|
||||||
return String(ctx.mod.Properties.Sdk_version) != ""
|
return String(ctx.mod.Properties.Sdk_version) != ""
|
||||||
@@ -2023,6 +2030,15 @@ func (c *Module) staticBinary() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Module) header() bool {
|
||||||
|
if h, ok := c.linker.(interface {
|
||||||
|
header() bool
|
||||||
|
}); ok {
|
||||||
|
return h.header()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
|
func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
|
||||||
name := actx.ModuleName()
|
name := actx.ModuleName()
|
||||||
if c.useVndk() {
|
if c.useVndk() {
|
||||||
|
@@ -232,7 +232,7 @@ func llndkHeadersFactory() android.Module {
|
|||||||
&library.MutatedProperties,
|
&library.MutatedProperties,
|
||||||
&library.flagExporter.Properties)
|
&library.flagExporter.Properties)
|
||||||
|
|
||||||
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
|
module.Init()
|
||||||
|
|
||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
185
cc/sanitize.go
185
cc/sanitize.go
@@ -125,6 +125,10 @@ func (t sanitizerType) name() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t sanitizerType) incompatibleWithCfi() bool {
|
||||||
|
return t == asan || t == fuzzer || t == hwasan
|
||||||
|
}
|
||||||
|
|
||||||
type SanitizeProperties struct {
|
type SanitizeProperties struct {
|
||||||
// enable AddressSanitizer, ThreadSanitizer, or UndefinedBehaviorSanitizer
|
// enable AddressSanitizer, ThreadSanitizer, or UndefinedBehaviorSanitizer
|
||||||
Sanitize struct {
|
Sanitize struct {
|
||||||
@@ -557,16 +561,18 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
|
||||||
// Add a suffix for CFI-enabled static libraries to allow surfacing both to make without a
|
// Add a suffix for cfi/hwasan/scs-enabled static/header libraries to allow surfacing
|
||||||
// name conflict.
|
// both the sanitized and non-sanitized variants to make without a name conflict.
|
||||||
if ret.Class == "STATIC_LIBRARIES" && Bool(sanitize.Properties.Sanitize.Cfi) {
|
if ret.Class == "STATIC_LIBRARIES" || ret.Class == "HEADER_LIBRARIES" {
|
||||||
ret.SubName += ".cfi"
|
if Bool(sanitize.Properties.Sanitize.Cfi) {
|
||||||
}
|
ret.SubName += ".cfi"
|
||||||
if ret.Class == "STATIC_LIBRARIES" && Bool(sanitize.Properties.Sanitize.Hwaddress) {
|
}
|
||||||
ret.SubName += ".hwasan"
|
if Bool(sanitize.Properties.Sanitize.Hwaddress) {
|
||||||
}
|
ret.SubName += ".hwasan"
|
||||||
if ret.Class == "STATIC_LIBRARIES" && Bool(sanitize.Properties.Sanitize.Scs) {
|
}
|
||||||
ret.SubName += ".scs"
|
if Bool(sanitize.Properties.Sanitize.Scs) {
|
||||||
|
ret.SubName += ".scs"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -871,7 +877,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
{Mutator: "image", Variation: c.imageVariation()},
|
{Mutator: "image", Variation: c.imageVariation()},
|
||||||
{Mutator: "arch", Variation: mctx.Target().String()},
|
{Mutator: "arch", Variation: mctx.Target().String()},
|
||||||
}, staticDepTag, runtimeLibrary)
|
}, staticDepTag, runtimeLibrary)
|
||||||
} else if !c.static() {
|
} else if !c.static() && !c.header() {
|
||||||
// dynamic executable and shared libs get shared runtime libs
|
// dynamic executable and shared libs get shared runtime libs
|
||||||
mctx.AddFarVariationDependencies([]blueprint.Variation{
|
mctx.AddFarVariationDependencies([]blueprint.Variation{
|
||||||
{Mutator: "link", Variation: "shared"},
|
{Mutator: "link", Variation: "shared"},
|
||||||
@@ -900,108 +906,69 @@ func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) {
|
|||||||
modules := mctx.CreateVariations(t.variationName())
|
modules := mctx.CreateVariations(t.variationName())
|
||||||
modules[0].(*Module).sanitize.SetSanitizer(t, true)
|
modules[0].(*Module).sanitize.SetSanitizer(t, true)
|
||||||
} else if c.sanitize.isSanitizerEnabled(t) || c.sanitize.Properties.SanitizeDep {
|
} else if c.sanitize.isSanitizerEnabled(t) || c.sanitize.Properties.SanitizeDep {
|
||||||
// Save original sanitizer status before we assign values to variant
|
|
||||||
// 0 as that overwrites the original.
|
|
||||||
isSanitizerEnabled := c.sanitize.isSanitizerEnabled(t)
|
isSanitizerEnabled := c.sanitize.isSanitizerEnabled(t)
|
||||||
|
if mctx.Device() && t.incompatibleWithCfi() {
|
||||||
|
// TODO: Make sure that cfi mutator runs "after" any of the sanitizers that
|
||||||
|
// are incompatible with cfi
|
||||||
|
c.sanitize.SetSanitizer(cfi, false)
|
||||||
|
}
|
||||||
|
if c.static() || c.header() || t == asan || t == fuzzer {
|
||||||
|
// Static and header libs are split into non-sanitized and sanitized variants.
|
||||||
|
// Shared libs are not split. However, for asan and fuzzer, we split even for shared
|
||||||
|
// libs because a library sanitized for asan/fuzzer can't be linked from a library
|
||||||
|
// that isn't sanitized for asan/fuzzer.
|
||||||
|
//
|
||||||
|
// Note for defaultVariation: since we don't split for shared libs but for static/header
|
||||||
|
// libs, it is possible for the sanitized variant of a static/header lib to depend
|
||||||
|
// on non-sanitized variant of a shared lib. Such unfulfilled variation causes an
|
||||||
|
// error when the module is split. defaultVariation is the name of the variation that
|
||||||
|
// will be used when such a dangling dependency occurs during the split of the current
|
||||||
|
// module. By setting it to the name of the sanitized variation, the dangling dependency
|
||||||
|
// is redirected to the sanitized variant of the dependent module.
|
||||||
|
defaultVariation := t.variationName()
|
||||||
|
mctx.SetDefaultDependencyVariation(&defaultVariation)
|
||||||
|
modules := mctx.CreateVariations("", t.variationName())
|
||||||
|
modules[0].(*Module).sanitize.SetSanitizer(t, false)
|
||||||
|
modules[1].(*Module).sanitize.SetSanitizer(t, true)
|
||||||
|
modules[0].(*Module).sanitize.Properties.SanitizeDep = false
|
||||||
|
modules[1].(*Module).sanitize.Properties.SanitizeDep = false
|
||||||
|
|
||||||
modules := mctx.CreateVariations("", t.variationName())
|
// For cfi/scs/hwasan, we can export both sanitized and un-sanitized variants
|
||||||
modules[0].(*Module).sanitize.SetSanitizer(t, false)
|
// to Make, because the sanitized version has a different suffix in name.
|
||||||
modules[1].(*Module).sanitize.SetSanitizer(t, true)
|
// For other types of sanitizers, suppress the variation that is disabled.
|
||||||
|
if t != cfi && t != scs && t != hwasan {
|
||||||
|
if isSanitizerEnabled {
|
||||||
|
modules[0].(*Module).Properties.PreventInstall = true
|
||||||
|
modules[0].(*Module).Properties.HideFromMake = true
|
||||||
|
} else {
|
||||||
|
modules[1].(*Module).Properties.PreventInstall = true
|
||||||
|
modules[1].(*Module).Properties.HideFromMake = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
modules[0].(*Module).sanitize.Properties.SanitizeDep = false
|
// Export the static lib name to make
|
||||||
modules[1].(*Module).sanitize.Properties.SanitizeDep = false
|
|
||||||
|
|
||||||
// We don't need both variants active for anything but CFI-enabled
|
|
||||||
// target static libraries, so suppress the appropriate variant in
|
|
||||||
// all other cases.
|
|
||||||
if t == cfi {
|
|
||||||
if c.static() {
|
if c.static() {
|
||||||
if !mctx.Device() {
|
if t == cfi {
|
||||||
if isSanitizerEnabled {
|
appendStringSync(c.Name(), cfiStaticLibs(mctx.Config()), &cfiStaticLibsMutex)
|
||||||
modules[0].(*Module).Properties.PreventInstall = true
|
} else if t == hwasan {
|
||||||
modules[0].(*Module).Properties.HideFromMake = true
|
if c.useVndk() {
|
||||||
|
appendStringSync(c.Name(), hwasanVendorStaticLibs(mctx.Config()),
|
||||||
|
&hwasanStaticLibsMutex)
|
||||||
} else {
|
} else {
|
||||||
modules[1].(*Module).Properties.PreventInstall = true
|
appendStringSync(c.Name(), hwasanStaticLibs(mctx.Config()),
|
||||||
modules[1].(*Module).Properties.HideFromMake = true
|
&hwasanStaticLibsMutex)
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
cfiStaticLibs := cfiStaticLibs(mctx.Config())
|
}
|
||||||
|
} else {
|
||||||
|
// Shared libs are not split. Only the sanitized variant is created.
|
||||||
|
modules := mctx.CreateVariations(t.variationName())
|
||||||
|
modules[0].(*Module).sanitize.SetSanitizer(t, true)
|
||||||
|
modules[0].(*Module).sanitize.Properties.SanitizeDep = false
|
||||||
|
|
||||||
cfiStaticLibsMutex.Lock()
|
// locate the asan libraries under /data/asan
|
||||||
*cfiStaticLibs = append(*cfiStaticLibs, c.Name())
|
if mctx.Device() && t == asan && isSanitizerEnabled {
|
||||||
cfiStaticLibsMutex.Unlock()
|
modules[0].(*Module).sanitize.Properties.InSanitizerDir = true
|
||||||
}
|
|
||||||
} else {
|
|
||||||
modules[0].(*Module).Properties.PreventInstall = true
|
|
||||||
modules[0].(*Module).Properties.HideFromMake = true
|
|
||||||
}
|
|
||||||
} else if t == asan {
|
|
||||||
if mctx.Device() {
|
|
||||||
// CFI and ASAN are currently mutually exclusive so disable
|
|
||||||
// CFI if this is an ASAN variant.
|
|
||||||
modules[1].(*Module).sanitize.Properties.InSanitizerDir = true
|
|
||||||
modules[1].(*Module).sanitize.SetSanitizer(cfi, false)
|
|
||||||
}
|
|
||||||
if isSanitizerEnabled {
|
|
||||||
modules[0].(*Module).Properties.PreventInstall = true
|
|
||||||
modules[0].(*Module).Properties.HideFromMake = true
|
|
||||||
} else {
|
|
||||||
modules[1].(*Module).Properties.PreventInstall = true
|
|
||||||
modules[1].(*Module).Properties.HideFromMake = true
|
|
||||||
}
|
|
||||||
} else if t == scs {
|
|
||||||
// We don't currently link any static libraries built with make into
|
|
||||||
// libraries built with SCS, so we don't need logic for propagating
|
|
||||||
// SCSness of dependencies into make.
|
|
||||||
if !c.static() {
|
|
||||||
if isSanitizerEnabled {
|
|
||||||
modules[0].(*Module).Properties.PreventInstall = true
|
|
||||||
modules[0].(*Module).Properties.HideFromMake = true
|
|
||||||
} else {
|
|
||||||
modules[1].(*Module).Properties.PreventInstall = true
|
|
||||||
modules[1].(*Module).Properties.HideFromMake = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if t == fuzzer {
|
|
||||||
// TODO(b/131771163): CFI and fuzzer support are mutually incompatible
|
|
||||||
// as CFI pulls in LTO.
|
|
||||||
if mctx.Device() {
|
|
||||||
modules[1].(*Module).sanitize.SetSanitizer(cfi, false)
|
|
||||||
}
|
|
||||||
if isSanitizerEnabled {
|
|
||||||
modules[0].(*Module).Properties.PreventInstall = true
|
|
||||||
modules[0].(*Module).Properties.HideFromMake = true
|
|
||||||
} else {
|
|
||||||
modules[1].(*Module).Properties.PreventInstall = true
|
|
||||||
modules[1].(*Module).Properties.HideFromMake = true
|
|
||||||
}
|
|
||||||
} else if t == hwasan {
|
|
||||||
if mctx.Device() {
|
|
||||||
// CFI and HWASAN are currently mutually exclusive so disable
|
|
||||||
// CFI if this is an HWASAN variant.
|
|
||||||
modules[1].(*Module).sanitize.SetSanitizer(cfi, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.static() {
|
|
||||||
if c.useVndk() {
|
|
||||||
hwasanVendorStaticLibs := hwasanVendorStaticLibs(mctx.Config())
|
|
||||||
hwasanStaticLibsMutex.Lock()
|
|
||||||
*hwasanVendorStaticLibs = append(*hwasanVendorStaticLibs, c.Name())
|
|
||||||
hwasanStaticLibsMutex.Unlock()
|
|
||||||
} else {
|
|
||||||
hwasanStaticLibs := hwasanStaticLibs(mctx.Config())
|
|
||||||
hwasanStaticLibsMutex.Lock()
|
|
||||||
*hwasanStaticLibs = append(*hwasanStaticLibs, c.Name())
|
|
||||||
hwasanStaticLibsMutex.Unlock()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if isSanitizerEnabled {
|
|
||||||
modules[0].(*Module).Properties.PreventInstall = true
|
|
||||||
modules[0].(*Module).Properties.HideFromMake = true
|
|
||||||
} else {
|
|
||||||
modules[1].(*Module).Properties.PreventInstall = true
|
|
||||||
modules[1].(*Module).Properties.HideFromMake = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1037,6 +1004,12 @@ func hwasanVendorStaticLibs(config android.Config) *[]string {
|
|||||||
}).(*[]string)
|
}).(*[]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func appendStringSync(item string, list *[]string, mutex *sync.Mutex) {
|
||||||
|
mutex.Lock()
|
||||||
|
*list = append(*list, item)
|
||||||
|
mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
func enableMinimalRuntime(sanitize *sanitize) bool {
|
func enableMinimalRuntime(sanitize *sanitize) bool {
|
||||||
if !Bool(sanitize.Properties.Sanitize.Address) &&
|
if !Bool(sanitize.Properties.Sanitize.Address) &&
|
||||||
!Bool(sanitize.Properties.Sanitize.Hwaddress) &&
|
!Bool(sanitize.Properties.Sanitize.Hwaddress) &&
|
||||||
|
Reference in New Issue
Block a user