xref: /llvm-project/compiler-rt/test/lit.common.cfg.py (revision d084bc291a21895fa2ecc74e2d1c9d1818ba4fd7)
18007ff1aSReid Kleckner# -*- Python -*-
28007ff1aSReid Kleckner
38007ff1aSReid Kleckner# Configuration file for 'lit' test runner.
48007ff1aSReid Kleckner# This file contains common rules for various compiler-rt testsuites.
58007ff1aSReid Kleckner# It is mostly copied from lit.cfg.py used by Clang.
68007ff1aSReid Klecknerimport os
78007ff1aSReid Klecknerimport platform
88007ff1aSReid Klecknerimport re
9aa6cb0f2SFangrui Songimport shlex
108007ff1aSReid Klecknerimport subprocess
118007ff1aSReid Klecknerimport json
128007ff1aSReid Kleckner
138007ff1aSReid Klecknerimport lit.formats
148007ff1aSReid Klecknerimport lit.util
158007ff1aSReid Kleckner
16f98ee40fSTobias Hieta
17ad7e1222SDan Liewdef get_path_from_clang(args, allow_failure):
18ad7e1222SDan Liew    clang_cmd = [
19ad7e1222SDan Liew        config.clang.strip(),
20f98ee40fSTobias Hieta        f"--target={config.target_triple}",
21dfafe382SAlexander Richardson        *args,
22ad7e1222SDan Liew    ]
23ad7e1222SDan Liew    path = None
24ad7e1222SDan Liew    try:
25ad7e1222SDan Liew        result = subprocess.run(
26f98ee40fSTobias Hieta            clang_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True
27ad7e1222SDan Liew        )
28ad7e1222SDan Liew        path = result.stdout.decode().strip()
29ad7e1222SDan Liew    except subprocess.CalledProcessError as e:
30f98ee40fSTobias Hieta        msg = f"Failed to run {clang_cmd}\nrc:{e.returncode}\nstdout:{e.stdout}\ne.stderr{e.stderr}"
31ad7e1222SDan Liew        if allow_failure:
32ad7e1222SDan Liew            lit_config.warning(msg)
33ad7e1222SDan Liew        else:
34ad7e1222SDan Liew            lit_config.fatal(msg)
35b7f60d86SDan Liew    return path, clang_cmd
36ad7e1222SDan Liew
37dfafe382SAlexander Richardson
38dfafe382SAlexander Richardsondef find_compiler_libdir():
39dfafe382SAlexander Richardson    """
40dfafe382SAlexander Richardson    Returns the path to library resource directory used
41dfafe382SAlexander Richardson    by the compiler.
42dfafe382SAlexander Richardson    """
43dfafe382SAlexander Richardson    if config.compiler_id != "Clang":
44dfafe382SAlexander Richardson        lit_config.warning(
45dfafe382SAlexander Richardson            f"Determining compiler's runtime directory is not supported for {config.compiler_id}"
46dfafe382SAlexander Richardson        )
47dfafe382SAlexander Richardson        # TODO: Support other compilers.
48dfafe382SAlexander Richardson        return None
49dfafe382SAlexander Richardson
50ad7e1222SDan Liew    # Try using `-print-runtime-dir`. This is only supported by very new versions of Clang.
51ad7e1222SDan Liew    # so allow failure here.
52f98ee40fSTobias Hieta    runtime_dir, clang_cmd = get_path_from_clang(
53f98ee40fSTobias Hieta        shlex.split(config.target_cflags) + ["-print-runtime-dir"], allow_failure=True
54f98ee40fSTobias Hieta    )
55ad7e1222SDan Liew    if runtime_dir:
56ad7e1222SDan Liew        if os.path.exists(runtime_dir):
57ad7e1222SDan Liew            return os.path.realpath(runtime_dir)
58b7f60d86SDan Liew        # TODO(dliew): This should be a fatal error but it seems to trip the `llvm-clang-win-x-aarch64`
59b7f60d86SDan Liew        # bot which is likely misconfigured
60b7f60d86SDan Liew        lit_config.warning(
61f98ee40fSTobias Hieta            f'Path reported by clang does not exist: "{runtime_dir}". '
62f98ee40fSTobias Hieta            f"This path was found by running {clang_cmd}."
63b7f60d86SDan Liew        )
64b7f60d86SDan Liew        return None
65ad7e1222SDan Liew
66ad7e1222SDan Liew    # Fall back for older AppleClang that doesn't support `-print-runtime-dir`
67ad7e1222SDan Liew    # Note `-print-file-name=<path to compiler-rt lib>` was broken for Apple
68ad7e1222SDan Liew    # platforms so we can't use that approach here (see https://reviews.llvm.org/D101682).
69f98ee40fSTobias Hieta    if config.host_os == "Darwin":
70f98ee40fSTobias Hieta        lib_dir, _ = get_path_from_clang(["-print-file-name=lib"], allow_failure=False)
71f98ee40fSTobias Hieta        runtime_dir = os.path.join(lib_dir, "darwin")
72ad7e1222SDan Liew        if not os.path.exists(runtime_dir):
73f98ee40fSTobias Hieta            lit_config.fatal(f"Path reported by clang does not exist: {runtime_dir}")
74ad7e1222SDan Liew        return os.path.realpath(runtime_dir)
75ad7e1222SDan Liew
76f98ee40fSTobias Hieta    lit_config.warning("Failed to determine compiler's runtime directory")
77ad7e1222SDan Liew    return None
78ad7e1222SDan Liew
79ad7e1222SDan Liew
8013771793SDmitry Vyukovdef push_dynamic_library_lookup_path(config, new_path):
8113771793SDmitry Vyukov    if platform.system() == "Windows":
8213771793SDmitry Vyukov        dynamic_library_lookup_var = "PATH"
8313771793SDmitry Vyukov    elif platform.system() == "Darwin":
8413771793SDmitry Vyukov        dynamic_library_lookup_var = "DYLD_LIBRARY_PATH"
85*d084bc29SJérôme Duval    elif platform.system() == "Haiku":
86*d084bc29SJérôme Duval        dynamic_library_lookup_var = "LIBRARY_PATH"
8713771793SDmitry Vyukov    else:
8813771793SDmitry Vyukov        dynamic_library_lookup_var = "LD_LIBRARY_PATH"
8913771793SDmitry Vyukov
9013771793SDmitry Vyukov    new_ld_library_path = os.path.pathsep.join(
9113771793SDmitry Vyukov        (new_path, config.environment.get(dynamic_library_lookup_var, ""))
9213771793SDmitry Vyukov    )
9313771793SDmitry Vyukov    config.environment[dynamic_library_lookup_var] = new_ld_library_path
9413771793SDmitry Vyukov
9513771793SDmitry Vyukov    if platform.system() == "FreeBSD":
9613771793SDmitry Vyukov        dynamic_library_lookup_var = "LD_32_LIBRARY_PATH"
9713771793SDmitry Vyukov        new_ld_32_library_path = os.path.pathsep.join(
9813771793SDmitry Vyukov            (new_path, config.environment.get(dynamic_library_lookup_var, ""))
9913771793SDmitry Vyukov        )
10013771793SDmitry Vyukov        config.environment[dynamic_library_lookup_var] = new_ld_32_library_path
10113771793SDmitry Vyukov
10213771793SDmitry Vyukov    if platform.system() == "SunOS":
10313771793SDmitry Vyukov        dynamic_library_lookup_var = "LD_LIBRARY_PATH_32"
10413771793SDmitry Vyukov        new_ld_library_path_32 = os.path.pathsep.join(
10513771793SDmitry Vyukov            (new_path, config.environment.get(dynamic_library_lookup_var, ""))
10613771793SDmitry Vyukov        )
10713771793SDmitry Vyukov        config.environment[dynamic_library_lookup_var] = new_ld_library_path_32
10813771793SDmitry Vyukov
10913771793SDmitry Vyukov        dynamic_library_lookup_var = "LD_LIBRARY_PATH_64"
11013771793SDmitry Vyukov        new_ld_library_path_64 = os.path.pathsep.join(
11113771793SDmitry Vyukov            (new_path, config.environment.get(dynamic_library_lookup_var, ""))
11213771793SDmitry Vyukov        )
11313771793SDmitry Vyukov        config.environment[dynamic_library_lookup_var] = new_ld_library_path_64
11413771793SDmitry Vyukov
11513771793SDmitry Vyukov
1168007ff1aSReid Kleckner# Choose between lit's internal shell pipeline runner and a real shell.  If
1178007ff1aSReid Kleckner# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
1188007ff1aSReid Kleckneruse_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
1198007ff1aSReid Klecknerif use_lit_shell:
1208007ff1aSReid Kleckner    # 0 is external, "" is default, and everything else is internal.
121f98ee40fSTobias Hieta    execute_external = use_lit_shell == "0"
1228007ff1aSReid Klecknerelse:
1238007ff1aSReid Kleckner    # Otherwise we default to internal on Windows and external elsewhere, as
1248007ff1aSReid Kleckner    # bash on Windows is usually very slow.
125f98ee40fSTobias Hieta    execute_external = not sys.platform in ["win32"]
1268007ff1aSReid Kleckner
127a566e616SSergej Jaskiewicz# Allow expanding substitutions that are based on other substitutions
128a566e616SSergej Jaskiewiczconfig.recursiveExpansionLimit = 10
129a566e616SSergej Jaskiewicz
1308007ff1aSReid Kleckner# Setup test format.
1318007ff1aSReid Klecknerconfig.test_format = lit.formats.ShTest(execute_external)
1328007ff1aSReid Klecknerif execute_external:
133f98ee40fSTobias Hieta    config.available_features.add("shell")
1348007ff1aSReid Kleckner
135f98ee40fSTobias Hietatarget_is_msvc = bool(re.match(r".*-windows-msvc$", config.target_triple))
136dfafe382SAlexander Richardsontarget_is_windows = bool(re.match(r".*-windows.*$", config.target_triple))
137bae2fbaeSAlvin Wong
138f98ee40fSTobias Hietacompiler_id = getattr(config, "compiler_id", None)
1398007ff1aSReid Klecknerif compiler_id == "Clang":
140f98ee40fSTobias Hieta    if not (platform.system() == "Windows" and target_is_msvc):
1418007ff1aSReid Kleckner        config.cxx_mode_flags = ["--driver-mode=g++"]
1428007ff1aSReid Kleckner    else:
1438007ff1aSReid Kleckner        config.cxx_mode_flags = []
1448007ff1aSReid Kleckner    # We assume that sanitizers should provide good enough error
1458007ff1aSReid Kleckner    # reports and stack traces even with minimal debug info.
1468007ff1aSReid Kleckner    config.debug_info_flags = ["-gline-tables-only"]
147f98ee40fSTobias Hieta    if platform.system() == "Windows" and target_is_msvc:
148bae2fbaeSAlvin Wong        # On MSVC, use CodeView with column info instead of DWARF. Both VS and
1498007ff1aSReid Kleckner        # windbg do not behave well when column info is enabled, but users have
1508007ff1aSReid Kleckner        # requested it because it makes ASan reports more precise.
1518007ff1aSReid Kleckner        config.debug_info_flags.append("-gcodeview")
1528007ff1aSReid Kleckner        config.debug_info_flags.append("-gcolumn-info")
15381935c5eSCharlie Bartoelif compiler_id == "MSVC":
15481935c5eSCharlie Barto    config.debug_info_flags = ["/Z7"]
15581935c5eSCharlie Barto    config.cxx_mode_flags = []
156f98ee40fSTobias Hietaelif compiler_id == "GNU":
1578007ff1aSReid Kleckner    config.cxx_mode_flags = ["-x c++"]
1588007ff1aSReid Kleckner    config.debug_info_flags = ["-g"]
1598007ff1aSReid Klecknerelse:
1608007ff1aSReid Kleckner    lit_config.fatal("Unsupported compiler id: %r" % compiler_id)
1618007ff1aSReid Kleckner# Add compiler ID to the list of available features.
1628007ff1aSReid Klecknerconfig.available_features.add(compiler_id)
1638007ff1aSReid Kleckner
1649111635cSFangrui Song# When LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on, the initial value of
1659111635cSFangrui Song# config.compiler_rt_libdir (COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR) has the
16611903e8cSRainer Orth# host triple as the trailing path component. The value is incorrect for 32-bit
16711903e8cSRainer Orth# tests on 64-bit hosts and vice versa. Adjust config.compiler_rt_libdir
16811903e8cSRainer Orth# accordingly.
1699111635cSFangrui Songif config.enable_per_target_runtime_dir:
17011903e8cSRainer Orth    if config.target_arch == "i386":
171f98ee40fSTobias Hieta        config.compiler_rt_libdir = re.sub(
172f98ee40fSTobias Hieta            r"/x86_64(?=-[^/]+$)", "/i386", config.compiler_rt_libdir
173f98ee40fSTobias Hieta        )
17411903e8cSRainer Orth    elif config.target_arch == "x86_64":
175f98ee40fSTobias Hieta        config.compiler_rt_libdir = re.sub(
176f98ee40fSTobias Hieta            r"/i386(?=-[^/]+$)", "/x86_64", config.compiler_rt_libdir
177f98ee40fSTobias Hieta        )
17811903e8cSRainer Orth    if config.target_arch == "sparc":
17911903e8cSRainer Orth        config.compiler_rt_libdir = re.sub(
18011903e8cSRainer Orth            r"/sparcv9(?=-[^/]+$)", "/sparc", config.compiler_rt_libdir
18111903e8cSRainer Orth        )
18211903e8cSRainer Orth    elif config.target_arch == "sparcv9":
18311903e8cSRainer Orth        config.compiler_rt_libdir = re.sub(
18411903e8cSRainer Orth            r"/sparc(?=-[^/]+$)", "/sparcv9", config.compiler_rt_libdir
18511903e8cSRainer Orth        )
186dfafe382SAlexander Richardson
187dfafe382SAlexander Richardson# Check if the test compiler resource dir matches the local build directory
188dfafe382SAlexander Richardson# (which happens with -DLLVM_ENABLE_PROJECTS=clang;compiler-rt) or if we are
189dfafe382SAlexander Richardson# using an installed clang to test compiler-rt standalone. In the latter case
190dfafe382SAlexander Richardson# we may need to override the resource dir to match the path of the just-built
191dfafe382SAlexander Richardson# compiler-rt libraries.
192dfafe382SAlexander Richardsontest_cc_resource_dir, _ = get_path_from_clang(
193dfafe382SAlexander Richardson    shlex.split(config.target_cflags) + ["-print-resource-dir"], allow_failure=True
194dfafe382SAlexander Richardson)
195dfafe382SAlexander Richardson# Normalize the path for comparison
196dfafe382SAlexander Richardsonif test_cc_resource_dir is not None:
197dfafe382SAlexander Richardson    test_cc_resource_dir = os.path.realpath(test_cc_resource_dir)
198dfafe382SAlexander Richardsonif lit_config.debug:
199dfafe382SAlexander Richardson    lit_config.note(f"Resource dir for {config.clang} is {test_cc_resource_dir}")
200dfafe382SAlexander Richardsonlocal_build_resource_dir = os.path.realpath(config.compiler_rt_output_dir)
201dfafe382SAlexander Richardsonif test_cc_resource_dir != local_build_resource_dir and config.test_standalone_build_libs:
202dfafe382SAlexander Richardson    if config.compiler_id == "Clang":
203dfafe382SAlexander Richardson        if lit_config.debug:
204dfafe382SAlexander Richardson            lit_config.note(
205dfafe382SAlexander Richardson                f"Overriding test compiler resource dir to use "
206dfafe382SAlexander Richardson                f'libraries in "{config.compiler_rt_libdir}"'
207dfafe382SAlexander Richardson            )
208dfafe382SAlexander Richardson        # Ensure that we use the just-built static libraries when linking by
209dfafe382SAlexander Richardson        # overriding the Clang resource directory. Additionally, we want to use
210dfafe382SAlexander Richardson        # the builtin headers shipped with clang (e.g. stdint.h), so we
211dfafe382SAlexander Richardson        # explicitly add this as an include path (since the headers are not
212dfafe382SAlexander Richardson        # going to be in the current compiler-rt build directory).
213dfafe382SAlexander Richardson        # We also tell the linker to add an RPATH entry for the local library
214dfafe382SAlexander Richardson        # directory so that the just-built shared libraries are used.
215dfafe382SAlexander Richardson        config.target_cflags += f" -nobuiltininc"
216dfafe382SAlexander Richardson        config.target_cflags += f" -I{config.compiler_rt_src_root}/include"
217dfafe382SAlexander Richardson        config.target_cflags += f" -idirafter {test_cc_resource_dir}/include"
218dfafe382SAlexander Richardson        config.target_cflags += f" -resource-dir={config.compiler_rt_output_dir}"
219dfafe382SAlexander Richardson        if not target_is_windows:
220dfafe382SAlexander Richardson            # Avoid passing -rpath on Windows where it is not supported.
221dfafe382SAlexander Richardson            config.target_cflags += f" -Wl,-rpath,{config.compiler_rt_libdir}"
222dfafe382SAlexander Richardson    else:
223dfafe382SAlexander Richardson        lit_config.warning(
224dfafe382SAlexander Richardson            f"Cannot override compiler-rt library directory with non-Clang "
225dfafe382SAlexander Richardson            f"compiler: {config.compiler_id}"
226dfafe382SAlexander Richardson        )
227dfafe382SAlexander Richardson
228dfafe382SAlexander Richardson
229ad7e1222SDan Liew# Ask the compiler for the path to libraries it is going to use. If this
230ad7e1222SDan Liew# doesn't match config.compiler_rt_libdir then it means we might be testing the
231ad7e1222SDan Liew# compiler's own runtime libraries rather than the ones we just built.
232dfafe382SAlexander Richardson# Warn about this and handle appropriately.
233ad7e1222SDan Liewcompiler_libdir = find_compiler_libdir()
234ad7e1222SDan Liewif compiler_libdir:
235ad7e1222SDan Liew    compiler_rt_libdir_real = os.path.realpath(config.compiler_rt_libdir)
236ad7e1222SDan Liew    if compiler_libdir != compiler_rt_libdir_real:
237ad7e1222SDan Liew        lit_config.warning(
238f98ee40fSTobias Hieta            "Compiler lib dir != compiler-rt lib dir\n"
239ad7e1222SDan Liew            f'Compiler libdir:     "{compiler_libdir}"\n'
240f98ee40fSTobias Hieta            f'compiler-rt libdir:  "{compiler_rt_libdir_real}"'
241f98ee40fSTobias Hieta        )
242ad7e1222SDan Liew        if config.test_standalone_build_libs:
243dfafe382SAlexander Richardson            # Use just built runtime libraries, i.e. the libraries this build just built.
244ad7e1222SDan Liew            if not config.test_suite_supports_overriding_runtime_lib_path:
245ad7e1222SDan Liew                # Test suite doesn't support this configuration.
2467085cd2fSDan Liew                # TODO(dliew): This should be an error but it seems several bots are
2477085cd2fSDan Liew                # testing incorrectly and having this as an error breaks them.
2487085cd2fSDan Liew                lit_config.warning(
249f98ee40fSTobias Hieta                    "COMPILER_RT_TEST_STANDALONE_BUILD_LIBS=ON, but this test suite "
250f98ee40fSTobias Hieta                    "does not support testing the just-built runtime libraries "
251f98ee40fSTobias Hieta                    "when the test compiler is configured to use different runtime "
252f98ee40fSTobias Hieta                    "libraries. Either modify this test suite to support this test "
253f98ee40fSTobias Hieta                    "configuration, or set COMPILER_RT_TEST_STANDALONE_BUILD_LIBS=OFF "
254f98ee40fSTobias Hieta                    "to test the runtime libraries included in the compiler instead."
255ad7e1222SDan Liew                )
256ad7e1222SDan Liew        else:
257ad7e1222SDan Liew            # Use Compiler's resource library directory instead.
258ad7e1222SDan Liew            config.compiler_rt_libdir = compiler_libdir
259ad7e1222SDan Liew        lit_config.note(f'Testing using libraries in "{config.compiler_rt_libdir}"')
260ad7e1222SDan Liew
2618007ff1aSReid Kleckner# If needed, add cflag for shadow scale.
262f98ee40fSTobias Hietaif config.asan_shadow_scale != "":
2638007ff1aSReid Kleckner    config.target_cflags += " -mllvm -asan-mapping-scale=" + config.asan_shadow_scale
264f98ee40fSTobias Hietaif config.memprof_shadow_scale != "":
265f98ee40fSTobias Hieta    config.target_cflags += (
266f98ee40fSTobias Hieta        " -mllvm -memprof-mapping-scale=" + config.memprof_shadow_scale
267f98ee40fSTobias Hieta    )
2688007ff1aSReid Kleckner
2698007ff1aSReid Kleckner# Clear some environment variables that might affect Clang.
270f98ee40fSTobias Hietapossibly_dangerous_env_vars = [
271f98ee40fSTobias Hieta    "ASAN_OPTIONS",
272f98ee40fSTobias Hieta    "DFSAN_OPTIONS",
273f98ee40fSTobias Hieta    "HWASAN_OPTIONS",
274f98ee40fSTobias Hieta    "LSAN_OPTIONS",
275f98ee40fSTobias Hieta    "MSAN_OPTIONS",
276f98ee40fSTobias Hieta    "UBSAN_OPTIONS",
277f98ee40fSTobias Hieta    "COMPILER_PATH",
278f98ee40fSTobias Hieta    "RC_DEBUG_OPTIONS",
279f98ee40fSTobias Hieta    "CINDEXTEST_PREAMBLE_FILE",
280f98ee40fSTobias Hieta    "CPATH",
281f98ee40fSTobias Hieta    "C_INCLUDE_PATH",
282f98ee40fSTobias Hieta    "CPLUS_INCLUDE_PATH",
283f98ee40fSTobias Hieta    "OBJC_INCLUDE_PATH",
284f98ee40fSTobias Hieta    "OBJCPLUS_INCLUDE_PATH",
285f98ee40fSTobias Hieta    "LIBCLANG_TIMING",
286f98ee40fSTobias Hieta    "LIBCLANG_OBJTRACKING",
287f98ee40fSTobias Hieta    "LIBCLANG_LOGGING",
288f98ee40fSTobias Hieta    "LIBCLANG_BGPRIO_INDEX",
289f98ee40fSTobias Hieta    "LIBCLANG_BGPRIO_EDIT",
290f98ee40fSTobias Hieta    "LIBCLANG_NOTHREADS",
291f98ee40fSTobias Hieta    "LIBCLANG_RESOURCE_USAGE",
292f98ee40fSTobias Hieta    "LIBCLANG_CODE_COMPLETION_LOGGING",
293f98ee40fSTobias Hieta    "XRAY_OPTIONS",
294f98ee40fSTobias Hieta]
295bae2fbaeSAlvin Wong# Clang/MSVC may refer to %INCLUDE%. vsvarsall.bat sets it.
296f98ee40fSTobias Hietaif not (platform.system() == "Windows" and target_is_msvc):
297f98ee40fSTobias Hieta    possibly_dangerous_env_vars.append("INCLUDE")
2988007ff1aSReid Klecknerfor name in possibly_dangerous_env_vars:
2998007ff1aSReid Kleckner    if name in config.environment:
3008007ff1aSReid Kleckner        del config.environment[name]
3018007ff1aSReid Kleckner
3028007ff1aSReid Kleckner# Tweak PATH to include llvm tools dir.
3038007ff1aSReid Klecknerif (not config.llvm_tools_dir) or (not os.path.exists(config.llvm_tools_dir)):
304f98ee40fSTobias Hieta    lit_config.fatal(
305f98ee40fSTobias Hieta        "Invalid llvm_tools_dir config attribute: %r" % config.llvm_tools_dir
306f98ee40fSTobias Hieta    )
307f98ee40fSTobias Hietapath = os.path.pathsep.join((config.llvm_tools_dir, config.environment["PATH"]))
308f98ee40fSTobias Hietaconfig.environment["PATH"] = path
3098007ff1aSReid Kleckner
3108007ff1aSReid Kleckner# Help MSVS link.exe find the standard libraries.
3118007ff1aSReid Kleckner# Make sure we only try to use it when targetting Windows.
312f98ee40fSTobias Hietaif platform.system() == "Windows" and target_is_msvc:
313f98ee40fSTobias Hieta    config.environment["LIB"] = os.environ["LIB"]
3148007ff1aSReid Kleckner
3158007ff1aSReid Klecknerconfig.available_features.add(config.host_os.lower())
3168007ff1aSReid Kleckner
317de066267SMitch Phillipsif config.target_triple.startswith("ppc") or config.target_triple.startswith("powerpc"):
318bd62b70bSMitch Phillips    config.available_features.add("ppc")
319bd62b70bSMitch Phillips
320f98ee40fSTobias Hietaif re.match(r"^x86_64.*-linux", config.target_triple):
3218007ff1aSReid Kleckner    config.available_features.add("x86_64-linux")
3228007ff1aSReid Kleckner
323415c689dSFangrui Songconfig.available_features.add("host-byteorder-" + sys.byteorder + "-endian")
324415c689dSFangrui Song
325fe2f0ab3SAlex Brachetif config.have_zlib:
3268007ff1aSReid Kleckner    config.available_features.add("zlib")
327eb0e4b14SPetr Hosek    config.substitutions.append(("%zlib_include_dir", config.zlib_include_dir))
328eb0e4b14SPetr Hosek    config.substitutions.append(("%zlib_library", config.zlib_library))
3298007ff1aSReid Kleckner
33023d1b657SVitaly Bukaif config.have_internal_symbolizer:
33123d1b657SVitaly Buka    config.available_features.add("internal_symbolizer")
33223d1b657SVitaly Buka
3338007ff1aSReid Kleckner# Use ugly construction to explicitly prohibit "clang", "clang++" etc.
3348007ff1aSReid Kleckner# in RUN lines.
3358007ff1aSReid Klecknerconfig.substitutions.append(
336f98ee40fSTobias Hieta    (
337f98ee40fSTobias Hieta        " clang",
338f98ee40fSTobias Hieta        """\n\n*** Do not use 'clangXXX' in tests,
339f98ee40fSTobias Hieta     instead define '%clangXXX' substitution in lit config. ***\n\n""",
340f98ee40fSTobias Hieta    )
341f98ee40fSTobias Hieta)
3428007ff1aSReid Kleckner
343f98ee40fSTobias Hietaif config.host_os == "NetBSD":
344f98ee40fSTobias Hieta    nb_commands_dir = os.path.join(
345f98ee40fSTobias Hieta        config.compiler_rt_src_root, "test", "sanitizer_common", "netbsd_commands"
346f98ee40fSTobias Hieta    )
347f98ee40fSTobias Hieta    config.netbsd_noaslr_prefix = "sh " + os.path.join(nb_commands_dir, "run_noaslr.sh")
348f98ee40fSTobias Hieta    config.netbsd_nomprotect_prefix = "sh " + os.path.join(
349f98ee40fSTobias Hieta        nb_commands_dir, "run_nomprotect.sh"
350f98ee40fSTobias Hieta    )
351f98ee40fSTobias Hieta    config.substitutions.append(("%run_nomprotect", config.netbsd_nomprotect_prefix))
352190b9110SMichał Górnyelse:
353f98ee40fSTobias Hieta    config.substitutions.append(("%run_nomprotect", "%run"))
354190b9110SMichał Górny
355eddbadfeSHafiz Abid Qadeer# Copied from libcxx's config.py
356eddbadfeSHafiz Abid Qadeerdef get_lit_conf(name, default=None):
357eddbadfeSHafiz Abid Qadeer    # Allow overriding on the command line using --param=<name>=<val>
358eddbadfeSHafiz Abid Qadeer    val = lit_config.params.get(name, None)
359eddbadfeSHafiz Abid Qadeer    if val is None:
360eddbadfeSHafiz Abid Qadeer        val = getattr(config, name, None)
361eddbadfeSHafiz Abid Qadeer        if val is None:
362eddbadfeSHafiz Abid Qadeer            val = default
363eddbadfeSHafiz Abid Qadeer    return val
364eddbadfeSHafiz Abid Qadeer
365f98ee40fSTobias Hieta
366f98ee40fSTobias Hietaemulator = get_lit_conf("emulator", None)
367f98ee40fSTobias Hieta
368eddbadfeSHafiz Abid Qadeer
369b6099fa5SEmily Shidef get_ios_commands_dir():
370f98ee40fSTobias Hieta    return os.path.join(
371f98ee40fSTobias Hieta        config.compiler_rt_src_root, "test", "sanitizer_common", "ios_commands"
372f98ee40fSTobias Hieta    )
373f98ee40fSTobias Hieta
374b6099fa5SEmily Shi
3758007ff1aSReid Kleckner# Allow tests to be executed on a simulator or remotely.
376eddbadfeSHafiz Abid Qadeerif emulator:
377f98ee40fSTobias Hieta    config.substitutions.append(("%run", emulator))
378f98ee40fSTobias Hieta    config.substitutions.append(("%env ", "env "))
3798007ff1aSReid Kleckner    # TODO: Implement `%device_rm` to perform removal of files in the emulator.
3808007ff1aSReid Kleckner    # For now just make it a no-op.
381f98ee40fSTobias Hieta    lit_config.warning("%device_rm is not implemented")
382f98ee40fSTobias Hieta    config.substitutions.append(("%device_rm", "echo "))
3838007ff1aSReid Kleckner    config.compile_wrapper = ""
384f98ee40fSTobias Hietaelif config.host_os == "Darwin" and config.apple_platform != "osx":
3858007ff1aSReid Kleckner    # Darwin tests can be targetting macOS, a device or a simulator. All devices
3868007ff1aSReid Kleckner    # are declared as "ios", even for iOS derivatives (tvOS, watchOS). Similarly,
3878007ff1aSReid Kleckner    # all simulators are "iossim". See the table below.
3888007ff1aSReid Kleckner    #
3898007ff1aSReid Kleckner    # =========================================================================
3908007ff1aSReid Kleckner    # Target             | Feature set
3918007ff1aSReid Kleckner    # =========================================================================
3928007ff1aSReid Kleckner    # macOS              | darwin
3938007ff1aSReid Kleckner    # iOS device         | darwin, ios
3948007ff1aSReid Kleckner    # iOS simulator      | darwin, ios, iossim
3958007ff1aSReid Kleckner    # tvOS device        | darwin, ios, tvos
3968007ff1aSReid Kleckner    # tvOS simulator     | darwin, ios, iossim, tvos, tvossim
3978007ff1aSReid Kleckner    # watchOS device     | darwin, ios, watchos
3988007ff1aSReid Kleckner    # watchOS simulator  | darwin, ios, iossim, watchos, watchossim
3998007ff1aSReid Kleckner    # =========================================================================
4008007ff1aSReid Kleckner
4018007ff1aSReid Kleckner    ios_or_iossim = "iossim" if config.apple_platform.endswith("sim") else "ios"
4028007ff1aSReid Kleckner
403f98ee40fSTobias Hieta    config.available_features.add("ios")
4048007ff1aSReid Kleckner    device_id_env = "SANITIZER_" + ios_or_iossim.upper() + "_TEST_DEVICE_IDENTIFIER"
4058007ff1aSReid Kleckner    if ios_or_iossim == "iossim":
406f98ee40fSTobias Hieta        config.available_features.add("iossim")
4078007ff1aSReid Kleckner        if device_id_env not in os.environ:
4088007ff1aSReid Kleckner            lit_config.fatal(
409f98ee40fSTobias Hieta                "{} must be set in the environment when running iossim tests".format(
410f98ee40fSTobias Hieta                    device_id_env
411f98ee40fSTobias Hieta                )
412f98ee40fSTobias Hieta            )
4138007ff1aSReid Kleckner    if config.apple_platform != "ios" and config.apple_platform != "iossim":
4148007ff1aSReid Kleckner        config.available_features.add(config.apple_platform)
4158007ff1aSReid Kleckner
416b6099fa5SEmily Shi    ios_commands_dir = get_ios_commands_dir()
4178007ff1aSReid Kleckner
4188007ff1aSReid Kleckner    run_wrapper = os.path.join(ios_commands_dir, ios_or_iossim + "_run.py")
4198007ff1aSReid Kleckner    env_wrapper = os.path.join(ios_commands_dir, ios_or_iossim + "_env.py")
4208007ff1aSReid Kleckner    compile_wrapper = os.path.join(ios_commands_dir, ios_or_iossim + "_compile.py")
4218007ff1aSReid Kleckner    prepare_script = os.path.join(ios_commands_dir, ios_or_iossim + "_prepare.py")
4228007ff1aSReid Kleckner
4238007ff1aSReid Kleckner    if device_id_env in os.environ:
4248007ff1aSReid Kleckner        config.environment[device_id_env] = os.environ[device_id_env]
425f98ee40fSTobias Hieta    config.substitutions.append(("%run", run_wrapper))
426f98ee40fSTobias Hieta    config.substitutions.append(("%env ", env_wrapper + " "))
4278007ff1aSReid Kleckner    # Current implementation of %device_rm uses the run_wrapper to do
4288007ff1aSReid Kleckner    # the work.
429f98ee40fSTobias Hieta    config.substitutions.append(("%device_rm", "{} rm ".format(run_wrapper)))
4308007ff1aSReid Kleckner    config.compile_wrapper = compile_wrapper
4318007ff1aSReid Kleckner
4328007ff1aSReid Kleckner    try:
433f98ee40fSTobias Hieta        prepare_output = (
434f98ee40fSTobias Hieta            subprocess.check_output(
435f98ee40fSTobias Hieta                [prepare_script, config.apple_platform, config.clang]
436f98ee40fSTobias Hieta            )
437f98ee40fSTobias Hieta            .decode()
438f98ee40fSTobias Hieta            .strip()
439f98ee40fSTobias Hieta        )
4408007ff1aSReid Kleckner    except subprocess.CalledProcessError as e:
4418007ff1aSReid Kleckner        print("Command failed:")
4428007ff1aSReid Kleckner        print(e.output)
4438007ff1aSReid Kleckner        raise e
444f98ee40fSTobias Hieta    if len(prepare_output) > 0:
445f98ee40fSTobias Hieta        print(prepare_output)
4468007ff1aSReid Kleckner    prepare_output_json = prepare_output.split("\n")[-1]
4478007ff1aSReid Kleckner    prepare_output = json.loads(prepare_output_json)
4488007ff1aSReid Kleckner    config.environment.update(prepare_output["env"])
4498007ff1aSReid Klecknerelif config.android:
450f98ee40fSTobias Hieta    config.available_features.add("android")
451f98ee40fSTobias Hieta    compile_wrapper = (
452f98ee40fSTobias Hieta        os.path.join(
453f98ee40fSTobias Hieta            config.compiler_rt_src_root,
454f98ee40fSTobias Hieta            "test",
455f98ee40fSTobias Hieta            "sanitizer_common",
456f98ee40fSTobias Hieta            "android_commands",
457f98ee40fSTobias Hieta            "android_compile.py",
458f98ee40fSTobias Hieta        )
459f98ee40fSTobias Hieta        + " "
460f98ee40fSTobias Hieta    )
4618007ff1aSReid Kleckner    config.compile_wrapper = compile_wrapper
462f98ee40fSTobias Hieta    config.substitutions.append(("%run", ""))
463f98ee40fSTobias Hieta    config.substitutions.append(("%env ", "env "))
4648007ff1aSReid Klecknerelse:
465f98ee40fSTobias Hieta    config.substitutions.append(("%run", ""))
466f98ee40fSTobias Hieta    config.substitutions.append(("%env ", "env "))
4678007ff1aSReid Kleckner    # When running locally %device_rm is a no-op.
468f98ee40fSTobias Hieta    config.substitutions.append(("%device_rm", "echo "))
4698007ff1aSReid Kleckner    config.compile_wrapper = ""
4708007ff1aSReid Kleckner
4718007ff1aSReid Kleckner# Define CHECK-%os to check for OS-dependent output.
472f98ee40fSTobias Hietaconfig.substitutions.append(("CHECK-%os", ("CHECK-" + config.host_os)))
4738007ff1aSReid Kleckner
4748007ff1aSReid Kleckner# Define %arch to check for architecture-dependent output.
475f98ee40fSTobias Hietaconfig.substitutions.append(("%arch", (config.host_arch)))
4768007ff1aSReid Kleckner
477f98ee40fSTobias Hietaif config.host_os == "Windows":
4788007ff1aSReid Kleckner    # FIXME: This isn't quite right. Specifically, it will succeed if the program
4798007ff1aSReid Kleckner    # does not crash but exits with a non-zero exit code. We ought to merge
4808007ff1aSReid Kleckner    # KillTheDoctor and not --crash to make the latter more useful and remove the
4818007ff1aSReid Kleckner    # need for this substitution.
4828007ff1aSReid Kleckner    config.expect_crash = "not KillTheDoctor "
4838007ff1aSReid Klecknerelse:
4848007ff1aSReid Kleckner    config.expect_crash = "not --crash "
4858007ff1aSReid Kleckner
4868007ff1aSReid Klecknerconfig.substitutions.append(("%expect_crash ", config.expect_crash))
4878007ff1aSReid Kleckner
488f98ee40fSTobias Hietatarget_arch = getattr(config, "target_arch", None)
4898007ff1aSReid Klecknerif target_arch:
490f98ee40fSTobias Hieta    config.available_features.add(target_arch + "-target-arch")
491f98ee40fSTobias Hieta    if target_arch in ["x86_64", "i386"]:
492f98ee40fSTobias Hieta        config.available_features.add("x86-target-arch")
493f98ee40fSTobias Hieta    config.available_features.add(target_arch + "-" + config.host_os.lower())
4948007ff1aSReid Kleckner
495f98ee40fSTobias Hietacompiler_rt_debug = getattr(config, "compiler_rt_debug", False)
4968007ff1aSReid Klecknerif not compiler_rt_debug:
497f98ee40fSTobias Hieta    config.available_features.add("compiler-rt-optimized")
4988007ff1aSReid Kleckner
499f98ee40fSTobias Hietalibdispatch = getattr(config, "compiler_rt_intercept_libdispatch", False)
5008007ff1aSReid Klecknerif libdispatch:
501f98ee40fSTobias Hieta    config.available_features.add("libdispatch")
5028007ff1aSReid Kleckner
503f98ee40fSTobias Hietasanitizer_can_use_cxxabi = getattr(config, "sanitizer_can_use_cxxabi", True)
5048007ff1aSReid Klecknerif sanitizer_can_use_cxxabi:
505f98ee40fSTobias Hieta    config.available_features.add("cxxabi")
5068007ff1aSReid Kleckner
507f98ee40fSTobias Hietaif not getattr(config, "sanitizer_uses_static_cxxabi", False):
508f98ee40fSTobias Hieta    config.available_features.add("shared_cxxabi")
509ac191bccSLeonard Chan
510f98ee40fSTobias Hietaif not getattr(config, "sanitizer_uses_static_unwind", False):
511f98ee40fSTobias Hieta    config.available_features.add("shared_unwind")
51277d5ccdcSLeonard Chan
5138007ff1aSReid Klecknerif config.has_lld:
514f98ee40fSTobias Hieta    config.available_features.add("lld-available")
5158007ff1aSReid Kleckner
51631125785SDinar Temirbulatovif config.aarch64_sme:
51731125785SDinar Temirbulatov    config.available_features.add("aarch64-sme-available")
51831125785SDinar Temirbulatov
5198007ff1aSReid Klecknerif config.use_lld:
520f98ee40fSTobias Hieta    config.available_features.add("lld")
5218007ff1aSReid Kleckner
5228007ff1aSReid Klecknerif config.can_symbolize:
523f98ee40fSTobias Hieta    config.available_features.add("can-symbolize")
5248007ff1aSReid Kleckner
5258007ff1aSReid Klecknerif config.gwp_asan:
526f98ee40fSTobias Hieta    config.available_features.add("gwp_asan")
5278007ff1aSReid Kleckner
5288007ff1aSReid Klecknerlit.util.usePlatformSdkOnDarwin(config, lit_config)
5298007ff1aSReid Kleckner
5301f3c92f9SJulian Lettnermin_macos_deployment_target_substitutions = [
5311f3c92f9SJulian Lettner    (10, 11),
5321f3c92f9SJulian Lettner    (10, 12),
5331f3c92f9SJulian Lettner]
5341f3c92f9SJulian Lettner# TLS requires watchOS 3+
535f98ee40fSTobias Hietaconfig.substitutions.append(
536f98ee40fSTobias Hieta    ("%darwin_min_target_with_tls_support", "%min_macos_deployment_target=10.12")
537f98ee40fSTobias Hieta)
538562c6b80SDan Liew
539f98ee40fSTobias Hietaif config.host_os == "Darwin":
5408007ff1aSReid Kleckner    osx_version = (10, 0, 0)
5418007ff1aSReid Kleckner    try:
542f98ee40fSTobias Hieta        osx_version = subprocess.check_output(
543f98ee40fSTobias Hieta            ["sw_vers", "-productVersion"], universal_newlines=True
544f98ee40fSTobias Hieta        )
545f98ee40fSTobias Hieta        osx_version = tuple(int(x) for x in osx_version.split("."))
546f98ee40fSTobias Hieta        if len(osx_version) == 2:
547f98ee40fSTobias Hieta            osx_version = (osx_version[0], osx_version[1], 0)
5488007ff1aSReid Kleckner        if osx_version >= (10, 11):
549f98ee40fSTobias Hieta            config.available_features.add("osx-autointerception")
550f98ee40fSTobias Hieta            config.available_features.add("osx-ld64-live_support")
5519d701c8aSLang Hames        if osx_version >= (13, 1):
552f98ee40fSTobias Hieta            config.available_features.add("jit-compatible-osx-swift-runtime")
553e071ea48SNico Weber    except subprocess.CalledProcessError:
5548007ff1aSReid Kleckner        pass
5558007ff1aSReid Kleckner
5568007ff1aSReid Kleckner    config.darwin_osx_version = osx_version
5578007ff1aSReid Kleckner
5588007ff1aSReid Kleckner    # Detect x86_64h
5598007ff1aSReid Kleckner    try:
5608007ff1aSReid Kleckner        output = subprocess.check_output(["sysctl", "hw.cpusubtype"])
5618007ff1aSReid Kleckner        output_re = re.match("^hw.cpusubtype: ([0-9]+)$", output)
5628007ff1aSReid Kleckner        if output_re:
5638007ff1aSReid Kleckner            cpu_subtype = int(output_re.group(1))
5648007ff1aSReid Kleckner            if cpu_subtype == 8:  # x86_64h
565f98ee40fSTobias Hieta                config.available_features.add("x86_64h")
5668007ff1aSReid Kleckner    except:
5678007ff1aSReid Kleckner        pass
5688007ff1aSReid Kleckner
5698007ff1aSReid Kleckner    # 32-bit iOS simulator is deprecated and removed in latest Xcode.
5708007ff1aSReid Kleckner    if config.apple_platform == "iossim":
5718007ff1aSReid Kleckner        if config.target_arch == "i386":
5728007ff1aSReid Kleckner            config.unsupported = True
5731f3c92f9SJulian Lettner
5741f3c92f9SJulian Lettner    def get_macos_aligned_version(macos_vers):
5751f3c92f9SJulian Lettner        platform = config.apple_platform
576f98ee40fSTobias Hieta        if platform == "osx":
5771f3c92f9SJulian Lettner            return macos_vers
5781f3c92f9SJulian Lettner
5791f3c92f9SJulian Lettner        macos_major, macos_minor = macos_vers
5801f3c92f9SJulian Lettner        assert macos_major >= 10
5811f3c92f9SJulian Lettner
5821f3c92f9SJulian Lettner        if macos_major == 10:  # macOS 10.x
5831f3c92f9SJulian Lettner            major = macos_minor
5841f3c92f9SJulian Lettner            minor = 0
5851f3c92f9SJulian Lettner        else:  # macOS 11+
5861f3c92f9SJulian Lettner            major = macos_major + 5
5871f3c92f9SJulian Lettner            minor = macos_minor
5881f3c92f9SJulian Lettner
5891f3c92f9SJulian Lettner        assert major >= 11
5901f3c92f9SJulian Lettner
591f98ee40fSTobias Hieta        if platform.startswith("ios") or platform.startswith("tvos"):
5921f3c92f9SJulian Lettner            major -= 2
593f98ee40fSTobias Hieta        elif platform.startswith("watch"):
5941f3c92f9SJulian Lettner            major -= 9
5958007ff1aSReid Kleckner        else:
5961f3c92f9SJulian Lettner            lit_config.fatal("Unsupported apple platform '{}'".format(platform))
5971f3c92f9SJulian Lettner
5981f3c92f9SJulian Lettner        return (major, minor)
5991f3c92f9SJulian Lettner
6001f3c92f9SJulian Lettner    for vers in min_macos_deployment_target_substitutions:
6011f3c92f9SJulian Lettner        flag = config.apple_platform_min_deployment_target_flag
6021f3c92f9SJulian Lettner        major, minor = get_macos_aligned_version(vers)
6031791b11bSthetruestblue        apple_device = ""
6041791b11bSthetruestblue        sim = ""
6051791b11bSthetruestblue        if "target" in flag:
6061791b11bSthetruestblue            apple_device = config.apple_platform.split("sim")[0]
607f98ee40fSTobias Hieta            sim = "-simulator" if "sim" in config.apple_platform else ""
6081791b11bSthetruestblue
609f98ee40fSTobias Hieta        config.substitutions.append(
610f98ee40fSTobias Hieta            (
611f98ee40fSTobias Hieta                "%%min_macos_deployment_target=%s.%s" % vers,
6121791b11bSthetruestblue                "{}={}{}.{}{}".format(flag, apple_device, major, minor, sim),
613f98ee40fSTobias Hieta            )
614f98ee40fSTobias Hieta        )
6151f3c92f9SJulian Lettnerelse:
6161f3c92f9SJulian Lettner    for vers in min_macos_deployment_target_substitutions:
617f98ee40fSTobias Hieta        config.substitutions.append(("%%min_macos_deployment_target=%s.%s" % vers, ""))
6188007ff1aSReid Kleckner
6198007ff1aSReid Klecknerif config.android:
6208007ff1aSReid Kleckner    env = os.environ.copy()
6218007ff1aSReid Kleckner    if config.android_serial:
622f98ee40fSTobias Hieta        env["ANDROID_SERIAL"] = config.android_serial
623f98ee40fSTobias Hieta        config.environment["ANDROID_SERIAL"] = config.android_serial
62425a8881bSVitaly Buka
625f98ee40fSTobias Hieta    adb = os.environ.get("ADB", "adb")
6263b3aef19SVy Nguyen
6273b3aef19SVy Nguyen    # These are needed for tests to upload/download temp files, such as
6283b3aef19SVy Nguyen    # suppression-files, to device.
629f98ee40fSTobias Hieta    config.substitutions.append(("%device_rundir/", "/data/local/tmp/Output/"))
630f98ee40fSTobias Hieta    config.substitutions.append(
631f98ee40fSTobias Hieta        ("%push_to_device", "%s -s '%s' push " % (adb, env["ANDROID_SERIAL"]))
632f98ee40fSTobias Hieta    )
633f98ee40fSTobias Hieta    config.substitutions.append(
634f98ee40fSTobias Hieta        ("%adb_shell ", "%s -s '%s' shell " % (adb, env["ANDROID_SERIAL"]))
635f98ee40fSTobias Hieta    )
636f98ee40fSTobias Hieta    config.substitutions.append(
637f98ee40fSTobias Hieta        ("%device_rm", "%s -s '%s' shell 'rm ' " % (adb, env["ANDROID_SERIAL"]))
638f98ee40fSTobias Hieta    )
6393b3aef19SVy Nguyen
6408007ff1aSReid Kleckner    try:
641f98ee40fSTobias Hieta        android_api_level_str = subprocess.check_output(
642f98ee40fSTobias Hieta            [adb, "shell", "getprop", "ro.build.version.sdk"], env=env
643f98ee40fSTobias Hieta        ).rstrip()
644f98ee40fSTobias Hieta        android_api_codename = (
645f98ee40fSTobias Hieta            subprocess.check_output(
646f98ee40fSTobias Hieta                [adb, "shell", "getprop", "ro.build.version.codename"], env=env
647f98ee40fSTobias Hieta            )
648f98ee40fSTobias Hieta            .rstrip()
649f98ee40fSTobias Hieta            .decode("utf-8")
650f98ee40fSTobias Hieta        )
6518007ff1aSReid Kleckner    except (subprocess.CalledProcessError, OSError):
652f98ee40fSTobias Hieta        lit_config.fatal(
653f98ee40fSTobias Hieta            "Failed to read ro.build.version.sdk (using '%s' as adb)" % adb
654f98ee40fSTobias Hieta        )
6558007ff1aSReid Kleckner    try:
6568007ff1aSReid Kleckner        android_api_level = int(android_api_level_str)
6578007ff1aSReid Kleckner    except ValueError:
658f98ee40fSTobias Hieta        lit_config.fatal(
659f98ee40fSTobias Hieta            "Failed to read ro.build.version.sdk (using '%s' as adb): got '%s'"
660f98ee40fSTobias Hieta            % (adb, android_api_level_str)
661f98ee40fSTobias Hieta        )
662e51631caSVitaly Buka    android_api_level = min(android_api_level, int(config.android_api_level))
663b834d630SRyan Prichard    for required in [26, 28, 29, 30]:
6640e2585c8SVitaly Buka        if android_api_level >= required:
665f98ee40fSTobias Hieta            config.available_features.add("android-%s" % required)
6660e2585c8SVitaly Buka    # FIXME: Replace with appropriate version when availible.
667f98ee40fSTobias Hieta    if android_api_level > 30 or (
668f98ee40fSTobias Hieta        android_api_level == 30 and android_api_codename == "S"
669f98ee40fSTobias Hieta    ):
670f98ee40fSTobias Hieta        config.available_features.add("android-thread-properties-api")
6718007ff1aSReid Kleckner
6728007ff1aSReid Kleckner    # Prepare the device.
673f98ee40fSTobias Hieta    android_tmpdir = "/data/local/tmp/Output"
6748007ff1aSReid Kleckner    subprocess.check_call([adb, "shell", "mkdir", "-p", android_tmpdir], env=env)
6758007ff1aSReid Kleckner    for file in config.android_files_to_push:
6768007ff1aSReid Kleckner        subprocess.check_call([adb, "push", file, android_tmpdir], env=env)
6773b3aef19SVy Nguyenelse:
678f98ee40fSTobias Hieta    config.substitutions.append(("%device_rundir/", ""))
679f98ee40fSTobias Hieta    config.substitutions.append(("%push_to_device", "echo "))
680f98ee40fSTobias Hieta    config.substitutions.append(("%adb_shell", "echo "))
6818007ff1aSReid Kleckner
682f98ee40fSTobias Hietaif config.host_os == "Linux":
6830c11478bSAlex Brachet    def add_glibc_versions(ver_string):
6840c11478bSAlex Brachet        if config.android:
6850c11478bSAlex Brachet            return
6860c11478bSAlex Brachet
6878007ff1aSReid Kleckner        from distutils.version import LooseVersion
688f98ee40fSTobias Hieta
6890c11478bSAlex Brachet        ver = LooseVersion(ver_string)
69022aa493aSVitaly Buka        any_glibc = False
691bbdccf4cSFangrui Song        for required in [
692bbdccf4cSFangrui Song            "2.19",
693bbdccf4cSFangrui Song            "2.27",
694bbdccf4cSFangrui Song            "2.30",
695bbdccf4cSFangrui Song            "2.33",
696bbdccf4cSFangrui Song            "2.34",
697bbdccf4cSFangrui Song            "2.37",
698bbdccf4cSFangrui Song            "2.38",
699bbdccf4cSFangrui Song            "2.40",
700bbdccf4cSFangrui Song        ]:
7010e2585c8SVitaly Buka            if ver >= LooseVersion(required):
7020e2585c8SVitaly Buka                config.available_features.add("glibc-" + required)
70322aa493aSVitaly Buka                any_glibc = True
70422aa493aSVitaly Buka            if any_glibc:
70522aa493aSVitaly Buka                config.available_features.add("glibc")
7068007ff1aSReid Kleckner
7070c11478bSAlex Brachet    # detect whether we are using glibc, and which version
7080c11478bSAlex Brachet    cmd_args = [
7090c11478bSAlex Brachet        config.clang.strip(),
7100c11478bSAlex Brachet        f"--target={config.target_triple}",
7110c11478bSAlex Brachet        "-xc",
7120c11478bSAlex Brachet        "-",
7130c11478bSAlex Brachet        "-o",
7140c11478bSAlex Brachet        "-",
7150c11478bSAlex Brachet        "-dM",
7160c11478bSAlex Brachet        "-E",
7170c11478bSAlex Brachet    ] + shlex.split(config.target_cflags)
7180c11478bSAlex Brachet    cmd = subprocess.Popen(
7190c11478bSAlex Brachet        cmd_args,
7200c11478bSAlex Brachet        stdout=subprocess.PIPE,
7210c11478bSAlex Brachet        stdin=subprocess.PIPE,
7220c11478bSAlex Brachet        stderr=subprocess.DEVNULL,
7230c11478bSAlex Brachet        env={"LANG": "C"},
7240c11478bSAlex Brachet    )
7250c11478bSAlex Brachet    try:
7260c11478bSAlex Brachet        sout, _ = cmd.communicate(b"#include <features.h>")
7270c11478bSAlex Brachet        m = dict(re.findall(r"#define (__GLIBC__|__GLIBC_MINOR__) (\d+)", str(sout)))
7280c11478bSAlex Brachet        add_glibc_versions(f"{m['__GLIBC__']}.{m['__GLIBC_MINOR__']}")
7290c11478bSAlex Brachet    except:
7300c11478bSAlex Brachet        pass
7310c11478bSAlex Brachet
7328007ff1aSReid Klecknersancovcc_path = os.path.join(config.llvm_tools_dir, "sancov")
7338007ff1aSReid Klecknerif os.path.exists(sancovcc_path):
7348007ff1aSReid Kleckner    config.available_features.add("has_sancovcc")
7358007ff1aSReid Kleckner    config.substitutions.append(("%sancovcc ", sancovcc_path))
7368007ff1aSReid Kleckner
737f98ee40fSTobias Hieta
738f6b2ddbfSNico Weberdef liblto_path():
739f98ee40fSTobias Hieta    return os.path.join(config.llvm_shlib_dir, "libLTO.dylib")
740f98ee40fSTobias Hieta
741f6b2ddbfSNico Weber
7428007ff1aSReid Klecknerdef is_darwin_lto_supported():
743f6b2ddbfSNico Weber    return os.path.exists(liblto_path())
7448007ff1aSReid Kleckner
745f98ee40fSTobias Hieta
746746b5fadSFangrui Songdef is_binutils_lto_supported():
747f98ee40fSTobias Hieta    if not os.path.exists(os.path.join(config.llvm_shlib_dir, "LLVMgold.so")):
7488007ff1aSReid Kleckner        return False
7498007ff1aSReid Kleckner
750746b5fadSFangrui Song    # We require both ld.bfd and ld.gold exist and support plugins. They are in
751746b5fadSFangrui Song    # the same repository 'binutils-gdb' and usually built together.
752746b5fadSFangrui Song    for exe in (config.gnu_ld_executable, config.gold_executable):
753ea953b9dSMichał Górny        try:
754f98ee40fSTobias Hieta            ld_cmd = subprocess.Popen(
755f98ee40fSTobias Hieta                [exe, "--help"], stdout=subprocess.PIPE, env={"LANG": "C"}
756f98ee40fSTobias Hieta            )
7578007ff1aSReid Kleckner            ld_out = ld_cmd.stdout.read().decode()
7588007ff1aSReid Kleckner            ld_cmd.wait()
759ea953b9dSMichał Górny        except OSError:
760ea953b9dSMichał Górny            return False
761f98ee40fSTobias Hieta        if not "-plugin" in ld_out:
7628007ff1aSReid Kleckner            return False
7638007ff1aSReid Kleckner
7648007ff1aSReid Kleckner    return True
7658007ff1aSReid Kleckner
766f98ee40fSTobias Hieta
767c467e609SJan Voungdef is_lld_lto_supported():
768c467e609SJan Voung    # LLD does support LTO, but we require it to be built with the latest
769c467e609SJan Voung    # changes to claim support. Otherwise older copies of LLD may not
770c467e609SJan Voung    # understand new bitcode versions.
771c467e609SJan Voung    return os.path.exists(os.path.join(config.llvm_tools_dir, "lld"))
772c467e609SJan Voung
773c467e609SJan Voung
7748007ff1aSReid Klecknerdef is_windows_lto_supported():
775bae2fbaeSAlvin Wong    if not target_is_msvc:
776bae2fbaeSAlvin Wong        return True
777f98ee40fSTobias Hieta    return os.path.exists(os.path.join(config.llvm_tools_dir, "lld-link.exe"))
7788007ff1aSReid Kleckner
779f98ee40fSTobias Hieta
780f98ee40fSTobias Hietaif config.host_os == "Darwin" and is_darwin_lto_supported():
7818007ff1aSReid Kleckner    config.lto_supported = True
782f98ee40fSTobias Hieta    config.lto_flags = ["-Wl,-lto_library," + liblto_path()]
783f98ee40fSTobias Hietaelif config.host_os in ["Linux", "FreeBSD", "NetBSD"]:
784746b5fadSFangrui Song    config.lto_supported = False
785c467e609SJan Voung    if config.use_lld and is_lld_lto_supported():
7868007ff1aSReid Kleckner        config.lto_supported = True
787746b5fadSFangrui Song    if is_binutils_lto_supported():
788f98ee40fSTobias Hieta        config.available_features.add("binutils_lto")
789746b5fadSFangrui Song        config.lto_supported = True
790746b5fadSFangrui Song
791746b5fadSFangrui Song    if config.lto_supported:
7928007ff1aSReid Kleckner        if config.use_lld:
7938007ff1aSReid Kleckner            config.lto_flags = ["-fuse-ld=lld"]
7948007ff1aSReid Kleckner        else:
7958007ff1aSReid Kleckner            config.lto_flags = ["-fuse-ld=gold"]
796f98ee40fSTobias Hietaelif config.host_os == "Windows" and is_windows_lto_supported():
7978007ff1aSReid Kleckner    config.lto_supported = True
7988007ff1aSReid Kleckner    config.lto_flags = ["-fuse-ld=lld"]
7998007ff1aSReid Klecknerelse:
8008007ff1aSReid Kleckner    config.lto_supported = False
8018007ff1aSReid Kleckner
8028007ff1aSReid Klecknerif config.lto_supported:
803f98ee40fSTobias Hieta    config.available_features.add("lto")
8048007ff1aSReid Kleckner    if config.use_thinlto:
805f98ee40fSTobias Hieta        config.available_features.add("thinlto")
8068007ff1aSReid Kleckner        config.lto_flags += ["-flto=thin"]
8078007ff1aSReid Kleckner    else:
8088007ff1aSReid Kleckner        config.lto_flags += ["-flto"]
8098007ff1aSReid Kleckner
8108007ff1aSReid Klecknerif config.have_rpc_xdr_h:
811f98ee40fSTobias Hieta    config.available_features.add("sunrpc")
8128007ff1aSReid Kleckner
8138007ff1aSReid Kleckner# Sanitizer tests tend to be flaky on Windows due to PR24554, so add some
8148007ff1aSReid Kleckner# retries. We don't do this on otther platforms because it's slower.
815f98ee40fSTobias Hietaif platform.system() == "Windows":
8168007ff1aSReid Kleckner    config.test_retry_attempts = 2
8178007ff1aSReid Kleckner
8188007ff1aSReid Kleckner# No throttling on non-Darwin platforms.
819f98ee40fSTobias Hietalit_config.parallelism_groups["shadow-memory"] = None
8208007ff1aSReid Kleckner
821f98ee40fSTobias Hietaif platform.system() == "Darwin":
822f98ee40fSTobias Hieta    ios_device = config.apple_platform != "osx" and not config.apple_platform.endswith(
823f98ee40fSTobias Hieta        "sim"
824f98ee40fSTobias Hieta    )
8258007ff1aSReid Kleckner    # Force sequential execution when running tests on iOS devices.
8268007ff1aSReid Kleckner    if ios_device:
827f98ee40fSTobias Hieta        lit_config.warning("Forcing sequential execution for iOS device tests")
828f98ee40fSTobias Hieta        lit_config.parallelism_groups["ios-device"] = 1
829f98ee40fSTobias Hieta        config.parallelism_group = "ios-device"
8308007ff1aSReid Kleckner
8318007ff1aSReid Kleckner    # Only run up to 3 processes that require shadow memory simultaneously on
8328007ff1aSReid Kleckner    # 64-bit Darwin. Using more scales badly and hogs the system due to
8338007ff1aSReid Kleckner    # inefficient handling of large mmap'd regions (terabytes) by the kernel.
834a5228bcaSJulian Lettner    else:
835f98ee40fSTobias Hieta        lit_config.warning(
836f98ee40fSTobias Hieta            "Throttling sanitizer tests that require shadow memory on Darwin"
837f98ee40fSTobias Hieta        )
838f98ee40fSTobias Hieta        lit_config.parallelism_groups["shadow-memory"] = 3
8398007ff1aSReid Kleckner
8408007ff1aSReid Kleckner# Multiple substitutions are necessary to support multiple shared objects used
8418007ff1aSReid Kleckner# at once.
8428007ff1aSReid Kleckner# Note that substitutions with numbers have to be defined first to avoid
8438007ff1aSReid Kleckner# being subsumed by substitutions with smaller postfix.
8448007ff1aSReid Klecknerfor postfix in ["2", "1", ""]:
845f98ee40fSTobias Hieta    if config.host_os == "Darwin":
846f98ee40fSTobias Hieta        config.substitutions.append(
847f98ee40fSTobias Hieta            (
848f98ee40fSTobias Hieta                "%ld_flags_rpath_exe" + postfix,
849f98ee40fSTobias Hieta                "-Wl,-rpath,@executable_path/ %dynamiclib" + postfix,
850f98ee40fSTobias Hieta            )
851f98ee40fSTobias Hieta        )
852f98ee40fSTobias Hieta        config.substitutions.append(
853f98ee40fSTobias Hieta            (
854f98ee40fSTobias Hieta                "%ld_flags_rpath_so" + postfix,
855f98ee40fSTobias Hieta                "-install_name @rpath/`basename %dynamiclib{}`".format(postfix),
856f98ee40fSTobias Hieta            )
857f98ee40fSTobias Hieta        )
858f98ee40fSTobias Hieta    elif config.host_os in ("FreeBSD", "NetBSD", "OpenBSD"):
859f98ee40fSTobias Hieta        config.substitutions.append(
860f98ee40fSTobias Hieta            (
861f98ee40fSTobias Hieta                "%ld_flags_rpath_exe" + postfix,
8622402b140SGeorgios Eleftheriou                r"-Wl,-z,origin -Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec"
863f98ee40fSTobias Hieta                + postfix,
864f98ee40fSTobias Hieta            )
865f98ee40fSTobias Hieta        )
866f98ee40fSTobias Hieta        config.substitutions.append(("%ld_flags_rpath_so" + postfix, ""))
867f98ee40fSTobias Hieta    elif config.host_os == "Linux":
868f98ee40fSTobias Hieta        config.substitutions.append(
869f98ee40fSTobias Hieta            (
870f98ee40fSTobias Hieta                "%ld_flags_rpath_exe" + postfix,
8712402b140SGeorgios Eleftheriou                r"-Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec" + postfix,
872f98ee40fSTobias Hieta            )
873f98ee40fSTobias Hieta        )
874f98ee40fSTobias Hieta        config.substitutions.append(("%ld_flags_rpath_so" + postfix, ""))
875f98ee40fSTobias Hieta    elif config.host_os == "SunOS":
876f98ee40fSTobias Hieta        config.substitutions.append(
877f98ee40fSTobias Hieta            (
878f98ee40fSTobias Hieta                "%ld_flags_rpath_exe" + postfix,
8792402b140SGeorgios Eleftheriou                r"-Wl,-R\$ORIGIN -L%T -l%xdynamiclib_namespec" + postfix,
880f98ee40fSTobias Hieta            )
881f98ee40fSTobias Hieta        )
882f98ee40fSTobias Hieta        config.substitutions.append(("%ld_flags_rpath_so" + postfix, ""))
8838007ff1aSReid Kleckner
8848007ff1aSReid Kleckner    # Must be defined after the substitutions that use %dynamiclib.
885f98ee40fSTobias Hieta    config.substitutions.append(
886f98ee40fSTobias Hieta        ("%dynamiclib" + postfix, "%T/%xdynamiclib_filename" + postfix)
887f98ee40fSTobias Hieta    )
888f98ee40fSTobias Hieta    config.substitutions.append(
889f98ee40fSTobias Hieta        (
890f98ee40fSTobias Hieta            "%xdynamiclib_filename" + postfix,
891f98ee40fSTobias Hieta            "lib%xdynamiclib_namespec{}.so".format(postfix),
892f98ee40fSTobias Hieta        )
893f98ee40fSTobias Hieta    )
894f98ee40fSTobias Hieta    config.substitutions.append(("%xdynamiclib_namespec", "%basename_t.dynamic"))
8958007ff1aSReid Kleckner
8968007ff1aSReid Klecknerconfig.default_sanitizer_opts = []
897f98ee40fSTobias Hietaif config.host_os == "Darwin":
8988007ff1aSReid Kleckner    # On Darwin, we default to `abort_on_error=1`, which would make tests run
8998007ff1aSReid Kleckner    # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
900f98ee40fSTobias Hieta    config.default_sanitizer_opts += ["abort_on_error=0"]
901f98ee40fSTobias Hieta    config.default_sanitizer_opts += ["log_to_syslog=0"]
902f98ee40fSTobias Hieta    if lit.util.which("log"):
903853a1e69SDan Liew        # Querying the log can only done by a privileged user so
904853a1e69SDan Liew        # so check if we can query the log.
905853a1e69SDan Liew        exit_code = -1
906f98ee40fSTobias Hieta        with open("/dev/null", "r") as f:
907853a1e69SDan Liew            # Run a `log show` command the should finish fairly quickly and produce very little output.
908f98ee40fSTobias Hieta            exit_code = subprocess.call(
909f98ee40fSTobias Hieta                ["log", "show", "--last", "1m", "--predicate", "1 == 0"],
910f98ee40fSTobias Hieta                stdout=f,
911f98ee40fSTobias Hieta                stderr=f,
912f98ee40fSTobias Hieta            )
913853a1e69SDan Liew        if exit_code == 0:
914f98ee40fSTobias Hieta            config.available_features.add("darwin_log_cmd")
915445b810fSDan Liew        else:
916f98ee40fSTobias Hieta            lit_config.warning("log command found but cannot queried")
917853a1e69SDan Liew    else:
918f98ee40fSTobias Hieta        lit_config.warning("log command not found. Some tests will be skipped.")
9198007ff1aSReid Klecknerelif config.android:
920f98ee40fSTobias Hieta    config.default_sanitizer_opts += ["abort_on_error=0"]
9218007ff1aSReid Kleckner
9228007ff1aSReid Kleckner# Allow tests to use REQUIRES=stable-runtime.  For use when you cannot use XFAIL
9238007ff1aSReid Kleckner# because the test hangs or fails on one configuration and not the other.
924f98ee40fSTobias Hietaif config.android or (config.target_arch not in ["arm", "armhf", "aarch64"]):
925f98ee40fSTobias Hieta    config.available_features.add("stable-runtime")
9268007ff1aSReid Kleckner
9278007ff1aSReid Klecknerif config.asan_shadow_scale:
9288007ff1aSReid Kleckner    config.available_features.add("shadow-scale-%s" % config.asan_shadow_scale)
9298007ff1aSReid Klecknerelse:
9308007ff1aSReid Kleckner    config.available_features.add("shadow-scale-3")
9318007ff1aSReid Kleckner
9323d4bba30STeresa Johnsonif config.memprof_shadow_scale:
933f98ee40fSTobias Hieta    config.available_features.add(
934f98ee40fSTobias Hieta        "memprof-shadow-scale-%s" % config.memprof_shadow_scale
935f98ee40fSTobias Hieta    )
9363d4bba30STeresa Johnsonelse:
9373d4bba30STeresa Johnson    config.available_features.add("memprof-shadow-scale-3")
9383d4bba30STeresa Johnson
939ad871e42SAlex Lorenzif config.expensive_checks:
940ad871e42SAlex Lorenz    config.available_features.add("expensive_checks")
941ad871e42SAlex Lorenz
9428007ff1aSReid Kleckner# Propagate the LLD/LTO into the clang config option, so nothing else is needed.
9438007ff1aSReid Klecknerrun_wrapper = []
944f98ee40fSTobias Hietatarget_cflags = [getattr(config, "target_cflags", None)]
9458007ff1aSReid Klecknerextra_cflags = []
9468007ff1aSReid Kleckner
9478007ff1aSReid Klecknerif config.use_lto and config.lto_supported:
9488007ff1aSReid Kleckner    extra_cflags += config.lto_flags
9498007ff1aSReid Klecknerelif config.use_lto and (not config.lto_supported):
9508007ff1aSReid Kleckner    config.unsupported = True
9518007ff1aSReid Kleckner
9528007ff1aSReid Klecknerif config.use_lld and config.has_lld and not config.use_lto:
9538007ff1aSReid Kleckner    extra_cflags += ["-fuse-ld=lld"]
9548007ff1aSReid Klecknerelif config.use_lld and (not config.has_lld):
9558007ff1aSReid Kleckner    config.unsupported = True
9568007ff1aSReid Kleckner
9573bc71c2aSUsama Hameedif config.host_os == "Darwin":
9583bc71c2aSUsama Hameed    if getattr(config, "darwin_linker_version", None):
9593bc71c2aSUsama Hameed        extra_cflags += ["-mlinker-version=" + config.darwin_linker_version]
9603bc71c2aSUsama Hameed
961deec343bSHafiz Abid Qadeer# Append any extra flags passed in lit_config
962f98ee40fSTobias Hietaappend_target_cflags = lit_config.params.get("append_target_cflags", None)
963deec343bSHafiz Abid Qadeerif append_target_cflags:
964deec343bSHafiz Abid Qadeer    lit_config.note('Appending to extra_cflags: "{}"'.format(append_target_cflags))
965deec343bSHafiz Abid Qadeer    extra_cflags += [append_target_cflags]
966deec343bSHafiz Abid Qadeer
967f98ee40fSTobias Hietaconfig.clang = (
968f98ee40fSTobias Hieta    " " + " ".join(run_wrapper + [config.compile_wrapper, config.clang]) + " "
969f98ee40fSTobias Hieta)
9708007ff1aSReid Klecknerconfig.target_cflags = " " + " ".join(target_cflags + extra_cflags) + " "
971b6099fa5SEmily Shi
972f98ee40fSTobias Hietaif config.host_os == "Darwin":
973f98ee40fSTobias Hieta    config.substitutions.append(
974f98ee40fSTobias Hieta        (
975b6099fa5SEmily Shi            "%get_pid_from_output",
976b6099fa5SEmily Shi            "{} {}/get_pid_from_output.py".format(
977aa6cb0f2SFangrui Song                shlex.quote(config.python_executable),
978f98ee40fSTobias Hieta                shlex.quote(get_ios_commands_dir()),
979f98ee40fSTobias Hieta            ),
980f98ee40fSTobias Hieta        )
981b6099fa5SEmily Shi    )
982b6099fa5SEmily Shi    config.substitutions.append(
983f98ee40fSTobias Hieta        (
984f98ee40fSTobias Hieta            "%print_crashreport_for_pid",
985b6099fa5SEmily Shi            "{} {}/print_crashreport_for_pid.py".format(
986aa6cb0f2SFangrui Song                shlex.quote(config.python_executable),
987f98ee40fSTobias Hieta                shlex.quote(get_ios_commands_dir()),
988f98ee40fSTobias Hieta            ),
989f98ee40fSTobias Hieta        )
990b6099fa5SEmily Shi    )
9918ab76255SSam James
9928ab76255SSam James# It is not realistically possible to account for all options that could
9938ab76255SSam James# possibly be present in system and user configuration files, so disable
9948ab76255SSam James# default configs for the test runs. In particular, anything hardening
9958ab76255SSam James# related is likely to cause issues with sanitizer tests, because it may
996ca50897aSSam James# preempt something we're looking to trap (e.g. _FORTIFY_SOURCE vs our ASAN).
997a14a83d9SMartin Storsjö#
998a14a83d9SMartin Storsjö# Only set this if we know we can still build for the target while disabling
999a14a83d9SMartin Storsjö# default configs.
1000a14a83d9SMartin Storsjöif config.has_no_default_config_flag:
10018ab76255SSam James    config.environment["CLANG_NO_DEFAULT_CONFIG"] = "1"
100213771793SDmitry Vyukov
1003445978eeSAlex Brachetif config.has_compiler_rt_libatomic:
1004445978eeSAlex Brachet  base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.atomic%s.so"
1005445978eeSAlex Brachet                          % config.target_suffix)
1006445978eeSAlex Brachet  if sys.platform in ['win32'] and execute_external:
1007445978eeSAlex Brachet    # Don't pass dosish path separator to msys bash.exe.
1008445978eeSAlex Brachet    base_lib = base_lib.replace('\\', '/')
1009445978eeSAlex Brachet  config.substitutions.append(("%libatomic", base_lib + f" -Wl,-rpath,{config.compiler_rt_libdir}"))
1010445978eeSAlex Brachetelse:
1011445978eeSAlex Brachet  config.substitutions.append(("%libatomic", "-latomic"))
1012445978eeSAlex Brachet
101313771793SDmitry Vyukov# Set LD_LIBRARY_PATH to pick dynamic runtime up properly.
101413771793SDmitry Vyukovpush_dynamic_library_lookup_path(config, config.compiler_rt_libdir)
101513771793SDmitry Vyukov
101613771793SDmitry Vyukov# GCC-ASan uses dynamic runtime by default.
101713771793SDmitry Vyukovif config.compiler_id == "GNU":
101813771793SDmitry Vyukov    gcc_dir = os.path.dirname(config.clang)
101913771793SDmitry Vyukov    libasan_dir = os.path.join(gcc_dir, "..", "lib" + config.bits)
102013771793SDmitry Vyukov    push_dynamic_library_lookup_path(config, libasan_dir)
1021e4763ca8SMircea Trofin
1022e4763ca8SMircea Trofin
1023e4763ca8SMircea Trofin# Help tests that make sure certain files are in-sync between compiler-rt and
1024e4763ca8SMircea Trofin# llvm.
1025e4763ca8SMircea Trofinconfig.substitutions.append(("%crt_src", config.compiler_rt_src_root))
1026e4763ca8SMircea Trofinconfig.substitutions.append(("%llvm_src", config.llvm_src_root))
1027