Merge "Bp2build Sanitizer Blocklist" am: cbaa0d6eb9

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2623054

Change-Id: I592655ac8f6ac14216b5ef8b0b5b41e1a04076e6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Trevor Radcliffe 2023-06-14 18:11:56 +00:00 committed by Automerger Merge Worker
commit 7d5001c804
8 changed files with 109 additions and 3 deletions

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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) {

View file

@ -1934,7 +1934,6 @@ func allEnabledSanitizersSupportedByBazel(ctx android.BaseModuleContext, c *Modu
sanitizeProps.Safestack,
sanitizeProps.Scudo,
BoolPtr(len(c.sanitize.Properties.Sanitize.Recover) > 0),
BoolPtr(c.sanitize.Properties.Sanitize.Blocklist != nil),
}
for _, san := range unsupportedSanitizers {
if Bool(san) {

View file

@ -62,12 +62,14 @@ var (
"-fast-isel=false",
}
sanitizeIgnorelistPrefix = "-fsanitize-ignorelist="
cfiBlocklistPath = "external/compiler-rt/lib/cfi"
cfiBlocklistFilename = "cfi_blocklist.txt"
cfiEnableFlag = "-fsanitize=cfi"
cfiCrossDsoFlag = "-fsanitize-cfi-cross-dso"
cfiCflags = []string{"-flto", cfiCrossDsoFlag,
"-fsanitize-ignorelist=" + cfiBlocklistPath + "/" + cfiBlocklistFilename}
sanitizeIgnorelistPrefix + cfiBlocklistPath + "/" + cfiBlocklistFilename}
// -flto and -fvisibility are required by clang when -fsanitize=cfi is
// used, but have no effect on assembly files
cfiAsflags = []string{"-flto", "-fvisibility=default"}
@ -401,6 +403,7 @@ func init() {
exportedVars.ExportStringList("CfiLdFlags", cfiLdflags[2:])
exportedVars.ExportStringList("CfiAsFlags", cfiAsflags[1:])
exportedVars.ExportString("SanitizeIgnorelistPrefix", sanitizeIgnorelistPrefix)
exportedVars.ExportString("CfiCrossDsoFlag", cfiCrossDsoFlag)
exportedVars.ExportString("CfiBlocklistPath", cfiBlocklistPath)
exportedVars.ExportString("CfiBlocklistFilename", cfiBlocklistFilename)
@ -965,7 +968,7 @@ func (s *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
blocklist := android.OptionalPathForModuleSrc(ctx, s.Properties.Sanitize.Blocklist)
if blocklist.Valid() {
flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize-ignorelist="+blocklist.String())
flags.Local.CFlags = append(flags.Local.CFlags, sanitizeIgnorelistPrefix+blocklist.String())
flags.CFlagsDeps = append(flags.CFlagsDeps, blocklist.Path())
}

View file

@ -101,6 +101,19 @@ function create_mock_soong {
symlink_directory external/spdx-tools
symlink_directory libcore
# TODO: b/286872909 - Remove these when the blocking bug is completed
symlink_directory external/libavc
symlink_directory external/libaom
symlink_directory external/libvpx
symlink_directory frameworks/base/libs/androidfw
symlink_directory external/libhevc
symlink_directory external/libexif
symlink_directory external/libopus
symlink_directory external/libmpeg2
symlink_directory external/expat
symlink_directory external/flac
symlink_directory system/extras/toolchain-extras
touch "$MOCK_TOP/Android.bp"
}