[compiler-rt] [llvm] [ORC][Runtime] Add `dlupdate` for MachO (PR #97441)
Matheus Izvekov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 13:49:26 PDT 2024
================
@@ -1236,6 +1258,68 @@ Error MachOPlatformRuntimeState::dlopenInitialize(
return Error::success();
}
+Expected<void *> MachOPlatformRuntimeState::dlupdateImpl(void *DSOHandle,
+ int Mode) {
+ std::unique_lock<std::mutex> Lock(JDStatesMutex);
+
+ // Try to find JITDylib state by DSOHandle.
+ auto *JDS = getJITDylibStateByHeader(DSOHandle);
+
+ if (!JDS) {
+ std::ostringstream ErrStream;
+ ErrStream << "No registered JITDylib for " << DSOHandle;
+ return make_error<StringError>(ErrStream.str());
+ }
+
+ if (!JDS->referenced())
+ return make_error<StringError>("dlupdate failed, JITDylib must be open.");
+
+ if (!JDS->Sealed) {
+ if (auto Err = dlupdateFull(Lock, *JDS))
+ return std::move(Err);
+ }
+
+ // Return the header address.
+ return JDS->Header;
+}
+
+Error MachOPlatformRuntimeState::dlupdateFull(
+ std::unique_lock<std::mutex> &JDStatesLock, JITDylibState &JDS) {
+ // Call back to the JIT to push the initializers.
+ Expected<MachOJITDylibDepInfoMap> DepInfo((MachOJITDylibDepInfoMap()));
+ // Unlock so that we can accept the initializer update.
+ JDStatesLock.unlock();
+ if (auto Err = WrapperFunction<SPSExpected<SPSMachOJITDylibDepInfoMap>(
+ SPSExecutorAddr)>::call(&__orc_rt_macho_push_initializers_tag,
+ DepInfo, ExecutorAddr::fromPtr(JDS.Header)))
+ return Err;
+ JDStatesLock.lock();
----------------
mizvekov wrote:
Is it ok to leave JDStatesLock unlocked in this error path?
https://github.com/llvm/llvm-project/pull/97441
More information about the llvm-commits
mailing list