@@ -110,6 +110,7 @@ class COFFPlatformRuntimeState {
110
110
111
111
const char *dlerror ();
112
112
void *dlopen (std::string_view Name, int Mode);
113
+ int dlupdate (void *DSOHandle);
113
114
int dlclose (void *Header);
114
115
void *dlsym (void *Header, std::string_view Symbol);
115
116
@@ -141,6 +142,10 @@ class COFFPlatformRuntimeState {
141
142
Error dlopenFull (JITDylibState &JDS);
142
143
Error dlopenInitialize (JITDylibState &JDS, COFFJITDylibDepInfoMap &DepInfo);
143
144
145
+ Error dlupdateImpl (void *DSOHandle);
146
+ Error dlupdateFull (JITDylibState &JDS);
147
+ Error dlupdateInitialize (JITDylibState &JDS);
148
+
144
149
Error dlcloseImpl (void *DSOHandle);
145
150
Error dlcloseDeinitialize (JITDylibState &JDS);
146
151
@@ -265,6 +270,20 @@ void *COFFPlatformRuntimeState::dlopen(std::string_view Path, int Mode) {
265
270
}
266
271
}
267
272
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
+
268
287
int COFFPlatformRuntimeState::dlclose (void *DSOHandle) {
269
288
ORC_RT_DEBUG ({
270
289
auto *JDS = getJITDylibStateByHeader (DSOHandle);
@@ -390,6 +409,55 @@ Error COFFPlatformRuntimeState::dlopenInitialize(
390
409
return Error::success ();
391
410
}
392
411
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
+
393
461
Error COFFPlatformRuntimeState::dlcloseImpl (void *DSOHandle) {
394
462
// Try to find JITDylib state by header.
395
463
auto *JDS = getJITDylibStateByHeader (DSOHandle);
@@ -667,6 +735,10 @@ void *__orc_rt_coff_jit_dlopen(const char *path, int mode) {
667
735
return COFFPlatformRuntimeState::get ().dlopen (path, mode);
668
736
}
669
737
738
+ int __orc_rt_coff_jit_dlupdate (void *dso_handle) {
739
+ return COFFPlatformRuntimeState::get ().dlupdate (dso_handle);
740
+ }
741
+
670
742
int __orc_rt_coff_jit_dlclose (void *header) {
671
743
return COFFPlatformRuntimeState::get ().dlclose (header);
672
744
}
0 commit comments