Skip to content

Commit c984132

Browse files
authored
[Driver][HIP][HIPSTDPAR][Windows] Link the HIP RT even when -nostdlib (#154630)
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-existent `glibc`. 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 breaks `hipstdpar`, 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.
1 parent f9bd187 commit c984132

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2986,7 +2986,8 @@ void tools::addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C,
29862986
const llvm::opt::ArgList &Args,
29872987
llvm::opt::ArgStringList &CmdArgs) {
29882988
if ((C.getActiveOffloadKinds() & Action::OFK_HIP) &&
2989-
!Args.hasArg(options::OPT_nostdlib) &&
2989+
(!Args.hasArg(options::OPT_nostdlib) ||
2990+
TC.getTriple().isKnownWindowsMSVCEnvironment()) &&
29902991
!Args.hasArg(options::OPT_no_hip_rt) && !Args.hasArg(options::OPT_r)) {
29912992
TC.AddHIPRuntimeLibArgs(Args, CmdArgs);
29922993
} else {

clang/test/Driver/hip-runtime-libs-msvc.hip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@
1010
// RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \
1111
// RUN: | FileCheck %s
1212

13+
// Test HIP runtime lib is linked even if -nostdlib is specified when the input
14+
// is a HIP file. This is important when composing with e.g. the UCRT or other
15+
// non glibc-like implementations of the C standard library.
16+
// RUN: %clang -### --target=x86_64-pc-windows-msvc -nogpuinc -nogpulib \
17+
// RUN: -nostdlib --rocm-path=%S/Inputs/rocm %s 2>&1 \
18+
// RUN: | FileCheck %s
19+
1320
// CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"

0 commit comments

Comments
 (0)