Skip to content

[Clang] Automatically link the compiler-rt for GPUs if present #109152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Sep 18, 2024

Summary:
This automically links copmiler-rt for offloading languages if it
exists in the resource directory.

Summary:
This automically links `copmiler-rt` for offloading languages if it
exists in the resource directory.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Sep 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2024

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)

Changes

Summary:
This automically links copmiler-rt for offloading languages if it
exists in the resource directory.


Full diff: https://github.com/llvm/llvm-project/pull/109152.diff

1 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+6)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index c00df5f5bc729c..1e615214580134 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9239,6 +9239,12 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
         CmdArgs.push_back(Args.MakeArgString(
             "--device-linker=" + TC.getTripleString() + "=" + "-lm"));
       }
+      auto HasCompilerRT = getToolChain().getVFS().exists(
+          TC.getCompilerRT(Args, "builtins", ToolChain::FT_Static));
+      if (HasCompilerRT)
+        CmdArgs.push_back(
+            Args.MakeArgString("--device-linker=" + TC.getTripleString() + "=" +
+                               "-lclang_rt.builtins"));
     });
   }
 

@jplehr
Copy link
Contributor

jplehr commented Sep 18, 2024

I guess that makes sense.

@shiltian
Copy link
Contributor

I'm not sure about this. What does compiler-rt provide?

@shiltian shiltian requested a review from yxsamliu September 18, 2024 19:01
@jhuber6
Copy link
Contributor Author

jhuber6 commented Sep 18, 2024

I'm not sure about this. What does compiler-rt provide?

It's clang_rt.builtins. So, basically complex number multiplication / division, wide integer stuff (I think the backend handles i128 now though). We currently have a wrapper header that defined __mulsc3 for the device even though it's supposed to come from the compiler-rt.

@shiltian
Copy link
Contributor

I like this direction and I think it should be the right way. However, IMHO, I think it needs discussion (and potentially an RFC).

@jhuber6
Copy link
Contributor Author

jhuber6 commented Sep 18, 2024

I like this direction and I think it should be the right way. However, IMHO, I think it needs discussion (and potentially an RFC).

Moving from the header to the definition in compiler-rt would warrant an RFC, this patch just automatically links something that exists and will only provide definitions if they are undefined. So the only effect this has right now is linking in a symbol that would otherwise be a linker error.

@jplehr
Copy link
Contributor

jplehr commented Sep 20, 2024

I ran this through a buildbot config and found no errors.

Copy link
Contributor

@jplehr jplehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a reasonable change.

@jhuber6 jhuber6 merged commit eb48aac into llvm:main Sep 25, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants