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
== "rtsan":
22 tool_cflags
= ["-fsanitize=realtime"]
23 tool_options
= "RTSAN_OPTIONS"
24 elif config
.tool_name
== "tsan":
25 tool_cflags
= ["-fsanitize=thread"]
26 tool_options
= "TSAN_OPTIONS"
27 elif config
.tool_name
== "msan":
28 tool_cflags
= ["-fsanitize=memory"]
29 tool_options
= "MSAN_OPTIONS"
30 collect_stack_traces
= "-fsanitize-memory-track-origins"
31 elif config
.tool_name
== "lsan":
32 tool_cflags
= ["-fsanitize=leak"]
33 tool_options
= "LSAN_OPTIONS"
34 elif config
.tool_name
== "ubsan":
35 tool_cflags
= ["-fsanitize=undefined"]
36 tool_options
= "UBSAN_OPTIONS"
38 lit_config
.fatal("Unknown tool for sanitizer_common tests: %r" % config
.tool_name
)
40 config
.available_features
.add(config
.tool_name
)
43 config
.host_os
== "Linux"
44 and config
.tool_name
== "lsan"
45 and config
.target_arch
== "i386"
47 config
.available_features
.add("lsan-x86")
50 config
.available_features
.add("thumb")
52 if config
.host_os
== "Darwin":
53 # On Darwin, we default to `abort_on_error=1`, which would make tests run
54 # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
55 default_tool_options
+= ["abort_on_error=0"]
56 if config
.tool_name
== "tsan":
57 default_tool_options
+= ["ignore_interceptors_accesses=0"]
59 # The same as on Darwin, we default to "abort_on_error=1" which slows down
60 # testing. Also, all existing tests are using "not" instead of "not --crash"
61 # which does not work for abort()-terminated programs.
62 default_tool_options
+= ["abort_on_error=0"]
64 default_tool_options_str
= ":".join(default_tool_options
)
65 if default_tool_options_str
:
66 config
.environment
[tool_options
] = default_tool_options_str
67 default_tool_options_str
+= ":"
71 if config
.host_os
in ["Linux"]:
72 extra_link_flags
+= ["-ldl"]
74 clang_cflags
= config
.debug_info_flags
+ tool_cflags
+ [config
.target_cflags
]
75 clang_cflags
+= ["-I%s" % os
.path
.dirname(os
.path
.dirname(__file__
))]
76 clang_cflags
+= extra_link_flags
77 clang_cxxflags
= config
.cxx_mode_flags
+ clang_cflags
80 def build_invocation(compile_flags
):
81 return " " + " ".join([config
.clang
] + compile_flags
) + " "
84 config
.substitutions
.append(("%clang ", build_invocation(clang_cflags
)))
85 config
.substitutions
.append(("%clangxx ", build_invocation(clang_cxxflags
)))
86 config
.substitutions
.append(("%collect_stack_traces", collect_stack_traces
))
87 config
.substitutions
.append(("%tool_name", config
.tool_name
))
88 config
.substitutions
.append(("%tool_options", tool_options
))
89 config
.substitutions
.append(
90 ("%env_tool_opts=", "env " + tool_options
+ "=" + default_tool_options_str
)
93 config
.suffixes
= [".c", ".cpp"]
95 if config
.host_os
not in ["Linux", "Darwin", "NetBSD", "FreeBSD", "SunOS"]:
96 config
.unsupported
= True
98 if not config
.parallelism_group
:
99 config
.parallelism_group
= "shadow-memory"
101 if config
.host_os
== "NetBSD":
102 config
.substitutions
.insert(0, ("%run", config
.netbsd_noaslr_prefix
))