[PATCH] D47343: [MCJIT] Call JIT notifiers only after code sections are ready.
Andres Freund via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 24 12:06:42 PDT 2018
anarazel created this revision.
anarazel added a reviewer: reames.
Herald added a subscriber: llvm-commits.
Extracted from https://reviews.llvm.org/D44892
Previously JIT notifiers were called before relocations were
performed (leading to ominious looking function calls of "0" being
shown in debugger / profiles), and before memory marked
executable (confusing some profilers).
Move notifications to finalizeLoadedModules().
Repository:
rL LLVM
https://reviews.llvm.org/D47343
Files:
lib/ExecutionEngine/MCJIT/MCJIT.cpp
lib/ExecutionEngine/MCJIT/MCJIT.h
Index: lib/ExecutionEngine/MCJIT/MCJIT.h
===================================================================
--- lib/ExecutionEngine/MCJIT/MCJIT.h
+++ lib/ExecutionEngine/MCJIT/MCJIT.h
@@ -190,6 +190,8 @@
SmallVector<std::unique_ptr<MemoryBuffer>, 2> Buffers;
SmallVector<std::unique_ptr<object::ObjectFile>, 2> LoadedObjects;
+ SmallVector<object::ObjectFile*, 2> PendingLoadedObjects;
+ SmallVector<std::unique_ptr<RuntimeDyld::LoadedObjectInfo>, 2> PendingLoadedObjectInfos;
// An optional ObjectCache to be notified of compiled objects and used to
// perform lookup of pre-compiled code to avoid re-compilation.
Index: lib/ExecutionEngine/MCJIT/MCJIT.cpp
===================================================================
--- lib/ExecutionEngine/MCJIT/MCJIT.cpp
+++ lib/ExecutionEngine/MCJIT/MCJIT.cpp
@@ -220,8 +220,10 @@
if (Dyld.hasError())
report_fatal_error(Dyld.getErrorString());
- NotifyObjectEmitted(*LoadedObject.get(), *L);
-
+ // Can't call notifiers yet, as relocations have not yet been
+ // performed, and memory hasn't been marked executable.
+ PendingLoadedObjects.push_back(LoadedObject->get());
+ PendingLoadedObjectInfos.push_back(std::move(L));
Buffers.push_back(std::move(ObjectToLoad));
LoadedObjects.push_back(std::move(*LoadedObject));
@@ -241,6 +243,16 @@
// Set page permissions.
MemMgr->finalizeMemory();
+
+ // Notify listeners about loaded objects, now that memory is marked
+ // executable and relocations have been performed.
+ for (size_t i = 0; i < PendingLoadedObjects.size(); i++) {
+ auto &Obj = PendingLoadedObjects[i];
+ auto &Info = PendingLoadedObjectInfos[i];
+ NotifyObjectEmitted(*Obj, *Info);
+ }
+ PendingLoadedObjects.clear();
+ PendingLoadedObjectInfos.clear();
}
// FIXME: Rename this.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47343.148461.patch
Type: text/x-patch
Size: 1808 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180524/8aa70ce0/attachment.bin>
More information about the llvm-commits
mailing list