[llvm] c0ebc18 - [orc] Fix asan error in RTDyldObjectLinkingLayer.cpp (#106300)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 18:28:43 PDT 2024
Author: Eugene Zhulenev
Date: 2024-08-27T18:28:40-07:00
New Revision: c0ebc1806a70dc66699f10160e80d1def8a8e3c9
URL: https://github.com/llvm/llvm-project/commit/c0ebc1806a70dc66699f10160e80d1def8a8e3c9
DIFF: https://github.com/llvm/llvm-project/commit/c0ebc1806a70dc66699f10160e80d1def8a8e3c9.diff
LOG: [orc] Fix asan error in RTDyldObjectLinkingLayer.cpp (#106300)
`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
#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
#3 0x7ff2a9a88b49 in operator() libcxx/include/__functional/function.h:210:12
#4 0x7ff2a9a88b49 in void std::__u::__function::__policy_invoker<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr,
```
Added:
Modified:
llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
index 0d48c343540188..bc3433d011551c 100644
--- a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+#include <memory>
+
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/Object/COFF.h"
@@ -184,11 +186,13 @@ 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,
@@ -196,7 +200,8 @@ void RTDyldObjectLinkingLayer::emit(
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 {
More information about the llvm-commits
mailing list