https://github.com/Meinersbur updated 
https://github.com/llvm/llvm-project/pull/151954

>From ea175cbbecc3f89319846fd20daa53711bd1969e Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-proj...@meinersbur.de>
Date: Mon, 4 Aug 2025 14:36:01 +0200
Subject: [PATCH 1/2] Do not use apple-specific scheme

---
 flang-rt/cmake/modules/GetToolchainDirs.cmake | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/flang-rt/cmake/modules/GetToolchainDirs.cmake 
b/flang-rt/cmake/modules/GetToolchainDirs.cmake
index fba12502b5946..d9381c88e6518 100644
--- a/flang-rt/cmake/modules/GetToolchainDirs.cmake
+++ b/flang-rt/cmake/modules/GetToolchainDirs.cmake
@@ -34,14 +34,8 @@
 function (get_toolchain_library_subdir outvar)
   set(outval "lib")
 
-  if (APPLE)
-    # Required to be "darwin" for MachO toolchain.
-    get_toolchain_os_dirname(os_dirname)
-    set(outval "${outval}/${os_dirname}")
-  else ()
-    get_toolchain_arch_dirname(arch_dirname)
-    set(outval "${outval}/${arch_dirname}")
-  endif ()
+  get_toolchain_arch_dirname(arch_dirname)
+  set(outval "${outval}/${arch_dirname}")
 
   set(${outvar} "${outval}" PARENT_SCOPE)
 endfunction ()

>From 4c430e70c88cd1421672a1490d3495b732e4ce81 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-proj...@meinersbur.de>
Date: Tue, 5 Aug 2025 13:11:52 +0200
Subject: [PATCH 2/2] Also use old Compiler-RT search path

---
 clang/lib/Driver/ToolChain.cpp                | 28 +++++++++++++------
 flang-rt/cmake/modules/GetToolchainDirs.cmake | 10 +++++--
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 25c6b5a486fd5..04a004b1d5c78 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -855,17 +855,29 @@ void ToolChain::addFortranRuntimeLibs(const ArgList &Args,
 
 void ToolChain::addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args,
                                              ArgStringList &CmdArgs) const {
-  // Default to the <driver-path>/../lib directory. This works fine on the
-  // platforms that we have tested so far. We will probably have to re-fine
-  // this in the future. In particular, on some platforms, we may need to use
-  // lib64 instead of lib.
+  auto AddLibrarySearchPathIfExists = [&](const Twine &Path) {
+    if (!llvm::sys::fs::is_directory(Path))
+      return;
+
+    if (getTriple().isKnownWindowsMSVCEnvironment())
+      CmdArgs.push_back(Args.MakeArgString("-libpath:" + Path));
+    else
+      CmdArgs.push_back(Args.MakeArgString("-L" + Path));
+  };
+
+  // Search for flang_rt.* at the same location as clang_rt.* with
+  // LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=0. On most platforms, flang_rt is
+  // located at the path returned by getRuntimePath() which is already added to
+  // the library search path. This exception is for Apple-Darwin.
+  AddLibrarySearchPathIfExists(getCompilerRTPath());
+
+  // Fall back to the non-resource directory <driver-path>/../lib. We will
+  // probably have to re-fine this in the future. In particular, on some
+  // platforms, we may need to use lib64 instead of lib.
   SmallString<256> DefaultLibPath =
       llvm::sys::path::parent_path(getDriver().Dir);
   llvm::sys::path::append(DefaultLibPath, "lib");
-  if (getTriple().isKnownWindowsMSVCEnvironment())
-    CmdArgs.push_back(Args.MakeArgString("-libpath:" + DefaultLibPath));
-  else
-    CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
+  AddLibrarySearchPathIfExists(DefaultLibPath);
 }
 
 void ToolChain::addFlangRTLibPath(const ArgList &Args,
diff --git a/flang-rt/cmake/modules/GetToolchainDirs.cmake 
b/flang-rt/cmake/modules/GetToolchainDirs.cmake
index d9381c88e6518..fba12502b5946 100644
--- a/flang-rt/cmake/modules/GetToolchainDirs.cmake
+++ b/flang-rt/cmake/modules/GetToolchainDirs.cmake
@@ -34,8 +34,14 @@
 function (get_toolchain_library_subdir outvar)
   set(outval "lib")
 
-  get_toolchain_arch_dirname(arch_dirname)
-  set(outval "${outval}/${arch_dirname}")
+  if (APPLE)
+    # Required to be "darwin" for MachO toolchain.
+    get_toolchain_os_dirname(os_dirname)
+    set(outval "${outval}/${os_dirname}")
+  else ()
+    get_toolchain_arch_dirname(arch_dirname)
+    set(outval "${outval}/${arch_dirname}")
+  endif ()
 
   set(${outvar} "${outval}" PARENT_SCOPE)
 endfunction ()

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to