Skip to content

Commit 50835f0

Browse files
authored
[Clang] Do not pass -shared when using -r for AMDGPU (#100760)
Summary: We can use `-r` and `--lto-emit-llvm` to get the LTO pass to optimize + link LLVM-IR. Currently this doesn't work on AMDGPU because it always passes `-shared` which is incompatible with `-r`. Fix that so we can use it.
1 parent 7345025 commit 50835f0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,10 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
620620
const char *LinkingOutput) const {
621621
std::string Linker = getToolChain().GetLinkerPath();
622622
ArgStringList CmdArgs;
623-
CmdArgs.push_back("--no-undefined");
624-
CmdArgs.push_back("-shared");
623+
if (!Args.hasArg(options::OPT_r)) {
624+
CmdArgs.push_back("--no-undefined");
625+
CmdArgs.push_back("-shared");
626+
}
625627

626628
addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
627629
Args.AddAllArgs(CmdArgs, options::OPT_L);

clang/test/Driver/amdgpu-toolchain.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@
2828
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
2929
// RUN: -fuse-ld=ld %s 2>&1 | FileCheck -check-prefixes=LD %s
3030
// LD: ld.lld
31+
32+
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
33+
// RUN: -r %s 2>&1 | FileCheck -check-prefixes=RELO %s
34+
// RELO-NOT: -shared

0 commit comments

Comments
 (0)