1# -*- Python -*-
2
3# Configuration file for 'lit' test runner.
4# This file contains common rules for various compiler-rt testsuites.
5# It is mostly copied from lit.cfg.py used by Clang.
6import os
7import platform
8import re
9import subprocess
10import json
11
12import lit.formats
13import lit.util
14
15# Choose between lit's internal shell pipeline runner and a real shell.  If
16# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
17use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
18if use_lit_shell:
19    # 0 is external, "" is default, and everything else is internal.
20    execute_external = (use_lit_shell == "0")
21else:
22    # Otherwise we default to internal on Windows and external elsewhere, as
23    # bash on Windows is usually very slow.
24    execute_external = (not sys.platform in ['win32'])
25
26# Allow expanding substitutions that are based on other substitutions
27config.recursiveExpansionLimit = 10
28
29# Setup test format.
30config.test_format = lit.formats.ShTest(execute_external)
31if execute_external:
32  config.available_features.add('shell')
33
34compiler_id = getattr(config, 'compiler_id', None)
35if compiler_id == "Clang":
36  if platform.system() != 'Windows':
37    config.cxx_mode_flags = ["--driver-mode=g++"]
38  else:
39    config.cxx_mode_flags = []
40  # We assume that sanitizers should provide good enough error
41  # reports and stack traces even with minimal debug info.
42  config.debug_info_flags = ["-gline-tables-only"]
43  if platform.system() == 'Windows':
44    # On Windows, use CodeView with column info instead of DWARF. Both VS and
45    # windbg do not behave well when column info is enabled, but users have
46    # requested it because it makes ASan reports more precise.
47    config.debug_info_flags.append("-gcodeview")
48    config.debug_info_flags.append("-gcolumn-info")
49elif compiler_id == 'GNU':
50  config.cxx_mode_flags = ["-x c++"]
51  config.debug_info_flags = ["-g"]
52else:
53  lit_config.fatal("Unsupported compiler id: %r" % compiler_id)
54# Add compiler ID to the list of available features.
55config.available_features.add(compiler_id)
56
57# If needed, add cflag for shadow scale.
58if config.asan_shadow_scale != '':
59  config.target_cflags += " -mllvm -asan-mapping-scale=" + config.asan_shadow_scale
60if config.memprof_shadow_scale != '':
61  config.target_cflags += " -mllvm -memprof-mapping-scale=" + config.memprof_shadow_scale
62
63config.environment = dict(os.environ)
64
65# Clear some environment variables that might affect Clang.
66possibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS',
67                               'MSAN_OPTIONS', 'UBSAN_OPTIONS',
68                               'COMPILER_PATH', 'RC_DEBUG_OPTIONS',
69                               'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
70                               'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
71                               'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
72                               'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
73                               'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
74                               'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
75                               'LIBCLANG_RESOURCE_USAGE',
76                               'LIBCLANG_CODE_COMPLETION_LOGGING',
77                               'XRAY_OPTIONS']
78# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
79if platform.system() != 'Windows':
80    possibly_dangerous_env_vars.append('INCLUDE')
81for name in possibly_dangerous_env_vars:
82  if name in config.environment:
83    del config.environment[name]
84
85# Tweak PATH to include llvm tools dir.
86if (not config.llvm_tools_dir) or (not os.path.exists(config.llvm_tools_dir)):
87  lit_config.fatal("Invalid llvm_tools_dir config attribute: %r" % config.llvm_tools_dir)
88path = os.path.pathsep.join((config.llvm_tools_dir, config.environment['PATH']))
89config.environment['PATH'] = path
90
91# Help MSVS link.exe find the standard libraries.
92# Make sure we only try to use it when targetting Windows.
93if platform.system() == 'Windows' and '-win' in config.target_triple:
94  config.environment['LIB'] = os.environ['LIB']
95
96config.available_features.add(config.host_os.lower())
97
98if re.match(r'^x86_64.*-linux', config.target_triple):
99  config.available_features.add("x86_64-linux")
100
101config.available_features.add("host-byteorder-" + sys.byteorder + "-endian")
102
103if config.have_zlib == "1":
104  config.available_features.add("zlib")
105
106# Use ugly construction to explicitly prohibit "clang", "clang++" etc.
107# in RUN lines.
108config.substitutions.append(
109    (' clang', """\n\n*** Do not use 'clangXXX' in tests,
110     instead define '%clangXXX' substitution in lit config. ***\n\n""") )
111
112if config.host_os == 'NetBSD':
113  nb_commands_dir = os.path.join(config.compiler_rt_src_root,
114                                 "test", "sanitizer_common", "netbsd_commands")
115  config.netbsd_noaslr_prefix = ('sh ' +
116                                 os.path.join(nb_commands_dir, 'run_noaslr.sh'))
117  config.netbsd_nomprotect_prefix = ('sh ' +
118                                     os.path.join(nb_commands_dir,
119                                                  'run_nomprotect.sh'))
120  config.substitutions.append( ('%run_nomprotect',
121                                config.netbsd_nomprotect_prefix) )
122else:
123  config.substitutions.append( ('%run_nomprotect', '%run') )
124
125# Copied from libcxx's config.py
126def get_lit_conf(name, default=None):
127    # Allow overriding on the command line using --param=<name>=<val>
128    val = lit_config.params.get(name, None)
129    if val is None:
130        val = getattr(config, name, None)
131        if val is None:
132            val = default
133    return val
134
135emulator = get_lit_conf('emulator', None)
136
137# Allow tests to be executed on a simulator or remotely.
138if emulator:
139  config.substitutions.append( ('%run', emulator) )
140  config.substitutions.append( ('%env ', "env ") )
141  # TODO: Implement `%device_rm` to perform removal of files in the emulator.
142  # For now just make it a no-op.
143  lit_config.warning('%device_rm is not implemented')
144  config.substitutions.append( ('%device_rm', 'echo ') )
145  config.compile_wrapper = ""
146elif config.host_os == 'Darwin' and config.apple_platform != "osx":
147  # Darwin tests can be targetting macOS, a device or a simulator. All devices
148  # are declared as "ios", even for iOS derivatives (tvOS, watchOS). Similarly,
149  # all simulators are "iossim". See the table below.
150  #
151  # =========================================================================
152  # Target             | Feature set
153  # =========================================================================
154  # macOS              | darwin
155  # iOS device         | darwin, ios
156  # iOS simulator      | darwin, ios, iossim
157  # tvOS device        | darwin, ios, tvos
158  # tvOS simulator     | darwin, ios, iossim, tvos, tvossim
159  # watchOS device     | darwin, ios, watchos
160  # watchOS simulator  | darwin, ios, iossim, watchos, watchossim
161  # =========================================================================
162
163  ios_or_iossim = "iossim" if config.apple_platform.endswith("sim") else "ios"
164
165  config.available_features.add('ios')
166  device_id_env = "SANITIZER_" + ios_or_iossim.upper() + "_TEST_DEVICE_IDENTIFIER"
167  if ios_or_iossim == "iossim":
168    config.available_features.add('iossim')
169    if device_id_env not in os.environ:
170      lit_config.fatal(
171        '{} must be set in the environment when running iossim tests'.format(
172          device_id_env))
173  if config.apple_platform != "ios" and config.apple_platform != "iossim":
174    config.available_features.add(config.apple_platform)
175
176  ios_commands_dir = os.path.join(config.compiler_rt_src_root, "test", "sanitizer_common", "ios_commands")
177
178  run_wrapper = os.path.join(ios_commands_dir, ios_or_iossim + "_run.py")
179  env_wrapper = os.path.join(ios_commands_dir, ios_or_iossim + "_env.py")
180  compile_wrapper = os.path.join(ios_commands_dir, ios_or_iossim + "_compile.py")
181  prepare_script = os.path.join(ios_commands_dir, ios_or_iossim + "_prepare.py")
182
183  if device_id_env in os.environ:
184    config.environment[device_id_env] = os.environ[device_id_env]
185  config.substitutions.append(('%run', run_wrapper))
186  config.substitutions.append(('%env ', env_wrapper + " "))
187  # Current implementation of %device_rm uses the run_wrapper to do
188  # the work.
189  config.substitutions.append(('%device_rm', '{} rm '.format(run_wrapper)))
190  config.compile_wrapper = compile_wrapper
191
192  try:
193    prepare_output = subprocess.check_output([prepare_script, config.apple_platform, config.clang]).decode().strip()
194  except subprocess.CalledProcessError as e:
195    print("Command failed:")
196    print(e.output)
197    raise e
198  if len(prepare_output) > 0: print(prepare_output)
199  prepare_output_json = prepare_output.split("\n")[-1]
200  prepare_output = json.loads(prepare_output_json)
201  config.environment.update(prepare_output["env"])
202elif config.android:
203  config.available_features.add('android')
204  compile_wrapper = os.path.join(config.compiler_rt_src_root, "test", "sanitizer_common", "android_commands", "android_compile.py") + " "
205  config.compile_wrapper = compile_wrapper
206  config.substitutions.append( ('%run', "") )
207  config.substitutions.append( ('%env ', "env ") )
208  # TODO: Implement `%device_rm` to perform removal of files on a device.  For
209  # now just make it a no-op.
210  lit_config.warning('%device_rm is not implemented')
211  config.substitutions.append( ('%device_rm', 'echo ') )
212else:
213  config.substitutions.append( ('%run', "") )
214  config.substitutions.append( ('%env ', "env ") )
215  # When running locally %device_rm is a no-op.
216  config.substitutions.append( ('%device_rm', 'echo ') )
217  config.compile_wrapper = ""
218
219# Define CHECK-%os to check for OS-dependent output.
220config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
221
222# Define %arch to check for architecture-dependent output.
223config.substitutions.append( ('%arch', (config.host_arch)))
224
225if config.host_os == 'Windows':
226  # FIXME: This isn't quite right. Specifically, it will succeed if the program
227  # does not crash but exits with a non-zero exit code. We ought to merge
228  # KillTheDoctor and not --crash to make the latter more useful and remove the
229  # need for this substitution.
230  config.expect_crash = "not KillTheDoctor "
231else:
232  config.expect_crash = "not --crash "
233
234config.substitutions.append( ("%expect_crash ", config.expect_crash) )
235
236target_arch = getattr(config, 'target_arch', None)
237if target_arch:
238  config.available_features.add(target_arch + '-target-arch')
239  if target_arch in ['x86_64', 'i386']:
240    config.available_features.add('x86-target-arch')
241  config.available_features.add(target_arch + '-' + config.host_os.lower())
242
243compiler_rt_debug = getattr(config, 'compiler_rt_debug', False)
244if not compiler_rt_debug:
245  config.available_features.add('compiler-rt-optimized')
246
247libdispatch = getattr(config, 'compiler_rt_intercept_libdispatch', False)
248if libdispatch:
249  config.available_features.add('libdispatch')
250
251sanitizer_can_use_cxxabi = getattr(config, 'sanitizer_can_use_cxxabi', True)
252if sanitizer_can_use_cxxabi:
253  config.available_features.add('cxxabi')
254
255if config.has_lld:
256  config.available_features.add('lld-available')
257
258if config.use_lld:
259  config.available_features.add('lld')
260
261if config.can_symbolize:
262  config.available_features.add('can-symbolize')
263
264if config.gwp_asan:
265  config.available_features.add('gwp_asan')
266
267lit.util.usePlatformSdkOnDarwin(config, lit_config)
268
269min_macos_deployment_target_substitutions = [
270  (10, 11),
271  (10, 12),
272]
273# TLS requires watchOS 3+
274config.substitutions.append( ('%darwin_min_target_with_tls_support', '%min_macos_deployment_target=10.12') )
275
276if config.host_os == 'Darwin':
277  osx_version = (10, 0, 0)
278  try:
279    osx_version = subprocess.check_output(["sw_vers", "-productVersion"],
280                                          universal_newlines=True)
281    osx_version = tuple(int(x) for x in osx_version.split('.'))
282    if len(osx_version) == 2: osx_version = (osx_version[0], osx_version[1], 0)
283    if osx_version >= (10, 11):
284      config.available_features.add('osx-autointerception')
285      config.available_features.add('osx-ld64-live_support')
286  except subprocess.CalledProcessError:
287    pass
288
289  config.darwin_osx_version = osx_version
290
291  # Detect x86_64h
292  try:
293    output = subprocess.check_output(["sysctl", "hw.cpusubtype"])
294    output_re = re.match("^hw.cpusubtype: ([0-9]+)$", output)
295    if output_re:
296      cpu_subtype = int(output_re.group(1))
297      if cpu_subtype == 8: # x86_64h
298        config.available_features.add('x86_64h')
299  except:
300    pass
301
302  # 32-bit iOS simulator is deprecated and removed in latest Xcode.
303  if config.apple_platform == "iossim":
304    if config.target_arch == "i386":
305      config.unsupported = True
306
307  def get_macos_aligned_version(macos_vers):
308    platform = config.apple_platform
309    if platform == 'osx':
310      return macos_vers
311
312    macos_major, macos_minor = macos_vers
313    assert macos_major >= 10
314
315    if macos_major == 10:  # macOS 10.x
316      major = macos_minor
317      minor = 0
318    else:                  # macOS 11+
319      major = macos_major + 5
320      minor = macos_minor
321
322    assert major >= 11
323
324    if platform.startswith('ios') or platform.startswith('tvos'):
325      major -= 2
326    elif platform.startswith('watch'):
327      major -= 9
328    else:
329      lit_config.fatal("Unsupported apple platform '{}'".format(platform))
330
331    return (major, minor)
332
333  for vers in min_macos_deployment_target_substitutions:
334    flag = config.apple_platform_min_deployment_target_flag
335    major, minor = get_macos_aligned_version(vers)
336    config.substitutions.append( ('%%min_macos_deployment_target=%s.%s' % vers, '{}={}.{}'.format(flag, major, minor)) )
337else:
338  for vers in min_macos_deployment_target_substitutions:
339    config.substitutions.append( ('%%min_macos_deployment_target=%s.%s' % vers, '') )
340
341if config.android:
342  env = os.environ.copy()
343  if config.android_serial:
344    env['ANDROID_SERIAL'] = config.android_serial
345    config.environment['ANDROID_SERIAL'] = config.android_serial
346
347  adb = os.environ.get('ADB', 'adb')
348
349  # These are needed for tests to upload/download temp files, such as
350  # suppression-files, to device.
351  config.substitutions.append( ('%device_rundir', "/data/local/tmp/Output") )
352  config.substitutions.append( ('%push_to_device', "%s -s '%s' push " % (adb, env['ANDROID_SERIAL']) ) )
353  config.substitutions.append( ('%pull_from_device', "%s -s '%s' pull " % (adb, env['ANDROID_SERIAL']) ) )
354  config.substitutions.append( ('%adb_shell ', "%s -s '%s' shell " % (adb, env['ANDROID_SERIAL']) ) )
355
356  try:
357    android_api_level_str = subprocess.check_output([adb, "shell", "getprop", "ro.build.version.sdk"], env=env).rstrip()
358    android_api_codename = subprocess.check_output([adb, "shell", "getprop", "ro.build.version.codename"], env=env).rstrip().decode("utf-8")
359  except (subprocess.CalledProcessError, OSError):
360    lit_config.fatal("Failed to read ro.build.version.sdk (using '%s' as adb)" % adb)
361  try:
362    android_api_level = int(android_api_level_str)
363  except ValueError:
364    lit_config.fatal("Failed to read ro.build.version.sdk (using '%s' as adb): got '%s'" % (adb, android_api_level_str))
365  if android_api_level >= 26:
366    config.available_features.add('android-26')
367  if android_api_level >= 28:
368    config.available_features.add('android-28')
369  if android_api_level >= 31 or android_api_codename == 'S':
370    config.available_features.add('android-thread-properties-api')
371
372  # Prepare the device.
373  android_tmpdir = '/data/local/tmp/Output'
374  subprocess.check_call([adb, "shell", "mkdir", "-p", android_tmpdir], env=env)
375  for file in config.android_files_to_push:
376    subprocess.check_call([adb, "push", file, android_tmpdir], env=env)
377else:
378  config.substitutions.append( ('%device_rundir', "") )
379  config.substitutions.append( ('%push_to_device', "echo ") )
380  config.substitutions.append( ('%pull_from_device', "echo ") )
381  config.substitutions.append( ('%adb_shell', "echo ") )
382
383if config.host_os == 'Linux':
384  # detect whether we are using glibc, and which version
385  # NB: 'ldd' is just one of the tools commonly installed as part of glibc
386  ldd_ver_cmd = subprocess.Popen(['ldd', '--version'],
387                                 stdout=subprocess.PIPE,
388                                 env={'LANG': 'C'})
389  sout, _ = ldd_ver_cmd.communicate()
390  ver_line = sout.splitlines()[0]
391  if not config.android and ver_line.startswith(b"ldd "):
392    from distutils.version import LooseVersion
393    ver = LooseVersion(ver_line.split()[-1].decode())
394    # 2.27 introduced some incompatibilities
395    if ver >= LooseVersion("2.27"):
396      config.available_features.add("glibc-2.27")
397
398sancovcc_path = os.path.join(config.llvm_tools_dir, "sancov")
399if os.path.exists(sancovcc_path):
400  config.available_features.add("has_sancovcc")
401  config.substitutions.append( ("%sancovcc ", sancovcc_path) )
402
403def is_darwin_lto_supported():
404  return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib'))
405
406def is_binutils_lto_supported():
407  if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
408    return False
409
410  # We require both ld.bfd and ld.gold exist and support plugins. They are in
411  # the same repository 'binutils-gdb' and usually built together.
412  for exe in (config.gnu_ld_executable, config.gold_executable):
413    ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
414    ld_out = ld_cmd.stdout.read().decode()
415    ld_cmd.wait()
416    if not '-plugin' in ld_out:
417      return False
418
419  return True
420
421def is_windows_lto_supported():
422  return os.path.exists(os.path.join(config.llvm_tools_dir, 'lld-link.exe'))
423
424if config.host_os == 'Darwin' and is_darwin_lto_supported():
425  config.lto_supported = True
426  config.lto_launch = ["env", "DYLD_LIBRARY_PATH=" + config.llvm_shlib_dir]
427  config.lto_flags = []
428elif config.host_os in ['Linux', 'FreeBSD', 'NetBSD']:
429  config.lto_supported = False
430  if config.use_lld:
431    config.lto_supported = True
432  if is_binutils_lto_supported():
433    config.available_features.add('binutils_lto')
434    config.lto_supported = True
435
436  if config.lto_supported:
437    config.lto_launch = []
438    if config.use_lld:
439      config.lto_flags = ["-fuse-ld=lld"]
440    else:
441      config.lto_flags = ["-fuse-ld=gold"]
442elif config.host_os == 'Windows' and is_windows_lto_supported():
443  config.lto_supported = True
444  config.lto_launch = []
445  config.lto_flags = ["-fuse-ld=lld"]
446else:
447  config.lto_supported = False
448
449if config.lto_supported:
450  config.available_features.add('lto')
451  if config.use_thinlto:
452    config.available_features.add('thinlto')
453    config.lto_flags += ["-flto=thin"]
454  else:
455    config.lto_flags += ["-flto"]
456  if config.use_newpm:
457    config.lto_flags += ["-fexperimental-new-pass-manager"]
458
459if config.have_rpc_xdr_h:
460  config.available_features.add('sunrpc')
461
462# Ask llvm-config about assertion mode.
463try:
464  llvm_config_cmd = subprocess.Popen(
465      [os.path.join(config.llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
466      stdout = subprocess.PIPE,
467      env=config.environment)
468except OSError as e:
469  print("Could not launch llvm-config in " + config.llvm_tools_dir)
470  print("    Failed with error #{0}: {1}".format(e.errno, e.strerror))
471  exit(42)
472
473if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
474  config.available_features.add('asserts')
475llvm_config_cmd.wait()
476
477# Sanitizer tests tend to be flaky on Windows due to PR24554, so add some
478# retries. We don't do this on otther platforms because it's slower.
479if platform.system() == 'Windows':
480  config.test_retry_attempts = 2
481
482# No throttling on non-Darwin platforms.
483lit_config.parallelism_groups['shadow-memory'] = None
484
485if platform.system() == 'Darwin':
486  ios_device = config.apple_platform != 'osx' and not config.apple_platform.endswith('sim')
487  # Force sequential execution when running tests on iOS devices.
488  if ios_device:
489    lit_config.warning('Forcing sequential execution for iOS device tests')
490    lit_config.parallelism_groups['ios-device'] = 1
491    config.parallelism_group = 'ios-device'
492
493  # Only run up to 3 processes that require shadow memory simultaneously on
494  # 64-bit Darwin. Using more scales badly and hogs the system due to
495  # inefficient handling of large mmap'd regions (terabytes) by the kernel.
496  elif config.target_arch in ['x86_64', 'x86_64h']:
497    lit_config.warning('Throttling sanitizer tests that require shadow memory on Darwin 64bit')
498    lit_config.parallelism_groups['shadow-memory'] = 3
499
500# Multiple substitutions are necessary to support multiple shared objects used
501# at once.
502# Note that substitutions with numbers have to be defined first to avoid
503# being subsumed by substitutions with smaller postfix.
504for postfix in ["2", "1", ""]:
505  if config.host_os == 'Darwin':
506    config.substitutions.append( ("%ld_flags_rpath_exe" + postfix, '-Wl,-rpath,@executable_path/ %dynamiclib' + postfix) )
507    config.substitutions.append( ("%ld_flags_rpath_so" + postfix, '-install_name @rpath/`basename %dynamiclib{}`'.format(postfix)) )
508  elif config.host_os in ('FreeBSD', 'NetBSD', 'OpenBSD'):
509    config.substitutions.append( ("%ld_flags_rpath_exe" + postfix, "-Wl,-z,origin -Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec" + postfix) )
510    config.substitutions.append( ("%ld_flags_rpath_so" + postfix, '') )
511  elif config.host_os == 'Linux':
512    config.substitutions.append( ("%ld_flags_rpath_exe" + postfix, "-Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec" + postfix) )
513    config.substitutions.append( ("%ld_flags_rpath_so" + postfix, '') )
514  elif config.host_os == 'SunOS':
515    config.substitutions.append( ("%ld_flags_rpath_exe" + postfix, "-Wl,-R\$ORIGIN -L%T -l%xdynamiclib_namespec" + postfix) )
516    config.substitutions.append( ("%ld_flags_rpath_so" + postfix, '') )
517
518  # Must be defined after the substitutions that use %dynamiclib.
519  config.substitutions.append( ("%dynamiclib" + postfix, '%T/%xdynamiclib_filename' + postfix) )
520  config.substitutions.append( ("%xdynamiclib_filename" + postfix, 'lib%xdynamiclib_namespec{}.so'.format(postfix)) )
521  config.substitutions.append( ("%xdynamiclib_namespec", '%basename_t.dynamic') )
522
523# Provide a substituion that can be used to tell Clang to use a static libstdc++.
524# The substitution expands to nothing on non Linux platforms.
525# FIXME: This should check the target OS, not the host OS.
526if config.host_os == 'Linux':
527  config.substitutions.append( ("%linux_static_libstdcplusplus", "-stdlib=libstdc++ -static-libstdc++") )
528else:
529  config.substitutions.append( ("%linux_static_libstdcplusplus", "") )
530
531config.default_sanitizer_opts = []
532if config.host_os == 'Darwin':
533  # On Darwin, we default to `abort_on_error=1`, which would make tests run
534  # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
535  config.default_sanitizer_opts += ['abort_on_error=0']
536  config.default_sanitizer_opts += ['log_to_syslog=0']
537  if lit.util.which('log'):
538    # Querying the log can only done by a privileged user so
539    # so check if we can query the log.
540    exit_code = -1
541    with open('/dev/null', 'r') as f:
542      # Run a `log show` command the should finish fairly quickly and produce very little output.
543      exit_code = subprocess.call(['log', 'show', '--last', '1m', '--predicate', '1 == 0'], stdout=f, stderr=f)
544    if exit_code == 0:
545      config.available_features.add('darwin_log_cmd')
546    else:
547      lit_config.warning('log command found but cannot queried')
548  else:
549    lit_config.warning('log command not found. Some tests will be skipped.')
550elif config.android:
551  config.default_sanitizer_opts += ['abort_on_error=0']
552
553# Allow tests to use REQUIRES=stable-runtime.  For use when you cannot use XFAIL
554# because the test hangs or fails on one configuration and not the other.
555if config.android or (config.target_arch not in ['arm', 'armhf', 'aarch64']):
556  config.available_features.add('stable-runtime')
557
558if config.asan_shadow_scale:
559  config.available_features.add("shadow-scale-%s" % config.asan_shadow_scale)
560else:
561  config.available_features.add("shadow-scale-3")
562
563if config.memprof_shadow_scale:
564  config.available_features.add("memprof-shadow-scale-%s" % config.memprof_shadow_scale)
565else:
566  config.available_features.add("memprof-shadow-scale-3")
567
568if config.expensive_checks:
569  config.available_features.add("expensive_checks")
570
571# Propagate the LLD/LTO into the clang config option, so nothing else is needed.
572run_wrapper = []
573target_cflags = [getattr(config, 'target_cflags', None)]
574extra_cflags = []
575
576if config.use_lto and config.lto_supported:
577  run_wrapper += config.lto_launch
578  extra_cflags += config.lto_flags
579elif config.use_lto and (not config.lto_supported):
580  config.unsupported = True
581
582if config.use_lld and config.has_lld and not config.use_lto:
583  extra_cflags += ["-fuse-ld=lld"]
584elif config.use_lld and (not config.has_lld):
585  config.unsupported = True
586
587config.clang = " " + " ".join(run_wrapper + [config.compile_wrapper, config.clang]) + " "
588config.target_cflags = " " + " ".join(target_cflags + extra_cflags) + " "
589