Skip to content

[Clang] Only link C device libraries by default for OpenMP #151239

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Jul 29, 2025

Summary:
We link these implicitly for OpenMP because it's the canonical
implementation of those C language features. This was inhereted by HIP
and ended up with these resolving functions. There are some useful
functions in here, but this can be problematic as it could potentially
override functions intended to be provided by the ROCm device libraries.
Additionally the HIP runtime does not currently provide the handling for
the RPC server required to run the host resources so those just segfault.

Summary:
We link these implicitly for OpenMP because it's the canonical
implementation of those C language features. This was inhereted by HIP
and ended up with these resolving functions. There are some useful
functions in here, but this can be problematic as it could potentially
override functions intended to be provided by the ROCm device libraries.
Additionally the HIP runtime does not currently provide the handling for
the RPC server required to run the host resources so those just segfault.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Jul 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 29, 2025

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)

Changes

Summary:
We link these implicitly for OpenMP because it's the canonical
implementation of those C language features. This was inhereted by HIP
and ended up with these resolving functions. There are some useful
functions in here, but this can be problematic as it could potentially
override functions intended to be provided by the ROCm device libraries.
Additionally the HIP runtime does not currently provide the handling for
the RPC server required to run the host resources so those just segfault.


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

1 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+3-2)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 9d882dbfd0c65..6e1d4aa8bc053 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9232,8 +9232,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
                    options::OPT_nogpulibc)) {
     forAllAssociatedToolChains(C, JA, getToolChain(), [&](const ToolChain &TC) {
       // The device C library is only available for NVPTX and AMDGPU targets
-      // currently.
-      if (!TC.getTriple().isNVPTX() && !TC.getTriple().isAMDGPU())
+      // and we only link it by default for OpenMP currently.
+      if (!TC.getTriple().isNVPTX() && !TC.getTriple().isAMDGPU() ||
+          !JA.isHostOffloading(Action::OFK_OpenMP))
         return;
       bool HasLibC = TC.getStdlibIncludePath().has_value();
       if (HasLibC) {

@arsenm
Copy link
Contributor

arsenm commented Jul 30, 2025

as it could potentially override functions intended to be provided by the ROCm device libraries.

These don't provide any of the standard entry point names

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

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

Missing test

@jhuber6
Copy link
Contributor Author

jhuber6 commented Jul 30, 2025

Missing test

I can't think of an easy way to test this since it looks at the compiler build tree.

@jhuber6 jhuber6 changed the title [Clang] Only C link device libraries by default for OpenMP [Clang] Only link C device libraries by default for OpenMP Jul 30, 2025
@jhuber6
Copy link
Contributor Author

jhuber6 commented Jul 30, 2025

as it could potentially override functions intended to be provided by the ROCm device libraries.

These don't provide any of the standard entry point names

It does in practice, though I haven't bothered to investigate why.

@arsenm
Copy link
Contributor

arsenm commented Aug 1, 2025

Missing test

I can't think of an easy way to test this since it looks at the compiler build tree.

Not sure how this could depend on the build tree, but we have various tests targeting fake sysroots in clang/test/Driver/Inputs

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.

3 participants