Here's one theoretical workaround, but which seems like a hack to what is a fundamental dyld problem. Dynamic libraries make little sense if you can't reload them dynamically. The dyld cache has been around forever, but seems to be not functioning properly here. The modstamp on the dylib is completely different in this case, and should be detected and that version loaded, instead of returning the old dylib.
Also how do you tell with otool if a dylib doesn't meet the criteria for hotloading? Are there any parameters which state that it uses ObjC, thread_local, or Swift code? There must be criteria that dyld uses to prevent hotloading.
Also is there a way to tell with all of the dyld environment flags the modstamp of the dylib that was just loaded? In this case, I'm just modifying a print statement, and then running that code, but it doesn't print the changed line until the app is reloaded.
if (modstamp differs from last load) {
Create a temp file (writeable since it’s in temp directory), use mkstmp
Store the modstamp
Copy newly built file from Library/Caches over to temp
dlclose() old file
dlopen() temp file dylib (does that work?, @rpath issues)
Let the system delete the temp file when user quits, next load starts from Library/Caches directory.
}
Topic:
App & System Services
SubTopic:
General
Tags: