18007ff1aSReid Kleckner# -*- Python -*- 28007ff1aSReid Kleckner 38007ff1aSReid Klecknerimport os 48007ff1aSReid Kleckner 58007ff1aSReid Kleckner# Setup config name. 6*f98ee40fSTobias Hietaconfig.name = "MemorySanitizer" + getattr(config, "name_suffix", "default") 78007ff1aSReid Kleckner 88007ff1aSReid Kleckner# Setup source root. 98007ff1aSReid Klecknerconfig.test_source_root = os.path.dirname(__file__) 108007ff1aSReid Kleckner 118007ff1aSReid Kleckner# Setup default compiler flags used with -fsanitize=memory option. 12*f98ee40fSTobias Hietaclang_msan_cflags = ( 13*f98ee40fSTobias Hieta [ 14*f98ee40fSTobias Hieta "-fsanitize=memory", 158007ff1aSReid Kleckner "-mno-omit-leaf-frame-pointer", 168007ff1aSReid Kleckner "-fno-omit-frame-pointer", 17*f98ee40fSTobias Hieta "-fno-optimize-sibling-calls", 18*f98ee40fSTobias Hieta ] 19*f98ee40fSTobias Hieta + [config.target_cflags] 20*f98ee40fSTobias Hieta + config.debug_info_flags 21*f98ee40fSTobias Hieta) 228007ff1aSReid Kleckner# Some Msan tests leverage backtrace() which requires libexecinfo on FreeBSD. 23*f98ee40fSTobias Hietaif config.host_os == "FreeBSD": 248007ff1aSReid Kleckner clang_msan_cflags += ["-lexecinfo", "-fPIC"] 25921009e6SIlya Leoshkevich# On SystemZ we need -mbackchain to make the fast unwinder work. 26*f98ee40fSTobias Hietaif config.target_arch == "s390x": 27921009e6SIlya Leoshkevich clang_msan_cflags.append("-mbackchain") 288007ff1aSReid Klecknerclang_msan_cxxflags = config.cxx_mode_flags + clang_msan_cflags 298007ff1aSReid Kleckner 308007ff1aSReid Kleckner# Flags for KMSAN invocation. This is C-only, we're not interested in C++. 31*f98ee40fSTobias Hietaclang_kmsan_cflags = ( 32*f98ee40fSTobias Hieta ["-fsanitize=kernel-memory"] + [config.target_cflags] + config.debug_info_flags 33*f98ee40fSTobias Hieta) 34*f98ee40fSTobias Hieta 358007ff1aSReid Kleckner 368007ff1aSReid Klecknerdef build_invocation(compile_flags): 378007ff1aSReid Kleckner return " " + " ".join([config.clang] + compile_flags) + " " 388007ff1aSReid Kleckner 39*f98ee40fSTobias Hieta 408007ff1aSReid Klecknerconfig.substitutions.append(("%clang_msan ", build_invocation(clang_msan_cflags))) 418007ff1aSReid Klecknerconfig.substitutions.append(("%clangxx_msan ", build_invocation(clang_msan_cxxflags))) 428007ff1aSReid Klecknerconfig.substitutions.append(("%clang_kmsan ", build_invocation(clang_kmsan_cflags))) 438007ff1aSReid Kleckner 448007ff1aSReid Kleckner# Default test suffixes. 45*f98ee40fSTobias Hietaconfig.suffixes = [".c", ".cpp"] 468007ff1aSReid Kleckner 47*f98ee40fSTobias Hietaif config.host_os not in ["Linux", "NetBSD", "FreeBSD"]: 488007ff1aSReid Kleckner config.unsupported = True 498007ff1aSReid Kleckner 508007ff1aSReid Kleckner# For mips64, mips64el we have forced store_context_size to 1 because these 518007ff1aSReid Kleckner# archs use slow unwinder which is not async signal safe. Therefore we only 528007ff1aSReid Kleckner# check the first frame since store_context size is 1. 53*f98ee40fSTobias Hietaif config.host_arch in ["mips64", "mips64el"]: 54*f98ee40fSTobias Hieta config.substitutions.append(("CHECK-%short-stack", "CHECK-SHORT-STACK")) 558007ff1aSReid Klecknerelse: 56*f98ee40fSTobias Hieta config.substitutions.append(("CHECK-%short-stack", "CHECK-FULL-STACK")) 576c2b2b9eSMichał Górny 58*f98ee40fSTobias Hietaif config.host_os == "NetBSD": 59*f98ee40fSTobias Hieta config.substitutions.insert(0, ("%run", config.netbsd_noaslr_prefix)) 60