835 lines · python
1# -*- Python -*-2 3# Configuration file for the 'lit' test runner.4 5import os6import sys7import re8import platform9import subprocess10 11import lit.util12import lit.formats13from lit.llvm import llvm_config14from lit.llvm.subst import FindTool15from lit.llvm.subst import ToolSubst16 17# name: The name of this test suite.18config.name = "LLVM"19 20# TODO: Consolidate the logic for turning on the internal shell by default for all LLVM test suites.21# See https://github.com/llvm/llvm-project/issues/106636 for more details.22#23# We prefer the lit internal shell which provides a better user experience on failures24# and is faster unless the user explicitly disables it with LIT_USE_INTERNAL_SHELL=025# env var.26use_lit_shell = True27lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")28if lit_shell_env:29 use_lit_shell = lit.util.pythonize_bool(lit_shell_env)30 31# testFormat: The test format to use to interpret tests.32extra_substitutions = extra_substitutions = (33 [34 (r"FileCheck .*", "cat > /dev/null"),35 (r"not FileCheck .*", "cat > /dev/null"),36 ]37 if config.enable_profcheck38 else []39)40config.test_format = lit.formats.ShTest(not use_lit_shell, extra_substitutions)41 42# suffixes: A list of file extensions to treat as test files. This is overriden43# by individual lit.local.cfg files in the test subdirectories.44config.suffixes = [".ll", ".c", ".test", ".txt", ".s", ".mir", ".yaml", ".spv"]45 46# excludes: A list of directories to exclude from the testsuite. The 'Inputs'47# subdirectories contain auxiliary inputs for various tests in their parent48# directories.49config.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt"]50 51if config.enable_profcheck:52 config.available_features.add("profcheck")53 # Exclude llvm-reduce tests for profcheck because we substitute the FileCheck54 # binary with a no-op command for profcheck, but llvm-reduce tests have RUN55 # commands of the form llvm-reduce --test FileCheck, which explode if we56 # substitute FileCheck because llvm-reduce expects FileCheck in these tests.57 # It's not really possible to exclude these tests from the command substitution,58 # so we just exclude llvm-reduce tests from this config altogether. This should59 # be fine though as profcheck config tests are mostly concerned with opt.60 config.excludes.append("llvm-reduce")61 # Exclude llvm-objcopy tests - not the target of this effort, and some use62 # cat in ways that conflict with how profcheck uses it.63 config.excludes.append("llvm-objcopy")64 # (Issue #161235) Temporarily exclude LoopVectorize.65 config.excludes.append("LoopVectorize")66 # exclude UpdateTestChecks - they fail because of inserted prof annotations67 config.excludes.append("UpdateTestChecks")68 # TODO(#166655): Reenable Instrumentation tests69 config.excludes.append("Instrumentation")70 # profiling doesn't work quite well on GPU, excluding71 config.excludes.append("AMDGPU")72 73# test_source_root: The root path where tests are located.74config.test_source_root = os.path.dirname(__file__)75 76# test_exec_root: The root path where tests should be run.77config.test_exec_root = os.path.join(config.llvm_obj_root, "test")78 79# Tweak the PATH to include the tools dir.80llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)81 82# Propagate some variables from the host environment.83llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])84 85 86# Set up OCAMLPATH to include newly built OCaml libraries.87top_ocaml_lib = os.path.join(config.llvm_lib_dir, "ocaml")88llvm_ocaml_lib = os.path.join(top_ocaml_lib, "llvm")89 90llvm_config.with_system_environment("OCAMLPATH")91llvm_config.with_environment("OCAMLPATH", top_ocaml_lib, append_path=True)92llvm_config.with_environment("OCAMLPATH", llvm_ocaml_lib, append_path=True)93 94llvm_config.with_system_environment("CAML_LD_LIBRARY_PATH")95llvm_config.with_environment("CAML_LD_LIBRARY_PATH", llvm_ocaml_lib, append_path=True)96 97# Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.98llvm_config.with_environment("OCAMLRUNPARAM", "b")99 100# Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if101# available. This is darwin specific since it's currently only needed on darwin.102 103 104def get_asan_rtlib():105 if (106 not "Address" in config.llvm_use_sanitizer107 or not "Darwin" in config.target_os108 or not "x86" in config.host_triple109 ):110 return ""111 try:112 import glob113 except:114 print("glob module not found, skipping get_asan_rtlib() lookup")115 return ""116 # The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative117 # path from the host cc.118 host_lib_dir = os.path.join(os.path.dirname(config.host_cc), "../lib")119 asan_dylib_dir_pattern = (120 host_lib_dir + "/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib"121 )122 found_dylibs = glob.glob(asan_dylib_dir_pattern)123 if len(found_dylibs) != 1:124 return ""125 return found_dylibs[0]126 127 128llvm_config.use_default_substitutions()129 130# Add site-specific substitutions.131config.substitutions.append(("%llvmshlibdir", config.llvm_shlib_dir))132config.substitutions.append(("%shlibext", config.llvm_shlib_ext))133config.substitutions.append(("%pluginext", config.llvm_plugin_ext))134config.substitutions.append(("%exeext", config.llvm_exe_ext))135config.substitutions.append(("%llvm_src_root", config.llvm_src_root))136 137# Add IR2Vec test vocabulary path substitution138config.substitutions.append(139 (140 "%ir2vec_test_vocab_dir",141 os.path.join(config.test_source_root, "Analysis", "IR2Vec", "Inputs"),142 )143)144 145lli_args = []146# The target triple used by default by lli is the process target triple (some147# triple appropriate for generating code for the current process) but because148# we don't support COFF in MCJIT well enough for the tests, force ELF format on149# Windows. FIXME: the process target triple should be used here, but this is150# difficult to obtain on Windows.151# Cygwin is excluded from this workaround, even though it is COFF, because this152# breaks remote tests due to not having a __register_frame function. The only153# test that succeeds with cygwin-elf but fails with cygwin is154# test/ExecutionEngine/MCJIT/stubs-sm-pic.ll so this test is marked as XFAIL155# for cygwin targets.156if re.search(r"windows-gnu|windows-msvc", config.host_triple):157 lli_args = ["-mtriple=" + config.host_triple + "-elf"]158 159llc_args = []160 161# Similarly, have a macro to use llc with DWARF even when the host is Windows162if re.search(r"windows-msvc", config.target_triple):163 llc_args = [" -mtriple=" + config.target_triple.replace("-msvc", "-gnu")]164 165# Provide the path to asan runtime lib if available. On darwin, this lib needs166# to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files167# to be linked contain instrumented sanitizer code.168ld64_cmd = config.ld64_executable169asan_rtlib = get_asan_rtlib()170if asan_rtlib:171 ld64_cmd = "env DYLD_INSERT_LIBRARIES={} {}".format(asan_rtlib, ld64_cmd)172if config.osx_sysroot:173 ld64_cmd = "{} -syslibroot {}".format(ld64_cmd, config.osx_sysroot)174 175ocamlc_command = "%s ocamlc -cclib -L%s %s" % (176 config.ocamlfind_executable,177 config.llvm_lib_dir,178 config.ocaml_flags,179)180ocamlopt_command = "true"181if config.have_ocamlopt:182 ocamlopt_command = "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" % (183 config.ocamlfind_executable,184 config.llvm_lib_dir,185 config.llvm_lib_dir,186 config.ocaml_flags,187 )188 189opt_viewer_cmd = "%s %s/tools/opt-viewer/opt-viewer.py" % (190 sys.executable,191 config.llvm_src_root,192)193 194llvm_original_di_preservation_cmd = os.path.join(195 config.llvm_src_root, "utils", "llvm-original-di-preservation.py"196)197config.substitutions.append(198 (199 "%llvm-original-di-preservation",200 "'%s' %s" % (config.python_executable, llvm_original_di_preservation_cmd),201 )202)203 204llvm_locstats_tool = os.path.join(config.llvm_tools_dir, "llvm-locstats")205config.substitutions.append(206 ("%llvm-locstats", "'%s' %s" % (config.python_executable, llvm_locstats_tool))207)208config.llvm_locstats_used = os.path.exists(llvm_locstats_tool)209 210tools = [211 ToolSubst("%llvm", FindTool("llvm"), unresolved="ignore"),212 ToolSubst("%lli", FindTool("lli"), post=".", extra_args=lli_args),213 ToolSubst("%llc_dwarf", FindTool("llc"), extra_args=llc_args),214 ToolSubst("%gold", config.gold_executable, unresolved="ignore"),215 ToolSubst("%ld64", ld64_cmd, unresolved="ignore"),216 ToolSubst("%ocamlc", ocamlc_command, unresolved="ignore"),217 ToolSubst("%ocamlopt", ocamlopt_command, unresolved="ignore"),218 ToolSubst("%opt-viewer", opt_viewer_cmd),219 ToolSubst("%llvm-objcopy", FindTool("llvm-objcopy")),220 ToolSubst("%llvm-strip", FindTool("llvm-strip")),221 ToolSubst("%llvm-install-name-tool", FindTool("llvm-install-name-tool")),222 ToolSubst("%llvm-bitcode-strip", FindTool("llvm-bitcode-strip")),223 ToolSubst("%split-file", FindTool("split-file")),224]225 226# FIXME: Why do we have both `lli` and `%lli` that do slightly different things?227tools.extend(228 [229 "dsymutil",230 "lli",231 "lli-child-target",232 "llvm-ar",233 "llvm-as",234 "llvm-addr2line",235 "llvm-bcanalyzer",236 "llvm-bitcode-strip",237 "llvm-cas",238 "llvm-cgdata",239 "llvm-config",240 "llvm-cov",241 "llvm-ctxprof-util",242 "llvm-cxxdump",243 "llvm-cvtres",244 "llvm-debuginfod-find",245 "llvm-debuginfo-analyzer",246 "llvm-diff",247 "llvm-dis",248 "llvm-dwarfdump",249 "llvm-dwarfutil",250 "llvm-dwp",251 "llvm-dlltool",252 "llvm-exegesis",253 "llvm-extract",254 "llvm-ir2vec",255 "llvm-isel-fuzzer",256 "llvm-ifs",257 "llvm-install-name-tool",258 "llvm-jitlink",259 "llvm-opt-fuzzer",260 "llvm-lib",261 "llvm-link",262 "llvm-lto",263 "llvm-lto2",264 "llvm-mc",265 "llvm-mca",266 "llvm-modextract",267 "llvm-nm",268 "llvm-objcopy",269 "llvm-objdump",270 "llvm-otool",271 "llvm-pdbutil",272 "llvm-profdata",273 "llvm-profgen",274 "llvm-ranlib",275 "llvm-rc",276 "llvm-readelf",277 "llvm-readobj",278 "llvm-rtdyld",279 "llvm-sim",280 "llvm-size",281 "llvm-split",282 "llvm-stress",283 "llvm-strings",284 "llvm-strip",285 "llvm-tblgen",286 "llvm-readtapi",287 "llvm-undname",288 "llvm-windres",289 "llvm-c-test",290 "llvm-cxxfilt",291 "llvm-xray",292 "yaml2obj",293 "obj2yaml",294 "yaml-bench",295 "verify-uselistorder",296 "bugpoint",297 "llc",298 "llvm-symbolizer",299 "opt",300 "sancov",301 "sanstats",302 "llvm-remarkutil",303 ]304)305 306# The following tools are optional307tools.extend(308 [309 ToolSubst("llvm-mt", unresolved="ignore"),310 ToolSubst("llvm-debuginfod", unresolved="ignore"),311 ToolSubst("Kaleidoscope-Ch3", unresolved="ignore"),312 ToolSubst("Kaleidoscope-Ch4", unresolved="ignore"),313 ToolSubst("Kaleidoscope-Ch5", unresolved="ignore"),314 ToolSubst("Kaleidoscope-Ch6", unresolved="ignore"),315 ToolSubst("Kaleidoscope-Ch7", unresolved="ignore"),316 ToolSubst("Kaleidoscope-Ch8", unresolved="ignore"),317 ToolSubst("LLJITWithThinLTOSummaries", unresolved="ignore"),318 ToolSubst("LLJITWithRemoteDebugging", unresolved="ignore"),319 ToolSubst("OrcV2CBindingsBasicUsage", unresolved="ignore"),320 ToolSubst("OrcV2CBindingsAddObjectFile", unresolved="ignore"),321 ToolSubst("OrcV2CBindingsRemovableCode", unresolved="ignore"),322 ToolSubst("OrcV2CBindingsLazy", unresolved="ignore"),323 ToolSubst("OrcV2CBindingsVeryLazy", unresolved="ignore"),324 ToolSubst("dxil-dis", unresolved="ignore"),325 ]326)327 328 329def ptxas_version(ptxas):330 output = subprocess.check_output([ptxas, "--version"], text=True)331 match = re.search(r"release (\d+)\.(\d+)", output)332 if not match:333 raise RuntimeError("Couldn't determine ptxas version")334 return int(match.group(1)), int(match.group(2))335 336 337def ptxas_isa_versions(ptxas):338 result = subprocess.run(339 [ptxas, "--list-version"],340 capture_output=True,341 text=True,342 )343 versions = []344 for line in result.stdout.splitlines():345 match = re.match(r"(\d+)\.(\d+)", line)346 if match:347 versions.append((int(match.group(1)), int(match.group(2))))348 return versions349 350 351def ptxas_supported_isa_versions(ptxas, major_version, minor_version):352 supported_isa_versions = ptxas_isa_versions(ptxas)353 if supported_isa_versions:354 return supported_isa_versions355 if major_version >= 13:356 raise RuntimeError(f"ptxas {ptxas} does not support ISA version listing")357 358 cuda_version_to_isa_version = {359 (12, 9): [(8, 8)],360 (12, 8): [(8, 7)],361 (12, 7): [(8, 6)],362 (12, 6): [(8, 5)],363 (12, 5): [(8, 5)],364 (12, 4): [(8, 4)],365 (12, 3): [(8, 3)],366 (12, 2): [(8, 2)],367 (12, 1): [(8, 1)],368 (12, 0): [(8, 0)],369 (11, 8): [(7, 8)],370 (11, 7): [(7, 7)],371 (11, 6): [(7, 6)],372 (11, 5): [(7, 5)],373 (11, 4): [(7, 4)],374 (11, 3): [(7, 3)],375 (11, 2): [(7, 2)],376 (11, 1): [(7, 1)],377 (11, 0): [(7, 0)],378 (10, 2): [(6, 5)],379 (10, 1): [(6, 4)],380 (10, 0): [(6, 3)],381 (9, 2): [(6, 2)],382 (9, 1): [(6, 1)],383 (9, 0): [(6, 0)],384 (8, 0): [(5, 0)],385 (7, 5): [(4, 3)],386 (7, 0): [(4, 2)],387 (6, 5): [(4, 1)],388 (6, 0): [(4, 0)],389 (5, 5): [(3, 2)],390 (5, 0): [(3, 1)],391 (4, 1): [(3, 0)],392 (4, 0): [(2, 3)],393 (3, 2): [(2, 2)],394 (3, 1): [(2, 1)],395 (3, 0): [(2, 0), (1, 5)],396 (2, 2): [(1, 4)],397 (2, 1): [(1, 3)],398 (2, 0): [(1, 2)],399 (1, 1): [(1, 1)],400 (1, 0): [(1, 0)],401 }402 403 supported_isa_versions = []404 for (major, minor), isa_versions in cuda_version_to_isa_version.items():405 if (major, minor) <= (major_version, minor_version):406 for isa_version in isa_versions:407 supported_isa_versions.append(isa_version)408 return supported_isa_versions409 410 411def ptxas_supported_sms(ptxas_executable):412 output = subprocess.check_output([ptxas_executable, "--help"], text=True)413 414 gpu_arch_section = re.search(r"--gpu-name(.*?)--", output, re.DOTALL)415 allowed_values = gpu_arch_section.group(1)416 supported_sms = re.findall(r"'sm_(\d+(?:[af]?))'", allowed_values)417 418 if not supported_sms:419 raise RuntimeError("No SM architecture values found in ptxas help output")420 return supported_sms421 422 423def ptxas_supports_address_size_32(ptxas_executable):424 # Linux outputs the error message to stderr, while Windows outputs to stdout.425 # Pipe both to stdout to make sure we get the error message.426 result = subprocess.run(427 [ptxas_executable, "-m 32"],428 stdout=subprocess.PIPE,429 stderr=subprocess.STDOUT,430 text=True,431 )432 if "is not defined for option 'machine'" in result.stdout:433 return False434 if "Missing .version directive at start of file" in result.stdout:435 return True436 raise RuntimeError(f"Unexpected ptxas output: {result.stdout}")437 438 439def enable_ptxas(ptxas_executable):440 config.available_features.add("ptxas")441 tools.extend(442 [443 ToolSubst("%ptxas", ptxas_executable),444 ToolSubst("%ptxas-verify", f"{ptxas_executable} -c -"),445 ]446 )447 448 major_version, minor_version = ptxas_version(ptxas_executable)449 config.available_features.add(f"ptxas-{major_version}.{minor_version}")450 451 for major, minor in ptxas_supported_isa_versions(452 ptxas_executable, major_version, minor_version453 ):454 config.available_features.add(f"ptxas-isa-{major}.{minor}")455 456 for sm in ptxas_supported_sms(ptxas_executable):457 config.available_features.add(f"ptxas-sm_{sm}")458 459 if ptxas_supports_address_size_32(ptxas_executable):460 config.available_features.add("ptxas-ptr32")461 462 463ptxas_executable = (464 os.environ.get("LLVM_PTXAS_EXECUTABLE", None) or config.ptxas_executable465)466if ptxas_executable:467 enable_ptxas(ptxas_executable)468 469llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)470 471# Targets472 473config.targets = frozenset(config.targets_to_build.split())474 475for arch in config.targets_to_build.split():476 config.available_features.add(arch.lower() + "-registered-target")477 478# Features479known_arches = ["x86_64", "mips64", "ppc64", "aarch64"]480if config.host_ldflags.find("-m32") < 0 and any(481 config.llvm_host_triple.startswith(x) for x in known_arches482):483 config.available_features.add("llvm-64-bits")484 485config.available_features.add("host-byteorder-" + sys.byteorder + "-endian")486if config.target_triple:487 if re.match(488 r"(aarch64_be|arc|armeb|bpfeb|lanai|m68k|mips|mips64|powerpc|powerpc64|sparc|sparcv9|sparc64|s390x|s390|tce|thumbeb)-.*",489 config.target_triple,490 ):491 config.available_features.add("target-byteorder-big-endian")492 else:493 config.available_features.add("target-byteorder-little-endian")494 495if sys.platform in ["win32", "cygwin"]:496 # ExecutionEngine, no weak symbols in COFF.497 config.available_features.add("uses_COFF")498 499if sys.platform not in ["win32"]:500 # Others/can-execute.txt501 config.available_features.add("can-execute")502 503# Detect Windows Subsystem for Linux (WSL)504uname_r = platform.uname().release505if uname_r.endswith("-Microsoft"):506 config.available_features.add("wsl1")507elif uname_r.endswith("microsoft-standard-WSL2"):508 config.available_features.add("wsl2")509 510# Loadable module511if config.has_plugins:512 config.available_features.add("plugins")513 514if config.build_examples:515 config.available_features.add("examples")516 517if config.linked_bye_extension:518 config.substitutions.append(("%llvmcheckext", "CHECK-EXT"))519 config.substitutions.append(("%loadbye", ""))520 config.substitutions.append(("%loadnewpmbye", ""))521else:522 config.substitutions.append(("%llvmcheckext", "CHECK-NOEXT"))523 config.substitutions.append(524 (525 "%loadbye",526 "-load={}/Bye{}".format(config.llvm_shlib_dir, config.llvm_shlib_ext),527 )528 )529 config.substitutions.append(530 (531 "%loadnewpmbye",532 "-load-pass-plugin={}/Bye{}".format(533 config.llvm_shlib_dir, config.llvm_shlib_ext534 ),535 )536 )537 538if config.linked_exampleirtransforms_extension:539 config.substitutions.append(("%loadexampleirtransforms", ""))540else:541 config.substitutions.append(542 (543 "%loadexampleirtransforms",544 "-load-pass-plugin={}/ExampleIRTransforms{}".format(545 config.llvm_shlib_dir, config.llvm_shlib_ext546 ),547 )548 )549 550# Static libraries are not built if BUILD_SHARED_LIBS is ON.551if not config.build_shared_libs and not config.link_llvm_dylib:552 config.available_features.add("static-libs")553 554if config.link_llvm_dylib:555 config.available_features.add("llvm-dylib")556 config.substitutions.append(557 (558 # libLLVM.so.19.0git559 "%llvmdylib",560 "{}/libLLVM{}.{}".format(561 config.llvm_shlib_dir, config.llvm_shlib_ext, config.llvm_dylib_version562 ),563 )564 )565 566if config.have_tf_aot:567 config.available_features.add("have_tf_aot")568 569if config.have_tflite:570 config.available_features.add("have_tflite")571 572if config.llvm_inliner_model_autogenerated:573 config.available_features.add("llvm_inliner_model_autogenerated")574 575if config.llvm_raevict_model_autogenerated:576 config.available_features.add("llvm_raevict_model_autogenerated")577 578 579def have_cxx_shared_library():580 readobj_exe = lit.util.which("llvm-readobj", config.llvm_tools_dir)581 if not readobj_exe:582 print("llvm-readobj not found")583 return False584 585 try:586 readobj_cmd = subprocess.Popen(587 [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE588 )589 except OSError:590 print("could not exec llvm-readobj")591 return False592 593 readobj_out = readobj_cmd.stdout.read().decode("utf-8")594 readobj_cmd.wait()595 596 regex = re.compile(r"(libc\+\+|libstdc\+\+|msvcp).*\.(so|dylib|dll)")597 needed_libs = False598 for line in readobj_out.splitlines():599 if "NeededLibraries [" in line:600 needed_libs = True601 if "]" in line:602 needed_libs = False603 if needed_libs and regex.search(line.lower()):604 return True605 return False606 607 608if have_cxx_shared_library():609 config.available_features.add("cxx-shared-library")610 611if config.libcxx_used:612 config.available_features.add("libcxx-used")613 614# LLVM can be configured with an empty default triple615# Some tests are "generic" and require a valid default triple616if config.target_triple:617 config.available_features.add("default_triple")618 # Direct object generation619 if not config.target_triple.startswith(("nvptx", "xcore")):620 config.available_features.add("object-emission")621 622if config.have_llvm_driver:623 config.available_features.add("llvm-driver")624 625import subprocess626 627 628def have_ld_plugin_support():629 if not os.path.exists(630 os.path.join(config.llvm_shlib_dir, "LLVMgold" + config.llvm_shlib_ext)631 ):632 return False633 634 ld_cmd = subprocess.Popen(635 [config.gold_executable, "--help"], stdout=subprocess.PIPE, env={"LANG": "C"}636 )637 ld_out = ld_cmd.stdout.read().decode()638 ld_cmd.wait()639 640 if not "-plugin" in ld_out:641 return False642 643 # check that the used emulations are supported.644 emu_line = [l for l in ld_out.split("\n") if "supported emulations" in l]645 if len(emu_line) != 1:646 return False647 emu_line = emu_line[0]648 fields = emu_line.split(":")649 if len(fields) != 3:650 return False651 emulations = fields[2].split()652 if "elf_x86_64" not in emulations:653 return False654 if "elf32ppc" in emulations:655 config.available_features.add("ld_emu_elf32ppc")656 657 ld_version = subprocess.Popen(658 [config.gold_executable, "--version"], stdout=subprocess.PIPE, env={"LANG": "C"}659 )660 if not "GNU gold" in ld_version.stdout.read().decode():661 return False662 ld_version.wait()663 664 return True665 666 667if have_ld_plugin_support():668 config.available_features.add("ld_plugin")669 670 671def have_ld64_plugin_support():672 if not os.path.exists(673 os.path.join(config.llvm_shlib_dir, "libLTO" + config.llvm_shlib_ext)674 ):675 return False676 677 if config.ld64_executable == "":678 return False679 680 ld_cmd = subprocess.Popen([config.ld64_executable, "-v"], stderr=subprocess.PIPE)681 ld_out = ld_cmd.stderr.read().decode()682 ld_cmd.wait()683 684 if "ld64" not in ld_out or "LTO" not in ld_out:685 return False686 687 return True688 689 690if have_ld64_plugin_support():691 config.available_features.add("ld64_plugin")692 693 694def host_unwind_supports_jit():695 # Do we expect the host machine to support JIT registration of clang's696 # default unwind info format for the host (e.g. eh-frames, compact-unwind,697 # etc.).698 699 # Linux and the BSDs use DWARF eh-frames and all known unwinders support700 # register_frame at minimum.701 if platform.system() in ["Linux", "FreeBSD", "NetBSD"]:702 return True703 704 # Windows does not support frame info without the ORC runtime.705 if platform.system() == "Windows":706 return False707 708 # On Darwin/x86-64 clang produces both eh-frames and compact-unwind, and709 # libunwind supports register_frame. On Darwin/arm64 clang produces710 # compact-unwind only, and JIT'd registration is not available before711 # macOS 14.0.712 if platform.system() == "Darwin":713 assert "arm64" in config.host_triple or "x86_64" in config.host_triple714 715 if "x86_64" in config.host_triple:716 return True717 718 # Must be arm64. Check the macOS version.719 try:720 osx_version = subprocess.check_output(721 ["sw_vers", "-productVersion"], universal_newlines=True722 )723 osx_version = tuple(int(x) for x in osx_version.split("."))724 if len(osx_version) == 2:725 osx_version = (osx_version[0], osx_version[1], 0)726 if osx_version >= (14, 0):727 return True728 except:729 pass730 731 return False732 733 return False734 735 736if host_unwind_supports_jit():737 config.available_features.add("host-unwind-supports-jit")738 739# Ask llvm-config about asserts740llvm_config.feature_config(741 [742 ("--assertion-mode", {"ON": "asserts"}),743 ("--build-mode", {"[Dd][Ee][Bb][Uu][Gg]": "debug"}),744 ]745)746 747if "darwin" == sys.platform:748 cmd = ["sysctl", "hw.optional.fma"]749 sysctl_cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE)750 751 # Non zero return, probably a permission issue752 if sysctl_cmd.wait():753 print(754 'Warning: sysctl exists but calling "{}" failed, defaulting to no fma3.'.format(755 " ".join(cmd)756 )757 )758 else:759 result = sysctl_cmd.stdout.read().decode("ascii")760 if "hw.optional.fma: 1" in result:761 config.available_features.add("fma3")762 763if not hasattr(sys, "getwindowsversion") or sys.getwindowsversion().build >= 17063:764 config.available_features.add("unix-sockets")765 766# .debug_frame is not emitted for targeting Windows x64, aarch64/arm64, AIX, or Apple Silicon Mac.767if (768 not re.match(769 r"^(x86_64|aarch64|arm64|powerpc|powerpc64).*-(windows-cygnus|windows-gnu|windows-msvc|aix)",770 config.target_triple,771 )772 and not re.match(773 r"^arm64(e)?-apple-(macos|darwin)",774 config.target_triple,775 )776 and not re.match(r".*-zos.*", config.target_triple)777):778 config.available_features.add("debug_frame")779 780if config.enable_backtrace:781 config.available_features.add("backtrace")782 783if config.enable_threads:784 config.available_features.add("thread_support")785 786if config.have_libxml2:787 config.available_features.add("libxml2")788 789if config.have_curl:790 config.available_features.add("curl")791 792if config.have_httplib:793 config.available_features.add("httplib")794 795if config.have_opt_viewer_modules:796 config.available_features.add("have_opt_viewer_modules")797 798if config.expensive_checks:799 config.available_features.add("expensive_checks")800 801if config.have_ondisk_cas:802 config.available_features.add("ondisk_cas")803 804if "MemoryWithOrigins" in config.llvm_use_sanitizer:805 config.available_features.add("use_msan_with_origins")806 807 808# Restrict the size of the on-disk CAS for tests. This allows testing in809# constrained environments (e.g. small TMPDIR). It also prevents leaving810# behind large files on file systems that do not support sparse files if a test811# crashes before resizing the file.812config.environment["LLVM_CAS_MAX_MAPPING_SIZE"] = "%d" % (100 * 1024 * 1024)813 814# Some tools support an environment variable "OBJECT_MODE" on AIX OS, which815# controls the kind of objects they will support. If there is no "OBJECT_MODE"816# environment variable specified, the default behaviour is to support 32-bit817# objects only. In order to not affect most test cases, which expect to support818# 32-bit and 64-bit objects by default, set the environment variable819# "OBJECT_MODE" to 'any' by default on AIX OS.820if "system-aix" in config.available_features:821 config.environment["OBJECT_MODE"] = "any"822 823if config.has_logf128:824 config.available_features.add("has_logf128")825 826if lit_config.update_tests:827 import sys828 import os829 830 utilspath = os.path.join(config.llvm_src_root, "utils")831 sys.path.append(utilspath)832 from update_any_test_checks import utc_lit_plugin833 834 lit_config.test_updaters.append(utc_lit_plugin)835