Commit 099fd374 authored by Richard Smith's avatar Richard Smith
Browse files

Fix undefined behavior due to deleting an object with a non-virtual

destructor via a pointer of the wrong static type.

This caused crashes during deallocation in C++14 builds when using a
deallocator whose sized delete requires the size argument to be correct.

Also make the LazyCallThroughManager destructor protected to catch this
sort of bug in the future.
parent f49edafd
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -250,7 +250,7 @@ private:
  // Create a single-threaded LLLazyJIT instance.
  LLLazyJIT(LLLazyJITBuilderState &S, Error &Err);

  std::unique_ptr<LazyCallThroughManager> LCTMgr;
  std::unique_ptr<LocalLazyCallThroughManager> LCTMgr;
  std::unique_ptr<CompileOnDemandLayer> CODLayer;
};

@@ -384,7 +384,7 @@ public:

  Triple TT;
  JITTargetAddress LazyCompileFailureAddr = 0;
  std::unique_ptr<LazyCallThroughManager> LCTMgr;
  std::unique_ptr<LocalLazyCallThroughManager> LCTMgr;
  IndirectStubsManagerBuilderFunction ISMBuilder;

  Error prepareForConstruction();
+2 −1
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ protected:

  LazyCallThroughManager(ExecutionSession &ES,
                         JITTargetAddress ErrorHandlerAddr, TrampolinePool *TP);
  ~LazyCallThroughManager() = default;

  struct ReexportsEntry {
    JITDylib *SourceJD;
@@ -127,7 +128,7 @@ public:

/// Create a LocalLazyCallThroughManager from the given triple and execution
/// session.
Expected<std::unique_ptr<LazyCallThroughManager>>
Expected<std::unique_ptr<LocalLazyCallThroughManager>>
createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES,
                                  JITTargetAddress ErrorHandlerAddr);

+1 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ void LazyCallThroughManager::resolveTrampolineLandingAddress(
      NoDependenciesToRegister);
}

Expected<std::unique_ptr<LazyCallThroughManager>>
Expected<std::unique_ptr<LocalLazyCallThroughManager>>
createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES,
                                  JITTargetAddress ErrorHandlerAddr) {
  switch (T.getArch()) {