CFI Bp2Build
Bug: 261733820 Test: Unit Tests and manual verification Change-Id: Ife1b33c58e3770177eab1b6168edbf7969418ad7
This commit is contained in:
@@ -1036,3 +1036,73 @@ func TestCcBinaryHiddenVisibilityConvertedToFeatureOsSpecific(t *testing.T) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcBinaryWithCfi(t *testing.T) {
|
||||
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
||||
description: "cc_binary has correct features when cfi is enabled",
|
||||
blueprint: `
|
||||
{rule_name} {
|
||||
name: "foo",
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
},
|
||||
}`,
|
||||
targets: []testBazelTarget{
|
||||
{"cc_binary", "foo", AttrNameToString{
|
||||
"features": `["android_cfi"]`,
|
||||
"local_includes": `["."]`,
|
||||
}},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcBinaryWithCfiOsSpecific(t *testing.T) {
|
||||
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
||||
description: "cc_binary has correct features when cfi is enabled for specific variants",
|
||||
blueprint: `
|
||||
{rule_name} {
|
||||
name: "foo",
|
||||
target: {
|
||||
android: {
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}`,
|
||||
targets: []testBazelTarget{
|
||||
{"cc_binary", "foo", AttrNameToString{
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/os:android": ["android_cfi"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
}},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcBinaryWithCfiAndCfiAssemblySupport(t *testing.T) {
|
||||
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
|
||||
description: "cc_binary has correct features when cfi is enabled with cfi assembly support",
|
||||
blueprint: `
|
||||
{rule_name} {
|
||||
name: "foo",
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
config: {
|
||||
cfi_assembly_support: true,
|
||||
},
|
||||
},
|
||||
}`,
|
||||
targets: []testBazelTarget{
|
||||
{"cc_binary", "foo", AttrNameToString{
|
||||
"features": `[
|
||||
"android_cfi",
|
||||
"android_cfi_assembly_support",
|
||||
]`,
|
||||
"local_includes": `["."]`,
|
||||
}},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@@ -4718,3 +4718,97 @@ func TestCcLibraryHostLdLibs(t *testing.T) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryWithCfi(t *testing.T) {
|
||||
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library has correct features when cfi is enabled",
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
||||
"features": `["android_cfi"]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"features": `["android_cfi"]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryWithCfiOsSpecific(t *testing.T) {
|
||||
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library has correct features when cfi is enabled for specific variants",
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
target: {
|
||||
android: {
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/os:android": ["android_cfi"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/os:android": ["android_cfi"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryWithCfiAndCfiAssemblySupport(t *testing.T) {
|
||||
runCcLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library has correct features when cfi is enabled with cfi_assembly_support",
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
config: {
|
||||
cfi_assembly_support: true,
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
||||
"features": `[
|
||||
"android_cfi",
|
||||
"android_cfi_assembly_support",
|
||||
]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"features": `[
|
||||
"android_cfi",
|
||||
"android_cfi_assembly_support",
|
||||
]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@@ -1445,3 +1445,73 @@ cc_library_shared {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedWithCfi(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_shared has correct features when cfi is enabled for specific variants",
|
||||
Blueprint: `
|
||||
cc_library_shared {
|
||||
name: "foo",
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"features": `["android_cfi"]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedWithCfiOsSpecific(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_shared has correct features when cfi is enabled",
|
||||
Blueprint: `
|
||||
cc_library_shared {
|
||||
name: "foo",
|
||||
target: {
|
||||
android: {
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/os:android": ["android_cfi"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedWithCfiAndCfiAssemblySupport(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_shared has correct features when cfi is enabled with cfi assembly support",
|
||||
Blueprint: `
|
||||
cc_library_static {
|
||||
name: "foo",
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
config: {
|
||||
cfi_assembly_support: true,
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||
"features": `[
|
||||
"android_cfi",
|
||||
"android_cfi_assembly_support",
|
||||
]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@@ -2075,3 +2075,73 @@ cc_library_static {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryStaticWithCfi(t *testing.T) {
|
||||
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_static has correct features when cfi is enabled",
|
||||
Blueprint: `
|
||||
cc_library_static {
|
||||
name: "foo",
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||
"features": `["android_cfi"]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryStaticWithCfiOsSpecific(t *testing.T) {
|
||||
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_static has correct features when cfi is enabled for specific variants",
|
||||
Blueprint: `
|
||||
cc_library_static {
|
||||
name: "foo",
|
||||
target: {
|
||||
android: {
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||
"features": `select({
|
||||
"//build/bazel/platforms/os:android": ["android_cfi"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryStaticWithCfiAndCfiAssemblySupport(t *testing.T) {
|
||||
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_static has correct features when cfi is enabled with cfi_assembly_support",
|
||||
Blueprint: `
|
||||
cc_library_static {
|
||||
name: "foo",
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
config: {
|
||||
cfi_assembly_support: true,
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||
"features": `[
|
||||
"android_cfi",
|
||||
"android_cfi_assembly_support",
|
||||
]`,
|
||||
"local_includes": `["."]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@@ -1757,6 +1757,12 @@ func bp2buildSanitizerFeatures(ctx android.BazelConversionPathContext, m *Module
|
||||
for _, sanitizer := range sanitizerProps.Sanitize.Misc_undefined {
|
||||
features = append(features, "ubsan_"+sanitizer)
|
||||
}
|
||||
if proptools.Bool(sanitizerProps.Sanitize.Cfi) {
|
||||
features = append(features, "android_cfi")
|
||||
if proptools.Bool(sanitizerProps.Sanitize.Config.Cfi_assembly_support) {
|
||||
features = append(features, "android_cfi_assembly_support")
|
||||
}
|
||||
}
|
||||
sanitizerFeatures.SetSelectValue(axis, config, features)
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user