Skip to content

Commit e7175b0

Browse files
authored
[HIP] do not link runtime for -r (#85675)
since it will cause duplicate symbols when the partially linked object is linked again.
1 parent db7d0ed commit e7175b0

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2830,7 +2830,7 @@ void tools::addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C,
28302830
llvm::opt::ArgStringList &CmdArgs) {
28312831
if ((C.getActiveOffloadKinds() & Action::OFK_HIP) &&
28322832
!Args.hasArg(options::OPT_nostdlib) &&
2833-
!Args.hasArg(options::OPT_no_hip_rt)) {
2833+
!Args.hasArg(options::OPT_no_hip_rt) && !Args.hasArg(options::OPT_r)) {
28342834
TC.AddHIPRuntimeLibArgs(Args, CmdArgs);
28352835
} else {
28362836
// Claim "no HIP libraries" arguments if any

clang/test/Driver/hip-partial-link.hip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
// OBJ: D __hip_gpubin_handle_[[ID2]]
4848

4949
// RUN: %clang -v --target=x86_64-unknown-linux-gnu --no-offload-new-driver \
50-
// RUN: --hip-link -no-hip-rt -fgpu-rdc --offload-arch=gfx906 \
50+
// RUN: --hip-link -fgpu-rdc --offload-arch=gfx906 \
5151
// RUN: -fuse-ld=lld -nostdlib -r %t.main.o %t.lib.o -o %t.final.o \
5252
// RUN: 2>&1 | FileCheck -check-prefix=LINK-O %s
5353
// LINK-O-NOT: Found undefined HIP {{.*}}symbol

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
// RUN: --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
4444
// RUN: | FileCheck -check-prefixes=NOHIPRT %s
4545

46+
// Test HIP runtime lib is not linked with -r.
47+
// RUN: %clang -### --hip-link -r --target=x86_64-linux-gnu \
48+
// RUN: --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
49+
// RUN: | FileCheck -check-prefixes=NOHIPRT %s
50+
4651
// Test HIP runtime lib is linked without hip-link if there is HIP input file.
4752
// RUN: %clang -### --target=x86_64-linux-gnu -nogpuinc -nogpulib \
4853
// RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \

0 commit comments

Comments
 (0)