diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -182,6 +182,16 @@ BundlerExecutable = sys::fs::getMainExecutable(argv[0], &BundlerExecutable); + // Find llvm-objcopy in order to create the bundle binary. + ErrorOr Objcopy = sys::findProgramByName( + "llvm-objcopy", + sys::path::parent_path(BundlerExecutable)); + if (!Objcopy) + Objcopy = sys::findProgramByName("llvm-objcopy"); + if (!Objcopy) + reportError(createStringError(Objcopy.getError(), + "unable to find 'llvm-objcopy' in path")); + if (InputFileNames.getNumOccurrences() != 0 && InputFileNamesDeprecatedOpt.getNumOccurrences() != 0) { reportError(createStringError( @@ -233,7 +243,7 @@ Config BundlerPrint; BundlerPrint.PrintExternalCommands = PrintExternalCommands; - BundlerPrint.BundlerExecutable = BundlerExecutable; + BundlerPrint.ObjcopyPath = *Objcopy; doWork([&]() { return ListBundleIDsInFile(InputFileNames.front(), &BundlerPrint); }); return 0; @@ -294,7 +304,7 @@ Config BundlerOpenmp; BundlerOpenmp.HipOpenmpCompatible = HipOpenmpCompatible; - BundlerOpenmp.BundlerExecutable = BundlerExecutable; + BundlerOpenmp.ObjcopyPath = *Objcopy; auto OffloadInfo = OffloadTargetInfo(Target, &BundlerOpenmp); bool KindIsValid = OffloadInfo.isOffloadKindValid(); bool TripleIsValid = OffloadInfo.isTripleValid(); @@ -344,7 +354,7 @@ BundlerConfig.BundleAlignment = BundleAlignment; BundlerConfig.HostInputIndex = HostInputIndex; BundlerConfig.FilesType = FilesType; - BundlerConfig.BundlerExecutable = BundlerExecutable; + BundlerConfig.ObjcopyPath = *Objcopy; BundlerConfig.TargetNames = TargetNames; BundlerConfig.InputFileNames = InputFileNames; diff --git a/clang/tools/clang-offload-bundler/OffloadBundler.h b/clang/tools/clang-offload-bundler/OffloadBundler.h --- a/clang/tools/clang-offload-bundler/OffloadBundler.h +++ b/clang/tools/clang-offload-bundler/OffloadBundler.h @@ -29,7 +29,7 @@ unsigned HostInputIndex = ~0u; std::string FilesType; - std::string BundlerExecutable; + std::string ObjcopyPath; // TODO: Convert these to llvm::SmallVector std::vector TargetNames; diff --git a/clang/tools/clang-offload-bundler/OffloadBundler.cpp b/clang/tools/clang-offload-bundler/OffloadBundler.cpp --- a/clang/tools/clang-offload-bundler/OffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/OffloadBundler.cpp @@ -587,15 +587,8 @@ // link editor to remove them from linker inputs when linking executable or // shared library. - // Find llvm-objcopy in order to create the bundle binary. - ErrorOr Objcopy = sys::findProgramByName( - "llvm-objcopy", - sys::path::parent_path(BundlerConfig->BundlerExecutable)); - if (!Objcopy) - Objcopy = sys::findProgramByName("llvm-objcopy"); - if (!Objcopy) - return createStringError(Objcopy.getError(), - "unable to find 'llvm-objcopy' in path"); + assert(BundlerConfig->ObjcopyPath != "" && + "llvm-objcopy path not specified"); // We write to the output file directly. So, we close it and use the name // to pass down to llvm-objcopy. @@ -636,7 +629,7 @@ BundlerConfig->InputFileNames[BundlerConfig->HostInputIndex]); ObjcopyArgs.push_back(BundlerConfig->OutputFileNames.front()); - if (Error Err = executeObjcopy(*Objcopy, ObjcopyArgs)) + if (Error Err = executeObjcopy(BundlerConfig->ObjcopyPath, ObjcopyArgs)) return Err; return Error::success();