4 config
.test_source_root
= os
.path
.join(os
.path
.dirname(__file__
), "TestCases")
6 config
.name
= "SanitizerCommon-" + config
.name_suffix
8 default_tool_options
= []
9 collect_stack_traces
= ""
10 if config
.tool_name
== "asan":
11 tool_cflags
= ["-fsanitize=address"]
12 tool_options
= "ASAN_OPTIONS"
13 elif config
.tool_name
== "hwasan":
14 tool_cflags
= ["-fsanitize=hwaddress", "-fuse-ld=lld"]
15 if config
.target_arch
== "x86_64":
16 tool_cflags
+= ["-fsanitize-hwaddress-experimental-aliasing"]
17 config
.available_features
.add("hwasan-aliasing")
18 tool_options
= "HWASAN_OPTIONS"
19 if not config
.has_lld
:
20 config
.unsupported
= True
21 elif config
.tool_name
== "tsan":
22 tool_cflags
= ["-fsanitize=thread"]
23 tool_options
= "TSAN_OPTIONS"
24 elif config
.tool_name
== "msan":
25 tool_cflags
= ["-fsanitize=memory"]
26 tool_options
= "MSAN_OPTIONS"
27 collect_stack_traces
= "-fsanitize-memory-track-origins"
28 elif config
.tool_name
== "lsan":
29 tool_cflags
= ["-fsanitize=leak"]
30 tool_options
= "LSAN_OPTIONS"
31 elif config
.tool_name
== "ubsan":
32 tool_cflags
= ["-fsanitize=undefined"]
33 tool_options
= "UBSAN_OPTIONS"
35 lit_config
.fatal("Unknown tool for sanitizer_common tests: %r" % config
.tool_name
)
37 config
.available_features
.add(config
.tool_name
)
40 config
.host_os
== "Linux"
41 and config
.tool_name
== "lsan"
42 and config
.target_arch
== "i386"
44 config
.available_features
.add("lsan-x86")
47 config
.available_features
.add("thumb")
49 if config
.host_os
== "Darwin":
50 # On Darwin, we default to `abort_on_error=1`, which would make tests run
51 # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
52 default_tool_options
+= ["abort_on_error=0"]
53 if config
.tool_name
== "tsan":
54 default_tool_options
+= ["ignore_interceptors_accesses=0"]
56 # The same as on Darwin, we default to "abort_on_error=1" which slows down
57 # testing. Also, all existing tests are using "not" instead of "not --crash"
58 # which does not work for abort()-terminated programs.
59 default_tool_options
+= ["abort_on_error=0"]
61 default_tool_options_str
= ":".join(default_tool_options
)
62 if default_tool_options_str
:
63 config
.environment
[tool_options
] = default_tool_options_str
64 default_tool_options_str
+= ":"
68 if config
.host_os
in ["Linux"]:
69 extra_link_flags
+= ["-ldl"]
71 clang_cflags
= config
.debug_info_flags
+ tool_cflags
+ [config
.target_cflags
]
72 clang_cflags
+= ["-I%s" % os
.path
.dirname(os
.path
.dirname(__file__
))]
73 clang_cflags
+= extra_link_flags
74 clang_cxxflags
= config
.cxx_mode_flags
+ clang_cflags
77 def build_invocation(compile_flags
):
78 return " " + " ".join([config
.clang
] + compile_flags
) + " "
81 config
.substitutions
.append(("%clang ", build_invocation(clang_cflags
)))
82 config
.substitutions
.append(("%clangxx ", build_invocation(clang_cxxflags
)))
83 config
.substitutions
.append(("%collect_stack_traces", collect_stack_traces
))
84 config
.substitutions
.append(("%tool_name", config
.tool_name
))
85 config
.substitutions
.append(("%tool_options", tool_options
))
86 config
.substitutions
.append(
87 ("%env_tool_opts=", "env " + tool_options
+ "=" + default_tool_options_str
)
90 config
.suffixes
= [".c", ".cpp"]
92 if config
.host_os
not in ["Linux", "Darwin", "NetBSD", "FreeBSD", "SunOS"]:
93 config
.unsupported
= True
95 if not config
.parallelism_group
:
96 config
.parallelism_group
= "shadow-memory"
98 if config
.host_os
== "NetBSD":
99 config
.substitutions
.insert(0, ("%run", config
.netbsd_noaslr_prefix
))