@@ -110,6 +110,7 @@ class COFFPlatformRuntimeState {
110110
111111 const char *dlerror ();
112112 void *dlopen (std::string_view Name, int Mode);
113+ int dlupdate (void *DSOHandle);
113114 int dlclose (void *Header);
114115 void *dlsym (void *Header, std::string_view Symbol);
115116
@@ -141,6 +142,10 @@ class COFFPlatformRuntimeState {
141142 Error dlopenFull (JITDylibState &JDS);
142143 Error dlopenInitialize (JITDylibState &JDS, COFFJITDylibDepInfoMap &DepInfo);
143144
145+ Error dlupdateImpl (void *DSOHandle);
146+ Error dlupdateFull (JITDylibState &JDS);
147+ Error dlupdateInitialize (JITDylibState &JDS);
148+
144149 Error dlcloseImpl (void *DSOHandle);
145150 Error dlcloseDeinitialize (JITDylibState &JDS);
146151
@@ -265,6 +270,20 @@ void *COFFPlatformRuntimeState::dlopen(std::string_view Path, int Mode) {
265270 }
266271}
267272
273+ int COFFPlatformRuntimeState::dlupdate (void *DSOHandle) {
274+ ORC_RT_DEBUG ({
275+ std::string S;
276+ printdbg (" COFFPlatform::dlupdate(%p) (%s)\n " , DSOHandle, S.c_str ());
277+ });
278+ std::lock_guard<std::recursive_mutex> Lock (JDStatesMutex);
279+ if (auto Err = dlupdateImpl (DSOHandle)) {
280+ // FIXME: Make dlerror thread safe.
281+ DLFcnError = toString (std::move (Err));
282+ return -1 ;
283+ }
284+ return 0 ;
285+ }
286+
268287int COFFPlatformRuntimeState::dlclose (void *DSOHandle) {
269288 ORC_RT_DEBUG ({
270289 auto *JDS = getJITDylibStateByHeader (DSOHandle);
@@ -390,6 +409,55 @@ Error COFFPlatformRuntimeState::dlopenInitialize(
390409 return Error::success ();
391410}
392411
412+ Error COFFPlatformRuntimeState::dlupdateImpl (void *DSOHandle) {
413+ // Try to find JITDylib state by header.
414+ auto *JDS = getJITDylibStateByHeader (DSOHandle);
415+
416+ if (!JDS) {
417+ std::ostringstream ErrStream;
418+ ErrStream << " No registered JITDylib for " << DSOHandle;
419+ return make_error<StringError>(ErrStream.str ());
420+ }
421+
422+ if (!JDS->referenced ())
423+ return make_error<StringError>(" dlupdate failed, JITDylib must be open." );
424+
425+ if (auto Err = dlupdateFull (*JDS))
426+ return Err;
427+
428+ return Error::success ();
429+ }
430+
431+ Error COFFPlatformRuntimeState::dlupdateFull (JITDylibState &JDS) {
432+ // Call back to the JIT to push the initializers.
433+ Expected<COFFJITDylibDepInfoMap> DepInfoMap ((COFFJITDylibDepInfoMap ()));
434+ if (auto Err = WrapperFunction<SPSExpected<SPSCOFFJITDylibDepInfoMap>(
435+ SPSExecutorAddr)>::
436+ call (JITDispatch (&__orc_rt_coff_push_initializers_tag), DepInfoMap,
437+ ExecutorAddr::fromPtr (JDS.Header )))
438+ return Err;
439+ if (!DepInfoMap)
440+ return DepInfoMap.takeError ();
441+
442+ if (auto Err = dlupdateInitialize (JDS))
443+ return Err;
444+
445+ return Error::success ();
446+ }
447+
448+ Error COFFPlatformRuntimeState::dlupdateInitialize (JITDylibState &JDS) {
449+ ORC_RT_DEBUG ({
450+ printdbg (" COFFPlatformRuntimeState::dlupdateInitialize(\" %s\" )\n " ,
451+ JDS.Name .c_str ());
452+ });
453+
454+ // Run static initializers.
455+ JDS.CInitSection .RunAllNewAndFlush ();
456+ JDS.CXXInitSection .RunAllNewAndFlush ();
457+
458+ return Error::success ();
459+ }
460+
393461Error COFFPlatformRuntimeState::dlcloseImpl (void *DSOHandle) {
394462 // Try to find JITDylib state by header.
395463 auto *JDS = getJITDylibStateByHeader (DSOHandle);
@@ -667,6 +735,10 @@ void *__orc_rt_coff_jit_dlopen(const char *path, int mode) {
667735 return COFFPlatformRuntimeState::get ().dlopen (path, mode);
668736}
669737
738+ int __orc_rt_coff_jit_dlupdate (void *dso_handle) {
739+ return COFFPlatformRuntimeState::get ().dlupdate (dso_handle);
740+ }
741+
670742int __orc_rt_coff_jit_dlclose (void *header) {
671743 return COFFPlatformRuntimeState::get ().dlclose (header);
672744}
0 commit comments