2012-07-31 23:43:11 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
|
|
|
|
import os
|
2014-05-28 16:38:13 +08:00
|
|
|
import platform
|
2017-04-11 22:58:26 +08:00
|
|
|
import re
|
2012-07-31 23:43:11 +08:00
|
|
|
|
2015-02-18 05:57:10 +08:00
|
|
|
import lit.formats
|
|
|
|
|
2019-06-22 00:54:58 +08:00
|
|
|
# Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if
|
|
|
|
# it's not available.
|
|
|
|
try:
|
|
|
|
import shlex
|
|
|
|
sh_quote = shlex.quote
|
|
|
|
except:
|
|
|
|
import pipes
|
|
|
|
sh_quote = pipes.quote
|
|
|
|
|
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 "
|
2019-06-28 04:56:04 +08:00
|
|
|
"to lit.site.cfg.py " % 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
|
|
|
|
Add support for FreeBSD's LD_32_LIBRARY_PATH
Summary:
Because the dynamic linker for 32-bit executables on 64-bit FreeBSD uses
the environment variable `LD_32_LIBRARY_PATH` instead of
`LD_LIBRARY_PATH` to find needed dynamic libraries, running the 32-bit
parts of the dynamic ASan tests will fail with errors similar to:
```
ld-elf32.so.1: Shared object "libclang_rt.asan-i386.so" not found, required by "Asan-i386-inline-Dynamic-Test"
```
This adds support for setting up `LD_32_LIBRARY_PATH` for the unit and
regression tests. It will likely also require a minor change to the
`TestingConfig` class in `llvm/utils/lit/lit`.
Reviewers: emaste, kcc, rnk, arichardson
Reviewed By: arichardson
Subscribers: kubamracek, krytarowski, fedor.sergeev, delcypher, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D65772
llvm-svn: 368516
2019-08-11 03:07:38 +08:00
|
|
|
if platform.system() == 'FreeBSD':
|
|
|
|
dynamic_library_lookup_var = 'LD_32_LIBRARY_PATH'
|
|
|
|
new_ld_32_library_path = os.path.pathsep.join(
|
|
|
|
(new_path, config.environment.get(dynamic_library_lookup_var, '')))
|
|
|
|
config.environment[dynamic_library_lookup_var] = new_ld_32_library_path
|
|
|
|
|
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.
|
2017-10-07 04:53:40 +08:00
|
|
|
default_asan_opts = list(config.default_sanitizer_opts)
|
2017-05-12 23:10:05 +08:00
|
|
|
|
2017-10-07 04:53:40 +08:00
|
|
|
# On Darwin, leak checking is not enabled by default. Enable for x86_64
|
|
|
|
# tests to prevent regressions
|
|
|
|
if config.host_os == 'Darwin' and config.target_arch == 'x86_64':
|
|
|
|
default_asan_opts += ['detect_leaks=1']
|
2016-09-10 02:43:24 +08:00
|
|
|
|
2017-10-07 04:53:40 +08:00
|
|
|
default_asan_opts_str = ':'.join(default_asan_opts)
|
|
|
|
if default_asan_opts_str:
|
|
|
|
config.environment['ASAN_OPTIONS'] = default_asan_opts_str
|
|
|
|
default_asan_opts_str += ':'
|
2015-08-13 07:50:12 +08:00
|
|
|
config.substitutions.append(('%env_asan_opts=',
|
2017-10-07 04:53:40 +08:00
|
|
|
'env ASAN_OPTIONS=' + default_asan_opts_str))
|
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__)
|
|
|
|
|
2018-05-19 09:02:51 +08:00
|
|
|
if config.host_os not in ['FreeBSD', 'NetBSD']:
|
2014-12-18 07:46:49 +08:00
|
|
|
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
|
|
|
|
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-17 21:08:10 +08:00
|
|
|
def build_invocation(compile_flags):
|
[ubsan] Re-commit: lit changes for lld testing, future lto testing.
Summary:
As discussed in https://github.com/google/oss-fuzz/issues/933,
it would be really awesome to be able to use ThinLTO for fuzzing.
However, as @kcc has pointed out, it is currently undefined (untested)
whether the sanitizers actually function properly with LLD and/or LTO.
This patch is inspired by the cfi test, which already do test with LTO
(and/or LLD), since LTO is required for CFI to function.
I started with UBSan, because it's cmakelists / lit.* files appeared
to be the cleanest. This patch adds the infrastructure to easily add
LLD and/or LTO sub-variants of the existing lit test configurations.
Also, this patch adds the LLD flavor, that explicitly does use LLD to link.
The check-ubsan does pass on my machine. And to minimize the [initial]
potential buildbot breakage i have put some restrictions on this flavour.
Please review carefully, i have not worked with lit/sanitizer tests before.
The original attempt, r319525 was reverted in r319526 due
to the failures in compiler-rt standalone builds.
Reviewers: eugenis, vitalybuka
Reviewed By: eugenis
Subscribers: #sanitizers, pcc, kubamracek, mgorny, llvm-commits, mehdi_amini, inglorion, kcc
Differential Revision: https://reviews.llvm.org/D39508
llvm-svn: 319575
2017-12-02 03:36:29 +08:00
|
|
|
return " " + " ".join([config.clang] + compile_flags) + " "
|
2012-07-31 23:43:11 +08:00
|
|
|
|
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)) )
|
2014-04-01 21:16:30 +08:00
|
|
|
if config.asan_dynamic:
|
Add support for FreeBSD's LD_32_LIBRARY_PATH
Summary:
Because the dynamic linker for 32-bit executables on 64-bit FreeBSD uses
the environment variable `LD_32_LIBRARY_PATH` instead of
`LD_LIBRARY_PATH` to find needed dynamic libraries, running the 32-bit
parts of the dynamic ASan tests will fail with errors similar to:
```
ld-elf32.so.1: Shared object "libclang_rt.asan-i386.so" not found, required by "Asan-i386-inline-Dynamic-Test"
```
This adds support for setting up `LD_32_LIBRARY_PATH` for the unit and
regression tests. It will likely also require a minor change to the
`TestingConfig` class in `llvm/utils/lit/lit`.
Reviewers: emaste, kcc, rnk, arichardson
Reviewed By: arichardson
Subscribers: kubamracek, krytarowski, fedor.sergeev, delcypher, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D65772
llvm-svn: 368516
2019-08-11 03:07:38 +08:00
|
|
|
if config.host_os in ['Linux', 'FreeBSD', 'NetBSD', 'SunOS']:
|
2018-10-13 07:36:23 +08:00
|
|
|
shared_libasan_path = os.path.join(config.compiler_rt_libdir, "libclang_rt.asan{}.so".format(config.target_suffix))
|
|
|
|
elif config.host_os == 'Darwin':
|
|
|
|
shared_libasan_path = os.path.join(config.compiler_rt_libdir, 'libclang_rt.asan_{}_dynamic.dylib'.format(config.apple_platform))
|
|
|
|
else:
|
|
|
|
lit_config.warning('%shared_libasan substitution not set but dynamic ASan is available.')
|
|
|
|
shared_libasan_path = None
|
|
|
|
|
|
|
|
if shared_libasan_path is not None:
|
|
|
|
config.substitutions.append( ("%shared_libasan", shared_libasan_path) )
|
2014-04-01 21:16:30 +08:00
|
|
|
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) )
|
|
|
|
|
2018-06-28 11:11:52 +08:00
|
|
|
base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.asan%%s%s.lib" % config.target_suffix)
|
2015-08-04 03:51:18 +08:00
|
|
|
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")
|
2019-06-22 00:54:58 +08:00
|
|
|
python_exec = sh_quote(get_required_attr(config, "python_executable"))
|
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
|
|
|
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)
|
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
|
2017-09-16 13:13:56 +08:00
|
|
|
if config.host_arch.find('64') != -1 and not config.android:
|
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")
|
|
|
|
|
2017-04-11 22:58:26 +08:00
|
|
|
# Fast unwinder doesn't work with Thumb
|
2018-06-01 14:23:36 +08:00
|
|
|
if re.search('mthumb', config.target_cflags) is None:
|
2017-04-11 22:58:26 +08:00
|
|
|
config.available_features.add('fast-unwinder-works')
|
|
|
|
|
2014-11-16 17:44:37 +08:00
|
|
|
# Turn on leak detection on 64-bit Linux.
|
2019-02-26 08:22:22 +08:00
|
|
|
leak_detection_linux = (config.host_os == 'Linux') and (not config.android) and (config.target_arch == 'x86_64' or config.target_arch == 'i386')
|
2017-05-12 23:10:05 +08:00
|
|
|
leak_detection_mac = (config.host_os == 'Darwin') and (config.target_arch == 'x86_64')
|
2019-09-09 07:53:36 +08:00
|
|
|
leak_detection_netbsd = (config.host_os == 'NetBSD') and (config.target_arch in ['x86_64', 'i386'])
|
2019-09-08 23:54:48 +08:00
|
|
|
if leak_detection_linux or leak_detection_mac or leak_detection_netbsd:
|
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.
|
2019-08-06 03:25:35 +08:00
|
|
|
config.suffixes = ['.c', '.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.
|
2018-02-15 22:59:59 +08:00
|
|
|
if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'SunOS', 'Windows', 'NetBSD']:
|
2012-08-15 16:29:17 +08:00
|
|
|
config.unsupported = True
|
2017-01-20 08:25:01 +08:00
|
|
|
|
2019-03-01 03:26:53 +08:00
|
|
|
if not config.parallelism_group:
|
|
|
|
config.parallelism_group = 'shadow-memory'
|
2019-12-03 21:44:33 +08:00
|
|
|
|
|
|
|
if config.host_os == 'NetBSD':
|
|
|
|
config.substitutions.insert(0, ('%run', config.netbsd_noaslr_prefix))
|