Skip to content

Commit 55b4344

Browse files
committed
[HIP] add --offload-add-rpath
Add an option --[no-]offload-add-rpath to control whether to pass -rpath to linker for HIP runtime library. By default it is off to match gcc/clang behavior for not adding -rpath for runtime library by default. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D136854
1 parent 5eb1fbd commit 55b4344

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4153,6 +4153,10 @@ def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, Flags<[NoArgumentUnused]>
41534153
HelpText<"Add -rpath with architecture-specific resource directory to the linker flags">;
41544154
def fno_rtlib_add_rpath: Flag<["-"], "fno-rtlib-add-rpath">, Flags<[NoArgumentUnused]>,
41554155
HelpText<"Do not add -rpath with architecture-specific resource directory to the linker flags">;
4156+
def offload_add_rpath: Flag<["--"], "offload-add-rpath">, Flags<[NoArgumentUnused]>,
4157+
HelpText<"Add -rpath with HIP runtime library directory to the linker flags">;
4158+
def no_offload_add_rpath: Flag<["--"], "no-offload-add-rpath">, Flags<[NoArgumentUnused]>,
4159+
HelpText<"Do not add -rpath with HIP runtime library directory to the linker flags">;
41564160
defm openmp_implicit_rpath: BoolFOption<"openmp-implicit-rpath",
41574161
LangOpts<"OpenMP">,
41584162
DefaultTrue,

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,13 @@ void Linux::AddHIPIncludeArgs(const ArgList &DriverArgs,
689689

690690
void Linux::AddHIPRuntimeLibArgs(const ArgList &Args,
691691
ArgStringList &CmdArgs) const {
692-
CmdArgs.append(
693-
{Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()),
694-
"-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
692+
CmdArgs.push_back(
693+
Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()));
694+
695+
if (Args.hasFlag(options::OPT_offload_add_rpath,
696+
options::OPT_no_offload_add_rpath, false))
697+
CmdArgs.append(
698+
{"-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
695699

696700
CmdArgs.push_back("-lamdhip64");
697701
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
// RUN: --target=x86_64-linux-gnu %t.o 2>&1 \
1313
// RUN: | FileCheck -check-prefixes=ROCM-PATH %s
1414

15+
// RUN: %clang -### --hip-link --target=x86_64-linux-gnu \
16+
// RUN: --rocm-path=%S/Inputs/rocm %t.o --offload-add-rpath 2>&1 \
17+
// RUN: | FileCheck -check-prefixes=ROCM-RPATH %s
18+
1519
// Test detecting latest /opt/rocm-{release} directory.
1620
// RUN: rm -rf %t && mkdir -p %t/opt
1721
// RUN: cp -r %S/Inputs/rocm %t/opt/rocm-3.9.0-1234
@@ -35,8 +39,9 @@
3539
// RUN: --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
3640
// RUN: | FileCheck -check-prefixes=NOHIPRT %s
3741

38-
// ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
39-
// ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
42+
// ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-lamdhip64"
43+
// ROCM-RPATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
44+
// ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-lamdhip64"
4045
// NOHIPRT-NOT: "-L{{.*/Inputs/rocm/lib}}"
4146
// NOHIPRT-NOT: "-rpath" "{{.*/Inputs/rocm/lib}}"
4247
// NOHIPRT-NOT: "-lamdhip64"

0 commit comments

Comments
 (0)