2012-07-31 23:43:11 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
|
|
|
|
import os
|
2014-05-28 16:38:13 +08:00
|
|
|
import platform
|
2012-07-31 23:43:11 +08:00
|
|
|
|
2015-02-18 05:57:10 +08:00
|
|
|
import lit.formats
|
|
|
|
|
2013-05-27 17:35:24 +08:00
|
|
|
def get_required_attr(config, attr_name):
|
|
|
|
attr_value = getattr(config, attr_name, None)
|
2014-05-01 05:32:30 +08:00
|
|
|
if attr_value == None:
|
2013-08-10 06:14:01 +08:00
|
|
|
lit_config.fatal(
|
|
|
|
"No attribute %r in test configuration! You may need to run "
|
|
|
|
"tests from your build directory or add this attribute "
|
|
|
|
"to lit.site.cfg " % attr_name)
|
2013-05-27 17:35:24 +08:00
|
|
|
return attr_value
|
|
|
|
|
2014-12-11 22:04:57 +08:00
|
|
|
def push_dynamic_library_lookup_path(config, new_path):
|
|
|
|
if platform.system() == 'Windows':
|
|
|
|
dynamic_library_lookup_var = 'PATH'
|
2015-02-19 02:26:58 +08:00
|
|
|
elif platform.system() == 'Darwin':
|
|
|
|
dynamic_library_lookup_var = 'DYLD_LIBRARY_PATH'
|
2014-12-11 22:04:57 +08:00
|
|
|
else:
|
|
|
|
dynamic_library_lookup_var = 'LD_LIBRARY_PATH'
|
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
new_ld_library_path = os.path.pathsep.join(
|
2015-01-14 09:28:08 +08:00
|
|
|
(new_path, config.environment.get(dynamic_library_lookup_var, '')))
|
2014-12-11 22:04:57 +08:00
|
|
|
config.environment[dynamic_library_lookup_var] = new_ld_library_path
|
2014-04-01 21:16:30 +08:00
|
|
|
|
2012-07-31 23:43:11 +08:00
|
|
|
# Setup config name.
|
2014-02-14 17:22:10 +08:00
|
|
|
config.name = 'AddressSanitizer' + config.name_suffix
|
2012-07-31 23:43:11 +08:00
|
|
|
|
2015-07-28 22:34:13 +08:00
|
|
|
# Platform-specific default ASAN_OPTIONS for lit tests.
|
2015-08-13 07:50:12 +08:00
|
|
|
default_asan_opts = ''
|
2015-07-28 22:34:13 +08:00
|
|
|
if config.host_os == 'Darwin':
|
|
|
|
# On Darwin, we default to `abort_on_error=1`, which would make tests run
|
|
|
|
# much slower. Let's override this and run lit tests with 'abort_on_error=0'.
|
Reapply: [asan] On OS X, log reports to syslog and os_trace
When ASan currently detects a bug, by default it will only print out the text
of the report to stderr. This patch changes this behavior and writes the full
text of the report to syslog before we terminate the process. It also calls
os_trace (Activity Tracing available on OS X and iOS) with a message saying
that the report is available in syslog. This is useful, because this message
will be shown in the crash log.
For this to work, the patch makes sure we store the full report into
error_message_buffer unconditionally, and it also strips out ANSI escape
sequences from the report (they are used when producing colored reports).
I've initially tried to log to syslog during printing, which is done on Android
right now. The advantage is that if we crash during error reporting or the
produced error does not go through ScopedInErrorReport, we would still get a
(partial) message in the syslog. However, that solution is very problematic on
OS X. One issue is that the logging routine uses GCD, which may spawn a new
thread on its behalf. In many cases, the reporting logic locks threadRegistry,
which leads to deadlocks.
Reviewed at http://reviews.llvm.org/D13452
(In addition, add sanitizer_common_libcdep.cc to buildgo.sh to avoid
build failures on Linux.)
llvm-svn: 253688
2015-11-21 02:41:44 +08:00
|
|
|
# Also, make sure we do not overwhelm the syslog while testing.
|
2015-08-13 07:50:12 +08:00
|
|
|
default_asan_opts = 'abort_on_error=0'
|
Reapply: [asan] On OS X, log reports to syslog and os_trace
When ASan currently detects a bug, by default it will only print out the text
of the report to stderr. This patch changes this behavior and writes the full
text of the report to syslog before we terminate the process. It also calls
os_trace (Activity Tracing available on OS X and iOS) with a message saying
that the report is available in syslog. This is useful, because this message
will be shown in the crash log.
For this to work, the patch makes sure we store the full report into
error_message_buffer unconditionally, and it also strips out ANSI escape
sequences from the report (they are used when producing colored reports).
I've initially tried to log to syslog during printing, which is done on Android
right now. The advantage is that if we crash during error reporting or the
produced error does not go through ScopedInErrorReport, we would still get a
(partial) message in the syslog. However, that solution is very problematic on
OS X. One issue is that the logging routine uses GCD, which may spawn a new
thread on its behalf. In many cases, the reporting logic locks threadRegistry,
which leads to deadlocks.
Reviewed at http://reviews.llvm.org/D13452
(In addition, add sanitizer_common_libcdep.cc to buildgo.sh to avoid
build failures on Linux.)
llvm-svn: 253688
2015-11-21 02:41:44 +08:00
|
|
|
default_asan_opts += ':log_to_syslog=0'
|
2016-09-10 02:43:24 +08:00
|
|
|
elif config.android:
|
|
|
|
# The same as on Darwin, we default to "abort_on_error=1" which slows down
|
|
|
|
# testing. Also, all existing tests are using "not" instead of "not --crash"
|
|
|
|
# which does not work for abort()-terminated programs.
|
|
|
|
default_asan_opts = 'abort_on_error=0'
|
|
|
|
|
2015-08-13 07:50:12 +08:00
|
|
|
if default_asan_opts:
|
|
|
|
config.environment['ASAN_OPTIONS'] = default_asan_opts
|
|
|
|
default_asan_opts += ':'
|
|
|
|
config.substitutions.append(('%env_asan_opts=',
|
|
|
|
'env ASAN_OPTIONS=' + default_asan_opts))
|
2015-06-16 04:43:42 +08:00
|
|
|
|
2012-07-31 23:43:11 +08:00
|
|
|
# Setup source root.
|
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
2014-12-18 07:46:49 +08:00
|
|
|
# There is no libdl on FreeBSD.
|
|
|
|
if config.host_os != 'FreeBSD':
|
|
|
|
libdl_flag = "-ldl"
|
|
|
|
else:
|
|
|
|
libdl_flag = ""
|
|
|
|
|
2014-02-19 23:13:14 +08:00
|
|
|
# GCC-ASan doesn't link in all the necessary libraries automatically, so
|
|
|
|
# we have to do it ourselves.
|
|
|
|
if config.compiler_id == 'GNU':
|
2017-01-10 12:33:04 +08:00
|
|
|
extra_link_flags = ["-pthread", "-lstdc++", libdl_flag]
|
2014-02-19 23:13:14 +08:00
|
|
|
else:
|
2017-01-10 12:33:04 +08:00
|
|
|
extra_link_flags = []
|
2014-07-16 17:53:00 +08:00
|
|
|
|
2015-08-01 08:01:23 +08:00
|
|
|
# BFD linker in 64-bit android toolchains fails to find libm.so, which is a
|
|
|
|
# transitive shared library dependency (via asan runtime).
|
|
|
|
if config.android:
|
2017-01-10 12:33:04 +08:00
|
|
|
extra_link_flags += ["-lm"]
|
2015-08-01 08:01:23 +08:00
|
|
|
|
2012-11-06 10:31:42 +08:00
|
|
|
# Setup default compiler flags used with -fsanitize=address option.
|
2012-07-31 23:43:11 +08:00
|
|
|
# FIXME: Review the set of required flags and check if it can be reduced.
|
2017-01-10 12:33:04 +08:00
|
|
|
target_cflags = [get_required_attr(config, "target_cflags")] + extra_link_flags
|
2014-02-19 23:13:14 +08:00
|
|
|
target_cxxflags = config.cxx_mode_flags + target_cflags
|
2014-09-06 06:05:32 +08:00
|
|
|
clang_asan_static_cflags = (["-fsanitize=address",
|
2014-05-28 16:38:13 +08:00
|
|
|
"-mno-omit-leaf-frame-pointer",
|
|
|
|
"-fno-omit-frame-pointer",
|
2014-09-06 06:05:32 +08:00
|
|
|
"-fno-optimize-sibling-calls"] +
|
|
|
|
config.debug_info_flags + target_cflags)
|
2016-05-12 16:49:34 +08:00
|
|
|
if config.target_arch == 's390x':
|
|
|
|
clang_asan_static_cflags.append("-mbackchain")
|
2014-04-01 21:16:30 +08:00
|
|
|
clang_asan_static_cxxflags = config.cxx_mode_flags + clang_asan_static_cflags
|
|
|
|
|
2016-11-02 23:39:08 +08:00
|
|
|
asan_dynamic_flags = []
|
2014-04-01 21:16:30 +08:00
|
|
|
if config.asan_dynamic:
|
2016-11-02 23:39:08 +08:00
|
|
|
asan_dynamic_flags = ["-shared-libasan"]
|
|
|
|
# On Windows, we need to simulate "clang-cl /MD" on the clang driver side.
|
|
|
|
if platform.system() == 'Windows':
|
|
|
|
asan_dynamic_flags += ["-D_MT", "-D_DLL", "-Wl,-nodefaultlib:libcmt,-defaultlib:msvcrt,-defaultlib:oldnames"]
|
2014-04-01 21:16:30 +08:00
|
|
|
config.available_features.add("asan-dynamic-runtime")
|
|
|
|
else:
|
|
|
|
config.available_features.add("asan-static-runtime")
|
2016-11-02 23:39:08 +08:00
|
|
|
clang_asan_cflags = clang_asan_static_cflags + asan_dynamic_flags
|
|
|
|
clang_asan_cxxflags = clang_asan_static_cxxflags + asan_dynamic_flags
|
|
|
|
|
|
|
|
# Add win32-(static|dynamic)-asan features to mark tests as passing or failing
|
|
|
|
# in those modes. lit doesn't support logical feature test combinations.
|
|
|
|
if platform.system() == 'Windows':
|
|
|
|
if config.asan_dynamic:
|
|
|
|
win_runtime_feature = "win32-dynamic-asan"
|
|
|
|
else:
|
|
|
|
win_runtime_feature = "win32-static-asan"
|
|
|
|
config.available_features.add(win_runtime_feature)
|
2014-02-14 17:22:10 +08:00
|
|
|
|
2014-02-14 22:06:10 +08:00
|
|
|
asan_lit_source_dir = get_required_attr(config, "asan_lit_source_dir")
|
2014-09-29 21:18:55 +08:00
|
|
|
if config.android == "1":
|
2014-02-14 17:22:10 +08:00
|
|
|
config.available_features.add('android')
|
2014-02-14 22:06:10 +08:00
|
|
|
clang_wrapper = os.path.join(asan_lit_source_dir,
|
2014-02-14 17:22:10 +08:00
|
|
|
"android_commands", "android_compile.py") + " "
|
|
|
|
else:
|
2014-11-26 23:44:15 +08:00
|
|
|
config.available_features.add('not-android')
|
2014-02-14 17:22:10 +08:00
|
|
|
clang_wrapper = ""
|
|
|
|
|
2014-02-17 21:08:10 +08:00
|
|
|
def build_invocation(compile_flags):
|
|
|
|
return " " + " ".join([clang_wrapper, config.clang] + compile_flags) + " "
|
2012-07-31 23:43:11 +08:00
|
|
|
|
2016-09-24 01:40:31 +08:00
|
|
|
# Clang driver link 'x86' (i686) architecture to 'i386'.
|
|
|
|
target_arch = config.target_arch
|
|
|
|
if (target_arch == "i686"):
|
|
|
|
target_arch = "i386"
|
|
|
|
|
2014-02-17 21:08:10 +08:00
|
|
|
config.substitutions.append( ("%clang ", build_invocation(target_cflags)) )
|
|
|
|
config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) )
|
|
|
|
config.substitutions.append( ("%clang_asan ", build_invocation(clang_asan_cflags)) )
|
|
|
|
config.substitutions.append( ("%clangxx_asan ", build_invocation(clang_asan_cxxflags)) )
|
2016-09-24 01:40:31 +08:00
|
|
|
config.substitutions.append( ("%shared_libasan", "libclang_rt.asan-%s.so" % target_arch))
|
2014-04-01 21:16:30 +08:00
|
|
|
if config.asan_dynamic:
|
|
|
|
config.substitutions.append( ("%clang_asan_static ", build_invocation(clang_asan_static_cflags)) )
|
|
|
|
config.substitutions.append( ("%clangxx_asan_static ", build_invocation(clang_asan_static_cxxflags)) )
|
2014-02-14 17:22:10 +08:00
|
|
|
|
2014-05-28 16:38:13 +08:00
|
|
|
# Windows-specific tests might also use the clang-cl.exe driver.
|
|
|
|
if platform.system() == 'Windows':
|
2017-02-22 00:09:38 +08:00
|
|
|
clang_cl_cxxflags = ["-Wno-deprecated-declarations",
|
|
|
|
"-WX",
|
|
|
|
"-D_HAS_EXCEPTIONS=0",
|
|
|
|
"-Zi"] + target_cflags
|
|
|
|
clang_cl_asan_cxxflags = ["-fsanitize=address"] + clang_cl_cxxflags
|
2014-08-22 20:38:07 +08:00
|
|
|
if config.asan_dynamic:
|
|
|
|
clang_cl_asan_cxxflags.append("-MD")
|
2017-02-22 00:09:38 +08:00
|
|
|
|
|
|
|
clang_cl_invocation = build_invocation(clang_cl_cxxflags)
|
|
|
|
clang_cl_invocation = clang_cl_invocation.replace("clang.exe","clang-cl.exe")
|
|
|
|
config.substitutions.append( ("%clang_cl ", clang_cl_invocation) )
|
|
|
|
|
|
|
|
clang_cl_asan_invocation = build_invocation(clang_cl_asan_cxxflags)
|
|
|
|
clang_cl_asan_invocation = clang_cl_asan_invocation.replace("clang.exe","clang-cl.exe")
|
|
|
|
config.substitutions.append( ("%clang_cl_asan ", clang_cl_asan_invocation) )
|
|
|
|
|
2015-08-04 03:51:18 +08:00
|
|
|
base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.asan%%s-%s.lib" % config.target_arch)
|
|
|
|
config.substitutions.append( ("%asan_lib", base_lib % "") )
|
|
|
|
config.substitutions.append( ("%asan_cxx_lib", base_lib % "_cxx") )
|
|
|
|
config.substitutions.append( ("%asan_dll_thunk", base_lib % "_dll_thunk") )
|
2014-05-28 16:38:13 +08:00
|
|
|
|
2016-07-23 02:41:22 +08:00
|
|
|
if platform.system() == 'Windows':
|
|
|
|
# Don't use -std=c++11 on Windows, as the driver will detect the appropriate
|
|
|
|
# default needed to use with the STL.
|
|
|
|
config.substitutions.append(("%stdcxx11 ", ""))
|
|
|
|
else:
|
|
|
|
# Some tests uses C++11 features such as lambdas and need to pass -std=c++11.
|
|
|
|
config.substitutions.append(("%stdcxx11 ", "-std=c++11 "))
|
|
|
|
|
2014-02-14 22:06:10 +08:00
|
|
|
# FIXME: De-hardcode this path.
|
|
|
|
asan_source_dir = os.path.join(
|
|
|
|
get_required_attr(config, "compiler_rt_src_root"), "lib", "asan")
|
2013-07-01 17:15:19 +08:00
|
|
|
# Setup path to asan_symbolize.py script.
|
|
|
|
asan_symbolize = os.path.join(asan_source_dir, "scripts", "asan_symbolize.py")
|
|
|
|
if not os.path.exists(asan_symbolize):
|
2013-08-10 06:14:01 +08:00
|
|
|
lit_config.fatal("Can't find script on path %r" % asan_symbolize)
|
2013-10-17 13:33:22 +08:00
|
|
|
python_exec = get_required_attr(config, "python_executable")
|
|
|
|
config.substitutions.append( ("%asan_symbolize", python_exec + " " + asan_symbolize + " ") )
|
2014-05-19 20:53:03 +08:00
|
|
|
# Setup path to sancov.py script.
|
|
|
|
sanitizer_common_source_dir = os.path.join(
|
|
|
|
get_required_attr(config, "compiler_rt_src_root"), "lib", "sanitizer_common")
|
|
|
|
sancov = os.path.join(sanitizer_common_source_dir, "scripts", "sancov.py")
|
|
|
|
if not os.path.exists(sancov):
|
|
|
|
lit_config.fatal("Can't find script on path %r" % sancov)
|
|
|
|
python_exec = get_required_attr(config, "python_executable")
|
2016-01-28 07:51:36 +08:00
|
|
|
config.substitutions.append( ("%sancov ", python_exec + " " + sancov + " ") )
|
2013-07-01 17:15:19 +08:00
|
|
|
|
2014-03-27 15:36:26 +08:00
|
|
|
# Determine kernel bitness
|
2014-09-29 21:18:55 +08:00
|
|
|
if config.host_arch.find('64') != -1 and config.android != "1":
|
2014-03-27 15:36:26 +08:00
|
|
|
kernel_bits = '64'
|
|
|
|
else:
|
|
|
|
kernel_bits = '32'
|
|
|
|
|
|
|
|
config.substitutions.append( ('CHECK-%kernel_bits', ("CHECK-kernel-" + kernel_bits + "-bits")))
|
2012-08-15 16:29:17 +08:00
|
|
|
|
2014-12-18 07:46:49 +08:00
|
|
|
config.substitutions.append( ("%libdl", libdl_flag) )
|
|
|
|
|
2013-06-07 17:38:55 +08:00
|
|
|
config.available_features.add("asan-" + config.bits + "-bits")
|
|
|
|
|
2015-04-01 20:13:03 +08:00
|
|
|
if config.host_os == 'Darwin':
|
|
|
|
config.substitutions.append( ("%ld_flags_rpath_exe", '-Wl,-rpath,@executable_path/ %dynamiclib') )
|
|
|
|
config.substitutions.append( ("%ld_flags_rpath_so", '-install_name @rpath/`basename %dynamiclib`') )
|
2015-04-20 20:25:11 +08:00
|
|
|
elif config.host_os == 'FreeBSD':
|
|
|
|
config.substitutions.append( ("%ld_flags_rpath_exe", "-Wl,-z,origin -Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec") )
|
|
|
|
config.substitutions.append( ("%ld_flags_rpath_so", '') )
|
|
|
|
elif config.host_os == 'Linux':
|
2015-04-01 20:13:03 +08:00
|
|
|
config.substitutions.append( ("%ld_flags_rpath_exe", "-Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec") )
|
|
|
|
config.substitutions.append( ("%ld_flags_rpath_so", '') )
|
|
|
|
|
|
|
|
# Must be defined after the substitutions that use %dynamiclib.
|
|
|
|
config.substitutions.append( ("%dynamiclib", '%T/lib%xdynamiclib_namespec.so') )
|
|
|
|
config.substitutions.append( ("%xdynamiclib_namespec", '$(basename %t).dynamic') )
|
|
|
|
|
2015-08-18 20:44:55 +08:00
|
|
|
# Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL
|
2015-09-30 02:35:55 +08:00
|
|
|
# because the test hangs. Adding armhf as we now have two modes.
|
|
|
|
if config.target_arch != 'arm' and config.target_arch != 'armhf' and config.target_arch != 'aarch64':
|
2015-08-18 20:44:55 +08:00
|
|
|
config.available_features.add('stable-runtime')
|
|
|
|
|
2014-11-16 17:44:37 +08:00
|
|
|
# Turn on leak detection on 64-bit Linux.
|
2017-01-31 15:15:37 +08:00
|
|
|
if config.host_os == 'Linux' and (config.target_arch == 'x86_64' or config.target_arch == 'i386'):
|
2014-11-25 15:56:04 +08:00
|
|
|
config.available_features.add('leak-detection')
|
2013-09-08 21:23:29 +08:00
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
# Set LD_LIBRARY_PATH to pick dynamic runtime up properly.
|
2014-12-11 22:04:57 +08:00
|
|
|
push_dynamic_library_lookup_path(config, config.compiler_rt_libdir)
|
2014-04-01 21:16:30 +08:00
|
|
|
|
|
|
|
# GCC-ASan uses dynamic runtime by default.
|
2014-02-19 23:13:14 +08:00
|
|
|
if config.compiler_id == 'GNU':
|
|
|
|
gcc_dir = os.path.dirname(config.clang)
|
|
|
|
libasan_dir = os.path.join(gcc_dir, "..", "lib" + config.bits)
|
2014-12-11 22:04:57 +08:00
|
|
|
push_dynamic_library_lookup_path(config, libasan_dir)
|
2014-02-19 23:13:14 +08:00
|
|
|
|
2016-11-02 23:39:08 +08:00
|
|
|
# Add the RT libdir to PATH directly so that we can successfully run the gtest
|
|
|
|
# binary to list its tests.
|
|
|
|
if config.host_os == 'Windows' and config.asan_dynamic:
|
|
|
|
os.environ['PATH'] = os.path.pathsep.join([config.compiler_rt_libdir,
|
|
|
|
os.environ.get('PATH', '')])
|
|
|
|
|
2012-07-31 23:43:11 +08:00
|
|
|
# Default test suffixes.
|
|
|
|
config.suffixes = ['.c', '.cc', '.cpp']
|
2012-08-15 16:29:17 +08:00
|
|
|
|
2014-03-14 18:41:49 +08:00
|
|
|
if config.host_os == 'Darwin':
|
|
|
|
config.suffixes.append('.mm')
|
|
|
|
|
2016-12-27 11:16:20 +08:00
|
|
|
if config.host_os == 'Windows':
|
|
|
|
config.substitutions.append(('%fPIC', ''))
|
|
|
|
config.substitutions.append(('%fPIE', ''))
|
|
|
|
config.substitutions.append(('%pie', ''))
|
|
|
|
else:
|
|
|
|
config.substitutions.append(('%fPIC', '-fPIC'))
|
|
|
|
config.substitutions.append(('%fPIE', '-fPIE'))
|
|
|
|
config.substitutions.append(('%pie', '-pie'))
|
|
|
|
|
2015-08-15 04:01:27 +08:00
|
|
|
# Only run the tests on supported OSs.
|
2015-08-15 01:39:48 +08:00
|
|
|
if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows']:
|
2012-08-15 16:29:17 +08:00
|
|
|
config.unsupported = True
|
2017-01-20 08:25:01 +08:00
|
|
|
|
|
|
|
if config.host_os == 'Darwin' and config.target_arch in ["x86_64", "x86_64h"]:
|
|
|
|
config.parallelism_group = "darwin-64bit-sanitizer"
|