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
|
|
|
|
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-04-01 21:16:30 +08:00
|
|
|
def push_ld_library_path(config, new_path):
|
|
|
|
new_ld_library_path = os.path.pathsep.join(
|
|
|
|
(new_path, config.environment['LD_LIBRARY_PATH']))
|
|
|
|
config.environment['LD_LIBRARY_PATH'] = new_ld_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
|
|
|
|
|
|
|
# Setup source root.
|
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
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':
|
2014-05-28 21:13:30 +08:00
|
|
|
extra_linkflags = ["-pthread", "-lstdc++", "-ldl"]
|
2014-02-19 23:13:14 +08:00
|
|
|
else:
|
|
|
|
extra_linkflags = []
|
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.
|
2014-02-19 23:13:14 +08:00
|
|
|
target_cflags = [get_required_attr(config, "target_cflags")] + extra_linkflags
|
|
|
|
target_cxxflags = config.cxx_mode_flags + target_cflags
|
2014-05-28 16:38:13 +08:00
|
|
|
clang_asan_static_cflags = ["-fsanitize=address",
|
|
|
|
"-mno-omit-leaf-frame-pointer",
|
|
|
|
"-fno-omit-frame-pointer",
|
|
|
|
"-fno-optimize-sibling-calls",
|
|
|
|
"-g"] + target_cflags
|
2014-04-01 21:16:30 +08:00
|
|
|
clang_asan_static_cxxflags = config.cxx_mode_flags + clang_asan_static_cflags
|
|
|
|
|
|
|
|
if config.asan_dynamic:
|
|
|
|
clang_asan_cflags = clang_asan_static_cflags + ['-shared-libasan']
|
|
|
|
clang_asan_cxxflags = clang_asan_static_cxxflags + ['-shared-libasan']
|
|
|
|
config.available_features.add("asan-dynamic-runtime")
|
|
|
|
else:
|
|
|
|
clang_asan_cflags = clang_asan_static_cflags
|
|
|
|
clang_asan_cxxflags = clang_asan_static_cxxflags
|
|
|
|
config.available_features.add("asan-static-runtime")
|
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-02-14 17:22:10 +08:00
|
|
|
if config.android == "TRUE":
|
|
|
|
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:
|
|
|
|
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
|
|
|
|
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
|
|
|
config.substitutions.append( ("%shared_libasan", "libclang_rt.asan-%s.so" % config.target_arch))
|
|
|
|
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':
|
|
|
|
clang_cl_asan_cxxflags = ["-fsanitize=address",
|
|
|
|
"-Wno-deprecated-declarations",
|
|
|
|
"-D_HAS_EXCEPTIONS=0",
|
|
|
|
"-Zi"] + target_cflags
|
|
|
|
clang_invocation = build_invocation(clang_cl_asan_cxxflags)
|
|
|
|
clang_cl_invocation = clang_invocation.replace("clang.exe","clang-cl.exe")
|
|
|
|
config.substitutions.append( ("%clang_cl_asan ", clang_cl_invocation) )
|
|
|
|
|
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")
|
|
|
|
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
|
|
|
|
if config.host_arch.find('64') != -1 and config.android != "TRUE":
|
|
|
|
kernel_bits = '64'
|
|
|
|
else:
|
|
|
|
kernel_bits = '32'
|
|
|
|
|
2012-08-15 16:29:17 +08:00
|
|
|
# Define CHECK-%os to check for OS-dependent output.
|
|
|
|
config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
|
2014-03-27 15:36:26 +08:00
|
|
|
config.substitutions.append( ('CHECK-%kernel_bits', ("CHECK-kernel-" + kernel_bits + "-bits")))
|
2012-08-15 16:29:17 +08:00
|
|
|
|
2013-06-07 17:38:55 +08:00
|
|
|
config.available_features.add("asan-" + config.bits + "-bits")
|
|
|
|
|
2013-09-08 21:23:29 +08:00
|
|
|
# Turn on leak detection on 64-bit Linux.
|
|
|
|
if config.host_os == 'Linux' and config.bits == '64':
|
|
|
|
config.environment['ASAN_OPTIONS'] = 'detect_leaks=1'
|
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
# Set LD_LIBRARY_PATH to pick dynamic runtime up properly.
|
|
|
|
push_ld_library_path(config, config.compiler_rt_libdir)
|
|
|
|
|
|
|
|
# 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-04-01 21:16:30 +08:00
|
|
|
push_ld_library_path(config, libasan_dir)
|
2014-02-19 23:13:14 +08:00
|
|
|
|
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')
|
|
|
|
|
2012-08-15 16:29:17 +08:00
|
|
|
# AddressSanitizer tests are currently supported on Linux and Darwin only.
|
|
|
|
if config.host_os not in ['Linux', 'Darwin']:
|
|
|
|
config.unsupported = True
|