[clang] [llvm] [Flang-RT] Do not use Apple-specific libdir scheme (PR #151954)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 5 04:27:02 PDT 2025
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-project at meinersbur.de>
Date: Mon, 4 Aug 2025 14:36:01 +0200
Subject: [PATCH 1/3] 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-project at meinersbur.de>
Date: Tue, 5 Aug 2025 13:11:52 +0200
Subject: [PATCH 2/3] 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 ()
>From 3a61f7935c5331d1dbcb64cac1e06b3062012bfe Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Tue, 5 Aug 2025 13:15:42 +0200
Subject: [PATCH 3/3] Add ../lib unconditionally
---
clang/lib/Driver/ToolChain.cpp | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 04a004b1d5c78..4d1de58289003 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -855,10 +855,7 @@ void ToolChain::addFortranRuntimeLibs(const ArgList &Args,
void ToolChain::addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args,
ArgStringList &CmdArgs) const {
- auto AddLibrarySearchPathIfExists = [&](const Twine &Path) {
- if (!llvm::sys::fs::is_directory(Path))
- return;
-
+ auto AddLibrarySearchPath = [&](const Twine &Path) {
if (getTriple().isKnownWindowsMSVCEnvironment())
CmdArgs.push_back(Args.MakeArgString("-libpath:" + Path));
else
@@ -869,7 +866,7 @@ void ToolChain::addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args,
// 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());
+ AddLibrarySearchPath(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
@@ -877,7 +874,7 @@ void ToolChain::addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args,
SmallString<256> DefaultLibPath =
llvm::sys::path::parent_path(getDriver().Dir);
llvm::sys::path::append(DefaultLibPath, "lib");
- AddLibrarySearchPathIfExists(DefaultLibPath);
+ AddLibrarySearchPath(DefaultLibPath);
}
void ToolChain::addFlangRTLibPath(const ArgList &Args,
More information about the llvm-commits
mailing list