1import lit.formats 2import os 3import subprocess 4import sys 5 6config.name = 'cfi' 7config.suffixes = ['.cpp'] 8config.test_source_root = os.path.dirname(__file__) 9 10def is_darwin_lto_supported(): 11 return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib')) 12 13def is_linux_lto_supported(): 14 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')): 15 return False 16 17 ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE) 18 ld_out = ld_cmd.stdout.read().decode() 19 ld_cmd.wait() 20 21 if not '-plugin' in ld_out: 22 return False 23 24 return True 25 26clangxx = ' '.join([config.clang] + config.cxx_mode_flags) 27 28config.substitutions.append((r"%clangxx ", clangxx + ' ')) 29 30if sys.platform == 'darwin' and is_darwin_lto_supported(): 31 config.substitutions.append((r"%clangxx_cfi ", 'env DYLD_LIBRARY_PATH=' + config.llvm_shlib_dir + ' ' + clangxx + ' -fsanitize=cfi ')) 32elif sys.platform.startswith('linux') and is_linux_lto_supported(): 33 config.substitutions.append((r"%clangxx_cfi ", clangxx + ' -fuse-ld=gold -fsanitize=cfi ')) 34else: 35 config.unsupported = True 36 37if lit_config.params.get('check_supported', None) and config.unsupported: 38 raise BaseException("Tests unsupported") 39