[llvm] [Liboffload] Add function for checking ELF file device compatibility (PR #156259)

Jonas Greifenhain via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 2 11:06:32 PDT 2025


cadivus wrote:

@jhuber6 The code for the detection exists, I just need to move it:
```
const char *llvmRegisterFatBinary(const char *Binary) {

  const auto *FW = reinterpret_cast<const FatbinWrapperTy *>(Binary);
  // printf("%s : %i : %s (%p:%p) :: %i\n", __PRETTY_FUNCTION__, FW->Magic,
  //        FW->Data, FW->Data, FW->DataEnd, FW->Version);

  // printf("%s : %s : %lu\n", FW->Data, HIP_FATBIN_MAGIC_STR,
  //        HIP_FATBIN_MAGIC_STR_LEN);
  if (FW->Magic == 0x466243b1) {
    readTUFatbin(Binary, FW);
  } else if (FW->Magic == 0x48495046) {
    if (!memcmp(FW->Data, HIP_FATBIN_MAGIC_STR, HIP_FATBIN_MAGIC_STR_LEN))
      readHIPFatbinEntries(Binary, FW->Data);
    else
      readTUFatbin(Binary, FW);
  } else {
    fprintf(stderr, "Unknown fatbin format");
  }

  return Binary;
}
```
(https://github.com/jdoerfert/llvm-project/blob/3c8c45d17024356438278f48f9d9e894f96c8c4e/offload/languages/kernel/src/LanguageRegistration.cpp#L219)

If you disable a few assertions across LLVM, you can technically load Cuda fat binaries. To not just hack it, I think it needs many changes across ofloading.

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


More information about the llvm-commits mailing list