@@ -143,6 +143,34 @@ lto_index_actions = [
143143 ACTION_NAMES .lto_index_for_nodeps_dynamic_library ,
144144]
145145
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+ "-fno-omit-frame-pointer" ,
155+ "-fno-sanitize-recover=all" ,
156+ ] + specific_compile_flags ),
157+ ],
158+ with_features = [
159+ with_feature_set (features = [name ]),
160+ ],
161+ ),
162+ flag_set (
163+ actions = all_link_actions ,
164+ flag_groups = [
165+ flag_group (flags = specific_link_flags ),
166+ ],
167+ with_features = [
168+ with_feature_set (features = [name ]),
169+ ],
170+ ),
171+ ],
172+ )
173+
146174def _impl (ctx ):
147175 tool_paths = [
148176 tool_path (name = name , path = path )
@@ -783,6 +811,24 @@ def _impl(ctx):
783811 ],
784812 )
785813
814+ is_linux = ctx .attr .target_libc != "macosx"
815+ if is_linux :
816+ versioned_library_flag_group = flag_group (
817+ flags = ["-l:%{libraries_to_link.name}" ],
818+ expand_if_equal = variable_with_value (
819+ name = "libraries_to_link.type" ,
820+ value = "versioned_dynamic_library" ,
821+ ),
822+ )
823+ else :
824+ versioned_library_flag_group = flag_group (
825+ flags = ["%{libraries_to_link.path}" ],
826+ expand_if_equal = variable_with_value (
827+ name = "libraries_to_link.type" ,
828+ value = "versioned_dynamic_library" ,
829+ ),
830+ )
831+
786832 libraries_to_link_feature = feature (
787833 name = "libraries_to_link" ,
788834 flag_sets = [
@@ -840,13 +886,7 @@ def _impl(ctx):
840886 value = "dynamic_library" ,
841887 ),
842888 ),
843- flag_group (
844- flags = ["-l:%{libraries_to_link.name}" ],
845- expand_if_equal = variable_with_value (
846- name = "libraries_to_link.type" ,
847- value = "versioned_dynamic_library" ,
848- ),
849- ),
889+ versioned_library_flag_group ,
850890 flag_group (
851891 flags = ["-Wl,-no-whole-archive" ],
852892 expand_if_true = "libraries_to_link.is_whole_archive" ,
@@ -1224,7 +1264,37 @@ def _impl(ctx):
12241264 enabled = True ,
12251265 )
12261266
1227- is_linux = ctx .attr .target_libc != "macosx"
1267+ asan_feature = _sanitizer_feature (
1268+ name = "asan" ,
1269+ specific_compile_flags = [
1270+ "-fsanitize=address" ,
1271+ "-fno-common" ,
1272+ ],
1273+ specific_link_flags = [
1274+ "-fsanitize=address" ,
1275+ ],
1276+ )
1277+
1278+ tsan_feature = _sanitizer_feature (
1279+ name = "tsan" ,
1280+ specific_compile_flags = [
1281+ "-fsanitize=thread" ,
1282+ ],
1283+ specific_link_flags = [
1284+ "-fsanitize=thread" ,
1285+ ],
1286+ )
1287+
1288+ ubsan_feature = _sanitizer_feature (
1289+ name = "ubsan" ,
1290+ specific_compile_flags = [
1291+ "-fsanitize=undefined" ,
1292+ ],
1293+ specific_link_flags = [
1294+ "-fsanitize=undefined" ,
1295+ ],
1296+ )
1297+
12281298 libtool_feature = feature (
12291299 name = "libtool" ,
12301300 enabled = not is_linux ,
@@ -1265,6 +1335,9 @@ def _impl(ctx):
12651335 strip_debug_symbols_feature ,
12661336 coverage_feature ,
12671337 supports_pic_feature ,
1338+ asan_feature ,
1339+ tsan_feature ,
1340+ ubsan_feature ,
12681341 ] + (
12691342 [
12701343 supports_start_end_lib_feature ,
@@ -1300,6 +1373,9 @@ def _impl(ctx):
13001373 libtool_feature ,
13011374 archiver_flags_feature ,
13021375 supports_pic_feature ,
1376+ asan_feature ,
1377+ tsan_feature ,
1378+ ubsan_feature ,
13031379 ] + (
13041380 [
13051381 supports_start_end_lib_feature ,
0 commit comments