LLVM 24.0.0git
llvm::orc::COFFAutoImportGenerator Class Reference

A utility class that synthesizes COFF dllimport __imp_ symbols and PLT stubs for the symbols exported by a single dynamic library ("easy mode" auto-import). More...

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

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

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.
ResourceTrackerSP getImportStubsResourceTracker () const
 Returns the ResourceTracker that owns the stubs synthesized by this generator, or null if none have been synthesized yet.
Public Member Functions inherited from llvm::orc::DefinitionGenerator
virtual ~DefinitionGenerator ()

Static Public Member Functions

static Expected< std::unique_ptr< COFFAutoImportGenerator > > Load (ExecutionSession &ES, ObjectLinkingLayer &L, DylibManager &DylibMgr, const char *LibraryPath)
 Loads the dynamic library at the given path in the executor (via the given DylibManager) and, on success, returns a COFFAutoImportGenerator that synthesizes imports for the symbols it exports.

Detailed Description

A utility class that synthesizes COFF dllimport __imp_ symbols and PLT stubs for the symbols exported by a single dynamic library ("easy mode" auto-import).

Unlike DLLImportDefinitionGenerator, which resolves the underlying symbol through the JITDylib's link order, this generator is bound to one dynamic library: that library's export table is the authority on what may be synthesized. Any requested symbol the library does not export is left unresolved, so the link fails exactly as a static link against the corresponding import library would.

Synthesis is lazy (driven by JITLink external-symbol lookups) and assumes every import is a function: for each resolved import X it creates an __imp_X pointer slot holding X's address in the library and an X thunk that jumps through that slot. Data imports are not distinguished from code and will misbehave; clients with data imports must supply an import library or use __declspec(dllimport). Note also that &X resolves to the synthesized thunk, not to X's address inside the library.

All synthesized stubs share a single ResourceTracker; see getImportStubsResourceTracker() to reclaim them.

Supports whichever architectures JITLink has a pointer / pointer-jump-stub creator registered for (see jitlink::getAnonymousPointerCreator and jitlink::getPointerJumpStubCreator); Load() fails for any other architecture.

Definition at line 53 of file COFFAutoImportGenerator.h.

Member Function Documentation

◆ getImportStubsResourceTracker()

ResourceTrackerSP llvm::orc::COFFAutoImportGenerator::getImportStubsResourceTracker ( ) const
inline

Returns the ResourceTracker that owns the stubs synthesized by this generator, or null if none have been synthesized yet.

Calling remove() on it reclaims every synthesized __imp_ slot and thunk without affecting other definitions in the JITDylib; synthesis afterwards transparently starts a fresh tracker. Not thread-safe with respect to lookups that may concurrently trigger synthesis – reclaim at a quiescent point.

Definition at line 74 of file COFFAutoImportGenerator.h.

◆ Load()

Expected< std::unique_ptr< COFFAutoImportGenerator > > llvm::orc::COFFAutoImportGenerator::Load ( ExecutionSession & ES,
ObjectLinkingLayer & L,
DylibManager & DylibMgr,
const char * LibraryPath )
static

Loads the dynamic library at the given path in the executor (via the given DylibManager) and, on success, returns a COFFAutoImportGenerator that synthesizes imports for the symbols it exports.

On failure returns the reason the library failed to load. Resolving imports through DylibManager means this works for both in-process and out-of-process execution.

Definition at line 19 of file COFFAutoImportGenerator.cpp.

References llvm::orc::DefinitionGenerator::ExecutionSession, llvm::jitlink::getAnonymousPointerCreator(), llvm::jitlink::getPointerJumpStubCreator(), llvm::inconvertibleErrorCode(), and llvm::make_error().

◆ tryToGenerate()

Error llvm::orc::COFFAutoImportGenerator::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 44 of file COFFAutoImportGenerator.cpp.

References llvm::orc::SymbolLookupSet::add(), llvm::sampleprof::Base, llvm::JITSymbolFlags::Callable, llvm::orc::JITDylib::createResourceTracker(), llvm::JITSymbolFlags::Exported, G, llvm::detail::DenseSetImpl< ValueT, MapTy >::insert(), llvm::orc::Resolved, llvm::orc::Result, llvm::size(), llvm::Error::success(), llvm::orc::WeaklyReferencedSymbol, and llvm::zip_equal().


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