@@ -143,6 +143,36 @@ lto_index_actions = [
143
143
ACTION_NAMES .lto_index_for_nodeps_dynamic_library ,
144
144
]
145
145
146
+ def _sanitizer_feature (name = "" , specific_compile_flags = [], specific_link_flags = []):
147
+ return feature (
148
+ name = name ,
149
+ flag_sets = [
150
+ flag_set (
151
+ actions = all_compile_actions ,
152
+ flag_groups = [
153
+ flag_group (flags = [
154
+ "-O1" ,
155
+ "-gline-tables-only" ,
156
+ "-fno-omit-frame-pointer" ,
157
+ "-fno-sanitize-recover=all" ,
158
+ ] + specific_compile_flags ),
159
+ ],
160
+ with_features = [
161
+ with_feature_set (features = [name ])
162
+ ],
163
+ ),
164
+ flag_set (
165
+ actions = all_link_actions ,
166
+ flag_groups = [
167
+ flag_group (flags = specific_link_flags ),
168
+ ],
169
+ with_features = [
170
+ with_feature_set (features = [name ])
171
+ ],
172
+ ),
173
+ ],
174
+ )
175
+
146
176
def _impl (ctx ):
147
177
tool_paths = [
148
178
tool_path (name = name , path = path )
@@ -1215,6 +1245,37 @@ def _impl(ctx):
1215
1245
enabled = True ,
1216
1246
)
1217
1247
1248
+ asan_feature = _sanitizer_feature (
1249
+ name = "asan" ,
1250
+ specific_compile_flags = [
1251
+ "-fsanitize=address" ,
1252
+ "-fno-common" ,
1253
+ ],
1254
+ specific_link_flags = [
1255
+ "-fsanitize=address" ,
1256
+ ],
1257
+ )
1258
+
1259
+ tsan_feature = _sanitizer_feature (
1260
+ name = "tsan" ,
1261
+ specific_compile_flags = [
1262
+ "-fsanitize=thread" ,
1263
+ ],
1264
+ specific_link_flags = [
1265
+ "-fsanitize=thread" ,
1266
+ ],
1267
+ )
1268
+
1269
+ ubsan_feature = _sanitizer_feature (
1270
+ name = "ubsan" ,
1271
+ specific_compile_flags = [
1272
+ "-fsanitize=undefined" ,
1273
+ ],
1274
+ specific_link_flags = [
1275
+ "-fsanitize=undefined" ,
1276
+ ],
1277
+ )
1278
+
1218
1279
is_linux = ctx .attr .target_libc != "macosx"
1219
1280
libtool_feature = feature (
1220
1281
name = "libtool" ,
@@ -1255,6 +1316,9 @@ def _impl(ctx):
1255
1316
strip_debug_symbols_feature ,
1256
1317
coverage_feature ,
1257
1318
supports_pic_feature ,
1319
+ asan_feature ,
1320
+ tsan_feature ,
1321
+ ubsan_feature ,
1258
1322
] + (
1259
1323
[
1260
1324
supports_start_end_lib_feature ,
0 commit comments