LLVM: lib/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

11

12#define DEBUG_TYPE "orc"

13

14using namespace llvm;

16

17namespace {

18constexpr StringRef JumpStubSectionName = "__orc_stubs";

19constexpr StringRef StubPtrSectionName = "__orc_stub_ptrs";

20constexpr StringRef StubSuffix = "$__stub_ptr";

21}

22

24 std::unique_ptr R, SymbolMap InitialDests) {

25

26 auto &ES = ObjLinkingLayer.getExecutionSession();

27 auto G = std::make_uniquejitlink::LinkGraph(

28 ("<indirect stubs graph #" + Twine(++StubGraphIdx) + ">").str(),

29 ES.getSymbolStringPool(), ES.getTargetTriple(), SubtargetFeatures(),

31 auto &PointerSection =

33 auto &StubsSection =

35

37 for (auto &[Name, Def] : InitialDests) {

39 if (Def.getAddress())

40 TargetSym = &G->addAbsoluteSymbol(

41 G->allocateName(*Name + "$__init_tgt"), Def.getAddress(), 0,

43

44 auto PtrName = ES.intern((*Name + StubSuffix).str());

45 auto &Ptr = AnonymousPtrCreator(*G, PointerSection, TargetSym, 0);

46 Ptr.setName(PtrName);

48 auto &Stub = PtrJumpStubCreator(*G, StubsSection, Ptr);

49 Stub.setName(Name);

55 }

56

57

58 if (auto Err = R->defineMaterializing(std::move(NewSymbols))) {

59 ES.reportError(std::move(Err));

60 return R->failMaterialization();

61 }

62

63 ObjLinkingLayer.emit(std::move(R), std::move(G));

64}

65

68 auto &ES = ObjLinkingLayer.getExecutionSession();

71 for (auto &[StubName, Sym] : NewDests) {

72 auto PtrName = ES.intern((*StubName + StubSuffix).str());

74 LS.add(std::move(PtrName));

75 }

76 auto PtrSyms =

78 if (!PtrSyms)

79 return PtrSyms.takeError();

80

81 std::vectortpctypes::PointerWrite PtrWrites;

82 for (auto &[PtrName, PtrSym] : *PtrSyms) {

84 assert(DestSymI != NewDests.end() && "Bad ptr -> stub mapping");

85 auto &DestSym = DestSymI->second;

86 PtrWrites.push_back({PtrSym.getAddress(), DestSym.getAddress()});

87 }

88

89 return ObjLinkingLayer.getExecutionSession()

90 .getExecutorProcessControl()

91 .getMemoryAccess()

92 .writePointers(PtrWrites);

93}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

ValueT lookup(const_arg_type_t< KeyT > Val) const

lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...

iterator find(const_arg_type_t< KeyT > Val)

Lightweight error class with error context and mandatory checking.

Flags for symbols in the JIT.

StringRef - Represent a constant reference to a string, i.e.

Manages the enabling and disabling of subtarget specific features.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

Represents a JIT'd dynamic library.

void emitRedirectableSymbols(std::unique_ptr< MaterializationResponsibility > R, SymbolMap InitialDests) override

Emit redirectable symbol.

Definition JITLinkRedirectableSymbolManager.cpp:23

Error redirect(JITDylib &JD, const SymbolMap &NewDests) override

Change the redirection destination of given symbols to new destination symbols.

Definition JITLinkRedirectableSymbolManager.cpp:66

Non-owning SymbolStringPool entry pointer.

A set of symbols to look up, each associated with a SymbolLookupFlags value.

LLVM_ABI const char * getGenericEdgeKindName(Edge::Kind K)

Returns the string name of the given generic edge kind, or "unknown" otherwise.

DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap

A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).

DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap

A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.

This is an optimization pass for GlobalISel generic memory operations.