[llvm] [llvm][tools] Add support to llvm-offload-binary to unbundle spirv64-intel images (PR #184774)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 5 05:34:40 PST 2026
================
@@ -135,6 +137,116 @@ static Error bundleImages() {
return Error::success();
}
+// Extract SPIR-V binaries from an ELF image with triple "spirv64-intel" or
+// "spirv32-intel". These ELF images contain SPIR-V binaries in sections named
+// "__openmp_offload_spirv_*".
+static Expected<SmallVector<StringRef>>
+extractSPIRVFromELF(StringRef ImageData) {
+ SmallVector<StringRef> SPIRVBinaries;
+
+ // Try to parse as ELF object file
+ Expected<std::unique_ptr<ObjectFile>> ObjOrErr =
+ ObjectFile::createObjectFile(MemoryBufferRef(ImageData, "spirv-elf"));
+ if (!ObjOrErr)
+ return ObjOrErr.takeError();
+
+ ObjectFile &Obj = *ObjOrErr->get();
+ if (!Obj.isELF())
+ return createStringError(inconvertibleErrorCode(),
+ "Expected ELF format for Intel SPIR-V image");
+
+ // Extract all sections with name matching "__openmp_offload_spirv_*"
+ for (const SectionRef &Sec : Obj.sections()) {
+ Expected<StringRef> NameOrErr = Sec.getName();
----------------
jhuber6 wrote:
Error needs to be consumed.
https://github.com/llvm/llvm-project/pull/184774
More information about the llvm-commits
mailing list