#31195
Native backends: hot code reloading by modifying running binary
Situation
v -live hot code reloading currently works only on the C backend. It compiles @[live] functions into a shared library, loads it with dlopen/GetProcAddress, and calls through impl_live_* function pointers (vlib/v/gen/c/live.v, vlib/v/live/executable/reloader.c.v).
The native (arm64) backend has no live-reload support:
vlib/v/gen/arm64has nolivecodegen, noimpl_live_*indirection, and no reload runtime.- The linker already imports the primitives needed for in-place patching (
_mprotect,_sys_icache_invalidate,_dlopen,_dlsym), but they are unused for hot reload. - The roadmap item remains unchecked: "Hot code reloading by modifying running binary (using the native backends)".
Goal
Implement hot code reloading for native backends by modifying the running binary in place, rather than relying on a shared library.
Proposed plan
- Reproduce the current gap:
v -compile-backend arm64 selfv -b arm64 -live run examples/hot_reload/message.v
- Add native live-function indirection analogous to
gen/c/live.v:- detect
@[live]functions; - emit
impl_live_*function pointers and wrappers; - add a mutex and reload entry point.
- detect
- Implement a native reload runtime:
- allocate executable pages;
- generate replacement function bodies;
- overwrite the original function entry;
mprotect+sys_icache_invalidate.
- Add file-watching/recompilation loop equivalent to
vlib/v/live/executable/reloader.c.v. - Add tests:
- smoke test with
examples/hot_reload/message.vunder-b arm64; - native runtime test for patching.
- smoke test with
Constraints
- Native backend is macOS ARM64 only.
- Requires
v -compile-backend arm64 self. - This is a large, backend-specific change; should land incrementally behind an experimental flag.
Activity
0No activity yet.