-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[Driver][HIP][HIPSTDPAR][Windows] Link the HIP RT even when -nostdlib
#154630
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
[Driver][HIP][HIPSTDPAR][Windows] Link the HIP RT even when -nostdlib
#154630
Conversation
… HIPSTDPAR runtime component.
…dlib_should_not_always_imply_no_hip_lib
@llvm/pr-subscribers-clang Author: Alex Voicu (AlexVlx) ChangesIn Windows, on a MSVC environment (e.g. when linking against the UCRT), Full diff: https://github.com/llvm/llvm-project/pull/154630.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index a21f89da55009..055906a8d721d 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2986,7 +2986,8 @@ void tools::addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C,
const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) {
if ((C.getActiveOffloadKinds() & Action::OFK_HIP) &&
- !Args.hasArg(options::OPT_nostdlib) &&
+ (!Args.hasArg(options::OPT_nostdlib) ||
+ TC.getTriple().isKnownWindowsMSVCEnvironment()) &&
!Args.hasArg(options::OPT_no_hip_rt) && !Args.hasArg(options::OPT_r)) {
TC.AddHIPRuntimeLibArgs(Args, CmdArgs);
} else {
diff --git a/clang/test/Driver/hip-runtime-libs-msvc.hip b/clang/test/Driver/hip-runtime-libs-msvc.hip
index 943cd0569f4fd..d282a2646342a 100644
--- a/clang/test/Driver/hip-runtime-libs-msvc.hip
+++ b/clang/test/Driver/hip-runtime-libs-msvc.hip
@@ -10,4 +10,11 @@
// RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \
// RUN: | FileCheck %s
+// Test HIP runtime lib is linked even if -nostdlib is specified when the input
+// is a HIP file. This is important when composing with e.g. the UCRT or other
+// non glibc-like implementations of the C standard library.
+// RUN: %clang -### --target=x86_64-pc-windows-msvc -nogpuinc -nogpulib \
+// RUN: -nostdlib --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN: | FileCheck %s
+
// CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"
|
@llvm/pr-subscribers-clang-driver Author: Alex Voicu (AlexVlx) ChangesIn Windows, on a MSVC environment (e.g. when linking against the UCRT), Full diff: https://github.com/llvm/llvm-project/pull/154630.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index a21f89da55009..055906a8d721d 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2986,7 +2986,8 @@ void tools::addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C,
const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) {
if ((C.getActiveOffloadKinds() & Action::OFK_HIP) &&
- !Args.hasArg(options::OPT_nostdlib) &&
+ (!Args.hasArg(options::OPT_nostdlib) ||
+ TC.getTriple().isKnownWindowsMSVCEnvironment()) &&
!Args.hasArg(options::OPT_no_hip_rt) && !Args.hasArg(options::OPT_r)) {
TC.AddHIPRuntimeLibArgs(Args, CmdArgs);
} else {
diff --git a/clang/test/Driver/hip-runtime-libs-msvc.hip b/clang/test/Driver/hip-runtime-libs-msvc.hip
index 943cd0569f4fd..d282a2646342a 100644
--- a/clang/test/Driver/hip-runtime-libs-msvc.hip
+++ b/clang/test/Driver/hip-runtime-libs-msvc.hip
@@ -10,4 +10,11 @@
// RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \
// RUN: | FileCheck %s
+// Test HIP runtime lib is linked even if -nostdlib is specified when the input
+// is a HIP file. This is important when composing with e.g. the UCRT or other
+// non glibc-like implementations of the C standard library.
+// RUN: %clang -### --target=x86_64-pc-windows-msvc -nogpuinc -nogpulib \
+// RUN: -nostdlib --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN: | FileCheck %s
+
// CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"
|
In Windows, on a MSVC environment (e.g. when linking against the UCRT),
-nostdlib
is used (for example, by CMake) to prevent linking in non-existentglibc
. However, an unintended side-effect is that we end up never linking in the HIP RT in these circumstances, even when--hip-link
is explicitly specified. This breakshipstdpar
, where we implicitly link in the HIP RT when--hipstdpar
is passed as a link flag. To fix this, we relax the restriction on linking the HIP RT, for known MSVC environments.