diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py --- a/compiler-rt/test/lit.common.cfg.py +++ b/compiler-rt/test/lit.common.cfg.py @@ -55,7 +55,9 @@ # Try using `-print-runtime-dir`. This is only supported by very new versions of Clang. # so allow failure here. - runtime_dir, clang_cmd = get_path_from_clang(['-print-runtime-dir'], allow_failure=True) + runtime_dir, clang_cmd = get_path_from_clang(shlex.split(config.target_cflags) + + ['-print-runtime-dir'], + allow_failure=True) if runtime_dir: if os.path.exists(runtime_dir): return os.path.realpath(runtime_dir) @@ -123,6 +125,16 @@ # Add compiler ID to the list of available features. config.available_features.add(compiler_id) +# When LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on, the initial value of +# config.compiler_rt_libdir (COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR) has the +# triple as the trailing path component. The value is incorrect for -m32/-m64. +# Adjust config.compiler_rt accordingly. +if config.enable_per_target_runtime_dir: + if '-m32' in shlex.split(config.target_cflags): + config.compiler_rt_libdir = re.sub(r'/x86_64(?=-[^/]+$)', '/i386', config.compiler_rt_libdir) + elif '-m64' in shlex.split(config.target_cflags): + config.compiler_rt_libdir = re.sub(r'/i386(?=-[^/]+$)', '/x86_64', config.compiler_rt_libdir) + # Ask the compiler for the path to libraries it is going to use. If this # doesn't match config.compiler_rt_libdir then it means we might be testing the # compiler's own runtime libraries rather than the ones we just built.