Skip to content

Commit 7e8f1f5

Browse files
authored
[HIP] Remove dots in HIP runtime path (#143792)
Remove the dots in the HIP path before passing to the rpath flag
1 parent 802fa92 commit 7e8f1f5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,11 @@ void Linux::AddHIPRuntimeLibArgs(const ArgList &Args,
743743
Args.MakeArgString(StringRef("-L") + RocmInstallation->getLibPath()));
744744

745745
if (Args.hasFlag(options::OPT_frtlib_add_rpath,
746-
options::OPT_fno_rtlib_add_rpath, false))
747-
CmdArgs.append(
748-
{"-rpath", Args.MakeArgString(RocmInstallation->getLibPath())});
746+
options::OPT_fno_rtlib_add_rpath, false)) {
747+
SmallString<0> p = RocmInstallation->getLibPath();
748+
llvm::sys::path::remove_dots(p, true);
749+
CmdArgs.append({"-rpath", Args.MakeArgString(p)});
750+
}
749751

750752
CmdArgs.push_back("-lamdhip64");
751753
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
// RUN: --rocm-path=%S/Inputs/rocm %t.o -frtlib-add-rpath 2>&1 \
2121
// RUN: | FileCheck -check-prefixes=ROCM-RPATH %s
2222

23+
// Test that a canonical HIP runtime path is passed to the -rpath flag
24+
// RUN: %clang -### --hip-link --target=x86_64-linux-gnu \
25+
// RUN: --rocm-path=%S/Inputs/rocm/./bin/../include/../ %t.o -frtlib-add-rpath 2>&1 \
26+
// RUN: | FileCheck -check-prefixes=ROCM-RPATH-CANONICAL %s
27+
2328
// Test detecting latest /opt/rocm-{release} directory.
2429
// RUN: rm -rf %t && mkdir -p %t/opt
2530
// RUN: cp -r %S/Inputs/rocm %t/opt/rocm-3.9.0-1234
@@ -55,6 +60,7 @@
5560

5661
// ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-lamdhip64"
5762
// ROCM-RPATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
63+
// ROCM-RPATH-CANONICAL: "-rpath" "{{.*/rocm/lib}}" "-lamdhip64"
5864
// ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-lamdhip64"
5965
// NOHIPRT-NOT: "-L{{.*/Inputs/rocm/lib}}"
6066
// NOHIPRT-NOT: "-rpath" "{{.*/Inputs/rocm/lib}}"

0 commit comments

Comments
 (0)