[clang] [Clang] Do not pass `-shared` when using `-r` for AMDGPU (PR #100760)
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 26 08:11:27 PDT 2024
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/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.
>From 139e9f9bb05b86ff2c33ea9c93113a02902ed974 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 26 Jul 2024 10:07:27 -0500
Subject: [PATCH] [Clang] Do not pass `-shared` when using `-r` for AMDGPU
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.
---
clang/lib/Driver/ToolChains/AMDGPU.cpp | 6 ++++--
clang/test/Driver/amdgpu-toolchain.c | 4 ++++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index f6c7300162b9e..f796c31af8f67 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -620,8 +620,10 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const char *LinkingOutput) const {
std::string Linker = getToolChain().GetLinkerPath();
ArgStringList CmdArgs;
- CmdArgs.push_back("--no-undefined");
- CmdArgs.push_back("-shared");
+ if (!Args.hasArg(options::OPT_r)) {
+ CmdArgs.push_back("--no-undefined");
+ CmdArgs.push_back("-shared");
+ }
addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
Args.AddAllArgs(CmdArgs, options::OPT_L);
diff --git a/clang/test/Driver/amdgpu-toolchain.c b/clang/test/Driver/amdgpu-toolchain.c
index 8ab6a07131474..ebd1158b63074 100644
--- a/clang/test/Driver/amdgpu-toolchain.c
+++ b/clang/test/Driver/amdgpu-toolchain.c
@@ -28,3 +28,7 @@
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
// RUN: -fuse-ld=ld %s 2>&1 | FileCheck -check-prefixes=LD %s
// LD: ld.lld
+
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
+// RUN: -r %s 2>&1 | FileCheck -check-prefixes=RELO %s
+// RELO-NOT: -shared
More information about the cfe-commits
mailing list