diff options
author | Trevor Radcliffe <tradical@google.com> | 2023-07-10 18:36:13 +0000 |
---|---|---|
committer | Trevor Radcliffe <tradical@google.com> | 2023-07-13 20:38:09 +0000 |
commit | c3e88221ca61f8b306325863f2b8ddf434b7ce63 (patch) | |
tree | 69485d10a80afbbeeb2179b9f672d44dfe20e28d | |
parent | 0b2acca7e55a2c242137868ed2eaf876e903aefd (diff) | |
download | linux-x86-c3e88221ca61f8b306325863f2b8ddf434b7ce63.tar.gz |
Don't require ubsan_enabled for blocklist
Also introduces a new sanitizers_enabled feature which is inert
but enabled whenever a sanitizer is enabled.
Bug: 290154899
Test: Forrest/Unit tests
Change-Id: I15e6d06270349aeb30ca052950a55f4e2760c293
-rw-r--r-- | BUILD.bazel | 8 | ||||
-rw-r--r-- | cc_toolchain_features.bzl | 27 | ||||
-rw-r--r-- | cc_toolchain_features_sanitizer_blocklist_test.bzl | 102 |
3 files changed, 127 insertions, 10 deletions
diff --git a/BUILD.bazel b/BUILD.bazel index ac1b3a383..9cabd8e46 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -54,6 +54,10 @@ load( "cc_toolchain_features_pack_relocation_test_suite", ) load( + ":cc_toolchain_features_sanitizer_blocklist_test.bzl", + "cc_toolchain_features_sanitizer_blocklist_test_suite", +) +load( ":cc_toolchain_features_thinlto_test.bzl", "cc_toolchain_features_lto_test_suite", ) @@ -450,6 +454,10 @@ cc_toolchain_features_lto_test_suite( name = "cc_toolchain_features_thinlto_tests", ) +cc_toolchain_features_sanitizer_blocklist_test_suite( + name = "cc_toolchain_features_sanitizer_blocklist_tests", +) + cc_toolchain_features_ubsan_test_suite( name = "cc_toolchain_features_ubsan_tests", ) diff --git a/cc_toolchain_features.bzl b/cc_toolchain_features.bzl index c46f8e080..46a2a0298 100644 --- a/cc_toolchain_features.bzl +++ b/cc_toolchain_features.bzl @@ -1644,6 +1644,15 @@ def _make_flag_set(actions, flags, with_features = [], with_not_features = []): ], ) +def _get_misc_sanitizer_features(): + return [ + # New sanitizers must imply this feature + feature( + name = "sanitizers_enabled", + enabled = False, + ), + ] + # TODO(b/276756817): Restrict for VNDK when we have VNDK in Bazel # TODO(b/276756319): Restrict for riscv64 when we have riscv64 in Bazel # TODO(b/276932249): Restrict for Fuzzer when we have Fuzzer in Bazel @@ -1670,7 +1679,7 @@ def _get_cfi_features(target_arch, target_os): _generated_sanitizer_constants.CfiAsFlags, ), ], - implies = ["android_full_lto"] + ( + implies = ["android_full_lto", "sanitizers_enabled"] + ( ["arm_isa_thumb"] if target_arch == _arches.Arm else [] ), ), @@ -1782,10 +1791,7 @@ def _sanitizer_flag_feature(name, actions, flags): # with_feature_set added here. with_features = [ with_feature_set( - features = ["ubsan_enabled"], - ), - with_feature_set( - features = ["android_cfi"], + features = ["sanitizers_enabled"], ), ], ), @@ -1868,17 +1874,17 @@ sanitizer_blocklist_dict = { "system/extras/toolchain-extras": "libprofile_clang_extras_blocklist.txt", } -def _get_ubsan_blocklist_features(): +def _get_sanitizer_blocklist_features(): features = [] for blocklist in sanitizer_blocklist_dict.items(): # Format the blocklist name to be used in a feature name blocklist_feature_name_suffix = blocklist[1].lower().replace(".", "_") features.append( feature( - name = "ubsan_blocklist_" + blocklist_feature_name_suffix, + name = "sanitizer_blocklist_" + blocklist_feature_name_suffix, enabled = False, requires = [ - feature_set(features = ["ubsan_enabled"]), + feature_set(features = ["sanitizers_enabled"]), ], flag_sets = [ flag_set( @@ -1910,6 +1916,7 @@ def _get_ubsan_features(target_os, libclang_rt_ubsan_minimal): feature( name = "ubsan_enabled", enabled = False, + implies = ["sanitizers_enabled"], ), ] @@ -2133,8 +2140,6 @@ def _get_ubsan_features(target_os, libclang_rt_ubsan_minimal): ), ) - ubsan_features.extend(_get_ubsan_blocklist_features()) - return ubsan_features def _manual_binder_interface_feature(): @@ -2203,6 +2208,8 @@ def get_features( # Sanitizers _get_cfi_features(target_arch, target_os), _get_ubsan_features(target_os, libclang_rt_ubsan_minimal), + _get_sanitizer_blocklist_features(), + _get_misc_sanitizer_features(), # Misc features _get_visibiility_hidden_feature(), # RTTI diff --git a/cc_toolchain_features_sanitizer_blocklist_test.bzl b/cc_toolchain_features_sanitizer_blocklist_test.bzl new file mode 100644 index 000000000..4bb8a8933 --- /dev/null +++ b/cc_toolchain_features_sanitizer_blocklist_test.bzl @@ -0,0 +1,102 @@ +"""Copyright (C) 2023 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +# TODO: b/286872909 - Remove this test when blocking bug is complete +load( + "//build/bazel/rules/test_common:flags.bzl", + "action_flags_absent_for_mnemonic_test", + "action_flags_present_only_for_mnemonic_test", +) + +def _test_sanitizer_blocklist_applied_when_ubsan_enabled(): + name = "sanitizer_blocklist_applied_when_ubsan_enabled" + native.cc_binary( + name = name, + srcs = ["foo.cpp"], + features = [ + "ubsan_undefined", + "sanitizer_blocklist_libavc_blocklist_txt", + ], + tags = ["manual"], + ) + + test_name = name + "_test" + action_flags_present_only_for_mnemonic_test( + name = test_name, + target_under_test = name, + mnemonics = ["CppCompile"], + expected_flags = [ + "-fsanitize-ignorelist=external/libavc/libavc_blocklist.txt", + ], + ) + + return test_name + +def _test_sanitizer_blocklist_applied_when_cfi_enabled(): + name = "sanitizer_blocklist_applied_when_cfi_enabled" + native.cc_binary( + name = name, + srcs = ["foo.cpp"], + features = [ + "android_cfi", + "sanitizer_blocklist_libavc_blocklist_txt", + ], + tags = ["manual"], + ) + + test_name = name + "_test" + action_flags_present_only_for_mnemonic_test( + name = test_name, + target_under_test = name, + mnemonics = ["CppCompile"], + expected_flags = [ + "-fsanitize-ignorelist=external/libavc/libavc_blocklist.txt", + ], + ) + + return test_name + +def _test_sanitizer_blocklist_not_applied_when_sanitizers_disabled(): + name = "sanitizer_blocklist_not_applied_when_sanitizers_disabled" + native.cc_binary( + name = name, + srcs = ["foo.cpp"], + features = [ + "sanitizer_blocklist_libavc_blocklist_txt", + ], + tags = ["manual"], + ) + + test_name = name + "_test" + action_flags_absent_for_mnemonic_test( + name = test_name, + target_under_test = name, + mnemonics = ["CppCompile"], + expected_absent_flags = [ + "-fsanitize-ignorelist=external/libavc/libavc_blocklist.txt", + ], + ) + + return test_name + +def cc_toolchain_features_sanitizer_blocklist_test_suite(name): + native.test_suite( + name = name, + tests = [ + _test_sanitizer_blocklist_applied_when_ubsan_enabled(), + _test_sanitizer_blocklist_applied_when_cfi_enabled(), + _test_sanitizer_blocklist_not_applied_when_sanitizers_disabled(), + ], + ) |