[clang] [clang] Ensure `--print-runtime-dir` path exists (PR #102834)

Alexandre Ganea via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 12 06:46:58 PDT 2024


aganea wrote:

To give the whole picture, the story is that while building the LLVM package on Windows, I was seeing this:
```
[51/52] Running sanitizer_common testsllvm-lit.py: C:\src\git\llvm-project\llvm\utils\lit\lit\llvm\config.py:57: note: using lit tools: C:\Program Files\Git\usr\bin\
llvm-lit.py: C:\src\git\llvm-project\compiler-rt\test\lit.common.cfg.py:60: warning: Path reported by clang does not exist: "C:\src\git\llvm-project\llvm_package_20.0.0\build64\lib\clang\20\lib\x86_64-pc-windows-msvc". This path was found by running ['C:/src/git/llvm-project/llvm_package_20.0.0/build64/./bin/clang.exe', '--target=x86_64-pc-windows-msvc', '-Wthread-safety', '-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit.py: C:\src\git\llvm-project\compiler-rt\test\lit.common.cfg.py:60: warning: Path reported by clang does not exist: "C:\src\git\llvm-project\llvm_package_20.0.0\build64\lib\clang\20\lib\x86_64-pc-windows-msvc". This path was found by running ['C:/src/git/llvm-project/llvm_package_20.0.0/build64/./bin/clang.exe', '--target=x86_64-pc-windows-msvc', '-Wthread-safety', '-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
```
This is, we don't set `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON` when building compiler-rt, so we end up taking this cmake codepath: https://github.com/llvm/llvm-project/blob/main/compiler-rt/cmake/base-config-ix.cmake#L106 which ends up with the compiler runtime libs in `{build_folder}\lib\clang\{version}\lib\windows`. However `ToolChain::getRuntimePath()` checks for the triple folder, as in `{build_folder}\lib\clang\{version}\lib\x86_64-pc-windows-msvc` which don't exist. `clang -print-runtime-dir` will just display that, without checking the folder's existence. However if we do `clang-cl a.cpp -fsanitize=address` then we check the library paths (which runtime is part of at this point) for existence: https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/MSVC.cpp#L153

I think we want to keep the dynamic aspect on supporting both `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON/OFF` at runtime in Clang like @mstorsjo was suggesting in https://discourse.llvm.org/t/runtime-directory-fallback/76860/2, I feel we should check the existence of the path before printing it, thus this PR.

https://github.com/llvm/llvm-project/pull/102834


More information about the cfe-commits mailing list