1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[CMake] Use compiler-rt location instead of resource directory to find clang-cls runtime directory

The current cmake script attempts to add the path containing clangs various runtime systems by getting the resource directory and then appending the hardcoded value /lib/windows to it. This works for a normal clang-cl build but fails for a build of clang using LLVM_ENABLE_PER_TARGET_RUNTIME_DIR, such as the builds from llvm/runtimes.

This patch instead uses -print-libgcc-file-name in conjunction with --rtlib=compiler-rt, and instead adds the containing directory as library path.

For non per-target runtime directory builds, such as the release builds, there is no change. Even if the builtins library were to be deleted or moved it would output the same path as before.
For per-target runtime builds that also have the builtins library, this now finds the correct directory containing all of clang runtime libraries.

Only case still not handled by this change, is if a per-target runtime directory build is used, but the builtins library was not built.
I believe that is the best we can do for now however, without modifying clang.

Differential Revision: https://reviews.llvm.org/D98786
This commit is contained in:
Markus Böck 2021-03-18 09:24:49 +01:00
parent cb148c2f12
commit 23b462c030

View File

@ -982,8 +982,8 @@ endif()
# linker directly, it isn't sufficient to pass -fsanitize=* to the linker.
if (CLANG_CL AND (LLVM_BUILD_INSTRUMENTED OR LLVM_USE_SANITIZER))
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} /clang:-print-resource-dir
OUTPUT_VARIABLE clang_resource_dir
COMMAND ${CMAKE_CXX_COMPILER} /clang:-print-libgcc-file-name /clang:--rtlib=compiler-rt
OUTPUT_VARIABLE clang_compiler_rt_file
ERROR_VARIABLE clang_cl_stderr
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
@ -992,8 +992,9 @@ if (CLANG_CL AND (LLVM_BUILD_INSTRUMENTED OR LLVM_USE_SANITIZER))
message(FATAL_ERROR
"Unable to invoke clang-cl to find resource dir: ${clang_cl_stderr}")
endif()
file(TO_CMAKE_PATH "${clang_resource_dir}" clang_resource_dir)
append("/libpath:${clang_resource_dir}/lib/windows"
file(TO_CMAKE_PATH "${clang_compiler_rt_file}" clang_compiler_rt_file)
get_filename_component(clang_runtime_dir "${clang_compiler_rt_file}" DIRECTORY)
append("/libpath:${clang_runtime_dir}"
CMAKE_EXE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS)