diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp --- a/clang/lib/Driver/ToolChains/HIPAMD.cpp +++ b/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, diff --git a/clang/test/Driver/hip-toolchain-rdc-separate.hip b/clang/test/Driver/hip-toolchain-rdc-separate.hip --- a/clang/test/Driver/hip-toolchain-rdc-separate.hip +++ b/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" diff --git a/clang/test/Driver/hip-toolchain-rdc-static-lib.hip b/clang/test/Driver/hip-toolchain-rdc-static-lib.hip --- a/clang/test/Driver/hip-toolchain-rdc-static-lib.hip +++ b/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"