Skip to content

Commit b1585a3

Browse files
authored
Make sanitizer builds respect -c for -g* (#614)
Previously for `--features=asan` you got `-gline-tables-only`. This isn't ideal if you actually want to debug the sanitized code. Now it respects `--compilation_mode` so with `-c dbg` you get `-g` and with `-c fastbuild` you get `-gline-tables-only`. This is a tiny bit weird because we don't pass any `-g` for `fastbuild` normally. Fixes #613
1 parent 20913e2 commit b1585a3

21 files changed

Lines changed: 696 additions & 48 deletions

crosstool/cc_toolchain_config.bzl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,15 +2153,21 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new
21532153
ACTION_NAMES.objc_compile,
21542154
ACTION_NAMES.objcpp_compile,
21552155
],
2156-
flag_groups = [
2157-
flag_group(
2158-
flags = [
2159-
"-gline-tables-only",
2160-
"-fno-omit-frame-pointer",
2161-
"-fno-sanitize-recover=all",
2162-
],
2163-
),
2156+
flag_groups = [flag_group(flags = ["-gline-tables-only"])],
2157+
with_features = [
2158+
with_feature_set(features = ["asan", "fastbuild"]),
2159+
with_feature_set(features = ["tsan", "fastbuild"]),
2160+
with_feature_set(features = ["ubsan", "fastbuild"]),
2161+
],
2162+
),
2163+
flag_set(
2164+
actions = [
2165+
ACTION_NAMES.c_compile,
2166+
ACTION_NAMES.cpp_compile,
2167+
ACTION_NAMES.objc_compile,
2168+
ACTION_NAMES.objcpp_compile,
21642169
],
2170+
flag_groups = [flag_group(flags = ["-fno-sanitize-recover=all"])],
21652171
with_features = [
21662172
with_feature_set(features = ["asan"]),
21672173
with_feature_set(features = ["tsan"]),

test/sanitizer_tests.bzl

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,42 @@ default_test = make_action_command_line_test_rule()
99

1010
asan_test = make_action_command_line_test_rule(
1111
config_settings = {
12+
"//command_line_option:compilation_mode": "fastbuild",
13+
"//command_line_option:features": ["asan"],
14+
},
15+
)
16+
17+
asan_dbg_test = make_action_command_line_test_rule(
18+
config_settings = {
19+
"//command_line_option:compilation_mode": "dbg",
1220
"//command_line_option:features": ["asan"],
1321
},
1422
)
1523

1624
tsan_test = make_action_command_line_test_rule(
1725
config_settings = {
26+
"//command_line_option:compilation_mode": "fastbuild",
27+
"//command_line_option:features": ["tsan"],
28+
},
29+
)
30+
31+
tsan_dbg_test = make_action_command_line_test_rule(
32+
config_settings = {
33+
"//command_line_option:compilation_mode": "dbg",
1834
"//command_line_option:features": ["tsan"],
1935
},
2036
)
2137

2238
ubsan_test = make_action_command_line_test_rule(
2339
config_settings = {
40+
"//command_line_option:compilation_mode": "fastbuild",
41+
"//command_line_option:features": ["ubsan"],
42+
},
43+
)
44+
45+
ubsan_dbg_test = make_action_command_line_test_rule(
46+
config_settings = {
47+
"//command_line_option:compilation_mode": "dbg",
2448
"//command_line_option:features": ["ubsan"],
2549
},
2650
)
@@ -53,13 +77,35 @@ def sanitizer_test_suite(name):
5377
name = "{}_asan_cc_compile_test".format(name),
5478
tags = [name],
5579
expected_argv = [
80+
"-fno-omit-frame-pointer",
5681
"-fsanitize=address",
5782
"-gline-tables-only",
83+
"-fno-sanitize-recover=all",
84+
],
85+
not_expected_argv = [
86+
"-D_FORTIFY_SOURCE=1",
87+
"-g",
88+
"-g0",
89+
],
90+
mnemonic = "CppCompile",
91+
target_under_test = "//test/test_data:cc_main",
92+
)
93+
94+
asan_dbg_test(
95+
name = "{}_asan_dbg_cc_compile_test".format(name),
96+
tags = [name],
97+
expected_argv = [
5898
"-fno-omit-frame-pointer",
99+
"-O0",
100+
"-DDEBUG",
101+
"-g",
102+
"-fsanitize=address",
59103
"-fno-sanitize-recover=all",
60104
],
61105
not_expected_argv = [
62106
"-D_FORTIFY_SOURCE=1",
107+
"-gline-tables-only",
108+
"-g0",
63109
],
64110
mnemonic = "CppCompile",
65111
target_under_test = "//test/test_data:cc_main",
@@ -69,13 +115,15 @@ def sanitizer_test_suite(name):
69115
name = "{}_asan_objc_compile_test".format(name),
70116
tags = [name],
71117
expected_argv = [
118+
"-fno-omit-frame-pointer",
72119
"-fsanitize=address",
73120
"-gline-tables-only",
74-
"-fno-omit-frame-pointer",
75121
"-fno-sanitize-recover=all",
76122
],
77123
not_expected_argv = [
78124
"-D_FORTIFY_SOURCE=1",
125+
"-g",
126+
"-g0",
79127
],
80128
mnemonic = "ObjcCompile",
81129
target_under_test = "//test/test_data:objc_lib",
@@ -106,11 +154,35 @@ def sanitizer_test_suite(name):
106154
tags = [name],
107155
expected_argv = [
108156
"-D_FORTIFY_SOURCE=1",
157+
"-fno-omit-frame-pointer",
109158
"-fsanitize=thread",
110159
"-gline-tables-only",
160+
"-fno-sanitize-recover=all",
161+
],
162+
not_expected_argv = [
163+
"-g",
164+
"-g0",
165+
],
166+
mnemonic = "CppCompile",
167+
target_under_test = "//test/test_data:cc_main",
168+
)
169+
170+
tsan_dbg_test(
171+
name = "{}_tsan_dbg_cc_compile_test".format(name),
172+
tags = [name],
173+
expected_argv = [
174+
"-D_FORTIFY_SOURCE=1",
111175
"-fno-omit-frame-pointer",
176+
"-O0",
177+
"-DDEBUG",
178+
"-g",
179+
"-fsanitize=thread",
112180
"-fno-sanitize-recover=all",
113181
],
182+
not_expected_argv = [
183+
"-gline-tables-only",
184+
"-g0",
185+
],
114186
mnemonic = "CppCompile",
115187
target_under_test = "//test/test_data:cc_main",
116188
)
@@ -120,11 +192,15 @@ def sanitizer_test_suite(name):
120192
tags = [name],
121193
expected_argv = [
122194
"-D_FORTIFY_SOURCE=1",
195+
"-fno-omit-frame-pointer",
123196
"-fsanitize=thread",
124197
"-gline-tables-only",
125-
"-fno-omit-frame-pointer",
126198
"-fno-sanitize-recover=all",
127199
],
200+
not_expected_argv = [
201+
"-g",
202+
"-g0",
203+
],
128204
mnemonic = "ObjcCompile",
129205
target_under_test = "//test/test_data:objc_lib",
130206
)
@@ -154,11 +230,35 @@ def sanitizer_test_suite(name):
154230
tags = [name],
155231
expected_argv = [
156232
"-D_FORTIFY_SOURCE=1",
233+
"-fno-omit-frame-pointer",
157234
"-fsanitize=undefined",
158235
"-gline-tables-only",
236+
"-fno-sanitize-recover=all",
237+
],
238+
not_expected_argv = [
239+
"-g",
240+
"-g0",
241+
],
242+
mnemonic = "CppCompile",
243+
target_under_test = "//test/test_data:cc_main",
244+
)
245+
246+
ubsan_dbg_test(
247+
name = "{}_ubsan_dbg_cc_compile_test".format(name),
248+
tags = [name],
249+
expected_argv = [
250+
"-D_FORTIFY_SOURCE=1",
159251
"-fno-omit-frame-pointer",
252+
"-O0",
253+
"-DDEBUG",
254+
"-g",
255+
"-fsanitize=undefined",
160256
"-fno-sanitize-recover=all",
161257
],
258+
not_expected_argv = [
259+
"-gline-tables-only",
260+
"-g0",
261+
],
162262
mnemonic = "CppCompile",
163263
target_under_test = "//test/test_data:cc_main",
164264
)
@@ -168,11 +268,15 @@ def sanitizer_test_suite(name):
168268
tags = [name],
169269
expected_argv = [
170270
"-D_FORTIFY_SOURCE=1",
271+
"-fno-omit-frame-pointer",
171272
"-fsanitize=undefined",
172273
"-gline-tables-only",
173-
"-fno-omit-frame-pointer",
174274
"-fno-sanitize-recover=all",
175275
],
276+
not_expected_argv = [
277+
"-g",
278+
"-g0",
279+
],
176280
mnemonic = "ObjcCompile",
177281
target_under_test = "//test/test_data:objc_lib",
178282
)

test/test_data/toolchain_configs/darwin_arm64.json

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4678,8 +4678,39 @@
46784678
"expand_if_true": null,
46794679
"flag_groups": [],
46804680
"flags": [
4681-
"-gline-tables-only",
4682-
"-fno-omit-frame-pointer",
4681+
"-gline-tables-only"
4682+
],
4683+
"iterate_over": null,
4684+
"type_name": "flag_group"
4685+
}
4686+
],
4687+
"type_name": "flag_set",
4688+
"with_features": [
4689+
{
4690+
"features": [
4691+
"fastbuild"
4692+
],
4693+
"not_features": [],
4694+
"type_name": "with_feature_set"
4695+
}
4696+
]
4697+
},
4698+
{
4699+
"actions": [
4700+
"c++-compile",
4701+
"c-compile",
4702+
"objc++-compile",
4703+
"objc-compile"
4704+
],
4705+
"flag_groups": [
4706+
{
4707+
"expand_if_available": null,
4708+
"expand_if_equal": null,
4709+
"expand_if_false": null,
4710+
"expand_if_not_available": null,
4711+
"expand_if_true": null,
4712+
"flag_groups": [],
4713+
"flags": [
46834714
"-fno-sanitize-recover=all"
46844715
],
46854716
"iterate_over": null,

test/test_data/toolchain_configs/darwin_arm64e.json

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4682,8 +4682,39 @@
46824682
"expand_if_true": null,
46834683
"flag_groups": [],
46844684
"flags": [
4685-
"-gline-tables-only",
4686-
"-fno-omit-frame-pointer",
4685+
"-gline-tables-only"
4686+
],
4687+
"iterate_over": null,
4688+
"type_name": "flag_group"
4689+
}
4690+
],
4691+
"type_name": "flag_set",
4692+
"with_features": [
4693+
{
4694+
"features": [
4695+
"fastbuild"
4696+
],
4697+
"not_features": [],
4698+
"type_name": "with_feature_set"
4699+
}
4700+
]
4701+
},
4702+
{
4703+
"actions": [
4704+
"c++-compile",
4705+
"c-compile",
4706+
"objc++-compile",
4707+
"objc-compile"
4708+
],
4709+
"flag_groups": [
4710+
{
4711+
"expand_if_available": null,
4712+
"expand_if_equal": null,
4713+
"expand_if_false": null,
4714+
"expand_if_not_available": null,
4715+
"expand_if_true": null,
4716+
"flag_groups": [],
4717+
"flags": [
46874718
"-fno-sanitize-recover=all"
46884719
],
46894720
"iterate_over": null,

test/test_data/toolchain_configs/darwin_x86_64.json

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4682,8 +4682,39 @@
46824682
"expand_if_true": null,
46834683
"flag_groups": [],
46844684
"flags": [
4685-
"-gline-tables-only",
4686-
"-fno-omit-frame-pointer",
4685+
"-gline-tables-only"
4686+
],
4687+
"iterate_over": null,
4688+
"type_name": "flag_group"
4689+
}
4690+
],
4691+
"type_name": "flag_set",
4692+
"with_features": [
4693+
{
4694+
"features": [
4695+
"fastbuild"
4696+
],
4697+
"not_features": [],
4698+
"type_name": "with_feature_set"
4699+
}
4700+
]
4701+
},
4702+
{
4703+
"actions": [
4704+
"c++-compile",
4705+
"c-compile",
4706+
"objc++-compile",
4707+
"objc-compile"
4708+
],
4709+
"flag_groups": [
4710+
{
4711+
"expand_if_available": null,
4712+
"expand_if_equal": null,
4713+
"expand_if_false": null,
4714+
"expand_if_not_available": null,
4715+
"expand_if_true": null,
4716+
"flag_groups": [],
4717+
"flags": [
46874718
"-fno-sanitize-recover=all"
46884719
],
46894720
"iterate_over": null,

test/test_data/toolchain_configs/ios_arm64.json

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4658,8 +4658,39 @@
46584658
"expand_if_true": null,
46594659
"flag_groups": [],
46604660
"flags": [
4661-
"-gline-tables-only",
4662-
"-fno-omit-frame-pointer",
4661+
"-gline-tables-only"
4662+
],
4663+
"iterate_over": null,
4664+
"type_name": "flag_group"
4665+
}
4666+
],
4667+
"type_name": "flag_set",
4668+
"with_features": [
4669+
{
4670+
"features": [
4671+
"fastbuild"
4672+
],
4673+
"not_features": [],
4674+
"type_name": "with_feature_set"
4675+
}
4676+
]
4677+
},
4678+
{
4679+
"actions": [
4680+
"c++-compile",
4681+
"c-compile",
4682+
"objc++-compile",
4683+
"objc-compile"
4684+
],
4685+
"flag_groups": [
4686+
{
4687+
"expand_if_available": null,
4688+
"expand_if_equal": null,
4689+
"expand_if_false": null,
4690+
"expand_if_not_available": null,
4691+
"expand_if_true": null,
4692+
"flag_groups": [],
4693+
"flags": [
46634694
"-fno-sanitize-recover=all"
46644695
],
46654696
"iterate_over": null,

0 commit comments

Comments
 (0)