LLVM 22.0.0git
llvm::orc::StaticLibraryDefinitionGenerator Class Reference

A utility class to expose symbols from a static library. More...

#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"

Inheritance diagram for llvm::orc::StaticLibraryDefinitionGenerator:
[legend]

Public Types

using GetObjectFileInterface
 Interface builder function for objects loaded from this archive.
using VisitMembersFunction
 Callback for visiting archive members at construction time.

Public Member Functions

Error tryToGenerate (LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) override
 DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
Public Member Functions inherited from llvm::orc::DefinitionGenerator
virtual ~DefinitionGenerator ()

Static Public Member Functions

static VisitMembersFunction loadAllObjectFileMembers (ObjectLayer &L, JITDylib &JD)
 A VisitMembersFunction that unconditionally loads all object files from the archive.
static std::unique_ptr< MemoryBuffercreateMemberBuffer (object::Archive &A, MemoryBufferRef BufRef, size_t Index)
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Load (ObjectLayer &L, const char *FileName, VisitMembersFunction VisitMembers=VisitMembersFunction(), GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
 Try to create a StaticLibraryDefinitionGenerator from the given path.
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Create (ObjectLayer &L, std::unique_ptr< MemoryBuffer > ArchiveBuffer, std::unique_ptr< object::Archive > Archive, VisitMembersFunction VisitMembers=VisitMembersFunction(), GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
 Try to create a StaticLibrarySearchGenerator from the given memory buffer and Archive object.
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Create (ObjectLayer &L, std::unique_ptr< MemoryBuffer > ArchiveBuffer, VisitMembersFunction VisitMembers=VisitMembersFunction(), GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
 Try to create a StaticLibrarySearchGenerator from the given memory buffer.

Detailed Description

A utility class to expose symbols from a static library.

If an instance of this class is attached to a JITDylib as a fallback definition generator, then any symbol found in the archive will result in the containing object being added to the JITDylib.

Definition at line 270 of file ExecutionUtils.h.

Member Typedef Documentation

◆ GetObjectFileInterface

Initial value:
friend class ExecutionSession
Definition Core.h:860
unique_function is a type-erasing functor similar to std::function.

Interface builder function for objects loaded from this archive.

Definition at line 273 of file ExecutionUtils.h.

◆ VisitMembersFunction

Initial value:

Callback for visiting archive members at construction time.

Can be used to pre-load members.

Callbacks are provided with a reference to the underlying archive, a MemoryBufferRef covering the bytes for the given member, and the index of the given member.

Implementations should return true if the given member file should be loadable via the generator, false if it should not, and an Error if the member is malformed in a way that renders the archive itself invalid.

Note: Linkers typically ignore invalid files within archives, so it's expected that implementations will usually return false (i.e. not-loadable) for malformed buffers, and will only return an Error in exceptional circumstances.

Definition at line 292 of file ExecutionUtils.h.

Member Function Documentation

◆ Create() [1/2]

◆ Create() [2/2]

Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > llvm::orc::StaticLibraryDefinitionGenerator::Create ( ObjectLayer & L,
std::unique_ptr< MemoryBuffer > ArchiveBuffer,
VisitMembersFunction VisitMembers = VisitMembersFunction(),
GetObjectFileInterface GetObjFileInterface = GetObjectFileInterface() )
static

Try to create a StaticLibrarySearchGenerator from the given memory buffer.

This call will succeed if the buffer contains a valid archive, otherwise it will return an error.

This call will succeed if the buffer contains a valid static library or a MachO universal binary containing a static library that is compatible with the ExecutionSession's triple. Otherwise it will return an error.

Definition at line 372 of file ExecutionUtils.cpp.

References B(), Create(), llvm::object::Archive::create(), llvm::object::createBinary(), llvm::dyn_cast(), llvm::orc::getMachOSliceRangeForTriple(), llvm::inconvertibleErrorCode(), llvm::isa(), and llvm::make_error().

◆ createMemberBuffer()

std::unique_ptr< MemoryBuffer > llvm::orc::StaticLibraryDefinitionGenerator::createMemberBuffer ( object::Archive & A,
MemoryBufferRef BufRef,
size_t Index )
static

◆ Load()

Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > llvm::orc::StaticLibraryDefinitionGenerator::Load ( ObjectLayer & L,
const char * FileName,
VisitMembersFunction VisitMembers = VisitMembersFunction(),
GetObjectFileInterface GetObjFileInterface = GetObjectFileInterface() )
static

Try to create a StaticLibraryDefinitionGenerator from the given path.

This call will succeed if the file at the given path is a static library or a MachO universal binary containing a static library that is compatible with the ExecutionSession's triple. Otherwise it will return an error.

Definition at line 295 of file ExecutionUtils.cpp.

References Create(), llvm::orc::loadLinkableFile(), and llvm::orc::Required.

Referenced by llvm::orc::ELFNixPlatform::Create(), llvm::orc::MachOPlatform::Create(), llvm::orc::LLJIT::linkStaticLibraryInto(), and LLVMOrcCreateStaticLibrarySearchGeneratorForPath().

◆ loadAllObjectFileMembers()

StaticLibraryDefinitionGenerator::VisitMembersFunction llvm::orc::StaticLibraryDefinitionGenerator::loadAllObjectFileMembers ( ObjectLayer & L,
JITDylib & JD )
static

A VisitMembersFunction that unconditionally loads all object files from the archive.

Archive members that are not valid object files will be skipped.

Definition at line 275 of file ExecutionUtils.cpp.

References A(), llvm::file_magic::coff_object, createMemberBuffer(), llvm::file_magic::elf_relocatable, llvm::identify_magic(), and llvm::file_magic::macho_object.

◆ tryToGenerate()

Error llvm::orc::StaticLibraryDefinitionGenerator::tryToGenerate ( LookupState & LS,
LookupKind K,
JITDylib & JD,
JITDylibLookupFlags JDLookupFlags,
const SymbolLookupSet & LookupSet )
overridevirtual

DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.

K specifies the kind of this lookup. JD specifies the target JITDylib being searched, and JDLookupFlags specifies whether the search should match against hidden symbols. Finally, Symbols describes the set of unresolved symbols and their associated lookup flags.

Implements llvm::orc::DefinitionGenerator.

Definition at line 416 of file ExecutionUtils.cpp.

References _, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::count(), createMemberBuffer(), llvm::orc::Static, llvm::Error::success(), and ToRemove.


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