1import lit.formats 2import os 3 4config.name = 'cfi' + config.name_suffix 5config.suffixes = ['.c', '.cpp', '.test'] 6config.test_source_root = os.path.dirname(__file__) 7 8def build_invocation(compile_flags): 9 return " " + " ".join([config.clang] + compile_flags) + " " 10 11clang = build_invocation([config.target_cflags]) 12clangxx = build_invocation([config.target_cflags] + config.cxx_mode_flags) 13 14config.substitutions.append((r"%clang ", clang + ' ')) 15config.substitutions.append((r"%clangxx ", clangxx + ' ')) 16 17if 'darwin' in config.available_features: 18 # -fsanitize=cfi is not supported on Darwin hosts 19 config.unsupported = True 20elif config.lto_supported: 21 clang_cfi = clang + '-fsanitize=cfi ' 22 23 if config.cfi_lit_test_mode == "Devirt": 24 config.available_features.add('devirt') 25 clang_cfi += '-fwhole-program-vtables ' 26 config.substitutions.append((r"%expect_crash_unless_devirt ", "")) 27 else: 28 config.substitutions.append((r"%expect_crash_unless_devirt ", config.expect_crash)) 29 30 cxx = ' '.join(config.cxx_mode_flags) + ' ' 31 diag = '-fno-sanitize-trap=cfi -fsanitize-recover=cfi ' 32 non_dso = '-fvisibility=hidden ' 33 dso = '-fsanitize-cfi-cross-dso -fvisibility=default ' 34 if config.android: 35 dso += '-include ' + config.test_source_root + '/cross-dso/util/cfi_stubs.h ' 36 config.substitutions.append((r"%clang_cfi ", clang_cfi + non_dso)) 37 config.substitutions.append((r"%clangxx_cfi ", clang_cfi + cxx + non_dso)) 38 config.substitutions.append((r"%clang_cfi_diag ", clang_cfi + non_dso + diag)) 39 config.substitutions.append((r"%clangxx_cfi_diag ", clang_cfi + cxx + non_dso + diag)) 40 config.substitutions.append((r"%clangxx_cfi_dso ", clang_cfi + cxx + dso)) 41 config.substitutions.append((r"%clangxx_cfi_dso_diag ", clang_cfi + cxx + dso + diag)) 42 config.substitutions.append((r"%debug_info_flags", ' '.join(config.debug_info_flags))) 43else: 44 config.unsupported = True 45 46if config.default_sanitizer_opts: 47 config.environment['UBSAN_OPTIONS'] = ':'.join(config.default_sanitizer_opts) 48 49if lit_config.params.get('check_supported', None) and config.unsupported: 50 raise BaseException("Tests unsupported") 51