diff --git a/src/cgmemmgr.cpp b/src/cgmemmgr.cpp index ee8ef948701369..5eb09fbc8cd977 100644 --- a/src/cgmemmgr.cpp +++ b/src/cgmemmgr.cpp @@ -59,7 +59,7 @@ static void *map_anon_page(size_t size) { #ifdef _OS_WINDOWS_ char *mem = (char*)VirtualAlloc(NULL, size + jl_page_size, - MEM_RESERVE, PAGE_READWRITE); + MEM_COMMIT, PAGE_READWRITE); assert(mem); mem = (char*)LLT_ALIGN(uintptr_t(mem), jl_page_size); #else @@ -800,6 +800,28 @@ class RTDyldMemoryManagerJL : public SectionMemoryManager { mapAddresses(Dyld, ro_alloc); mapAddresses(Dyld, exe_alloc); } +#ifdef _OS_WINDOWS_ + template + void *lookupWriteAddressFor(void *rt_addr, Alloc *allocator) + { + for (auto &alloc: allocator->allocations) { + if (alloc.rt_addr == rt_addr) { + return alloc.wr_addr; + } + } + return nullptr; + } + void *lookupWriteAddressFor(void *rt_addr) + { + if (!ro_alloc) + return rt_addr; + if (void *ptr = lookupWriteAddressFor(rt_addr, ro_alloc)) + return ptr; + if (void *ptr = lookupWriteAddressFor(rt_addr, exe_alloc)) + return ptr; + return rt_addr; + } +#endif }; uint8_t *RTDyldMemoryManagerJL::allocateCodeSection(uintptr_t Size, @@ -883,6 +905,13 @@ void notifyObjectLoaded(RTDyldMemoryManager *memmgr, } #endif +#ifdef _OS_WINDOWS_ +void *lookupWriteAddressFor(RTDyldMemoryManager *memmgr, void *rt_addr) +{ + return ((RTDyldMemoryManagerJL*)memmgr)->lookupWriteAddressFor(rt_addr); +} +#endif + #else typedef SectionMemoryManager RTDyldMemoryManagerJL; #endif diff --git a/src/codegen_internal.h b/src/codegen_internal.h index f939edc118807a..47db6d841da35b 100644 --- a/src/codegen_internal.h +++ b/src/codegen_internal.h @@ -28,8 +28,12 @@ extern bool jl_dylib_DI_for_fptr(size_t pointer, const object::ObjectFile **obje bool onlySysImg, bool *isSysImg, void **saddr, char **name, char **filename); #ifdef USE_ORCJIT -extern JL_DLLEXPORT void ORCNotifyObjectEmitted(JITEventListener *Listener, - const object::ObjectFile &obj, - const object::ObjectFile &debugObj, - const RuntimeDyld::LoadedObjectInfo &L); +JL_DLLEXPORT void ORCNotifyObjectEmitted(JITEventListener *Listener, + const object::ObjectFile &obj, + const object::ObjectFile &debugObj, + const RuntimeDyld::LoadedObjectInfo &L, + RTDyldMemoryManager *memmgr); +#ifdef _OS_WINDOWS_ +void *lookupWriteAddressFor(RTDyldMemoryManager *memmgr, void *rt_addr); +#endif #endif diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index b9144a0e434071..ad93b7111fe600 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -298,12 +298,13 @@ class JuliaJITEventListener: public JITEventListener virtual void NotifyObjectEmitted(const object::ObjectFile &obj, const RuntimeDyld::LoadedObjectInfo &L) { - return _NotifyObjectEmitted(obj,obj,L); + return _NotifyObjectEmitted(obj,obj,L,nullptr); } virtual void _NotifyObjectEmitted(const object::ObjectFile &obj, - const object::ObjectFile &debugObj, - const RuntimeDyld::LoadedObjectInfo &L) + const object::ObjectFile &debugObj, + const RuntimeDyld::LoadedObjectInfo &L, + RTDyldMemoryManager *memmgr) #else virtual void NotifyObjectEmitted(const ObjectImage &obj) #endif @@ -397,14 +398,20 @@ class JuliaJITEventListener: public JITEventListener #endif Addr -= SectionAddr - SectionLoadAddr; *pAddr = (uint8_t*)Addr; - if (SectionLoadOffset != 1) - assert(SectionLoadOffset == SectionAddr - SectionLoadAddr); - else - SectionLoadOffset = SectionAddr - SectionLoadAddr; if (SectionAddrCheck) assert(SectionAddrCheck == SectionLoadAddr); else SectionAddrCheck = SectionLoadAddr; +#ifdef USE_ORCJIT + if (memmgr) + SectionAddr = + (uintptr_t)lookupWriteAddressFor(memmgr, + (void*)SectionLoadAddr); +#endif + if (SectionLoadOffset != 1) + assert(SectionLoadOffset == SectionAddr - SectionLoadAddr); + else + SectionLoadOffset = SectionAddr - SectionLoadAddr; } } assert(catchjmp); @@ -613,9 +620,10 @@ class JuliaJITEventListener: public JITEventListener JL_DLLEXPORT void ORCNotifyObjectEmitted(JITEventListener *Listener, const object::ObjectFile &obj, const object::ObjectFile &debugObj, - const RuntimeDyld::LoadedObjectInfo &L) + const RuntimeDyld::LoadedObjectInfo &L, + RTDyldMemoryManager *memmgr) { - ((JuliaJITEventListener*)Listener)->_NotifyObjectEmitted(obj,debugObj,L); + ((JuliaJITEventListener*)Listener)->_NotifyObjectEmitted(obj,debugObj,L,memmgr); } #endif diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index af2c6e2df380f6..f7bf9073a000b0 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -266,7 +266,7 @@ class JuliaOJIT { ORCNotifyObjectEmitted(JuliaListener.get(), *Object, *SavedObjects.back().getBinary(), - *LO); + *LO, JIT.MemMgr); // record all of the exported symbols defined in this object // in the primary hash table for the enclosing JIT