Skip to content

Commit 65850de

Browse files
authored
[HIP] Hack around CMake incorrectly parsing OpenMP support in HIP mode (#164482)
Summary: The new driver uses an embedded clang job to handle the device compilation. This correctly returns the linker as being `ld.lld`. The CMake parser to detect things like OpenMP support in the linker will parse the output of `-v` for the linker job. If the user is also using LLD for their linker, it will think this job is the linker and then fail as it does not see the required libraries. For these special HIP compilations, just print the linker wrapper invocation and nothing else. This will still show users the steps used to generate the binary but it will hack around this issue.
1 parent 18d4ba5 commit 65850de

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9099,6 +9099,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
90999099
};
91009100
auto ShouldForward = [&](const llvm::DenseSet<unsigned> &Set, Arg *A,
91019101
const ToolChain &TC) {
9102+
// CMake hack to avoid printing verbose informatoin for HIP non-RDC mode.
9103+
if (A->getOption().matches(OPT_v) && JA.getType() == types::TY_Object)
9104+
return false;
91029105
return (Set.contains(A->getOption().getID()) ||
91039106
(A->getOption().getGroup().isValid() &&
91049107
Set.contains(A->getOption().getGroup().getID()))) &&
@@ -9174,7 +9177,12 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
91749177

91759178
CmdArgs.push_back(
91769179
Args.MakeArgString("--host-triple=" + getToolChain().getTripleString()));
9177-
if (Args.hasArg(options::OPT_v))
9180+
9181+
// CMake hack, suppress passing verbose arguments for the special-case HIP
9182+
// non-RDC mode compilation. This confuses default CMake implicit linker
9183+
// argument parsing when the language is set to HIP and the system linker is
9184+
// also `ld.lld`.
9185+
if (Args.hasArg(options::OPT_v) && JA.getType() != types::TY_Object)
91789186
CmdArgs.push_back("--wrapper-verbose");
91799187
if (Arg *A = Args.getLastArg(options::OPT_cuda_path_EQ))
91809188
CmdArgs.push_back(

clang/test/Driver/hip-toolchain-no-rdc.hip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,10 @@
214214
// AMDGCNSPIRV: {{".*clang-offload-bundler.*"}} "-type=o"
215215
// AMDGCNSPIRV-SAME: "-targets={{.*}}hipv4-spirv64-amd-amdhsa--amdgcnspirv,hipv4-amdgcn-amd-amdhsa--gfx900"
216216
// AMDGCNSPIRV-SAME: "-input=[[AMDGCNSPV_CO]]" "-input=[[GFX900_CO]]"
217+
218+
// Check verbose printing with the new driver.
219+
// RUN: %clang -### --target=x86_64-linux-gnu -fno-gpu-rdc -nogpulib -nogpuinc \
220+
// RUN: --offload-new-driver --offload-arch=gfx908 -v %s 2>&1 | FileCheck %s --check-prefix=VERBOSE
221+
// VERBOSE: clang-linker-wrapper
222+
// VERBOSE-NOT: --device-compiler=amdgcn-amd-amdhsa=-v
223+
// VERBOSE-NOT: --wrapper-verbose

0 commit comments

Comments
 (0)