Patch rust functions at runtime with magic and linker hacks.
roughly:
- diff object files
- figure out what exactly changed
- combine the changed object files using the dep map
- figure out affected symbols and functions
- package the .o files together into a single cursed dylib that tricks dlopen
- disable a bunch of stuff like ASLR
- dlopen that dylib at the same address as the program root itself such that our pic/pie code can work properly
- resolve missing symbols against the running binary
- tell the app that we've patched it and it should maybe try to do new stuff
and voila you have in-place binary patching for a running rust app.
Not only does completely circumvent the typical close, rebuild, relink, restart, reinitialize, resume flow, but it uses rust's incremental compiler WITHOUT LINKING - the only unnecessary cost we pay here is the compiler frontend + macro expansion. This is faster than pretty much anything else you could design.**
** currently uses the linker in a sort of pass-thru mode. we still need to handle compilation-level relocations. eventually will drop this entirely.
-
dlopen seems to be working on ios?
-
https://fasterthanli.me/series/making-our-own-executable-packer/part-18
-
https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-54839/index.html
-
https://davidlattimore.github.io/posts/2024/02/04/speeding-up-the-rust-edit-build-run-cycle.html
can't we just define the existing symbols - except for the target - from the already resolved symbols in space?