Skip to content

Commit 1778dec

Browse files
committed
Make sanitizer flags come before user flags
While not super recommended users should be able to override the `-g` flags set by sanitizers
1 parent b1585a3 commit 1778dec

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

crosstool/cc_toolchain_config.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,16 +2384,16 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new
23842384
apply_implicit_frameworks_feature,
23852385
link_cocoa_feature,
23862386
apply_simulator_compiler_flags_feature,
2387+
asan_feature,
2388+
tsan_feature,
2389+
ubsan_feature,
2390+
default_sanitizer_flags_feature,
23872391
user_compile_flags_feature,
23882392
unfiltered_compile_flags_feature,
23892393
linker_param_file_feature,
23902394
compiler_input_flags_feature,
23912395
compiler_output_flags_feature,
23922396
set_install_name,
2393-
asan_feature,
2394-
tsan_feature,
2395-
ubsan_feature,
2396-
default_sanitizer_flags_feature,
23972397
suppress_warnings_feature,
23982398
treat_warnings_as_errors_feature,
23992399
no_warn_duplicate_libraries_feature,

test/sanitizer_tests.bzl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ asan_dbg_test = make_action_command_line_test_rule(
2121
},
2222
)
2323

24+
asan_copt_order_test = make_action_command_line_test_rule(
25+
config_settings = {
26+
"//command_line_option:copt": ["-DFROM_COPTS_FLAG=1"],
27+
"//command_line_option:features": ["asan"],
28+
},
29+
)
30+
2431
tsan_test = make_action_command_line_test_rule(
2532
config_settings = {
2633
"//command_line_option:compilation_mode": "fastbuild",
@@ -129,6 +136,22 @@ def sanitizer_test_suite(name):
129136
target_under_test = "//test/test_data:objc_lib",
130137
)
131138

139+
asan_copt_order_test(
140+
name = "{}_asan_copt_order_test".format(name),
141+
tags = [name],
142+
expected_argv = [
143+
"-fsanitize=address",
144+
"-gline-tables-only",
145+
"-fno-omit-frame-pointer",
146+
"-fno-sanitize-recover=all",
147+
"-DCOPTS_ENV=1",
148+
"-DFROM_COPTS_FLAG=1",
149+
"-DFROM_BUILD_COPTS=1",
150+
],
151+
mnemonic = "CppCompile",
152+
target_under_test = "//test/test_data:cc_lib",
153+
)
154+
132155
asan_test(
133156
name = "{}_asan_link_test".format(name),
134157
tags = [name],

toolchain/BUILD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,10 @@ cc_toolchain(
902902
"@apple_support_toolchain_env//:linkopts_from_env", # TODO: Join with the copts below
903903
":default_required_flags",
904904
":__apply_simulator_compiler_flags",
905+
"//toolchain/sanitizers:asan_wrapper",
906+
"//toolchain/sanitizers:tsan_wrapper",
907+
"//toolchain/sanitizers:ubsan_wrapper",
908+
"//toolchain/sanitizers:default_sanitizer_flags",
905909
"@apple_support_toolchain_env//:copts_from_env",
906910
":default_link_flags",
907911
":no_deduplicate",
@@ -916,10 +920,6 @@ cc_toolchain(
916920
"@rules_cc//cc/toolchains/args/compiler_output_flags:feature",
917921
"@rules_cc//cc/toolchains/args/linker_param_file:feature",
918922
":set_install_name",
919-
"//toolchain/sanitizers:asan_wrapper",
920-
"//toolchain/sanitizers:tsan_wrapper",
921-
"//toolchain/sanitizers:ubsan_wrapper",
922-
"//toolchain/sanitizers:default_sanitizer_flags",
923923
":suppress_warnings_wrapper",
924924
":treat_warnings_as_errors_wrapper",
925925
":no_warn_duplicate_libraries",

0 commit comments

Comments
 (0)