[Openmp-commits] [PATCH] D124525: [OpenMP][ClangLinkerWrapper] Extending linker wrapper to embed metadata for multi-arch fat binaries

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed May 4 08:00:03 PDT 2022


jhuber6 added a comment.

I'm suggesting instead we define a new `__tgt_device_image` and a new `__tgt_register_lib` function to support this. This new `__tgt_device_image` will simply contain a pointer to an optional information struct.

  struct __tgt_device_image_v2 {
    void* 	ImageStart;
    void* 	ImageEnd;
    __tgt_offload_entry* 	EntriesBegin;
    __tgt_offload_entry* 	EntriesEnd;
    __tgt_image_into*  ImageInfo;
  };

This new struct breaks the ABI with the old `__tgt_device_image` because these are put into an array and we change the size, but we should be able to provide backwards compatibility by copying from the old format to the new format and creating a new array. We can detect the new vs. old ABI by expecting that existing applications will call the `__tgt_register_image` function. We will create a new `__tgt_register_image_v2` function for example that all new programs will call. In `libomptarget` we then change `__tgt_register_image` to do the necessary translation.

  struct __tgt_bin_desc {                                                                                                                                                                  
    int32_t NumDeviceImages;           // Number of device types supported                                                                                                                   
    __tgt_device_image *DeviceImages;  // Array of device images (1 per dev. type)                                                        
    __tgt_offload_entry *HostEntriesBegin; // Begin of table with all host entries                                                           
    __tgt_offload_entry *HostEntriesEnd;   // End of table (non inclusive)                                                                                                           
  };
  
  EXTERN void __tgt_register_lib(__tgt_bin_desc *desc) {
    __tgt_device_image_v2 *new_image = alloc_new_version(desc);
    desc->DeviceImages = new_Image;
    __tgt_register_lib_v2(desc);
  }
  
  EXTERN void __tgt_unregister_lib(__tgt_bin_desc *desc) { // Probably called by __tgt_unregister_lib_v2
    dealloc(desc->DeviceImages);
  }

Now the rest of `libomptarget` solely uses the new format, and we check if information is available by seeing that the `ImageInfo` field is non-null.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124525/new/

https://reviews.llvm.org/D124525



More information about the Openmp-commits mailing list