originally, this repository was a testing ground for ideas. now, it's been integrated into the Dioxus CLI (dx).
The PR that inlined this work into dioxus itself is here DioxusLabs/dioxus#3797
This repository demonstrated how to make binary patching work using just linker flags and a custom compiler setup on macOS, but the official Dioxus version works for all platforms:
- web
- desktop (mac / win / linux)
- android
- ios
- x64 + wasm + aarch64
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.