LLVM  13.0.0git
TPCDynamicLibrarySearchGenerator.cpp
Go to the documentation of this file.
1 //===---------------- TPCDynamicLibrarySearchGenerator.cpp ----------------===//
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 
11 namespace llvm {
12 namespace orc {
13 
14 Expected<std::unique_ptr<TPCDynamicLibrarySearchGenerator>>
16  const char *LibraryPath,
17  SymbolPredicate Allow) {
18  auto Handle = TPC.loadDylib(LibraryPath);
19  if (!Handle)
20  return Handle.takeError();
21 
22  return std::make_unique<TPCDynamicLibrarySearchGenerator>(TPC, *Handle,
23  std::move(Allow));
24 }
25 
28  JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) {
29 
30  if (Symbols.empty())
31  return Error::success();
32 
33  SymbolLookupSet LookupSymbols;
34 
35  for (auto &KV : Symbols) {
36  // Skip symbols that don't match the filter.
37  if (Allow && !Allow(KV.first))
38  continue;
39  LookupSymbols.add(KV.first, SymbolLookupFlags::WeaklyReferencedSymbol);
40  }
41 
42  SymbolMap NewSymbols;
43 
44  TargetProcessControl::LookupRequest Request(H, LookupSymbols);
45  auto Result = TPC.lookupSymbols(Request);
46  if (!Result)
47  return Result.takeError();
48 
49  assert(Result->size() == 1 && "Results for more than one library returned");
50  assert(Result->front().size() == LookupSymbols.size() &&
51  "Result has incorrect number of elements");
52 
53  auto ResultI = Result->front().begin();
54  for (auto &KV : LookupSymbols) {
55  if (*ResultI)
56  NewSymbols[KV.first] =
58  ++ResultI;
59  }
60 
61  // If there were no resolved symbols bail out.
62  if (NewSymbols.empty())
63  return Error::success();
64 
65  // Define resolved symbols.
66  return JD.define(absoluteSymbols(std::move(NewSymbols)));
67 }
68 
69 } // end namespace orc
70 } // end namespace llvm
llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
llvm::orc::JITDylib
A symbol table that supports asynchoronous symbol queries.
Definition: Core.h:894
llvm::unique_function< bool(const SymbolStringPtr &)>
llvm::orc::SymbolLookupSet
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:172
llvm::orc::TPCDynamicLibrarySearchGenerator::Load
static Expected< std::unique_ptr< TPCDynamicLibrarySearchGenerator > > Load(TargetProcessControl &TPC, const char *LibraryPath, SymbolPredicate Allow=SymbolPredicate())
Permanently loads the library at the given path and, on success, returns a DynamicLibrarySearchGenera...
Definition: TPCDynamicLibrarySearchGenerator.cpp:15
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:332
llvm::orc::TargetProcessControl::LookupRequest
A pair of a dylib and a set of symbols to be looked up.
Definition: TargetProcessControl.h:94
llvm::orc::LookupKind
LookupKind
Describes the kind of lookup being performed.
Definition: Core.h:146
llvm::JITEvaluatedSymbol
Represents a symbol that has been evaluated to an address already.
Definition: JITSymbol.h:229
TPCDynamicLibrarySearchGenerator.h
llvm::orc::TPCDynamicLibrarySearchGenerator::tryToGenerate
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.
Definition: TPCDynamicLibrarySearchGenerator.cpp:26
llvm::orc::SymbolLookupSet::add
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
Definition: Core.h:221
llvm::orc::TargetProcessControl::loadDylib
virtual Expected< tpctypes::DylibHandle > loadDylib(const char *DylibPath)=0
Load the dynamic library at the given path and return a handle to it.
llvm::orc::SymbolLookupFlags::WeaklyReferencedSymbol
@ WeaklyReferencedSymbol
llvm::orc::TargetProcessControl
TargetProcessControl supports interaction with a JIT target process.
Definition: TargetProcessControl.h:32
llvm::orc::SymbolLookupSet::size
UnderlyingVector::size_type size() const
Definition: Core.h:236
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::DenseMap< SymbolStringPtr, JITEvaluatedSymbol >
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::orc::TargetProcessControl::lookupSymbols
virtual Expected< std::vector< tpctypes::LookupResult > > lookupSymbols(ArrayRef< LookupRequest > Request)=0
Search for symbols in the target process.
llvm::orc::LookupState
Wraps state for a lookup-in-progress.
Definition: Core.h:848
llvm::DenseMapBase::empty
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:97
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::AArch64CC::LS
@ LS
Definition: AArch64BaseInfo.h:245
llvm::orc::absoluteSymbols
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Definition: Core.h:716
llvm::orc::JITDylib::define
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:1531
llvm::orc::JITDylibLookupFlags
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
Definition: Core.h:124
llvm::JITSymbolFlags::Exported
@ Exported
Definition: JITSymbol.h:85