LLVM 23.0.0git
llvm::object::OffloadBinary Class Reference

A simple binary serialization of an offloading file. More...

#include "llvm/Object/OffloadBinary.h"

Inheritance diagram for llvm::object::OffloadBinary:
[legend]

Classes

struct  Entry
struct  Header
struct  OffloadingImage
 The offloading metadata that will be serialized to a memory buffer. More...
struct  StringEntry
struct  StringEntryV1

Public Types

using string_iterator = MapVector<StringRef, StringRef>::const_iterator
using string_iterator_range = iterator_range<string_iterator>

Public Member Functions

ImageKind getImageKind () const
OffloadKind getOffloadKind () const
uint32_t getVersion () const
uint32_t getFlags () const
uint64_t getSize () const
uint64_t getIndex () const
StringRef getTriple () const
StringRef getArch () const
StringRef getImage () const
string_iterator_range strings () const
StringRef getString (StringRef Key) const
Public Member Functions inherited from llvm::object::Binary
 Binary ()=delete
 Binary (const Binary &other)=delete
virtual ~Binary ()
virtual Error initContent ()
StringRef getData () const
StringRef getFileName () const
MemoryBufferRef getMemoryBufferRef () const
unsigned int getType () const
bool isObject () const
bool isSymbolic () const
bool isArchive () const
bool isMachOUniversalBinary () const
bool isTapiUniversal () const
bool isELF () const
bool isMachO () const
bool isCOFF () const
bool isXCOFF () const
bool isWasm () const
bool isOffloadFile () const
bool isCOFFImportFile () const
bool isIR () const
bool isGOFF () const
bool isMinidump () const
bool isTapiFile () const
bool isLittleEndian () const
bool isWinRes () const
bool isDXContainer () const
Triple::ObjectFormatType getTripleObjectFormat () const

Static Public Member Functions

static LLVM_ABI Expected< const Header * > extractHeader (MemoryBufferRef Buf)
 Attempt to extract and validate the header from the offloading binary in Buf.
static LLVM_ABI Expected< SmallVector< std::unique_ptr< OffloadBinary > > > create (MemoryBufferRef Buf, std::optional< uint64_t > Index=std::nullopt)
 Attempt to parse the offloading binary stored in Buf.
static LLVM_ABI SmallString< 0 > write (ArrayRef< OffloadingImage > OffloadingData)
 Serialize the contents of OffloadingData to a binary buffer to be read later.
static uint64_t getAlignment ()
static bool classof (const Binary *V)
Static Public Member Functions inherited from llvm::object::Binary
static Error checkOffset (MemoryBufferRef M, uintptr_t Addr, const uint64_t Size)

Static Public Attributes

static const uint32_t Version = 2
 The current version of the binary used for backwards compatibility.

Additional Inherited Members

Protected Types inherited from llvm::object::Binary
enum  {
  ID_Archive , ID_MachOUniversalBinary , ID_COFFImportFile , ID_IR ,
  ID_TapiUniversal , ID_TapiFile , ID_Minidump , ID_WinRes ,
  ID_Offload , ID_StartObjects , ID_COFF , ID_XCOFF32 ,
  ID_XCOFF64 , ID_ELF32L , ID_ELF32B , ID_ELF64L ,
  ID_ELF64B , ID_MachO32L , ID_MachO32B , ID_MachO64L ,
  ID_MachO64B , ID_GOFF , ID_Wasm , ID_DXContainer ,
  ID_EndObjects
}
Protected Member Functions inherited from llvm::object::Binary
 Binary (unsigned int Type, MemoryBufferRef Source)
Static Protected Member Functions inherited from llvm::object::Binary
static unsigned int getELFType (bool isLE, bool is64Bits)
static unsigned int getMachOType (bool isLE, bool is64Bits)
Protected Attributes inherited from llvm::object::Binary
MemoryBufferRef Data

Detailed Description

A simple binary serialization of an offloading file.

We use this format to embed the offloading image into the host executable so it can be extracted and used by the linker.

Many of these could be stored in the same section by the time the linker sees it so we mark this information with a header. The version is used to detect ABI stability and the size is used to find other offloading entries that may exist in the same section. All offsets are given as absolute byte offsets from the beginning of the file.

Definition at line 71 of file OffloadBinary.h.

Member Typedef Documentation

◆ string_iterator

◆ string_iterator_range

Member Function Documentation

◆ classof()

bool llvm::object::OffloadBinary::classof ( const Binary * V)
inlinestatic

Definition at line 160 of file OffloadBinary.h.

References llvm::object::Binary::Binary().

◆ create()

Expected< SmallVector< std::unique_ptr< OffloadBinary > > > OffloadBinary::create ( MemoryBufferRef Buf,
std::optional< uint64_t > Index = std::nullopt )
static

Attempt to parse the offloading binary stored in Buf.

For version 1 binaries, always returns a single OffloadBinary. For version 2+ binaries:

  • If Index is provided, returns the OffloadBinary at that index.
  • If Index is std::nullopt, returns all OffloadBinary entries.
    Parameters
    BufThe memory buffer containing the offload binary.
    IndexOptional index to select a specific entry. If not provided, all entries are returned (version 2+ only).
    Returns
    An array of unique pointers to OffloadBinary objects, or an error.

Definition at line 234 of file OffloadBinary.cpp.

References llvm::SmallVectorImpl< T >::emplace_back(), llvm::errorCodeToError(), extractHeader(), llvm::MemoryBufferRef::getBufferSize(), llvm::MemoryBufferRef::getBufferStart(), I, llvm::object::parse_failed, llvm::Error::success(), and llvm::object::unexpected_eof.

Referenced by llvm::object::OffloadFile::copy(), and llvm::object::createBinary().

◆ extractHeader()

◆ getAlignment()

uint64_t llvm::object::OffloadBinary::getAlignment ( )
inlinestatic

◆ getArch()

StringRef llvm::object::OffloadBinary::getArch ( ) const
inline

Definition at line 150 of file OffloadBinary.h.

References getString().

◆ getFlags()

uint32_t llvm::object::OffloadBinary::getFlags ( ) const
inline

Definition at line 145 of file OffloadBinary.h.

◆ getImage()

StringRef llvm::object::OffloadBinary::getImage ( ) const
inline

Definition at line 151 of file OffloadBinary.h.

◆ getImageKind()

ImageKind llvm::object::OffloadBinary::getImageKind ( ) const
inline

Definition at line 142 of file OffloadBinary.h.

◆ getIndex()

uint64_t llvm::object::OffloadBinary::getIndex ( ) const
inline

Definition at line 147 of file OffloadBinary.h.

◆ getOffloadKind()

OffloadKind llvm::object::OffloadBinary::getOffloadKind ( ) const
inline

Definition at line 143 of file OffloadBinary.h.

◆ getSize()

uint64_t llvm::object::OffloadBinary::getSize ( ) const
inline

Definition at line 146 of file OffloadBinary.h.

◆ getString()

StringRef llvm::object::OffloadBinary::getString ( StringRef Key) const
inline

◆ getTriple()

StringRef llvm::object::OffloadBinary::getTriple ( ) const
inline

Definition at line 149 of file OffloadBinary.h.

References getString().

◆ getVersion()

uint32_t llvm::object::OffloadBinary::getVersion ( ) const
inline

Definition at line 144 of file OffloadBinary.h.

◆ strings()

string_iterator_range llvm::object::OffloadBinary::strings ( ) const
inline

Definition at line 156 of file OffloadBinary.h.

◆ write()

Member Data Documentation

◆ Version

const uint32_t llvm::object::OffloadBinary::Version = 2
static

The current version of the binary used for backwards compatibility.

Definition at line 77 of file OffloadBinary.h.

Referenced by extractHeader().


The documentation for this class was generated from the following files: