[PATCH] D152207: [HIP] Instruct lld to go through all archives
Siu Chi Chan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 5 16:00:29 PDT 2023
scchan created this revision.
Herald added a subscriber: yaxunl.
Herald added a project: All.
scchan requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.
Add the --whole-archive flag when linking HIP programs to instruct lld
to go through every archive library to link in all the kernel functions
(entry pointers to the GPU program); otherwise, lld may skip some
library files if there are no more symbols that need to be resolved.
Change-Id: Ic7ea61ec3e6925f80a63d04654ac72177ffb27c8
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D152207
Files:
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/test/Driver/hip-toolchain-rdc-separate.hip
clang/test/Driver/hip-toolchain-rdc-static-lib.hip
Index: clang/test/Driver/hip-toolchain-rdc-static-lib.hip
===================================================================
--- clang/test/Driver/hip-toolchain-rdc-static-lib.hip
+++ clang/test/Driver/hip-toolchain-rdc-static-lib.hip
@@ -81,6 +81,7 @@
// CHECK: [[LLD]] {{.*}} "-plugin-opt=-amdgpu-internalize-symbols"
// CHECK-SAME: "-plugin-opt=mcpu=gfx900"
// CHECK-SAME: "-o" "[[IMG_DEV2:.*out]]" [[A_BC2]] [[B_BC2]]
+// CHECK-SAME: "--whole-archive"
// combine images generated into hip fat binary object
// CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
Index: clang/test/Driver/hip-toolchain-rdc-separate.hip
===================================================================
--- clang/test/Driver/hip-toolchain-rdc-separate.hip
+++ clang/test/Driver/hip-toolchain-rdc-separate.hip
@@ -129,6 +129,7 @@
// LLD-TMP-SAME: "-o" "[[IMG_DEV1:.*.out]]"
// LLD-FIN-SAME: "-o" "[[IMG_DEV1:a.out-.*gfx803]]"
// LINK-SAME "[[A_BC1]]" "[[B_BC1]]"
+// LINK-SAME: "--whole-archive"
// LINK-NOT: "*.llvm-link"
// LINK-NOT: ".*opt"
@@ -138,6 +139,7 @@
// LLD-TMP-SAME: "-o" "[[IMG_DEV2:.*.out]]"
// LLD-FIN-SAME: "-o" "[[IMG_DEV1:a.out-.*gfx900]]"
// LINK-SAME "[[A_BC2]]" "[[B_BC2]]"
+// LINK-SAME: "--whole-archive"
// LINK-BUNDLE: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
// LINK-BUNDLE-SAME: "-targets={{.*}},hipv4-amdgcn-amd-amdhsa--gfx803,hipv4-amdgcn-amd-amdhsa--gfx900"
Index: clang/lib/Driver/ToolChains/HIPAMD.cpp
===================================================================
--- clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -163,6 +163,9 @@
// Look for archive of bundled bitcode in arguments, and add temporary files
// for the extracted archive of bitcode to inputs.
+ // The archive libraries have to be linked with --whole-archive to instruct
+ // the linker to go through every library to look for kernel functions
+ LldArgs.push_back("--whole-archive");
auto TargetID = Args.getLastArgValue(options::OPT_mcpu_EQ);
AddStaticDeviceLibsLinking(C, *this, JA, Inputs, Args, LldArgs, "amdgcn",
TargetID,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152207.528615.patch
Type: text/x-patch
Size: 2138 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230605/cd9916f7/attachment.bin>
More information about the cfe-commits
mailing list