• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- Python -*-
2
3# Configuration file for the 'lit' test runner.
4
5import os
6import sys
7import re
8import platform
9import subprocess
10
11import lit.util
12import lit.formats
13from lit.llvm import llvm_config
14from lit.llvm.subst import FindTool
15from lit.llvm.subst import ToolSubst
16
17# name: The name of this test suite.
18config.name = 'LLVM'
19
20# testFormat: The test format to use to interpret tests.
21config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
22
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.
25config.suffixes = ['.ll', '.c', '.test', '.txt', '.s', '.mir', '.yaml']
26
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.
30config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
31
32# test_source_root: The root path where tests are located.
33config.test_source_root = os.path.dirname(__file__)
34
35# test_exec_root: The root path where tests should be run.
36config.test_exec_root = os.path.join(config.llvm_obj_root, 'test')
37
38# Tweak the PATH to include the tools dir.
39llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
40
41# Propagate some variables from the host environment.
42llvm_config.with_system_environment(
43    ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
44
45
46# Set up OCAMLPATH to include newly built OCaml libraries.
47top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml')
48llvm_ocaml_lib = os.path.join(top_ocaml_lib, 'llvm')
49
50llvm_config.with_system_environment('OCAMLPATH')
51llvm_config.with_environment('OCAMLPATH', top_ocaml_lib, append_path=True)
52llvm_config.with_environment('OCAMLPATH', llvm_ocaml_lib, append_path=True)
53
54llvm_config.with_system_environment('CAML_LD_LIBRARY_PATH')
55llvm_config.with_environment(
56    'CAML_LD_LIBRARY_PATH', llvm_ocaml_lib, append_path=True)
57
58# Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
59llvm_config.with_environment('OCAMLRUNPARAM', 'b')
60
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.
63
64
65def get_asan_rtlib():
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 ''
70    try:
71        import glob
72    except:
73        print('glob module not found, skipping get_asan_rtlib() lookup')
74        return ''
75    # The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative
76    # path from the host cc.
77    host_lib_dir = os.path.join(os.path.dirname(config.host_cc), '../lib')
78    asan_dylib_dir_pattern = host_lib_dir + \
79        '/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib'
80    found_dylibs = glob.glob(asan_dylib_dir_pattern)
81    if len(found_dylibs) != 1:
82        return ''
83    return found_dylibs[0]
84
85# Define this first. Afterwards, use_default_substitutions will add the rule for
86# expanding FileCheck to the full path.
87config.substitutions.append(('%FileCheckWithUnusedPrefixes%',
88    'FileCheck --allow-unused-prefixes=true'))
89
90llvm_config.use_default_substitutions()
91
92# Add site-specific substitutions.
93config.substitutions.append(('%llvmshlibdir', config.llvm_shlib_dir))
94config.substitutions.append(('%shlibext', config.llvm_shlib_ext))
95config.substitutions.append(('%exeext', config.llvm_exe_ext))
96
97
98lli_args = []
99# The target triple used by default by lli is the process target triple (some
100# triple appropriate for generating code for the current process) but because
101# we don't support COFF in MCJIT well enough for the tests, force ELF format on
102# Windows.  FIXME: the process target triple should be used here, but this is
103# difficult to obtain on Windows.
104if re.search(r'cygwin|windows-gnu|windows-msvc', config.host_triple):
105    lli_args = ['-mtriple=' + config.host_triple + '-elf']
106
107llc_args = []
108
109# Similarly, have a macro to use llc with DWARF even when the host is Windows
110if re.search(r'windows-msvc', config.target_triple):
111    llc_args = [' -mtriple=' +
112                config.target_triple.replace('-msvc', '-gnu')]
113
114# Provide the path to asan runtime lib if available. On darwin, this lib needs
115# to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files
116# to be linked contain instrumented sanitizer code.
117ld64_cmd = config.ld64_executable
118asan_rtlib = get_asan_rtlib()
119if asan_rtlib:
120    ld64_cmd = 'DYLD_INSERT_LIBRARIES={} {}'.format(asan_rtlib, ld64_cmd)
121
122ocamlc_command = '%s ocamlc -cclib -L%s %s' % (
123    config.ocamlfind_executable, config.llvm_lib_dir, config.ocaml_flags)
124ocamlopt_command = 'true'
125if config.have_ocamlopt:
126    ocamlopt_command = '%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s' % (
127        config.ocamlfind_executable, config.llvm_lib_dir, config.llvm_lib_dir, config.ocaml_flags)
128
129opt_viewer_cmd = '%s %s/tools/opt-viewer/opt-viewer.py' % (sys.executable, config.llvm_src_root)
130
131llvm_locstats_tool = os.path.join(config.llvm_tools_dir, 'llvm-locstats')
132config.substitutions.append(
133    ('%llvm-locstats', "'%s' %s" % (config.python_executable, llvm_locstats_tool)))
134config.llvm_locstats_used = os.path.exists(llvm_locstats_tool)
135
136tools = [
137    ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args),
138    ToolSubst('%llc_dwarf', FindTool('llc'), extra_args=llc_args),
139    ToolSubst('%go', config.go_executable, unresolved='ignore'),
140    ToolSubst('%gold', config.gold_executable, unresolved='ignore'),
141    ToolSubst('%ld64', ld64_cmd, unresolved='ignore'),
142    ToolSubst('%ocamlc', ocamlc_command, unresolved='ignore'),
143    ToolSubst('%ocamlopt', ocamlopt_command, unresolved='ignore'),
144    ToolSubst('%opt-viewer', opt_viewer_cmd),
145    ToolSubst('%llvm-objcopy', FindTool('llvm-objcopy')),
146    ToolSubst('%llvm-strip', FindTool('llvm-strip')),
147    ToolSubst('%llvm-install-name-tool', FindTool('llvm-install-name-tool')),
148    ToolSubst('%llvm-bitcode-strip', FindTool('llvm-bitcode-strip')),
149    ToolSubst('%split-file', FindTool('split-file')),
150]
151
152# FIXME: Why do we have both `lli` and `%lli` that do slightly different things?
153tools.extend([
154    'dsymutil', 'lli', 'lli-child-target', 'llvm-ar', 'llvm-as',
155    'llvm-addr2line', 'llvm-bcanalyzer', 'llvm-bitcode-strip', 'llvm-config',
156    'llvm-cov', 'llvm-cxxdump', 'llvm-cvtres', 'llvm-diff', 'llvm-dis',
157    'llvm-dwarfdump', 'llvm-dlltool', 'llvm-exegesis', 'llvm-extract',
158    'llvm-isel-fuzzer', 'llvm-ifs',
159    'llvm-install-name-tool', 'llvm-jitlink', 'llvm-opt-fuzzer', 'llvm-lib',
160    'llvm-link', 'llvm-lto', 'llvm-lto2', 'llvm-mc', 'llvm-mca',
161    'llvm-modextract', 'llvm-nm', 'llvm-objcopy', 'llvm-objdump',
162    'llvm-pdbutil', 'llvm-profdata', 'llvm-ranlib', 'llvm-rc', 'llvm-readelf',
163    'llvm-readobj', 'llvm-rtdyld', 'llvm-size', 'llvm-split', 'llvm-strings',
164    'llvm-strip', 'llvm-tblgen', 'llvm-undname', 'llvm-c-test', 'llvm-cxxfilt',
165    'llvm-xray', 'yaml2obj', 'obj2yaml', 'yaml-bench', 'verify-uselistorder',
166    'bugpoint', 'llc', 'llvm-symbolizer', 'opt', 'sancov', 'sanstats'])
167
168# The following tools are optional
169tools.extend([
170    ToolSubst('llvm-go', unresolved='ignore'),
171    ToolSubst('llvm-mt', unresolved='ignore'),
172    ToolSubst('Kaleidoscope-Ch3', unresolved='ignore'),
173    ToolSubst('Kaleidoscope-Ch4', unresolved='ignore'),
174    ToolSubst('Kaleidoscope-Ch5', unresolved='ignore'),
175    ToolSubst('Kaleidoscope-Ch6', unresolved='ignore'),
176    ToolSubst('Kaleidoscope-Ch7', unresolved='ignore'),
177    ToolSubst('Kaleidoscope-Ch8', unresolved='ignore'),
178    ToolSubst('LLJITWithThinLTOSummaries', unresolved='ignore')])
179
180llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)
181
182# Targets
183
184config.targets = frozenset(config.targets_to_build.split())
185
186for arch in config.targets_to_build.split():
187    config.available_features.add(arch.lower() + '-registered-target')
188
189# Features
190known_arches = ["x86_64", "mips64", "ppc64", "aarch64"]
191if (config.host_ldflags.find("-m32") < 0
192    and any(config.llvm_host_triple.startswith(x) for x in known_arches)):
193  config.available_features.add("llvm-64-bits")
194
195config.available_features.add("host-byteorder-" + sys.byteorder + "-endian")
196
197if sys.platform in ['win32']:
198    # ExecutionEngine, no weak symbols in COFF.
199    config.available_features.add('uses_COFF')
200else:
201    # Others/can-execute.txt
202    config.available_features.add('can-execute')
203
204# Loadable module
205if config.has_plugins:
206    config.available_features.add('plugins')
207
208if config.build_examples:
209    config.available_features.add('examples')
210
211if config.linked_bye_extension:
212    config.substitutions.append(('%llvmcheckext', 'CHECK-EXT'))
213    config.substitutions.append(('%loadbye', ''))
214    config.substitutions.append(('%loadnewpmbye', ''))
215else:
216    config.substitutions.append(('%llvmcheckext', 'CHECK-NOEXT'))
217    config.substitutions.append(('%loadbye',
218                                 '-load={}/Bye{}'.format(config.llvm_shlib_dir,
219                                                         config.llvm_shlib_ext)))
220    config.substitutions.append(('%loadnewpmbye',
221                                 '-load-pass-plugin={}/Bye{}'
222                                 .format(config.llvm_shlib_dir,
223                                         config.llvm_shlib_ext)))
224
225
226# Static libraries are not built if BUILD_SHARED_LIBS is ON.
227if not config.build_shared_libs and not config.link_llvm_dylib:
228    config.available_features.add('static-libs')
229
230if config.have_tf_aot:
231    config.available_features.add("have_tf_aot")
232
233if config.have_tf_api:
234    config.available_features.add("have_tf_api")
235
236def have_cxx_shared_library():
237    readobj_exe = lit.util.which('llvm-readobj', config.llvm_tools_dir)
238    if not readobj_exe:
239        print('llvm-readobj not found')
240        return False
241
242    try:
243        readobj_cmd = subprocess.Popen(
244            [readobj_exe, '-needed-libs', readobj_exe], stdout=subprocess.PIPE)
245    except OSError:
246        print('could not exec llvm-readobj')
247        return False
248
249    readobj_out = readobj_cmd.stdout.read().decode('ascii')
250    readobj_cmd.wait()
251
252    regex = re.compile(r'(libc\+\+|libstdc\+\+|msvcp).*\.(so|dylib|dll)')
253    needed_libs = False
254    for line in readobj_out.splitlines():
255        if 'NeededLibraries [' in line:
256            needed_libs = True
257        if ']' in line:
258            needed_libs = False
259        if needed_libs and regex.search(line.lower()):
260            return True
261    return False
262
263if have_cxx_shared_library():
264    config.available_features.add('cxx-shared-library')
265
266if config.libcxx_used:
267    config.available_features.add('libcxx-used')
268
269# LLVM can be configured with an empty default triple
270# Some tests are "generic" and require a valid default triple
271if config.target_triple:
272    config.available_features.add('default_triple')
273
274import subprocess
275
276
277def have_ld_plugin_support():
278    if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold' + config.llvm_shlib_ext)):
279        return False
280
281    ld_cmd = subprocess.Popen(
282        [config.gold_executable, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
283    ld_out = ld_cmd.stdout.read().decode()
284    ld_cmd.wait()
285
286    if not '-plugin' in ld_out:
287        return False
288
289    # check that the used emulations are supported.
290    emu_line = [l for l in ld_out.split('\n') if 'supported emulations' in l]
291    if len(emu_line) != 1:
292        return False
293    emu_line = emu_line[0]
294    fields = emu_line.split(':')
295    if len(fields) != 3:
296        return False
297    emulations = fields[2].split()
298    if 'elf_x86_64' not in emulations:
299        return False
300    if 'elf32ppc' in emulations:
301        config.available_features.add('ld_emu_elf32ppc')
302
303    ld_version = subprocess.Popen(
304        [config.gold_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 'C'})
305    if not 'GNU gold' in ld_version.stdout.read().decode():
306        return False
307    ld_version.wait()
308
309    return True
310
311
312if have_ld_plugin_support():
313    config.available_features.add('ld_plugin')
314
315
316def have_ld64_plugin_support():
317    if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO' + config.llvm_shlib_ext)):
318        return False
319
320    if config.ld64_executable == '':
321        return False
322
323    ld_cmd = subprocess.Popen(
324        [config.ld64_executable, '-v'], stderr=subprocess.PIPE)
325    ld_out = ld_cmd.stderr.read().decode()
326    ld_cmd.wait()
327
328    if 'ld64' not in ld_out or 'LTO' not in ld_out:
329        return False
330
331    return True
332
333
334if have_ld64_plugin_support():
335    config.available_features.add('ld64_plugin')
336
337# Ask llvm-config about asserts
338llvm_config.feature_config(
339    [('--assertion-mode', {'ON': 'asserts'}),
340     ('--build-mode', {'[Dd][Ee][Bb][Uu][Gg]': 'debug'})])
341
342if 'darwin' == sys.platform:
343    cmd = ['sysctl', 'hw.optional.fma']
344    sysctl_cmd = subprocess.Popen(cmd, stdout=subprocess.PIPE)
345
346    # Non zero return, probably a permission issue
347    if sysctl_cmd.wait():
348        print(
349          "Warning: sysctl exists but calling \"{}\" failed, defaulting to no fma3.".format(
350          " ".join(cmd)))
351    else:
352        result = sysctl_cmd.stdout.read().decode('ascii')
353        if 'hw.optional.fma: 1' in result:
354            config.available_features.add('fma3')
355
356# .debug_frame is not emitted for targeting Windows x64.
357if not re.match(r'^x86_64.*-(windows-gnu|windows-msvc)', config.target_triple):
358    config.available_features.add('debug_frame')
359
360if config.have_libxar:
361    config.available_features.add('xar')
362
363if config.enable_threads:
364    config.available_features.add('thread_support')
365
366if config.have_libxml2:
367    config.available_features.add('libxml2')
368
369if config.have_opt_viewer_modules:
370    config.available_features.add('have_opt_viewer_modules')
371
372if config.expensive_checks:
373    config.available_features.add('expensive_checks')
374