1# -*- Python -*- 2 3import os 4 5# Setup config name. 6config.name = "GWP-ASan" + config.name_suffix 7 8# Setup source root. 9config.test_source_root = os.path.dirname(__file__) 10 11# Test suffixes. 12config.suffixes = [".c", ".cpp", ".test"] 13 14# C & CXX flags. 15c_flags = [config.target_cflags] 16 17cxx_flags = c_flags + config.cxx_mode_flags + ["-std=c++14"] 18 19libscudo_standalone = os.path.join( 20 config.compiler_rt_libdir, "libclang_rt.scudo_standalone%s.a" % config.target_suffix 21) 22libscudo_standalone_cxx = os.path.join( 23 config.compiler_rt_libdir, 24 "libclang_rt.scudo_standalone_cxx%s.a" % config.target_suffix, 25) 26 27scudo_link_flags = [ 28 "-pthread", 29 "-Wl,--whole-archive", 30 libscudo_standalone, 31 "-Wl,--no-whole-archive", 32] 33scudo_link_cxx_flags = [ 34 "-Wl,--whole-archive", 35 libscudo_standalone_cxx, 36 "-Wl,--no-whole-archive", 37] 38 39# -rdynamic is necessary for online function symbolization. 40gwp_asan_flags = ["-rdynamic"] + scudo_link_flags 41 42 43def build_invocation(compile_flags): 44 return " " + " ".join([config.clang] + compile_flags) + " " 45 46 47# Add substitutions. 48config.substitutions.append(("%clang ", build_invocation(c_flags))) 49config.substitutions.append( 50 ("%clang_gwp_asan ", build_invocation(c_flags + gwp_asan_flags)) 51) 52config.substitutions.append( 53 ( 54 "%clangxx_gwp_asan ", 55 build_invocation(cxx_flags + gwp_asan_flags + scudo_link_cxx_flags), 56 ) 57) 58 59# Platform-specific default GWP_ASAN for lit tests. Ensure that GWP-ASan is 60# enabled and that it samples every allocation. 61default_gwp_asan_options = "GWP_ASAN_Enabled=1:GWP_ASAN_SampleRate=1" 62 63config.environment["SCUDO_OPTIONS"] = default_gwp_asan_options 64default_gwp_asan_options += ":" 65config.substitutions.append( 66 ("%env_scudo_options=", "env SCUDO_OPTIONS=" + default_gwp_asan_options) 67) 68 69# GWP-ASan tests are currently supported on Linux only. 70if config.host_os not in ["Linux"]: 71 config.unsupported = True 72