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

Markus Böck via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 17 08:49:32 PDT 2021


zero9178 created this revision.
zero9178 added reviewers: rnk, mstorsjo, hans, phosek.
Herald added subscribers: pengfei, mgorny, dberris.
zero9178 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.

Example command line outputs:
LLVM 11 binaries distributed by LLVM:

  C:\Program Files\LLVM\bin>clang-cl /clang:-print-libgcc-file-name /clang:--rtlib=compiler-rt
  C:\Program Files\LLVM\lib\clang\11.0.1\lib\windows\clang_rt.builtins-x86_64.lib

Per-target runtime dir build of clang:

  clang-cl /clang:-print-libgcc-file-name /clang:--rtlib=compiler-rt
  C:\clang\Default\lib\clang\11.1.0\lib\x86_64-pc-windows-msvc\clang_rt.builtins.lib


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98786

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -982,8 +982,8 @@
 # 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 @@
     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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98786.331273.patch
Type: text/x-patch
Size: 1289 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210317/81bcd3e6/attachment.bin>


More information about the llvm-commits mailing list