Hot-code reloading on macOS/arm64 with Zig
jakubkonka.com
Hot-code reloading on macOS/arm64 with Zig
1–10 of 57 posts
Re: Hot-code reloading on macOS/arm64 with Zig
#2Re: Hot-code reloading on macOS/arm64 with Zig
#3Re: Hot-code reloading on macOS/arm64 with Zig
#4This isn't crazy - this is how just-in-time compilers work.
Re: Hot-code reloading on macOS/arm64 with Zig
#5This seems like it would just crash or make your program get into an inconsistent state. What happens if you are executing a transaction but mid transaction your binary gets updated and your transaction now has done half of what's needed by the old version and half of what's needed by the new version. I don't think it would be that hard to get into an inconsistent state.
Re: Hot-code reloading on macOS/arm64 with Zig
#6Re: Hot-code reloading on macOS/arm64 with Zig
#7> Instead of having your program managed by a running side-by-side loader program, what if the compiler would “simply” update the memory of the running process? You will most inevitably think I have gone completely crazy This isn't crazy - this is how just-in-time compilers work.
In the case of JIT, it may swap the bytecode but the flow of execution remains the same.
Hot code reloading usually requires a different approach.
Re: Hot-code reloading on macOS/arm64 with Zig
#8Why not simply use MAP_JIT? There is no need to do these weird tricks, plus you’re putting your process and the rest of the system at risk by elevating privilege and using task-for-pid.
Re: Hot-code reloading on macOS/arm64 with Zig
#9Why not simply use MAP_JIT? There is no need to do these weird tricks, plus you’re putting your process and the rest of the system at risk by elevating privilege and using task-for-pid.
Hey, author of the article here. Thanks for the suggestion! I actually didn't know about the MAP_JIT flag to mmap before and will defo consider it. As to elevating your privs - this is just a temp solution until I work out how to add this entitlement https://developer.apple.com/documentation/bundleresources/en... to the Zig compiler. I wrote the default Zig's MachO linker from scratch and it can embed the adhoc code…
The debugger entitlement is even more powerful, but once again since you’re modifying your own memory you don’t need it.
Re: Hot-code reloading on macOS/arm64 with Zig
#10This seems like it would just crash or make your program get into an inconsistent state. What happens if you are executing a transaction but mid transaction your binary gets updated and your transaction now has done half of what's needed by the old version and half of what's needed by the new version. I don't think it would be that hard to get into an inconsistent state.