9 def get_required_attr(config
, attr_name
):
10 attr_value
= getattr(config
, attr_name
, None)
11 if attr_value
is None:
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
)
19 config
.name
= 'AddressSanitizerABI' + config
.name_suffix
21 # Platform-specific default ASAN_ABI_OPTIONS for lit tests.
22 default_asan_abi_opts
= list(config
.default_sanitizer_opts
)
24 default_asan_abi_opts_str
= ':'.join(default_asan_abi_opts
)
25 if default_asan_abi_opts_str
:
26 config
.environment
['ASAN_ABI_OPTIONS'] = default_asan_abi_opts_str
27 default_asan_abi_opts_str
+= ':'
28 config
.substitutions
.append(('%env_asan_abi_opts=',
29 'env ASAN_ABI_OPTIONS=' + default_asan_abi_opts_str
))
32 config
.test_source_root
= os
.path
.dirname(__file__
)
34 # GCC-ASan doesn't link in all the necessary libraries automatically, so
35 # we have to do it ourselves.
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.
40 target_cflags
= [get_required_attr(config
, 'target_cflags')] + extra_link_flags
41 target_cxxflags
= config
.cxx_mode_flags
+ target_cflags
42 clang_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
)
48 clang_asan_abi_static_cxxflags
= config
.cxx_mode_flags
+ clang_asan_abi_static_cflags
50 config
.available_features
.add('asan_abi-static-runtime')
51 clang_asan_abi_cflags
= clang_asan_abi_static_cflags
52 clang_asan_abi_cxxflags
= clang_asan_abi_static_cxxflags
54 def build_invocation(compile_flags
):
55 return ' ' + ' '.join([config
.clang
] + compile_flags
) + ' '
57 config
.substitutions
.append( ('%clang ', build_invocation(target_cflags
)) )
58 config
.substitutions
.append( ('%clangxx ', build_invocation(target_cxxflags
)) )
59 config
.substitutions
.append( ('%clang_asan_abi ', build_invocation(clang_asan_abi_cflags
)) )
60 config
.substitutions
.append( ('%clangxx_asan_abi ', build_invocation(clang_asan_abi_cxxflags
)) )
62 libasan_abi_path
= os
.path
.join(config
.compiler_rt_libdir
, 'libclang_rt.asan_abi_osx.a'.format(config
.apple_platform
))
64 if 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
)) )
69 config
.suffixes
= ['.c', '.cpp']
71 if config
.host_os
== 'Darwin':
72 config
.suffixes
.append('.mm')
74 config
.unsupported
= True