[clang] [llvm] [Flang] Search flang_rt in clang_rt path (PR #151954)

Tarun Prabhu via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 5 13:13:43 PDT 2025


================
@@ -855,17 +855,26 @@ 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 AddLibrarySearchPath = [&](const Twine &Path) {
+    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.
+  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
----------------
tarunprabhu wrote:

nit
```suggestion
  // probably have to refine this in the future. In particular, on some
```

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


More information about the llvm-commits mailing list