Commit 9111635c authored by Fangrui Song's avatar Fangrui Song
Browse files

[test] Fix asan/scudo -shared-libsan tests with -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on

On x86_64-unknown-linux-gnu, `-m32` tests set LD_LIBRARY_PATH to
`config.compiler_rt_libdir` (`$build/lib/clang/14.0.0/lib/x86_64-unknown-linux-gnu`)
instead of i386-unknown-linux-gnu, so `-shared-libsan` executables
cannot find their runtime (e.g. `TestCases/replaceable_new_delete.cpp`).

Detect -m32 and -m64 in config.target_cflags, and adjust `config.compiler_rt_libdir`.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D108859
parent 0a07789f
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -55,7 +55,9 @@ def find_compiler_libdir():

  # 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 @@ else:
# 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.