LLVM 24.0.0git
InstanceSymbolGenerator.cpp
Go to the documentation of this file.
1//===- InstanceSymbolGenerator.cpp - Executor instance symbols ------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
13
14#define DEBUG_TYPE "orc"
15
16namespace llvm::orc {
17
19 JITDylib &JD,
20 JITDylibLookupFlags JDLookupFlags,
21 const SymbolLookupSet &Symbols) {
22
23 if (Symbols.empty())
24 return Error::success();
25
27 dbgs() << "InstanceSymbolGenerator trying to generate " << Symbols << "\n";
28 });
29
30 // Look the symbols up as required, so that names that aren't instance
31 // symbols come back as std::nullopt rather than as null addresses. This
32 // doesn't fail the lookup: those names are just left undefined.
33 SymbolLookupSet LookupSymbols;
34 for (auto &[Name, Flags] : Symbols)
35 LookupSymbols.add(Name, SymbolLookupFlags::RequiredSymbol);
36
37 Lookup(
38 [&JD, LS = std::move(LS),
39 LookupSymbols](Expected<SymbolLookupResult> Result) mutable {
40 if (!Result)
41 return LS.continueLookup(Result.takeError());
42
43 if (Result->size() != LookupSymbols.size())
44 return LS.continueLookup(make_error<StringError>(
45 "Instance symbol lookup returned " + Twine(Result->size()) +
46 " results for " + Twine(LookupSymbols.size()) + " symbols",
48
49 SymbolMap NewSymbols;
50 auto ResultIt = Result->begin();
51 for (auto &[Name, Flags] : LookupSymbols) {
52 const auto &Addr = *ResultIt++;
53 if (Addr)
54 NewSymbols[Name] = {*Addr, JITSymbolFlags::Exported};
55 }
56
58 dbgs() << "InstanceSymbolGenerator lookup returned " << NewSymbols
59 << "\n";
60 });
61
62 if (NewSymbols.empty())
63 return LS.continueLookup(Error::success());
64
65 LS.continueLookup(JD.define(absoluteSymbols(std::move(NewSymbols))));
66 },
67 JD.getExecutionSession(), LookupSymbols);
68
69 return Error::success();
70}
71
72} // namespace llvm::orc
#define LLVM_DEBUG(...)
Definition Debug.h:119
bool empty() const
Definition DenseMap.h:717
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
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.
Represents a JIT'd dynamic library.
Definition Core.h:676
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
Definition Core.h:1629
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
Definition Core.h:695
Wraps state for a lookup-in-progress.
Definition Core.h:608
A set of symbols to look up, each associated with a SymbolLookupFlags value.
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
Definition Core.h:133
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
LookupKind
Describes the kind of lookup being performed.
Definition Core.h:145
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:94
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340