Huge binaries: I thunk therefore I am
4 months ago
- #optimization
- #x86_64
- #linking
- The post discusses the 'sound barrier' of x86_64 linking, specifically the 32-bit relative CALL instruction and its potential to cause relocation overflows.
- Using -mcmodel=large can fix the issue but leads to 'instruction bloat' and possible performance penalties.
- Dynamic libraries are a common solution to avoid static linking issues, though they introduce performance penalties and complexity in deployment.
- Link Time Optimizations (LTO) offer advanced optimizations but require significant RAM and slow down builds, with ongoing research in ThinLTO and profile-guided optimizations.
- Linker thunks (or trampolines) are proposed as a solution to maintain fast, small code-models even for large binaries, with prior art in LLVM for architectures like AArch64.
- The post explores the possibility of implementing thunks for x86_64 to bypass the 2GiB limit, suggesting modifications to GOT and PLT accesses.
- The author invites collaboration to further explore these ideas, emphasizing the trade-offs between binary size and performance.