[PATCH] D158582: WIP: [AMDGPU] Respect unresolved symbol option if forwarded to linker
Jacob Lambert via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 22 23:29:27 PDT 2023
lamb-j created this revision.
Herald added subscribers: cfe-commits, kerbowa, tpr, dstuttard, yaxunl, jvesely, kzhuravl.
Herald added projects: clang, All.
lamb-j requested review of this revision.
Herald added subscribers: MaskRay, wdng.
Previously, for linking in amdgpu contexts, we always supplied the
--no-undefined option to lld. However, if a user supplies a
"-Wl,--unresolved-symbols=*" or "-Xlinker --unresolved-symbols=*"
option to a clang invocation, that option is now respected over the
default --no-undefined.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158582
Files:
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/test/Driver/amdgpu-toolchain-opencl.cl
clang/test/Driver/amdgpu-toolchain.c
Index: clang/test/Driver/amdgpu-toolchain.c
===================================================================
--- clang/test/Driver/amdgpu-toolchain.c
+++ clang/test/Driver/amdgpu-toolchain.c
@@ -10,6 +10,14 @@
// DWARF_VER: "-dwarf-version=5"
+// RUN: %clang -### --target=amdgcn--amdhsa -x assembler \
+// RUN: -Wl,--unresolved-symbols=ignore-all %s 2>&1 | FileCheck -check-prefix=AS_LINK_UR %s
+// RUN: %clang -### --target=amdgcn--amdhsa -x assembler \
+// RUN: -Xlinker --unresolved-symbols=ignore-all %s 2>&1 | FileCheck -check-prefix=AS_LINK_UR %s
+
+// AS_LINK_UR: "-cc1as"
+// AS_LINK_UR: ld.lld{{.*}} "--unresolved-symbols=ignore-all"
+
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
// RUN: -L. -flto -fconvergent-functions %s 2>&1 | FileCheck -check-prefixes=LTO,MCPU %s
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
Index: clang/test/Driver/amdgpu-toolchain-opencl.cl
===================================================================
--- clang/test/Driver/amdgpu-toolchain-opencl.cl
+++ clang/test/Driver/amdgpu-toolchain-opencl.cl
@@ -28,3 +28,7 @@
// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK %s
// CHK-LINK: ld.lld{{.*}} "--no-undefined" "-shared"
+
+// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -Wl,--unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -Xlinker --unresolved-symbols=ignore-all -x cl -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHK-LINK_UR %s
+// CHK-LINK_UR: ld.lld{{.*}} "--unresolved-symbols=ignore-all"
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -560,7 +560,20 @@
else if (Args.hasArg(options::OPT_mcpu_EQ))
CmdArgs.push_back(Args.MakeArgString(
"-plugin-opt=mcpu=" + Args.getLastArgValue(options::OPT_mcpu_EQ)));
- CmdArgs.push_back("--no-undefined");
+
+ // If the user has manually passed -Wl,--unresolved-symbols=* as a linker
+ // option, we should not add --no-undefined
+ bool UnresolvedOpt = false;
+ for (auto A : Args)
+ if (A->getOption().matches(options::OPT_Wl_COMMA) ||
+ A->getOption().matches(options::OPT_Xlinker))
+ for (StringRef V : A->getValues())
+ if (V.contains("unresolved-symbols"))
+ UnresolvedOpt = true;
+
+ if (!UnresolvedOpt)
+ CmdArgs.push_back("--no-undefined");
+
CmdArgs.push_back("-shared");
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158582.552600.patch
Type: text/x-patch
Size: 2737 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230823/fc9ee1c5/attachment.bin>
More information about the cfe-commits
mailing list