brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · dd99a53 Raw
75 lines · python
1# -*- Python -*-2 3import os4import platform5import re6 7import lit.formats8 9def get_required_attr(config, attr_name):10  attr_value = getattr(config, attr_name, None)11  if attr_value is None:12    lit_config.fatal(13      'No attribute %r in test configuration! You may need to run '14      'tests from your build directory or add this attribute '15      'to lit.site.cfg.py ' % attr_name)16  return attr_value17 18# Setup config name.19config.name = 'AddressSanitizerABI' + config.name_suffix20 21# Platform-specific default ASAN_ABI_OPTIONS for lit tests.22default_asan_abi_opts = list(config.default_sanitizer_opts)23 24default_asan_abi_opts_str = ':'.join(default_asan_abi_opts)25if default_asan_abi_opts_str:26  config.environment['ASAN_ABI_OPTIONS'] = default_asan_abi_opts_str27  default_asan_abi_opts_str += ':'28config.substitutions.append(('%env_asan_abi_opts=',29                             'env ASAN_ABI_OPTIONS=' + default_asan_abi_opts_str))30 31# Setup source root.32config.test_source_root = os.path.dirname(__file__)33 34# GCC-ASan doesn't link in all the necessary libraries automatically, so35# we have to do it ourselves.36extra_link_flags = []37 38# Setup default compiler flags used with -fsanitize=address option.39# FIXME: Review the set of required flags and check if it can be reduced.40target_cflags = [get_required_attr(config, 'target_cflags')] + extra_link_flags41target_cxxflags = config.cxx_mode_flags + target_cflags42clang_asan_abi_static_cflags = (['-fsanitize=address',43                            '-fsanitize-stable-abi',44                            '-mno-omit-leaf-frame-pointer',45                            '-fno-omit-frame-pointer',46                            '-fno-optimize-sibling-calls'] +47                            config.debug_info_flags + target_cflags)48clang_asan_abi_static_cxxflags = config.cxx_mode_flags + clang_asan_abi_static_cflags49 50config.available_features.add('asan_abi-static-runtime')51clang_asan_abi_cflags = clang_asan_abi_static_cflags52clang_asan_abi_cxxflags = clang_asan_abi_static_cxxflags53 54def build_invocation(compile_flags):55  return ' ' + ' '.join([config.clang] + compile_flags) + ' '56 57config.substitutions.append( ('%clang ', build_invocation(target_cflags)) )58config.substitutions.append( ('%clangxx ', build_invocation(target_cxxflags)) )59config.substitutions.append( ('%clang_asan_abi ', build_invocation(clang_asan_abi_cflags)) )60config.substitutions.append( ('%clangxx_asan_abi ', build_invocation(clang_asan_abi_cxxflags)) )61 62libasan_abi_path = os.path.join(config.compiler_rt_libdir, 'libclang_rt.asan_abi_osx.a'.format(config.apple_platform))63 64if libasan_abi_path is not None:65  config.substitutions.append( ('%libasan_abi', libasan_abi_path) )66  config.substitutions.append( ('%clang_asan_abi_static ', build_invocation(clang_asan_abi_static_cflags)) )67  config.substitutions.append( ('%clangxx_asan_abi_static ', build_invocation(clang_asan_abi_static_cxxflags)) )68 69config.suffixes = ['.c', '.cpp']70 71if config.target_os == 'Darwin':72  config.suffixes.append('.mm')73else:74  config.unsupported = True75