Skip to content
This repository was archived by the owner on May 2, 2025. It is now read-only.
/ ipbp Public archive

in place binary patching for runtime rust hotreloading

Notifications You must be signed in to change notification settings

jkelleyrtp/ipbp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

this project has moved!

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

ipbp.rs - in place binary patching

it works

Patch rust functions at runtime with magic and linker hacks.

how it works

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.

Notes

About

in place binary patching for runtime rust hotreloading

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages