Can rust create truly postion independent code?
⚓ Rust 📅 2026-03-09 👤 surdeus 👁️ 1I have a kernel (elf binary) which I load into an arbitrary location and jump to it.
This works, for the most part, but I noticed that attempts to use a trait causes a crash because the vtables contain absolute addresses, and so are jumping to a location where my code hasn't been loaded.
I tried adding the following to my target file:
"position-independent-executables": true,
"relocation-model": "pic"
But that doesn't appear to work either (still tries to call into where code isn't loaded, but not really sure how/where the addresses are coming from).
I found a similar thread here:
Which seems to suggest that a fully relocatable binary isn't really possible without manually patching the absolute data pointers in the vtable the GOT (what is the GOT, btw? Where can I learn more about this?). Is this still the case, or are there other ways to create a binary which can be loaded and executed from any address?
I am curious if there are thoughts about the last post, though, which seems to imply that the original poster was able to get it somewhat working.
1 post - 1 participant
🏷️ Rust_feed