Merge "bp2build conversion for Sanitize.Integer_overflow"
This commit is contained in:
@@ -789,3 +789,82 @@ func TestCcBinaryWithSyspropSrcsSomeConfigs(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCcBinaryWithIntegerOverflowProperty(t *testing.T) {
|
||||||
|
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
||||||
|
description: "cc_binary with integer overflow property specified",
|
||||||
|
blueprint: `
|
||||||
|
{rule_name} {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
integer_overflow: true,
|
||||||
|
},
|
||||||
|
}`,
|
||||||
|
targets: []testBazelTarget{
|
||||||
|
{"cc_binary", "foo", AttrNameToString{
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
"features": `["ubsan_integer_overflow"]`,
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcBinaryWithMiscUndefinedProperty(t *testing.T) {
|
||||||
|
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
||||||
|
description: "cc_binary with miscellaneous properties specified",
|
||||||
|
blueprint: `
|
||||||
|
{rule_name} {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["undefined", "nullability"],
|
||||||
|
},
|
||||||
|
}`,
|
||||||
|
targets: []testBazelTarget{
|
||||||
|
{"cc_binary", "foo", AttrNameToString{
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
"features": `[
|
||||||
|
"ubsan_undefined",
|
||||||
|
"ubsan_nullability",
|
||||||
|
]`,
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcBinaryWithUBSanPropertiesArchSpecific(t *testing.T) {
|
||||||
|
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
||||||
|
description: "cc_binary has correct feature select when UBSan props are specified in arch specific blocks",
|
||||||
|
blueprint: `
|
||||||
|
{rule_name} {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["undefined", "nullability"],
|
||||||
|
},
|
||||||
|
target: {
|
||||||
|
android: {
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["alignment"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
linux_glibc: {
|
||||||
|
sanitize: {
|
||||||
|
integer_overflow: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}`,
|
||||||
|
targets: []testBazelTarget{
|
||||||
|
{"cc_binary", "foo", AttrNameToString{
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
"features": `[
|
||||||
|
"ubsan_undefined",
|
||||||
|
"ubsan_nullability",
|
||||||
|
] + select({
|
||||||
|
"//build/bazel/platforms/os:android": ["ubsan_alignment"],
|
||||||
|
"//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
})`,
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -3908,3 +3908,113 @@ cc_library {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCcLibraryWithIntegerOverflowProperty(t *testing.T) {
|
||||||
|
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "cc_library has correct features when integer_overflow property is provided",
|
||||||
|
ModuleTypeUnderTest: "cc_library",
|
||||||
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||||
|
Blueprint: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
integer_overflow: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
||||||
|
"features": `["ubsan_integer_overflow"]`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||||
|
"features": `["ubsan_integer_overflow"]`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcLibraryWithMiscUndefinedProperty(t *testing.T) {
|
||||||
|
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "cc_library has correct features when misc_undefined property is provided",
|
||||||
|
ModuleTypeUnderTest: "cc_library",
|
||||||
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||||
|
Blueprint: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["undefined", "nullability"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
||||||
|
"features": `[
|
||||||
|
"ubsan_undefined",
|
||||||
|
"ubsan_nullability",
|
||||||
|
]`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||||
|
"features": `[
|
||||||
|
"ubsan_undefined",
|
||||||
|
"ubsan_nullability",
|
||||||
|
]`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcLibraryWithUBSanPropertiesArchSpecific(t *testing.T) {
|
||||||
|
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "cc_library has correct feature select when UBSan props are specified in arch specific blocks",
|
||||||
|
ModuleTypeUnderTest: "cc_library",
|
||||||
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||||
|
Blueprint: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["undefined", "nullability"],
|
||||||
|
},
|
||||||
|
target: {
|
||||||
|
android: {
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["alignment"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
linux_glibc: {
|
||||||
|
sanitize: {
|
||||||
|
integer_overflow: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
||||||
|
"features": `[
|
||||||
|
"ubsan_undefined",
|
||||||
|
"ubsan_nullability",
|
||||||
|
] + select({
|
||||||
|
"//build/bazel/platforms/os:android": ["ubsan_alignment"],
|
||||||
|
"//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
})`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||||
|
"features": `[
|
||||||
|
"ubsan_undefined",
|
||||||
|
"ubsan_nullability",
|
||||||
|
] + select({
|
||||||
|
"//build/bazel/platforms/os:android": ["ubsan_alignment"],
|
||||||
|
"//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
})`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -885,3 +885,85 @@ func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCcLibrarySharedWithIntegerOverflowProperty(t *testing.T) {
|
||||||
|
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "cc_library_shared has correct features when integer_overflow property is provided",
|
||||||
|
Blueprint: `
|
||||||
|
cc_library_shared {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
integer_overflow: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||||
|
"features": `["ubsan_integer_overflow"]`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcLibrarySharedWithMiscUndefinedProperty(t *testing.T) {
|
||||||
|
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "cc_library_shared has correct features when misc_undefined property is provided",
|
||||||
|
Blueprint: `
|
||||||
|
cc_library_shared {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["undefined", "nullability"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||||
|
"features": `[
|
||||||
|
"ubsan_undefined",
|
||||||
|
"ubsan_nullability",
|
||||||
|
]`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcLibrarySharedWithUBSanPropertiesArchSpecific(t *testing.T) {
|
||||||
|
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "cc_library_shared has correct feature select when UBSan props are specified in arch specific blocks",
|
||||||
|
Blueprint: `
|
||||||
|
cc_library_shared {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["undefined", "nullability"],
|
||||||
|
},
|
||||||
|
target: {
|
||||||
|
android: {
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["alignment"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
linux_glibc: {
|
||||||
|
sanitize: {
|
||||||
|
integer_overflow: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||||
|
"features": `[
|
||||||
|
"ubsan_undefined",
|
||||||
|
"ubsan_nullability",
|
||||||
|
] + select({
|
||||||
|
"//build/bazel/platforms/os:android": ["ubsan_alignment"],
|
||||||
|
"//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
})`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -1723,3 +1723,85 @@ cc_library_static {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCcLibraryStaticWithIntegerOverflowProperty(t *testing.T) {
|
||||||
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "cc_library_static has correct features when integer_overflow property is provided",
|
||||||
|
Blueprint: `
|
||||||
|
cc_library_static {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
integer_overflow: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||||
|
"features": `["ubsan_integer_overflow"]`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcLibraryStaticWithMiscUndefinedProperty(t *testing.T) {
|
||||||
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "cc_library_static has correct features when misc_undefined property is provided",
|
||||||
|
Blueprint: `
|
||||||
|
cc_library_static {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["undefined", "nullability"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||||
|
"features": `[
|
||||||
|
"ubsan_undefined",
|
||||||
|
"ubsan_nullability",
|
||||||
|
]`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCcLibraryStaticWithUBSanPropertiesArchSpecific(t *testing.T) {
|
||||||
|
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "cc_library_static has correct feature select when UBSan props are specified in arch specific blocks",
|
||||||
|
Blueprint: `
|
||||||
|
cc_library_static {
|
||||||
|
name: "foo",
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["undefined", "nullability"],
|
||||||
|
},
|
||||||
|
target: {
|
||||||
|
android: {
|
||||||
|
sanitize: {
|
||||||
|
misc_undefined: ["alignment"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
linux_glibc: {
|
||||||
|
sanitize: {
|
||||||
|
integer_overflow: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||||
|
"features": `[
|
||||||
|
"ubsan_undefined",
|
||||||
|
"ubsan_nullability",
|
||||||
|
] + select({
|
||||||
|
"//build/bazel/platforms/os:android": ["ubsan_alignment"],
|
||||||
|
"//build/bazel/platforms/os:linux_glibc": ["ubsan_integer_overflow"],
|
||||||
|
"//conditions:default": [],
|
||||||
|
})`,
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -354,7 +354,7 @@ type baseAttributes struct {
|
|||||||
compilerAttributes
|
compilerAttributes
|
||||||
linkerAttributes
|
linkerAttributes
|
||||||
|
|
||||||
// A combination of compilerAttributes.features and linkerAttributes.features
|
// A combination of compilerAttributes.features and linkerAttributes.features, as well as sanitizer features
|
||||||
features bazel.StringListAttribute
|
features bazel.StringListAttribute
|
||||||
protoDependency *bazel.LabelAttribute
|
protoDependency *bazel.LabelAttribute
|
||||||
aidlDependency *bazel.LabelAttribute
|
aidlDependency *bazel.LabelAttribute
|
||||||
@@ -804,7 +804,7 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
|
|||||||
(&linkerAttrs).wholeArchiveDeps.Add(bp2buildCcSysprop(ctx, module.Name(), module.Properties.Min_sdk_version, compilerAttrs.syspropSrcs))
|
(&linkerAttrs).wholeArchiveDeps.Add(bp2buildCcSysprop(ctx, module.Name(), module.Properties.Min_sdk_version, compilerAttrs.syspropSrcs))
|
||||||
}
|
}
|
||||||
|
|
||||||
features := compilerAttrs.features.Clone().Append(linkerAttrs.features)
|
features := compilerAttrs.features.Clone().Append(linkerAttrs.features).Append(bp2buildSanitizerFeatures(ctx, module))
|
||||||
features.DeduplicateAxesFromBase()
|
features.DeduplicateAxesFromBase()
|
||||||
|
|
||||||
return baseAttributes{
|
return baseAttributes{
|
||||||
@@ -1430,3 +1430,20 @@ func bp2buildBinaryLinkerProps(ctx android.BazelConversionPathContext, m *Module
|
|||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bp2buildSanitizerFeatures(ctx android.BazelConversionPathContext, m *Module) bazel.StringListAttribute {
|
||||||
|
sanitizerFeatures := bazel.StringListAttribute{}
|
||||||
|
bp2BuildPropParseHelper(ctx, m, &SanitizeProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
||||||
|
var features []string
|
||||||
|
if sanitizerProps, ok := props.(*SanitizeProperties); ok {
|
||||||
|
if sanitizerProps.Sanitize.Integer_overflow != nil && *sanitizerProps.Sanitize.Integer_overflow {
|
||||||
|
features = append(features, "ubsan_integer_overflow")
|
||||||
|
}
|
||||||
|
for _, sanitizer := range sanitizerProps.Sanitize.Misc_undefined {
|
||||||
|
features = append(features, "ubsan_"+sanitizer)
|
||||||
|
}
|
||||||
|
sanitizerFeatures.SetSelectValue(axis, config, features)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return sanitizerFeatures
|
||||||
|
}
|
||||||
|
7
cc/cc.go
7
cc/cc.go
@@ -1873,8 +1873,11 @@ func (c *Module) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable mixed builds as long as the cc_* module type has a bazel handler.
|
// TODO(b/261058727): Remove this (enable mixed builds for modules with UBSan)
|
||||||
return c.bazelHandler != nil
|
ubsanEnabled := c.sanitize != nil &&
|
||||||
|
((c.sanitize.Properties.Sanitize.Integer_overflow != nil && *c.sanitize.Properties.Sanitize.Integer_overflow) ||
|
||||||
|
c.sanitize.Properties.Sanitize.Misc_undefined != nil)
|
||||||
|
return c.bazelHandler != nil && !ubsanEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) {
|
func (c *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) {
|
||||||
|
Reference in New Issue
Block a user