• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- Python -*-
2
3import os
4
5# Setup config name.
6config.name = 'HWAddressSanitizer' + getattr(config, 'name_suffix', 'default')
7
8# Setup source root.
9config.test_source_root = os.path.dirname(__file__)
10
11# Setup default compiler flags used with -fsanitize=memory option.
12clang_cflags = [config.target_cflags] + config.debug_info_flags
13clang_cxxflags = config.cxx_mode_flags + clang_cflags
14clang_hwasan_common_cflags = clang_cflags + ["-fsanitize=hwaddress", "-fuse-ld=lld"]
15if config.target_arch == 'x86_64':
16  # This does basically the same thing as tagged-globals on aarch64. Because
17  # the x86_64 implementation is for testing purposes only there is no
18  # equivalent target feature implemented on x86_64.
19  clang_hwasan_common_cflags += ["-mcmodel=large"]
20clang_hwasan_cflags = clang_hwasan_common_cflags + ["-mllvm", "-hwasan-globals",
21                                                   "-mllvm", "-hwasan-use-short-granules",
22                                                   "-mllvm", "-hwasan-instrument-landing-pads=0",
23                                                   "-mllvm", "-hwasan-instrument-personality-functions"]
24clang_hwasan_oldrt_cflags = clang_hwasan_common_cflags + ["-mllvm", "-hwasan-use-short-granules=0",
25                                                          "-mllvm", "-hwasan-instrument-landing-pads=1",
26                                                          "-mllvm", "-hwasan-instrument-personality-functions=0"]
27
28clang_hwasan_cxxflags = config.cxx_mode_flags + clang_hwasan_cflags
29clang_hwasan_oldrt_cxxflags = config.cxx_mode_flags + clang_hwasan_oldrt_cflags
30
31def build_invocation(compile_flags):
32  return " " + " ".join([config.clang] + compile_flags) + " "
33
34config.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) )
35config.substitutions.append( ("%clang_hwasan ", build_invocation(clang_hwasan_cflags)) )
36config.substitutions.append( ("%clang_hwasan_oldrt ", build_invocation(clang_hwasan_oldrt_cflags)) )
37config.substitutions.append( ("%clangxx_hwasan ", build_invocation(clang_hwasan_cxxflags)) )
38config.substitutions.append( ("%clangxx_hwasan_oldrt ", build_invocation(clang_hwasan_oldrt_cxxflags)) )
39config.substitutions.append( ("%compiler_rt_libdir", config.compiler_rt_libdir) )
40
41default_hwasan_opts_str = ':'.join(['disable_allocator_tagging=1', 'random_tags=0'] + config.default_sanitizer_opts)
42if default_hwasan_opts_str:
43  config.environment['HWASAN_OPTIONS'] = default_hwasan_opts_str
44  default_hwasan_opts_str += ':'
45config.substitutions.append(('%env_hwasan_opts=',
46                             'env HWASAN_OPTIONS=' + default_hwasan_opts_str))
47
48# Default test suffixes.
49config.suffixes = ['.c', '.cpp']
50
51if config.host_os not in ['Linux', 'Android'] or not config.has_lld:
52  config.unsupported = True
53