1 # -*- Python -*- 2 3 import os 4 5 # Setup config name. 6 config.name = 'MemorySanitizer' 7 8 # Setup source root. 9 config.test_source_root = os.path.dirname(__file__) 10 11 def DisplayNoConfigMessage(): 12 lit.fatal("No site specific configuration available! " + 13 "Try running your test from the build tree or running " + 14 "make check-msan") 15 16 # Figure out LLVM source root. 17 llvm_src_root = getattr(config, 'llvm_src_root', None) 18 if 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 msan_site_cfg = lit.params.get('msan_site_config', None) 23 if (msan_site_cfg) and (os.path.exists(msan_site_cfg)): 24 lit.load_config(config, msan_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 msan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt", 36 "lib", "msan", "lit_tests") 37 if (os.path.realpath(msan_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 msan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt", 44 "lib", "msan", "lit_tests", "lit.site.cfg") 45 if (not msan_site_cfg) or (not os.path.exists(msan_site_cfg)): 46 DisplayNoConfigMessage() 47 48 lit.load_config(config, msan_site_cfg) 49 raise SystemExit 50 51 # Setup attributes common for all compiler-rt projects. 52 compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt", 53 "lib", "lit.common.cfg") 54 if (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) 57 lit.load_config(config, compiler_rt_lit_cfg) 58 59 # Setup default compiler flags used with -fsanitize=memory option. 60 clang_msan_cflags = ["-fsanitize=memory", 61 "-mno-omit-leaf-frame-pointer", 62 "-fno-omit-frame-pointer", 63 "-fno-optimize-sibling-calls", 64 "-g", 65 "-fPIE", 66 "-pie"] 67 clang_msan_cxxflags = ["-ccc-cxx "] + clang_msan_cflags 68 config.substitutions.append( ("%clang_msan ", 69 " ".join([config.clang] + clang_msan_cflags) + 70 " ") ) 71 config.substitutions.append( ("%clangxx_msan ", 72 " ".join([config.clang] + clang_msan_cxxflags) + 73 " ") ) 74 75 # Setup path to external LLVM symbolizer to run MemorySanitizer output tests. 76 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) 77 if llvm_tools_dir: 78 llvm_symbolizer_path = os.path.join(llvm_tools_dir, "llvm-symbolizer") 79 config.environment['MSAN_SYMBOLIZER_PATH'] = llvm_symbolizer_path 80 81 # Default test suffixes. 82 config.suffixes = ['.c', '.cc', '.cpp'] 83 84 # MemorySanitizer tests are currently supported on Linux only. 85 if config.host_os not in ['Linux']: 86 config.unsupported = True 87