[clang] [llvm] [SYCL] Add clang-linker-wrapper changes to call clang-sycl-linker for SYCL offloads (PR #135683)

Arvind Sudarsanam via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 14 16:23:31 PDT 2025


================
@@ -937,13 +961,47 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
       InputFiles.emplace_back(*FileNameOrErr);
     }
 
+    if (HasSYCLOffloadKind) {
+      // Link the remaining device files using the device linker.
+      auto OutputOrErr = linkDevice(InputFiles, LinkerArgs, HasSYCLOffloadKind);
+      if (!OutputOrErr)
+        return OutputOrErr.takeError();
+      // Output is a packaged object of device images. Unpackage the images and
+      // copy them to Images[Kind]
+      ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
+          MemoryBuffer::getFileOrSTDIN(*OutputOrErr);
+      if (std::error_code EC = BufferOrErr.getError())
+        return createFileError(*OutputOrErr, EC);
+
+      MemoryBufferRef Buffer = **BufferOrErr;
+      SmallVector<OffloadFile> Binaries;
+      if (Error Err = extractOffloadBinaries(Buffer, Binaries))
+        return std::move(Err);
+      for (auto &OffloadFile : Binaries) {
----------------
asudarsa wrote:

There are subtle changes here. In the other use site, we look at input filenames provided to clang-linker-wrapper and collect two lists of OffloadFiles - object files and archived files. In this new use site, we look at the output file returned by clang-sycl-linker and try to collect a list of OffloadingImages corresponding to the list of object files generated in clang-sycl-linker.
I tried merging the two use sites. it seems to make the code more complicated than necessary.
Please let me know if I am missing something here.

Thanks 

https://github.com/llvm/llvm-project/pull/135683


More information about the llvm-commits mailing list