Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cbaa0d6e authored by Trevor Radcliffe's avatar Trevor Radcliffe Committed by Gerrit Code Review
Browse files

Merge "Bp2build Sanitizer Blocklist"

parents 9b5198f3 ded095ce
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -868,6 +868,25 @@ func TestCcBinaryWithUBSanPropertiesArchSpecific(t *testing.T) {
	})
}

func TestCcBinaryWithSanitizerBlocklist(t *testing.T) {
	runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
		description: "cc_binary has the correct feature when sanitize.blocklist is provided",
		blueprint: `
{rule_name} {
	name: "foo",
	sanitize: {
		blocklist: "foo_blocklist.txt",
	},
}`,
		targets: []testBazelTarget{
			{"cc_binary", "foo", AttrNameToString{
				"local_includes": `["."]`,
				"features":       `["ubsan_blocklist_foo_blocklist_txt"]`,
			}},
		},
	})
}

func TestCcBinaryWithThinLto(t *testing.T) {
	runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
		description: "cc_binary has correct features when thin LTO is enabled",
+26 −0
Original line number Diff line number Diff line
@@ -4179,6 +4179,32 @@ cc_library {
	})
}

func TestCcLibraryWithSanitizerBlocklist(t *testing.T) {
	runCcLibraryTestCase(t, Bp2buildTestCase{
		Description:                "cc_library has correct feature when sanitize.blocklist is provided",
		ModuleTypeUnderTest:        "cc_library",
		ModuleTypeUnderTestFactory: cc.LibraryFactory,
		Blueprint: `
cc_library {
		name: "foo",
		sanitize: {
			blocklist: "foo_blocklist.txt",
		},
}
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
				"features":       `["ubsan_blocklist_foo_blocklist_txt"]`,
				"local_includes": `["."]`,
			}),
			MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
				"features":       `["ubsan_blocklist_foo_blocklist_txt"]`,
				"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",
+20 −0
Original line number Diff line number Diff line
@@ -1212,6 +1212,26 @@ cc_library_shared {
	})
}

func TestCcLibrarySharedWithSanitizerBlocklist(t *testing.T) {
	runCcLibrarySharedTestCase(t, Bp2buildTestCase{
		Description: "cc_library_shared has correct features when sanitize.blocklist is provided",
		Blueprint: `
cc_library_shared {
	name: "foo",
	sanitize: {
		blocklist: "foo_blocklist.txt",
	},
}
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
				"features":       `["ubsan_blocklist_foo_blocklist_txt"]`,
				"local_includes": `["."]`,
			}),
		},
	})
}

func TestCcLibrarySharedWithThinLto(t *testing.T) {
	runCcLibrarySharedTestCase(t, Bp2buildTestCase{
		Description: "cc_library_shared has correct features when thin lto is enabled",
+20 −0
Original line number Diff line number Diff line
@@ -1905,6 +1905,26 @@ cc_library_static {
	})
}

func TestCcLibraryStaticWithSanitizerBlocklist(t *testing.T) {
	runCcLibraryStaticTestCase(t, Bp2buildTestCase{
		Description: "cc_library_static has correct features when sanitize.blocklist is provided",
		Blueprint: `
cc_library_static {
	name: "foo",
	sanitize: {
		blocklist: "foo_blocklist.txt",
	},
}
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
				"features":       `["ubsan_blocklist_foo_blocklist_txt"]`,
				"local_includes": `["."]`,
			}),
		},
	})
}

func TestCcLibraryStaticWithThinLto(t *testing.T) {
	runCcLibraryStaticTestCase(t, Bp2buildTestCase{
		Description: "cc_library_static has correct features when thin lto is enabled",
+6 −0
Original line number Diff line number Diff line
@@ -1781,6 +1781,12 @@ func bp2buildSanitizerFeatures(ctx android.BazelConversionPathContext, m *Module
			for _, sanitizer := range sanitizerProps.Sanitize.Misc_undefined {
				features = append(features, "ubsan_"+sanitizer)
			}
			blocklist := sanitizerProps.Sanitize.Blocklist
			if blocklist != nil {
				// Format the blocklist name to be used in a feature name
				blocklistFeatureSuffix := strings.Replace(strings.ToLower(*blocklist), ".", "_", -1)
				features = append(features, "ubsan_blocklist_"+blocklistFeatureSuffix)
			}
			if proptools.Bool(sanitizerProps.Sanitize.Cfi) {
				features = append(features, "android_cfi")
				if proptools.Bool(sanitizerProps.Sanitize.Config.Cfi_assembly_support) {
Loading