1# -*- Python -*- 2 3import os 4 5# Setup config name. 6config.name = 'AddressSanitizer' 7 8# Setup source root. 9config.test_source_root = os.path.dirname(__file__) 10 11def DisplayNoConfigMessage(): 12 lit.fatal("No site specific configuration available! " + 13 "Try running your test from the build tree or running " + 14 "make check-asan") 15 16# Figure out LLVM source root. 17llvm_src_root = getattr(config, 'llvm_src_root', None) 18if llvm_src_root is None: 19 # We probably haven't loaded the site-specific configuration: the user 20 # is likely trying to run a test file directly, and the site configuration 21 # wasn't created by the build system. 22 asan_site_cfg = lit.params.get('asan_site_config', None) 23 if (asan_site_cfg) and (os.path.exists(asan_site_cfg)): 24 lit.load_config(config, asan_site_cfg) 25 raise SystemExit 26 27 # Try to guess the location of site-specific configuration using llvm-config 28 # util that can point where the build tree is. 29 llvm_config = lit.util.which("llvm-config", config.environment["PATH"]) 30 if not llvm_config: 31 DisplayNoConfigMessage() 32 33 # Validate that llvm-config points to the same source tree. 34 llvm_src_root = lit.util.capture(["llvm-config", "--src-root"]).strip() 35 asan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt", 36 "lib", "asan", "lit_tests") 37 if (os.path.realpath(asan_test_src_root) != 38 os.path.realpath(config.test_source_root)): 39 DisplayNoConfigMessage() 40 41 # Find out the presumed location of generated site config. 42 llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip() 43 asan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt", 44 "lib", "asan", "lit_tests", "lit.site.cfg") 45 if (not asan_site_cfg) or (not os.path.exists(asan_site_cfg)): 46 DisplayNoConfigMessage() 47 48 lit.load_config(config, asan_site_cfg) 49 raise SystemExit 50 51# Setup attributes common for all compiler-rt projects. 52compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt", 53 "lib", "lit.common.cfg") 54if (not compiler_rt_lit_cfg) or (not os.path.exists(compiler_rt_lit_cfg)): 55 lit.fatal("Can't find common compiler-rt lit config at: %r" 56 % compiler_rt_lit_cfg) 57lit.load_config(config, compiler_rt_lit_cfg) 58 59# Setup default compiler flags used with -faddress-sanitizer option. 60# FIXME: Review the set of required flags and check if it can be reduced. 61clang_asan_cxxflags = ("-ccc-clang-cxx " 62 + "-ccc-cxx " 63 + "-faddress-sanitizer " 64 + "-mno-omit-leaf-frame-pointer " 65 + "-fno-omit-frame-pointer " 66 + "-fno-optimize-sibling-calls " 67 + "-g") 68config.substitutions.append( ("%clangxx_asan ", (" " + config.clang + " " + 69 clang_asan_cxxflags + " ")) ) 70 71# Setup path to symbolizer script. 72# FIXME: Instead we should copy this script to the build tree and point 73# at it there. 74asan_source_dir = os.path.join(config.test_source_root, "..") 75symbolizer = os.path.join(asan_source_dir, 76 'scripts', 'asan_symbolize.py') 77if not os.path.exists(symbolizer): 78 lit.fatal("Can't find symbolizer script on path %r" % symbolizer) 79# Define %symbolize substitution that filters output through 80# symbolizer and c++filt (for demangling). 81config.substitutions.append( ("%symbolize ", (" " + symbolizer + 82 " | c++filt " ))) 83 84# Define CHECK-%os to check for OS-dependent output. 85config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os))) 86 87# Default test suffixes. 88config.suffixes = ['.c', '.cc', '.cpp'] 89 90# AddressSanitizer tests are currently supported on Linux and Darwin only. 91if config.host_os not in ['Linux', 'Darwin']: 92 config.unsupported = True 93