1*6f026ff0SRoy Sundahl# -*- Python -*- 2*6f026ff0SRoy Sundahl 3*6f026ff0SRoy Sundahlimport os 4*6f026ff0SRoy Sundahlimport platform 5*6f026ff0SRoy Sundahlimport re 6*6f026ff0SRoy Sundahl 7*6f026ff0SRoy Sundahlimport lit.formats 8*6f026ff0SRoy Sundahl 9*6f026ff0SRoy Sundahldef get_required_attr(config, attr_name): 10*6f026ff0SRoy Sundahl attr_value = getattr(config, attr_name, None) 11*6f026ff0SRoy Sundahl if attr_value is None: 12*6f026ff0SRoy Sundahl lit_config.fatal( 13*6f026ff0SRoy Sundahl 'No attribute %r in test configuration! You may need to run ' 14*6f026ff0SRoy Sundahl 'tests from your build directory or add this attribute ' 15*6f026ff0SRoy Sundahl 'to lit.site.cfg.py ' % attr_name) 16*6f026ff0SRoy Sundahl return attr_value 17*6f026ff0SRoy Sundahl 18*6f026ff0SRoy Sundahl# Setup config name. 19*6f026ff0SRoy Sundahlconfig.name = 'AddressSanitizerABI' + config.name_suffix 20*6f026ff0SRoy Sundahl 21*6f026ff0SRoy Sundahl# Platform-specific default ASAN_ABI_OPTIONS for lit tests. 22*6f026ff0SRoy Sundahldefault_asan_abi_opts = list(config.default_sanitizer_opts) 23*6f026ff0SRoy Sundahl 24*6f026ff0SRoy Sundahldefault_asan_abi_opts_str = ':'.join(default_asan_abi_opts) 25*6f026ff0SRoy Sundahlif default_asan_abi_opts_str: 26*6f026ff0SRoy Sundahl config.environment['ASAN_ABI_OPTIONS'] = default_asan_abi_opts_str 27*6f026ff0SRoy Sundahl default_asan_abi_opts_str += ':' 28*6f026ff0SRoy Sundahlconfig.substitutions.append(('%env_asan_abi_opts=', 29*6f026ff0SRoy Sundahl 'env ASAN_ABI_OPTIONS=' + default_asan_abi_opts_str)) 30*6f026ff0SRoy Sundahl 31*6f026ff0SRoy Sundahl# Setup source root. 32*6f026ff0SRoy Sundahlconfig.test_source_root = os.path.dirname(__file__) 33*6f026ff0SRoy Sundahl 34*6f026ff0SRoy Sundahl# GCC-ASan doesn't link in all the necessary libraries automatically, so 35*6f026ff0SRoy Sundahl# we have to do it ourselves. 36*6f026ff0SRoy Sundahlextra_link_flags = [] 37*6f026ff0SRoy Sundahl 38*6f026ff0SRoy Sundahl# Setup default compiler flags used with -fsanitize=address option. 39*6f026ff0SRoy Sundahl# FIXME: Review the set of required flags and check if it can be reduced. 40*6f026ff0SRoy Sundahltarget_cflags = [get_required_attr(config, 'target_cflags')] + extra_link_flags 41*6f026ff0SRoy Sundahltarget_cxxflags = config.cxx_mode_flags + target_cflags 42*6f026ff0SRoy Sundahlclang_asan_abi_static_cflags = (['-fsanitize=address', 43*6f026ff0SRoy Sundahl '-fsanitize-stable-abi', 44*6f026ff0SRoy Sundahl '-mno-omit-leaf-frame-pointer', 45*6f026ff0SRoy Sundahl '-fno-omit-frame-pointer', 46*6f026ff0SRoy Sundahl '-fno-optimize-sibling-calls'] + 47*6f026ff0SRoy Sundahl config.debug_info_flags + target_cflags) 48*6f026ff0SRoy Sundahlclang_asan_abi_static_cxxflags = config.cxx_mode_flags + clang_asan_abi_static_cflags 49*6f026ff0SRoy Sundahl 50*6f026ff0SRoy Sundahlconfig.available_features.add('asan_abi-static-runtime') 51*6f026ff0SRoy Sundahlclang_asan_abi_cflags = clang_asan_abi_static_cflags 52*6f026ff0SRoy Sundahlclang_asan_abi_cxxflags = clang_asan_abi_static_cxxflags 53*6f026ff0SRoy Sundahl 54*6f026ff0SRoy Sundahldef build_invocation(compile_flags): 55*6f026ff0SRoy Sundahl return ' ' + ' '.join([config.clang] + compile_flags) + ' ' 56*6f026ff0SRoy Sundahl 57*6f026ff0SRoy Sundahlconfig.substitutions.append( ('%clang ', build_invocation(target_cflags)) ) 58*6f026ff0SRoy Sundahlconfig.substitutions.append( ('%clangxx ', build_invocation(target_cxxflags)) ) 59*6f026ff0SRoy Sundahlconfig.substitutions.append( ('%clang_asan_abi ', build_invocation(clang_asan_abi_cflags)) ) 60*6f026ff0SRoy Sundahlconfig.substitutions.append( ('%clangxx_asan_abi ', build_invocation(clang_asan_abi_cxxflags)) ) 61*6f026ff0SRoy Sundahl 62*6f026ff0SRoy Sundahllibasan_abi_path = os.path.join(config.compiler_rt_libdir, 'libclang_rt.asan_abi_osx.a'.format(config.apple_platform)) 63*6f026ff0SRoy Sundahl 64*6f026ff0SRoy Sundahlif libasan_abi_path is not None: 65*6f026ff0SRoy Sundahl config.substitutions.append( ('%libasan_abi', libasan_abi_path) ) 66*6f026ff0SRoy Sundahl config.substitutions.append( ('%clang_asan_abi_static ', build_invocation(clang_asan_abi_static_cflags)) ) 67*6f026ff0SRoy Sundahl config.substitutions.append( ('%clangxx_asan_abi_static ', build_invocation(clang_asan_abi_static_cxxflags)) ) 68*6f026ff0SRoy Sundahl 69*6f026ff0SRoy Sundahlconfig.suffixes = ['.c', '.cpp'] 70*6f026ff0SRoy Sundahl 71*6f026ff0SRoy Sundahlif config.host_os == 'Darwin': 72*6f026ff0SRoy Sundahl config.suffixes.append('.mm') 73*6f026ff0SRoy Sundahlelse: 74*6f026ff0SRoy Sundahl config.unsupported = True 75