Skip to content

Commit

Permalink
[orc] Fix asan error in RTDyldObjectLinkingLayer.cpp (llvm#106300)
Browse files Browse the repository at this point in the history
`JITDylibSearchOrderResolver` local variable can be destroyed before
completion of all callbacks. Capture it together with `Deps` in
`OnEmitted` callback.

Original error:

```
==2035==ERROR: AddressSanitizer: stack-use-after-return on address 0x7bebfa155b70 at pc 0x7ff2a9a88b4a bp 0x7bec08d51980 sp 0x7bec08d51978
READ of size 8 at 0x7bebfa155b70 thread T87 (tf_xla-cpu-llvm)
    #0 0x7ff2a9a88b49 in operator() llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp:55:58
    #1 0x7ff2a9a88b49 in __invoke<(lambda at llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp:55:9) &, const llvm::DenseMap<llvm::orc::JITDylib *, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> >, llvm::DenseMapInfo<llvm::orc::JITDylib *, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib *, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> > > > &> libcxx/include/__type_traits/invoke.h:149:25
    llvm#2 0x7ff2a9a88b49 in __call<(lambda at llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp:55:9) &, const llvm::DenseMap<llvm::orc::JITDylib *, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> >, llvm::DenseMapInfo<llvm::orc::JITDylib *, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib *, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> > > > &> libcxx/include/__type_traits/invoke.h:224:5
    llvm#3 0x7ff2a9a88b49 in operator() libcxx/include/__functional/function.h:210:12
    llvm#4 0x7ff2a9a88b49 in void std::__u::__function::__policy_invoker<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr,
```
  • Loading branch information
ezhulenev authored Aug 28, 2024
1 parent c1a4896 commit c0ebc18
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include <memory>

#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/Object/COFF.h"

Expand Down Expand Up @@ -184,19 +186,22 @@ void RTDyldObjectLinkingLayer::emit(
std::shared_ptr<MaterializationResponsibility> SharedR(std::move(R));
auto Deps = std::make_unique<SymbolDependenceMap>();

JITDylibSearchOrderResolver Resolver(*SharedR, *Deps);
auto Resolver =
std::make_unique<JITDylibSearchOrderResolver>(*SharedR, *Deps);
auto *ResolverPtr = Resolver.get();

jitLinkForORC(
object::OwningBinary<object::ObjectFile>(std::move(*Obj), std::move(O)),
MemMgrRef, Resolver, ProcessAllSections,
MemMgrRef, *ResolverPtr, ProcessAllSections,
[this, SharedR, &MemMgrRef, InternalSymbols](
const object::ObjectFile &Obj,
RuntimeDyld::LoadedObjectInfo &LoadedObjInfo,
std::map<StringRef, JITEvaluatedSymbol> ResolvedSymbols) {
return onObjLoad(*SharedR, Obj, MemMgrRef, LoadedObjInfo,
ResolvedSymbols, *InternalSymbols);
},
[this, SharedR, MemMgr = std::move(MemMgr), Deps = std::move(Deps)](
[this, SharedR, MemMgr = std::move(MemMgr), Deps = std::move(Deps),
Resolver = std::move(Resolver)](
object::OwningBinary<object::ObjectFile> Obj,
std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo,
Error Err) mutable {
Expand Down

0 comments on commit c0ebc18

Please sign in to comment.