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 + ' ')) 16if config.lto_supported: 17 clang_cfi = clang + '-fsanitize=cfi ' 18 19 if config.cfi_lit_test_mode == "Devirt": 20 config.available_features.add('devirt') 21 clang_cfi += '-fwhole-program-vtables ' 22 config.substitutions.append((r"%expect_crash_unless_devirt ", "")) 23 else: 24 config.substitutions.append((r"%expect_crash_unless_devirt ", config.expect_crash)) 25 26 cxx = ' '.join(config.cxx_mode_flags) + ' ' 27 diag = '-fno-sanitize-trap=cfi -fsanitize-recover=cfi ' 28 non_dso = '-fvisibility=hidden ' 29 dso = '-fsanitize-cfi-cross-dso -fvisibility=default ' 30 if config.android: 31 dso += '-include ' + config.test_source_root + '/cross-dso/util/cfi_stubs.h ' 32 config.substitutions.append((r"%clang_cfi ", clang_cfi + non_dso)) 33 config.substitutions.append((r"%clangxx_cfi ", clang_cfi + cxx + non_dso)) 34 config.substitutions.append((r"%clang_cfi_diag ", clang_cfi + non_dso + diag)) 35 config.substitutions.append((r"%clangxx_cfi_diag ", clang_cfi + cxx + non_dso + diag)) 36 config.substitutions.append((r"%clangxx_cfi_dso ", clang_cfi + cxx + dso)) 37 config.substitutions.append((r"%clangxx_cfi_dso_diag ", clang_cfi + cxx + dso + diag)) 38 config.substitutions.append((r"%debug_info_flags", ' '.join(config.debug_info_flags))) 39else: 40 config.unsupported = True 41 42if config.default_sanitizer_opts: 43 config.environment['UBSAN_OPTIONS'] = ':'.join(config.default_sanitizer_opts) 44 45if lit_config.params.get('check_supported', None) and config.unsupported: 46 raise BaseException("Tests unsupported") 47