A personal proof-of-concept linker that works only on Linux x86_64, with hot-reload potential
This project is a proof-of-concept linker built in Rust. The purpose of this project was to learn more about how linkers and loaders work. It's one of those things you don't think about until you need to, and if you're like me, you're a little surprised at the complexity that hides behind such a simple interface. But if it was just a linker, that's not very interesting, so I'm also working on adding some hot-reloading functionality that will swap out code at runtime. I wrote a wild blog post about this called Hot-Reloading like it's 1972. It turns out that hot-reloading is a bit of a difficult problem, which is why you don't see it much any more as the focus has moved from developer productivity towards production stability. I still think the developer experience aspect is important though, so I'd like to explore it's potential further as part of my language research.
- Only compiles for Linux on x86_64
- Limited linker options, only the simplest were used for implementation
- Hot-reloading is very primitive and not yet usable
- Single code model
- Code must by position independent (-fPIC)
You will need a few libraries to build the test functions. On ubuntu you will need:
# install dependencies
sudo apt install libsigsegv-dev libsdl2-dev libuv1-dev musl-dev
# run test-suite
make test
See the Makefile for examples of usage.
Some helpful links for building linkers:
- https://wiki.osdev.org/ELF
- https://web.archive.org/web/20140130143820/http://www.robinhoksbergen.com/papers/howto_elf.html
- http://www.skyfree.org/linux/references/ELF_Format.pdf
- https://gitlab.com/x86-psABIs/x86-64-ABI
- https://refspecs.linuxbase.org/elf/x86_64-abi-0.98.pdf
- https://github.com/c-testsuite/c-testsuite
- https://eli.thegreenplace.net/2012/01/03/understanding-the-x64-code-models