[llvm] [aarch64][win] Add support for import call optimization (equivalent to MSVC /d2ImportCallOptimization) (PR #121516)

Daniel Paoliello via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 3 14:40:07 PST 2025


dpaoliello wrote:

> When the linker uses these dynamic relocations, it changes a br or blr indirect branch instruction into a direct b or bl, if the target address is close enough within the address space - right? (The other instructions for loading the address are left untouched, as those instructions can be anywhere detached from the branch, and we can't speculate on whether the register contents is needed elsewhere.)
> As the 64 bit address space is kinda large, and the b and bl instructions only have a +/- 128 MB range, I guess that this optimization simply can't be applied, if the target is too far away? Intuitively, it feels like this wouldn't end up effective all that often? Then again, I guess most DLLs are loaded close to each other in the virtual memory layout, and the base EXE, with dynamic base enabled (as always on aarch64) also would end up somewhere close.

The linker doesn't do the rewriting, the kernel-mode loader does, but yes it will rewrite the indirect branches to direct branches. Since it is the loader doing this work, it knows how far away the target address is and, therefore, if the instruction can be rewritten or not. Since this is an optimization, the loader can choose not to rewrite the instruction without affecting correctness.

https://github.com/llvm/llvm-project/pull/121516


More information about the llvm-commits mailing list