diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4253,13 +4253,15 @@ def rtlib_EQ : Joined<["-", "--"], "rtlib=">, HelpText<"Compiler runtime library to use">; def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, Flags<[NoArgumentUnused]>, - HelpText<"Add -rpath with architecture-specific resource directory to the linker flags">; + HelpText<"Add -rpath with architecture-specific resource directory to the linker flags. " + "When --hip-link is specified, also add -rpath with HIP runtime library directory to the linker flags">; def fno_rtlib_add_rpath: Flag<["-"], "fno-rtlib-add-rpath">, Flags<[NoArgumentUnused]>, - HelpText<"Do not add -rpath with architecture-specific resource directory to the linker flags">; + HelpText<"Do not add -rpath with architecture-specific resource directory to the linker flags. " + "When --hip-link is specified, do not add -rpath with HIP runtime library directory to the linker flags">; def offload_add_rpath: Flag<["--"], "offload-add-rpath">, Flags<[NoArgumentUnused]>, - HelpText<"Add -rpath with HIP runtime library directory to the linker flags">; + Alias; def no_offload_add_rpath: Flag<["--"], "no-offload-add-rpath">, Flags<[NoArgumentUnused]>, - HelpText<"Do not add -rpath with HIP runtime library directory to the linker flags">; + Alias; def r : Flag<["-"], "r">, Flags<[LinkerInput,NoArgumentUnused]>, Group; def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[CC1Option, FlangOption, NoXarchOption]>, diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -694,8 +694,8 @@ CmdArgs.push_back( Args.MakeArgString(StringRef("-L") + RocmInstallation->getLibPath())); - if (Args.hasFlag(options::OPT_offload_add_rpath, - options::OPT_no_offload_add_rpath, false)) + if (Args.hasFlag(options::OPT_frtlib_add_rpath, + options::OPT_fno_rtlib_add_rpath, false)) CmdArgs.append( {"-rpath", Args.MakeArgString(RocmInstallation->getLibPath())}); diff --git a/clang/test/Driver/hip-runtime-libs-linux.hip b/clang/test/Driver/hip-runtime-libs-linux.hip --- a/clang/test/Driver/hip-runtime-libs-linux.hip +++ b/clang/test/Driver/hip-runtime-libs-linux.hip @@ -16,6 +16,10 @@ // RUN: --rocm-path=%S/Inputs/rocm %t.o --offload-add-rpath 2>&1 \ // RUN: | FileCheck -check-prefixes=ROCM-RPATH %s +// RUN: %clang -### --hip-link --target=x86_64-linux-gnu \ +// RUN: --rocm-path=%S/Inputs/rocm %t.o -frtlib-add-rpath 2>&1 \ +// RUN: | FileCheck -check-prefixes=ROCM-RPATH %s + // Test detecting latest /opt/rocm-{release} directory. // RUN: rm -rf %t && mkdir -p %t/opt // RUN: cp -r %S/Inputs/rocm %t/opt/rocm-3.9.0-1234