Commit 3d931e85 authored by Lang Hames's avatar Lang Hames
Browse files

[ORC] Don't take ownership of the trampoline pool in LazyReexportsManager.

LazyReexportsManager instances use the trampoline pool, but they don't need to
own it. Keeping TrampolinePool ownership separate allows re-use of the
trampoline pool by other clients.
parent 438e95e9
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -55,8 +55,7 @@ protected:
      TrampolinePool::NotifyLandingResolvedFunction;

  LazyCallThroughManager(ExecutionSession &ES,
                         JITTargetAddress ErrorHandlerAddr,
                         std::unique_ptr<TrampolinePool> TP);
                         JITTargetAddress ErrorHandlerAddr, TrampolinePool *TP);

  struct ReexportsEntry {
    JITDylib *SourceJD;
@@ -67,9 +66,7 @@ protected:
  Expected<ReexportsEntry> findReexport(JITTargetAddress TrampolineAddr);
  Error notifyResolved(JITTargetAddress TrampolineAddr,
                       JITTargetAddress ResolvedAddr);
  void setTrampolinePool(std::unique_ptr<TrampolinePool> TP) {
    this->TP = std::move(TP);
  }
  void setTrampolinePool(TrampolinePool &TP) { this->TP = &TP; }

private:
  using ReexportsMap = std::map<JITTargetAddress, ReexportsEntry>;
@@ -79,7 +76,7 @@ private:
  std::mutex LCTMMutex;
  ExecutionSession &ES;
  JITTargetAddress ErrorHandlerAddr;
  std::unique_ptr<TrampolinePool> TP;
  TrampolinePool *TP = nullptr;
  ReexportsMap Reexports;
  NotifiersMap Notifiers;
};
@@ -105,10 +102,13 @@ private:
    if (!TP)
      return TP.takeError();

    setTrampolinePool(std::move(*TP));
    this->TP = std::move(*TP);
    setTrampolinePool(*this->TP);
    return Error::success();
  }

  std::unique_ptr<TrampolinePool> TP;

public:
  /// Create a LocalLazyCallThroughManager using the given ABI. See
  /// createLocalLazyCallThroughManager.
+4 −3
Original line number Diff line number Diff line
@@ -17,13 +17,14 @@ namespace llvm {
namespace orc {

LazyCallThroughManager::LazyCallThroughManager(
    ExecutionSession &ES, JITTargetAddress ErrorHandlerAddr,
    std::unique_ptr<TrampolinePool> TP)
    : ES(ES), ErrorHandlerAddr(ErrorHandlerAddr), TP(std::move(TP)) {}
    ExecutionSession &ES, JITTargetAddress ErrorHandlerAddr, TrampolinePool *TP)
    : ES(ES), ErrorHandlerAddr(ErrorHandlerAddr), TP(TP) {}

Expected<JITTargetAddress> LazyCallThroughManager::getCallThroughTrampoline(
    JITDylib &SourceJD, SymbolStringPtr SymbolName,
    NotifyResolvedFunction NotifyResolved) {
  assert(TP && "TrampolinePool not set");

  std::lock_guard<std::mutex> Lock(LCTMMutex);
  auto Trampoline = TP->getTrampoline();