Skip to content

Commit

Permalink
Add sanitizer features to unix_cc_toolchain_config
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlee committed Dec 28, 2022
1 parent 9c11145 commit 3966604
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tools/cpp/unix_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,36 @@ lto_index_actions = [
ACTION_NAMES.lto_index_for_nodeps_dynamic_library,
]

def _sanitizer_feature(name = "", specific_compile_flags = [], specific_link_flags = []):
return feature(
name = name,
flag_sets = [
flag_set(
actions = all_compile_actions,
flag_groups = [
flag_group(flags = [
"-O1",
"-gline-tables-only",
"-fno-omit-frame-pointer",
"-fno-sanitize-recover=all",
] + specific_compile_flags),
],
with_features = [
with_feature_set(features = [name]),
],
),
flag_set(
actions = all_link_actions,
flag_groups = [
flag_group(flags = specific_link_flags),
],
with_features = [
with_feature_set(features = [name]),
],
),
],
)

def _impl(ctx):
tool_paths = [
tool_path(name = name, path = path)
Expand Down Expand Up @@ -1215,6 +1245,37 @@ def _impl(ctx):
enabled = True,
)

asan_feature = _sanitizer_feature(
name = "asan",
specific_compile_flags = [
"-fsanitize=address",
"-fno-common",
],
specific_link_flags = [
"-fsanitize=address",
],
)

tsan_feature = _sanitizer_feature(
name = "tsan",
specific_compile_flags = [
"-fsanitize=thread",
],
specific_link_flags = [
"-fsanitize=thread",
],
)

ubsan_feature = _sanitizer_feature(
name = "ubsan",
specific_compile_flags = [
"-fsanitize=undefined",
],
specific_link_flags = [
"-fsanitize=undefined",
],
)

is_linux = ctx.attr.target_libc != "macosx"
libtool_feature = feature(
name = "libtool",
Expand Down Expand Up @@ -1255,6 +1316,9 @@ def _impl(ctx):
strip_debug_symbols_feature,
coverage_feature,
supports_pic_feature,
asan_feature,
tsan_feature,
ubsan_feature,
] + (
[
supports_start_end_lib_feature,
Expand Down

0 comments on commit 3966604

Please sign in to comment.