Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | # Configuration file for the 'lit' test runner. |
| 4 | |
| 5 | import os |
NAKAMURA Takumi | b3ccc12 | 2010-11-29 00:20:09 +0000 | [diff] [blame] | 6 | import sys |
David Greene | 18d4987 | 2011-01-03 17:30:25 +0000 | [diff] [blame] | 7 | import re |
Rafael Espindola | d2930d3 | 2012-10-26 02:19:02 +0000 | [diff] [blame] | 8 | import platform |
David L. Jones | 8804b79 | 2017-07-06 21:46:47 +0000 | [diff] [blame] | 9 | import subprocess |
Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 10 | |
Daniel Dunbar | 27c35d9 | 2013-08-09 16:22:05 +0000 | [diff] [blame] | 11 | import lit.util |
| 12 | import lit.formats |
Zachary Turner | 4af1a22 | 2017-09-16 18:46:21 +0000 | [diff] [blame] | 13 | from lit.llvm import llvm_config |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 14 | from lit.llvm.subst import FindTool |
| 15 | from lit.llvm.subst import ToolSubst |
Daniel Dunbar | 27c35d9 | 2013-08-09 16:22:05 +0000 | [diff] [blame] | 16 | |
Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 17 | # name: The name of this test suite. |
| 18 | config.name = 'LLVM' |
| 19 | |
| 20 | # testFormat: The test format to use to interpret tests. |
Zachary Turner | 4af1a22 | 2017-09-16 18:46:21 +0000 | [diff] [blame] | 21 | config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) |
Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 22 | |
Daniel Dunbar | 9d11edb | 2013-08-08 20:59:13 +0000 | [diff] [blame] | 23 | # suffixes: A list of file extensions to treat as test files. This is overriden |
| 24 | # by individual lit.local.cfg files in the test subdirectories. |
Matthias Braun | 7b7e713 | 2016-04-04 21:23:44 +0000 | [diff] [blame] | 25 | config.suffixes = ['.ll', '.c', '.cxx', '.test', '.txt', '.s', '.mir'] |
Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 26 | |
Chandler Carruth | 7e621f3 | 2012-07-02 10:18:06 +0000 | [diff] [blame] | 27 | # excludes: A list of directories to exclude from the testsuite. The 'Inputs' |
| 28 | # subdirectories contain auxiliary inputs for various tests in their parent |
| 29 | # directories. |
Daniel Dunbar | 24ec2e5 | 2013-08-16 00:37:11 +0000 | [diff] [blame] | 30 | config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt'] |
Chandler Carruth | 7e621f3 | 2012-07-02 10:18:06 +0000 | [diff] [blame] | 31 | |
Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 32 | # test_source_root: The root path where tests are located. |
| 33 | config.test_source_root = os.path.dirname(__file__) |
| 34 | |
| 35 | # test_exec_root: The root path where tests should be run. |
Zachary Turner | a0f1ea3 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 36 | config.test_exec_root = os.path.join(config.llvm_obj_root, 'test') |
Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 37 | |
Nico Rieck | 7e87373 | 2013-04-12 04:07:13 +0000 | [diff] [blame] | 38 | # Tweak the PATH to include the tools dir. |
Zachary Turner | 4af1a22 | 2017-09-16 18:46:21 +0000 | [diff] [blame] | 39 | llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True) |
Daniel Dunbar | 5ed7be1 | 2009-11-08 09:08:00 +0000 | [diff] [blame] | 40 | |
Zachary Turner | 4af1a22 | 2017-09-16 18:46:21 +0000 | [diff] [blame] | 41 | # Propagate some variables from the host environment. |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 42 | llvm_config.with_system_environment( |
| 43 | ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']) |
Michael J. Spencer | 44d392a | 2010-12-07 01:23:49 +0000 | [diff] [blame] | 44 | |
Daniel Dunbar | 9b2cb69 | 2010-06-12 16:21:19 +0000 | [diff] [blame] | 45 | |
Peter Zotov | 47f88b5 | 2014-10-30 08:29:45 +0000 | [diff] [blame] | 46 | # Set up OCAMLPATH to include newly built OCaml libraries. |
Zachary Turner | a0f1ea3 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 47 | top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml') |
| 48 | llvm_ocaml_lib = os.path.join(top_ocaml_lib, 'llvm') |
Peter Zotov | 95a8dca | 2014-11-03 09:50:53 +0000 | [diff] [blame] | 49 | |
Zachary Turner | 4af1a22 | 2017-09-16 18:46:21 +0000 | [diff] [blame] | 50 | llvm_config.with_system_environment('OCAMLPATH') |
| 51 | llvm_config.with_environment('OCAMLPATH', top_ocaml_lib, append_path=True) |
| 52 | llvm_config.with_environment('OCAMLPATH', llvm_ocaml_lib, append_path=True) |
| 53 | |
| 54 | llvm_config.with_system_environment('CAML_LD_LIBRARY_PATH') |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 55 | llvm_config.with_environment( |
| 56 | 'CAML_LD_LIBRARY_PATH', llvm_ocaml_lib, append_path=True) |
Peter Zotov | 47f88b5 | 2014-10-30 08:29:45 +0000 | [diff] [blame] | 57 | |
Peter Zotov | d1fc3a0 | 2014-10-30 08:29:57 +0000 | [diff] [blame] | 58 | # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests. |
Zachary Turner | 4af1a22 | 2017-09-16 18:46:21 +0000 | [diff] [blame] | 59 | llvm_config.with_environment('OCAMLRUNPARAM', 'b') |
Peter Zotov | d1fc3a0 | 2014-10-30 08:29:57 +0000 | [diff] [blame] | 60 | |
Bruno Cardoso Lopes | 749f338 | 2016-08-04 22:01:38 +0000 | [diff] [blame] | 61 | # Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if |
| 62 | # available. This is darwin specific since it's currently only needed on darwin. |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 63 | |
| 64 | |
Bruno Cardoso Lopes | 749f338 | 2016-08-04 22:01:38 +0000 | [diff] [blame] | 65 | def get_asan_rtlib(): |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 66 | if not 'Address' in config.llvm_use_sanitizer or \ |
| 67 | not 'Darwin' in config.host_os or \ |
| 68 | not 'x86' in config.host_triple: |
| 69 | return '' |
Bruno Cardoso Lopes | 749f338 | 2016-08-04 22:01:38 +0000 | [diff] [blame] | 70 | try: |
| 71 | import glob |
| 72 | except: |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 73 | print('glob module not found, skipping get_asan_rtlib() lookup') |
| 74 | return '' |
Bruno Cardoso Lopes | 749f338 | 2016-08-04 22:01:38 +0000 | [diff] [blame] | 75 | # The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative |
| 76 | # path from the host cc. |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 77 | host_lib_dir = os.path.join(os.path.dirname(config.host_cc), '../lib') |
Bruno Cardoso Lopes | 749f338 | 2016-08-04 22:01:38 +0000 | [diff] [blame] | 78 | asan_dylib_dir_pattern = host_lib_dir + \ |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 79 | '/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib' |
Bruno Cardoso Lopes | 749f338 | 2016-08-04 22:01:38 +0000 | [diff] [blame] | 80 | found_dylibs = glob.glob(asan_dylib_dir_pattern) |
| 81 | if len(found_dylibs) != 1: |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 82 | return '' |
Bruno Cardoso Lopes | 749f338 | 2016-08-04 22:01:38 +0000 | [diff] [blame] | 83 | return found_dylibs[0] |
| 84 | |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 85 | |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 86 | llvm_config.use_default_substitutions() |
| 87 | |
| 88 | # Add site-specific substitutions. |
| 89 | config.substitutions.append(('%llvmshlibdir', config.llvm_shlib_dir)) |
| 90 | config.substitutions.append(('%shlibext', config.llvm_shlib_ext)) |
| 91 | config.substitutions.append(('%exeext', config.llvm_exe_ext)) |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 92 | |
| 93 | |
| 94 | lli_args = [] |
Peter Collingbourne | fbb662f | 2013-01-16 17:27:22 +0000 | [diff] [blame] | 95 | # The target triple used by default by lli is the process target triple (some |
| 96 | # triple appropriate for generating code for the current process) but because |
| 97 | # we don't support COFF in MCJIT well enough for the tests, force ELF format on |
| 98 | # Windows. FIXME: the process target triple should be used here, but this is |
| 99 | # difficult to obtain on Windows. |
Petr Hosek | 13ced78 | 2018-08-09 02:16:18 +0000 | [diff] [blame] | 100 | if re.search(r'cygwin|windows-gnu|windows-msvc', config.host_triple): |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 101 | lli_args = ['-mtriple=' + config.host_triple + '-elf'] |
| 102 | |
| 103 | llc_args = [] |
Andrew Kaylor | 7bbd6e3 | 2012-10-02 18:38:34 +0000 | [diff] [blame] | 104 | |
Petr Hosek | 13ced78 | 2018-08-09 02:16:18 +0000 | [diff] [blame] | 105 | # Similarly, have a macro to use llc with DWARF even when the host is Windows |
| 106 | if re.search(r'windows-msvc', config.target_triple): |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 107 | llc_args = [' -mtriple=' + |
Petr Hosek | 13ced78 | 2018-08-09 02:16:18 +0000 | [diff] [blame] | 108 | config.target_triple.replace('-msvc', '-gnu')] |
Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 109 | |
Bruno Cardoso Lopes | 749f338 | 2016-08-04 22:01:38 +0000 | [diff] [blame] | 110 | # Provide the path to asan runtime lib if available. On darwin, this lib needs |
| 111 | # to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files |
| 112 | # to be linked contain instrumented sanitizer code. |
Bruno Cardoso Lopes | 4544896 | 2016-08-04 23:58:30 +0000 | [diff] [blame] | 113 | ld64_cmd = config.ld64_executable |
| 114 | asan_rtlib = get_asan_rtlib() |
| 115 | if asan_rtlib: |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 116 | ld64_cmd = 'DYLD_INSERT_LIBRARIES={} {}'.format(asan_rtlib, ld64_cmd) |
Bruno Cardoso Lopes | 749f338 | 2016-08-04 22:01:38 +0000 | [diff] [blame] | 117 | |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 118 | ocamlc_command = '%s ocamlc -cclib -L%s %s' % ( |
| 119 | config.ocamlfind_executable, config.llvm_lib_dir, config.ocaml_flags) |
| 120 | ocamlopt_command = 'true' |
Michal Gorny | 1159e42 | 2017-01-06 21:33:48 +0000 | [diff] [blame] | 121 | if config.have_ocamlopt: |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 122 | ocamlopt_command = '%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s' % ( |
| 123 | config.ocamlfind_executable, config.llvm_lib_dir, config.llvm_lib_dir, config.ocaml_flags) |
Peter Zotov | b4d023a | 2014-10-28 22:39:36 +0000 | [diff] [blame] | 124 | |
Adam Nemet | d3ee065 | 2017-11-29 17:07:41 +0000 | [diff] [blame] | 125 | opt_viewer_cmd = '%s %s/tools/opt-viewer/opt-viewer.py' % (sys.executable, config.llvm_src_root) |
Paul Robinson | b9d6263 | 2014-03-21 17:31:35 +0000 | [diff] [blame] | 126 | |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 127 | tools = [ |
| 128 | ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args), |
| 129 | ToolSubst('%llc_dwarf', FindTool('llc'), extra_args=llc_args), |
| 130 | ToolSubst('%go', config.go_executable, unresolved='ignore'), |
| 131 | ToolSubst('%gold', config.gold_executable, unresolved='ignore'), |
| 132 | ToolSubst('%ld64', ld64_cmd, unresolved='ignore'), |
| 133 | ToolSubst('%ocamlc', ocamlc_command, unresolved='ignore'), |
| 134 | ToolSubst('%ocamlopt', ocamlopt_command, unresolved='ignore'), |
Adam Nemet | d3ee065 | 2017-11-29 17:07:41 +0000 | [diff] [blame] | 135 | ToolSubst('%opt-viewer', opt_viewer_cmd), |
Yunlian Jiang | edd00e4 | 2018-04-13 05:03:28 +0000 | [diff] [blame] | 136 | ToolSubst('%llvm-objcopy', FindTool('llvm-objcopy')), |
Alexander Shaposhnikov | 6608b6d | 2018-05-07 21:07:01 +0000 | [diff] [blame] | 137 | ToolSubst('%llvm-strip', FindTool('llvm-strip')), |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 138 | ] |
Eli Bendersky | dafd1a6 | 2013-06-14 19:14:52 +0000 | [diff] [blame] | 139 | |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 140 | # FIXME: Why do we have both `lli` and `%lli` that do slightly different things? |
| 141 | tools.extend([ |
Clement Courbet | 7167e4d | 2018-09-25 13:59:35 +0000 | [diff] [blame] | 142 | 'dsymutil', 'lli', 'lli-child-target', 'llvm-ar', 'llvm-as', |
| 143 | 'llvm-bcanalyzer', 'llvm-config', 'llvm-cov', 'llvm-cxxdump', 'llvm-cvtres', |
| 144 | 'llvm-diff', 'llvm-dis', 'llvm-dwarfdump', 'llvm-exegesis', 'llvm-extract', |
| 145 | 'llvm-isel-fuzzer', 'llvm-opt-fuzzer', 'llvm-lib', 'llvm-link', 'llvm-lto', |
| 146 | 'llvm-lto2', 'llvm-mc', 'llvm-mca', 'llvm-modextract', 'llvm-nm', |
| 147 | 'llvm-objcopy', 'llvm-objdump', 'llvm-pdbutil', 'llvm-profdata', |
James Henderson | a4a9a18 | 2018-12-12 10:34:01 +0000 | [diff] [blame] | 148 | 'llvm-ranlib', 'llvm-readelf', 'llvm-readobj', 'llvm-rtdyld', 'llvm-size', |
| 149 | 'llvm-split', 'llvm-strings', 'llvm-strip', 'llvm-tblgen', 'llvm-undname', |
| 150 | 'llvm-c-test', 'llvm-cxxfilt', 'llvm-xray', 'yaml2obj', 'obj2yaml', |
| 151 | 'yaml-bench', 'verify-uselistorder', 'bugpoint', 'llc', 'llvm-symbolizer', |
| 152 | 'opt', 'sancov', 'sanstats']) |
Justin Bogner | a2c5cae | 2015-09-02 18:03:01 +0000 | [diff] [blame] | 153 | |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 154 | # The following tools are optional |
| 155 | tools.extend([ |
| 156 | ToolSubst('llvm-go', unresolved='ignore'), |
| 157 | ToolSubst('llvm-mt', unresolved='ignore'), |
| 158 | ToolSubst('Kaleidoscope-Ch3', unresolved='ignore'), |
| 159 | ToolSubst('Kaleidoscope-Ch4', unresolved='ignore'), |
| 160 | ToolSubst('Kaleidoscope-Ch5', unresolved='ignore'), |
| 161 | ToolSubst('Kaleidoscope-Ch6', unresolved='ignore'), |
| 162 | ToolSubst('Kaleidoscope-Ch7', unresolved='ignore'), |
| 163 | ToolSubst('Kaleidoscope-Ch8', unresolved='ignore')]) |
Justin Bogner | a2c5cae | 2015-09-02 18:03:01 +0000 | [diff] [blame] | 164 | |
Zachary Turner | 19ac6f8 | 2017-10-06 17:54:46 +0000 | [diff] [blame] | 165 | llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir) |
Justin Bogner | a2c5cae | 2015-09-02 18:03:01 +0000 | [diff] [blame] | 166 | |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 167 | # Targets |
Alp Toker | 8aeca44 | 2014-06-09 22:42:55 +0000 | [diff] [blame] | 168 | |
| 169 | config.targets = frozenset(config.targets_to_build.split()) |
| 170 | |
Reid Kleckner | d3396f4 | 2016-08-10 19:03:18 +0000 | [diff] [blame] | 171 | for arch in config.targets_to_build.split(): |
| 172 | config.available_features.add(arch.lower() + '-registered-target') |
| 173 | |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 174 | # Features |
Jake Ehrlich | 56898c1 | 2017-11-02 23:14:55 +0000 | [diff] [blame] | 175 | known_arches = ["x86_64", "mips64", "ppc64", "aarch64"] |
NAKAMURA Takumi | ce4da27 | 2017-11-04 06:55:55 +0000 | [diff] [blame] | 176 | if (config.host_ldflags.find("-m32") < 0 |
| 177 | and any(config.llvm_host_triple.startswith(x) for x in known_arches)): |
Jake Ehrlich | 56898c1 | 2017-11-02 23:14:55 +0000 | [diff] [blame] | 178 | config.available_features.add("llvm-64-bits") |
NAKAMURA Takumi | b3ccc12 | 2010-11-29 00:20:09 +0000 | [diff] [blame] | 179 | |
NAKAMURA Takumi | 7e980a6 | 2013-06-26 10:56:44 +0000 | [diff] [blame] | 180 | # Others/can-execute.txt |
| 181 | if sys.platform not in ['win32']: |
| 182 | config.available_features.add('can-execute') |
Lang Hames | d5ab2f8 | 2016-08-09 20:48:22 +0000 | [diff] [blame] | 183 | config.available_features.add('not_COFF') |
NAKAMURA Takumi | 7e980a6 | 2013-06-26 10:56:44 +0000 | [diff] [blame] | 184 | |
NAKAMURA Takumi | b3ccc12 | 2010-11-29 00:20:09 +0000 | [diff] [blame] | 185 | # Loadable module |
| 186 | # FIXME: This should be supplied by Makefile or autoconf. |
| 187 | if sys.platform in ['win32', 'cygwin']: |
| 188 | loadable_module = (config.enable_shared == 1) |
| 189 | else: |
| 190 | loadable_module = True |
| 191 | |
| 192 | if loadable_module: |
| 193 | config.available_features.add('loadable_module') |
Andrew Trick | f2a5842 | 2011-06-22 23:23:19 +0000 | [diff] [blame] | 194 | |
Michal Gorny | 4d35239 | 2017-01-06 21:33:54 +0000 | [diff] [blame] | 195 | # Static libraries are not built if BUILD_SHARED_LIBS is ON. |
Sam Clegg | 88d22be | 2017-10-18 19:37:30 +0000 | [diff] [blame] | 196 | if not config.build_shared_libs and not config.link_llvm_dylib: |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 197 | config.available_features.add('static-libs') |
Michal Gorny | 4d35239 | 2017-01-06 21:33:54 +0000 | [diff] [blame] | 198 | |
Petr Hosek | b10b158 | 2018-01-08 02:48:41 +0000 | [diff] [blame] | 199 | def have_cxx_shared_library(): |
| 200 | readobj_exe = lit.util.which('llvm-readobj', config.llvm_tools_dir) |
| 201 | if not readobj_exe: |
| 202 | print('llvm-readobj not found') |
| 203 | return False |
| 204 | |
| 205 | try: |
| 206 | readobj_cmd = subprocess.Popen( |
| 207 | [readobj_exe, '-needed-libs', readobj_exe], stdout=subprocess.PIPE) |
| 208 | except OSError: |
| 209 | print('could not exec llvm-readobj') |
| 210 | return False |
| 211 | |
| 212 | readobj_out = readobj_cmd.stdout.read().decode('ascii') |
| 213 | readobj_cmd.wait() |
| 214 | |
| 215 | regex = re.compile(r'(libc\+\+|libstdc\+\+|msvcp).*\.(so|dylib|dll)') |
| 216 | needed_libs = False |
| 217 | for line in readobj_out.splitlines(): |
| 218 | if 'NeededLibraries [' in line: |
| 219 | needed_libs = True |
| 220 | if ']' in line: |
| 221 | needed_libs = False |
| 222 | if needed_libs and regex.search(line.lower()): |
| 223 | return True |
| 224 | return False |
| 225 | |
| 226 | if have_cxx_shared_library(): |
| 227 | config.available_features.add('cxx-shared-library') |
| 228 | |
Jyotsna Verma | f0ca9a8 | 2013-04-10 19:53:26 +0000 | [diff] [blame] | 229 | # Direct object generation |
NAKAMURA Takumi | 01e490b | 2015-12-20 03:48:23 +0000 | [diff] [blame] | 230 | if not 'hexagon' in config.target_triple: |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 231 | config.available_features.add('object-emission') |
Jyotsna Verma | f0ca9a8 | 2013-04-10 19:53:26 +0000 | [diff] [blame] | 232 | |
Mehdi Amini | 793a2b1 | 2015-09-16 05:34:32 +0000 | [diff] [blame] | 233 | # LLVM can be configured with an empty default triple |
| 234 | # Some tests are "generic" and require a valid default triple |
| 235 | if config.target_triple: |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 236 | config.available_features.add('default_triple') |
Amaury de la Vieuville | 2c9d79b | 2013-09-13 10:59:01 +0000 | [diff] [blame] | 237 | |
NAKAMURA Takumi | f86186e | 2011-11-28 05:09:15 +0000 | [diff] [blame] | 238 | import subprocess |
Rafael Espindola | 12cc465 | 2014-07-27 23:11:06 +0000 | [diff] [blame] | 239 | |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 240 | |
Rafael Espindola | 12cc465 | 2014-07-27 23:11:06 +0000 | [diff] [blame] | 241 | def have_ld_plugin_support(): |
Eugene Leviant | 737553b | 2018-06-20 15:32:47 +0000 | [diff] [blame] | 242 | if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold' + config.llvm_shlib_ext)): |
Rafael Espindola | 12cc465 | 2014-07-27 23:11:06 +0000 | [diff] [blame] | 243 | return False |
| 244 | |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 245 | ld_cmd = subprocess.Popen( |
| 246 | [config.gold_executable, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'}) |
NAKAMURA Takumi | 19d9f34 | 2015-01-05 14:18:04 +0000 | [diff] [blame] | 247 | ld_out = ld_cmd.stdout.read().decode() |
Rafael Espindola | 12cc465 | 2014-07-27 23:11:06 +0000 | [diff] [blame] | 248 | ld_cmd.wait() |
| 249 | |
Rafael Espindola | bc64560 | 2014-11-11 05:27:12 +0000 | [diff] [blame] | 250 | if not '-plugin' in ld_out: |
| 251 | return False |
| 252 | |
| 253 | # check that the used emulations are supported. |
| 254 | emu_line = [l for l in ld_out.split('\n') if 'supported emulations' in l] |
| 255 | if len(emu_line) != 1: |
| 256 | return False |
| 257 | emu_line = emu_line[0] |
| 258 | fields = emu_line.split(':') |
| 259 | if len(fields) != 3: |
| 260 | return False |
| 261 | emulations = fields[2].split() |
Peter Collingbourne | 5e86804 | 2015-03-19 18:23:31 +0000 | [diff] [blame] | 262 | if 'elf_x86_64' not in emulations: |
Rafael Espindola | bc64560 | 2014-11-11 05:27:12 +0000 | [diff] [blame] | 263 | return False |
Peter Collingbourne | 5e86804 | 2015-03-19 18:23:31 +0000 | [diff] [blame] | 264 | if 'elf32ppc' in emulations: |
| 265 | config.available_features.add('ld_emu_elf32ppc') |
Rafael Espindola | bc64560 | 2014-11-11 05:27:12 +0000 | [diff] [blame] | 266 | |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 267 | ld_version = subprocess.Popen( |
| 268 | [config.gold_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 'C'}) |
Chandler Carruth | 45d67e9 | 2015-02-14 09:05:56 +0000 | [diff] [blame] | 269 | if not 'GNU gold' in ld_version.stdout.read().decode(): |
Rafael Espindola | 12cc465 | 2014-07-27 23:11:06 +0000 | [diff] [blame] | 270 | return False |
| 271 | ld_version.wait() |
| 272 | |
| 273 | return True |
| 274 | |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 275 | |
Rafael Espindola | 12cc465 | 2014-07-27 23:11:06 +0000 | [diff] [blame] | 276 | if have_ld_plugin_support(): |
| 277 | config.available_features.add('ld_plugin') |
| 278 | |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 279 | |
Peter Collingbourne | aa01400 | 2015-03-19 23:55:38 +0000 | [diff] [blame] | 280 | def have_ld64_plugin_support(): |
Michal Gorny | 1159e42 | 2017-01-06 21:33:48 +0000 | [diff] [blame] | 281 | if not config.llvm_tool_lto_build or config.ld64_executable == '': |
Peter Collingbourne | aa01400 | 2015-03-19 23:55:38 +0000 | [diff] [blame] | 282 | return False |
| 283 | |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 284 | ld_cmd = subprocess.Popen( |
| 285 | [config.ld64_executable, '-v'], stderr=subprocess.PIPE) |
Peter Collingbourne | aa01400 | 2015-03-19 23:55:38 +0000 | [diff] [blame] | 286 | ld_out = ld_cmd.stderr.read().decode() |
| 287 | ld_cmd.wait() |
| 288 | |
| 289 | if 'ld64' not in ld_out or 'LTO' not in ld_out: |
| 290 | return False |
| 291 | |
| 292 | return True |
| 293 | |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 294 | |
Peter Collingbourne | aa01400 | 2015-03-19 23:55:38 +0000 | [diff] [blame] | 295 | if have_ld64_plugin_support(): |
| 296 | config.available_features.add('ld64_plugin') |
| 297 | |
Zachary Turner | 4af1a22 | 2017-09-16 18:46:21 +0000 | [diff] [blame] | 298 | # Ask llvm-config about asserts and global-isel. |
Zachary Turner | af03e79 | 2017-09-18 22:26:48 +0000 | [diff] [blame] | 299 | llvm_config.feature_config( |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 300 | [('--assertion-mode', {'ON': 'asserts'}), |
| 301 | ('--has-global-isel', {'ON': 'global-isel'})]) |
David Dean | 2c3c7fd | 2013-07-11 23:36:57 +0000 | [diff] [blame] | 302 | |
Nadav Rotem | 9397683 | 2013-08-21 05:02:12 +0000 | [diff] [blame] | 303 | if 'darwin' == sys.platform: |
| 304 | try: |
| 305 | sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'], |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 306 | stdout=subprocess.PIPE) |
Nadav Rotem | 9397683 | 2013-08-21 05:02:12 +0000 | [diff] [blame] | 307 | except OSError: |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 308 | print('Could not exec sysctl') |
Daniel Dunbar | 51a0b77 | 2013-08-21 22:26:44 +0000 | [diff] [blame] | 309 | result = sysctl_cmd.stdout.read().decode('ascii') |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 310 | if -1 != result.find('hw.optional.fma: 1'): |
Nadav Rotem | 9397683 | 2013-08-21 05:02:12 +0000 | [diff] [blame] | 311 | config.available_features.add('fma3') |
| 312 | sysctl_cmd.wait() |
| 313 | |
NAKAMURA Takumi | fe755c5 | 2014-06-22 12:35:39 +0000 | [diff] [blame] | 314 | # .debug_frame is not emitted for targeting Windows x64. |
Petr Hosek | 13ced78 | 2018-08-09 02:16:18 +0000 | [diff] [blame] | 315 | if not re.match(r'^x86_64.*-(windows-gnu|windows-msvc)', config.target_triple): |
NAKAMURA Takumi | fe755c5 | 2014-06-22 12:35:39 +0000 | [diff] [blame] | 316 | config.available_features.add('debug_frame') |
| 317 | |
Kevin Enderby | 866cdd5 | 2016-05-23 21:34:12 +0000 | [diff] [blame] | 318 | if config.have_libxar: |
| 319 | config.available_features.add('xar') |
NAKAMURA Takumi | 4e7fb91 | 2017-06-07 00:22:52 +0000 | [diff] [blame] | 320 | |
Lang Hames | 91c25db | 2018-09-26 16:26:59 +0000 | [diff] [blame] | 321 | if config.enable_threads: |
| 322 | config.available_features.add('thread_support') |
| 323 | |
Zachary Turner | e959bd0 | 2017-10-06 17:54:27 +0000 | [diff] [blame] | 324 | if config.llvm_libxml2_enabled == '1': |
Eric Beckmann | b99edc0 | 2017-07-27 01:11:53 +0000 | [diff] [blame] | 325 | config.available_features.add('libxml2') |
Adam Nemet | d3ee065 | 2017-11-29 17:07:41 +0000 | [diff] [blame] | 326 | |
| 327 | if config.have_opt_viewer_modules: |
| 328 | config.available_features.add('have_opt_viewer_modules') |