@@ -110,6 +110,7 @@ class COFFPlatformRuntimeState {
110110
111111 const char *dlerror ();
112112 void *dlopen (std::string_view Name, int Mode);
113+ void *dlupdate (void *DSOHandle, int Mode);
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+ Expected<void *> dlupdateImpl (void *DSOHandle, int Mode);
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,21 @@ void *COFFPlatformRuntimeState::dlopen(std::string_view Path, int Mode) {
265270 }
266271}
267272
273+ void *COFFPlatformRuntimeState::dlupdate (void *DSOHandle, int Mode) {
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 H = dlupdateImpl (DSOHandle, Mode))
280+ return *H;
281+ else {
282+ // FIXME: Make dlerror thread safe.
283+ DLFcnError = toString (H.takeError ());
284+ return nullptr ;
285+ }
286+ }
287+
268288int COFFPlatformRuntimeState::dlclose (void *DSOHandle) {
269289 ORC_RT_DEBUG ({
270290 auto *JDS = getJITDylibStateByHeader (DSOHandle);
@@ -390,6 +410,57 @@ Error COFFPlatformRuntimeState::dlopenInitialize(
390410 return Error::success ();
391411}
392412
413+ Expected<void *> COFFPlatformRuntimeState::dlupdateImpl (void *DSOHandle,
414+ int Mode) {
415+ // Try to find JITDylib state by name.
416+ auto *JDS = getJITDylibStateByHeader (DSOHandle);
417+
418+ if (!JDS) {
419+ std::ostringstream ErrStream;
420+ ErrStream << " No registered JITDylib for " << DSOHandle;
421+ return make_error<StringError>(ErrStream.str ());
422+ }
423+
424+ if (!JDS->referenced ())
425+ return make_error<StringError>(" dlupdate failed, JITDylib must be open." );
426+
427+ if (auto Err = dlupdateFull (*JDS))
428+ return std::move (Err);
429+
430+ // Return the header address.
431+ return JDS->Header ;
432+ }
433+
434+ Error COFFPlatformRuntimeState::dlupdateFull (JITDylibState &JDS) {
435+ // Call back to the JIT to push the initializers.
436+ Expected<COFFJITDylibDepInfoMap> DepInfoMap ((COFFJITDylibDepInfoMap ()));
437+ if (auto Err = WrapperFunction<SPSExpected<SPSCOFFJITDylibDepInfoMap>(
438+ SPSExecutorAddr)>::call (&__orc_rt_coff_push_initializers_tag,
439+ DepInfoMap,
440+ ExecutorAddr::fromPtr (JDS.Header )))
441+ return Err;
442+ if (!DepInfoMap)
443+ return DepInfoMap.takeError ();
444+
445+ if (auto Err = dlupdateInitialize (JDS))
446+ return Err;
447+
448+ return Error::success ();
449+ }
450+
451+ Error COFFPlatformRuntimeState::dlupdateInitialize (JITDylibState &JDS) {
452+ ORC_RT_DEBUG ({
453+ printdbg (" COFFPlatformRuntimeState::dlupdateInitialize(\" %s\" )\n " ,
454+ JDS.Name .c_str ());
455+ });
456+
457+ // Run static initializers.
458+ JDS.CInitSection .RunAllNewAndFlush ();
459+ JDS.CXXInitSection .RunAllNewAndFlush ();
460+
461+ return Error::success ();
462+ }
463+
393464Error COFFPlatformRuntimeState::dlcloseImpl (void *DSOHandle) {
394465 // Try to find JITDylib state by header.
395466 auto *JDS = getJITDylibStateByHeader (DSOHandle);
@@ -667,6 +738,10 @@ void *__orc_rt_coff_jit_dlopen(const char *path, int mode) {
667738 return COFFPlatformRuntimeState::get ().dlopen (path, mode);
668739}
669740
741+ void *__orc_rt_coff_jit_dlupdate (void *dso_handle, int mode) {
742+ return COFFPlatformRuntimeState::get ().dlupdate (dso_handle, mode);
743+ }
744+
670745int __orc_rt_coff_jit_dlclose (void *header) {
671746 return COFFPlatformRuntimeState::get ().dlclose (header);
672747}
0 commit comments