@@ -898,7 +898,7 @@ Error handleOverrideImages(
898898// / be registered by the runtime.
899899Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles (
900900 SmallVectorImpl<SmallVector<OffloadFile>> &LinkerInputFiles,
901- const InputArgList &Args, char **Argv, int Argc) {
901+ InputArgList &Args, char **Argv, int Argc) {
902902 llvm::TimeTraceScope TimeScope (" Handle all device input" );
903903
904904 std::mutex ImageMtx;
@@ -909,6 +909,9 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
909909 if (Error Err = handleOverrideImages (Args, Images))
910910 return std::move (Err);
911911
912+ bool ExcludeNVPTX = Args.hasArg (OPT_no_nvptx_whole_archive);
913+ bool ExcludeAMDGPU = Args.hasArg (OPT_no_amdgpu_whole_archive);
914+
912915 auto Err = parallelForEachError (LinkerInputFiles, [&](auto &Input) -> Error {
913916 llvm::TimeTraceScope TimeScope (" Link device input" );
914917
@@ -923,6 +926,13 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
923926 });
924927 auto LinkerArgs = getLinkerArgs (Input, BaseArgs);
925928
929+ const llvm::Triple Triple (LinkerArgs.getLastArgValue (OPT_triple_EQ));
930+ if (Triple.isNVPTX () && ExcludeNVPTX)
931+ return Error::success ();
932+
933+ if (Triple.isAMDGPU () && ExcludeAMDGPU)
934+ return Error::success ();
935+
926936 DenseSet<OffloadKind> ActiveOffloadKinds;
927937 for (const auto &File : Input)
928938 if (File.getBinary ()->getOffloadKind () != OFK_None)
@@ -975,6 +985,13 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
975985 if (Err)
976986 return std::move (Err);
977987
988+ // This option is specific to this link phase and the preceding link tools
989+ // do not understand this option so we remove it now that we're done with it.
990+ if (ExcludeNVPTX)
991+ Args.eraseArg (OPT_no_nvptx_whole_archive);
992+ if (ExcludeAMDGPU)
993+ Args.eraseArg (OPT_no_amdgpu_whole_archive);
994+
978995 // Create a binary image of each offloading image and embed it into a new
979996 // object file.
980997 SmallVector<StringRef> WrappedOutput;
0 commit comments