[llvm] f710b04 - [ORC] Fail early in ExecutionSession::registerJITDispatchHandlers.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 27 20:32:03 PST 2024
Author: Lang Hames
Date: 2024-11-28T15:29:16+11:00
New Revision: f710b042336d93fd1080124d3ec889702b77a730
URL: https://github.com/llvm/llvm-project/commit/f710b042336d93fd1080124d3ec889702b77a730
DIFF: https://github.com/llvm/llvm-project/commit/f710b042336d93fd1080124d3ec889702b77a730.diff
LOG: [ORC] Fail early in ExecutionSession::registerJITDispatchHandlers.
Check that we're not reusing any handler tag addresses before installing any
handlers. This ensures that either all of the handlers are installed*, or none
of them are, simplifying error recovery.
* Ignoring handlers whose tags couldn't be resolved at all: these were never
installed.
Added:
Modified:
llvm/lib/ExecutionEngine/Orc/Core.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp
index 78041993648834..43c8cda558e186 100644
--- a/llvm/lib/ExecutionEngine/Orc/Core.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp
@@ -1878,31 +1878,39 @@ ExecutionSession::lookup(ArrayRef<JITDylib *> SearchOrder, StringRef Name,
Error ExecutionSession::registerJITDispatchHandlers(
JITDylib &JD, JITDispatchHandlerAssociationMap WFs) {
- auto TagAddrs = lookup({{&JD, JITDylibLookupFlags::MatchAllSymbols}},
- SymbolLookupSet::fromMapKeys(
- WFs, SymbolLookupFlags::WeaklyReferencedSymbol));
- if (!TagAddrs)
- return TagAddrs.takeError();
+ auto TagSyms = lookup({{&JD, JITDylibLookupFlags::MatchAllSymbols}},
+ SymbolLookupSet::fromMapKeys(
+ WFs, SymbolLookupFlags::WeaklyReferencedSymbol));
+ if (!TagSyms)
+ return TagSyms.takeError();
// Associate tag addresses with implementations.
std::lock_guard<std::mutex> Lock(JITDispatchHandlersMutex);
- for (auto &KV : *TagAddrs) {
- auto TagAddr = KV.second.getAddress();
+
+ // Check that no tags are being overwritten.
+ for (auto &[TagName, TagSym] : *TagSyms) {
+ auto TagAddr = TagSym.getAddress();
if (JITDispatchHandlers.count(TagAddr))
- return make_error<StringError>("Tag " + formatv("{0:x16}", TagAddr) +
- " (for " + *KV.first +
+ return make_error<StringError>("Tag " + formatv("{0:x}", TagAddr) +
+ " (for " + *TagName +
") already registered",
inconvertibleErrorCode());
- auto I = WFs.find(KV.first);
+ }
+
+ // At this point we're guaranteed to succeed. Install the handlers.
+ for (auto &[TagName, TagSym] : *TagSyms) {
+ auto TagAddr = TagSym.getAddress();
+ auto I = WFs.find(TagName);
assert(I != WFs.end() && I->second &&
"JITDispatchHandler implementation missing");
- JITDispatchHandlers[KV.second.getAddress()] =
+ JITDispatchHandlers[TagAddr] =
std::make_shared<JITDispatchHandlerFunction>(std::move(I->second));
LLVM_DEBUG({
- dbgs() << "Associated function tag \"" << *KV.first << "\" ("
- << formatv("{0:x}", KV.second.getAddress()) << ") with handler\n";
+ dbgs() << "Associated function tag \"" << *TagName << "\" ("
+ << formatv("{0:x}", TagAddr) << ") with handler\n";
});
}
+
return Error::success();
}
More information about the llvm-commits
mailing list