diff --git a/compiler-rt/test/asan/lit.cfg.py b/compiler-rt/test/asan/lit.cfg.py --- a/compiler-rt/test/asan/lit.cfg.py +++ b/compiler-rt/test/asan/lit.cfg.py @@ -53,6 +53,41 @@ (new_path, config.environment.get(dynamic_library_lookup_var, ''))) config.environment[dynamic_library_lookup_var] = new_ld_library_path_64 +def find_clang_compiler_rt_libdir(config): + import subprocess + clang_cmd = [ + config.clang.strip(), + '-print-file-name=lib', + ] + try: + result = subprocess.run( + clang_cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + check=True + ) + except subprocess.CalledProcessError as e: + msg = 'Failed to run {}\nrc:{}\nstdout:{}\nstderr:{}\n'.format( + clang_cmd, + e.returncode, + e.stdout, + e.stderr) + lit_config.fatal(msg) + path = result.stdout.decode().strip() + if not os.path.exists(path): + lit_config.fatal('Path reported by clang does not exist: {}'.format(path)) + path = os.path.realpath(path) + if config.host_os == 'Darwin': + path = os.path.join(path, 'darwin') + + config_crt_libdir_real = os.path.realpath(config.compiler_rt_libdir) + if path != config_crt_libdir_real: + # Note it's possible for this mismatch to occur when doing a + # Standalone build of compiler-rt. + lit_config.warning('Path reported by clang ({}) != configured path ({})'.format( + path, config_crt_libdir_real)) + return path + # Setup config name. config.name = 'AddressSanitizer' + config.name_suffix @@ -134,7 +169,9 @@ if config.host_os in ['Linux', 'FreeBSD', 'NetBSD', 'SunOS']: shared_libasan_path = os.path.join(config.compiler_rt_libdir, "libclang_rt.asan{}.so".format(config.target_suffix)) elif config.host_os == 'Darwin': - shared_libasan_path = os.path.join(config.compiler_rt_libdir, 'libclang_rt.asan_{}_dynamic.dylib'.format(config.apple_platform)) + shared_libasan_path = os.path.join( + find_clang_compiler_rt_libdir(config), + 'libclang_rt.asan_{}_dynamic.dylib'.format(config.apple_platform)) else: lit_config.warning('%shared_libasan substitution not set but dynamic ASan is available.') shared_libasan_path = None