[clang] [Flang] Link `-lflang_rt.runtime` if available on the device (PR #132737)

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 24 07:05:26 PDT 2025


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/132737

Summary:
Now that we can build the Fortran runtime on the GPU (mostly) we should
be able to implicitly link it if it exists. This matches the normal
behavior where it is included implicity. No tests because it
would require a full VFS and is fairly trivial.


>From abf867e63c939e70916017e3abcabc5a947fb41e Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 24 Mar 2025 09:01:08 -0500
Subject: [PATCH] [Flang] Link `-lflang_rt.runtime` if available on the device

Summary:
Now that we can build the Fortran runtime on the GPU (mostly) we should
be able to implicitly link it if it exists. This matches the normal
behavior where it is included implicity. No tests because it
would require a full VFS and is fairly trivial.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index fb3ed2db0e3c0..d7da2af321e7b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9337,6 +9337,11 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
         CmdArgs.push_back(
             Args.MakeArgString("--device-linker=" + TC.getTripleString() + "=" +
                                "-lclang_rt.builtins"));
+      bool HasFlangRT = HasCompilerRT && C.getDriver().IsFlangMode();
+      if (HasCompilerRT)
+        CmdArgs.push_back(
+            Args.MakeArgString("--device-linker=" + TC.getTripleString() + "=" +
+                               "-lflang_rt.runtime"));
     });
   }
 



More information about the cfe-commits mailing list