@@ -105,6 +105,7 @@ class ELFNixPlatformRuntimeState {
105
105
106
106
const char *dlerror ();
107
107
void *dlopen (std::string_view Name, int Mode);
108
+ int dlupdate (void *DSOHandle);
108
109
int dlclose (void *DSOHandle);
109
110
void *dlsym (void *DSOHandle, std::string_view Symbol);
110
111
@@ -136,6 +137,10 @@ class ELFNixPlatformRuntimeState {
136
137
Error dlopenInitialize (std::unique_lock<std::recursive_mutex> &JDStatesLock,
137
138
PerJITDylibState &JDS,
138
139
ELFNixJITDylibDepInfoMap &DepInfo);
140
+ Error dlupdateImpl (void *DSOHandle);
141
+ Error dlupdateFull (std::unique_lock<std::recursive_mutex> &JDStatesLock,
142
+ PerJITDylibState &JDS);
143
+
139
144
Error dlcloseImpl (void *DSOHandle);
140
145
Error dlcloseInitialize (std::unique_lock<std::recursive_mutex> &JDStatesLock,
141
146
PerJITDylibState &JDS);
@@ -309,6 +314,15 @@ void *ELFNixPlatformRuntimeState::dlopen(std::string_view Path, int Mode) {
309
314
}
310
315
}
311
316
317
+ int ELFNixPlatformRuntimeState::dlupdate (void *DSOHandle) {
318
+ if (auto Err = dlupdateImpl (DSOHandle)) {
319
+ // FIXME: Make dlerror thread safe.
320
+ DLFcnError = toString (std::move (Err));
321
+ return -1 ;
322
+ }
323
+ return 0 ;
324
+ }
325
+
312
326
int ELFNixPlatformRuntimeState::dlclose (void *DSOHandle) {
313
327
if (auto Err = dlcloseImpl (DSOHandle)) {
314
328
DLFcnError = toString (std::move (Err));
@@ -523,6 +537,50 @@ Error ELFNixPlatformRuntimeState::dlopenInitialize(
523
537
return Error::success ();
524
538
}
525
539
540
+ Error ELFNixPlatformRuntimeState::dlupdateImpl (void *DSOHandle) {
541
+ std::unique_lock<std::recursive_mutex> Lock (JDStatesMutex);
542
+
543
+ // Try to find JITDylib state by name.
544
+ auto *JDS = getJITDylibStateByHeaderAddr (DSOHandle);
545
+
546
+ if (!JDS) {
547
+ std::ostringstream ErrStream;
548
+ ErrStream << " No registered JITDylib for " << DSOHandle;
549
+ return make_error<StringError>(ErrStream.str ());
550
+ }
551
+
552
+ if (!JDS->referenced ())
553
+ return make_error<StringError>(" dlupdate failed, JITDylib must be open." );
554
+
555
+ if (auto Err = dlupdateFull (Lock, *JDS))
556
+ return Err;
557
+
558
+ return Error::success ();
559
+ }
560
+
561
+ Error ELFNixPlatformRuntimeState::dlupdateFull (
562
+ std::unique_lock<std::recursive_mutex> &JDStatesLock,
563
+ PerJITDylibState &JDS) {
564
+ // Call back to the JIT to push the initializers.
565
+ Expected<ELFNixJITDylibDepInfoMap> DepInfo ((ELFNixJITDylibDepInfoMap ()));
566
+ // Unlock so that we can accept the initializer update.
567
+ JDStatesLock.unlock ();
568
+ if (auto Err = WrapperFunction<SPSExpected<SPSELFNixJITDylibDepInfoMap>(
569
+ SPSExecutorAddr)>::
570
+ call (JITDispatch (&__orc_rt_elfnix_push_initializers_tag), DepInfo,
571
+ ExecutorAddr::fromPtr (JDS.Header )))
572
+ return Err;
573
+ JDStatesLock.lock ();
574
+
575
+ if (!DepInfo)
576
+ return DepInfo.takeError ();
577
+
578
+ if (auto Err = runInits (JDStatesLock, JDS))
579
+ return Err;
580
+
581
+ return Error::success ();
582
+ }
583
+
526
584
Error ELFNixPlatformRuntimeState::dlcloseImpl (void *DSOHandle) {
527
585
528
586
std::unique_lock<std::recursive_mutex> Lock (JDStatesMutex);
@@ -765,6 +823,10 @@ void *__orc_rt_elfnix_jit_dlopen(const char *path, int mode) {
765
823
return ELFNixPlatformRuntimeState::get ().dlopen (path, mode);
766
824
}
767
825
826
+ int __orc_rt_elfnix_jit_dlupdate (void *dso_handle) {
827
+ return ELFNixPlatformRuntimeState::get ().dlupdate (dso_handle);
828
+ }
829
+
768
830
int __orc_rt_elfnix_jit_dlclose (void *dso_handle) {
769
831
return ELFNixPlatformRuntimeState::get ().dlclose (dso_handle);
770
832
}
0 commit comments