[clang] [llvm] [AArch64] Add support for -mlong-calls code generation (PR #142982)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 5 09:42:00 PDT 2025


smithp35 wrote:

> > My understanding is that this will make all calls to global functions into long calls.
> > In AArch64 static linkes are required to insert range extension thunks for out of range BLs. In the best case this is just another direct branch, at worst case for `--pic-veneer` this is just `adrp, add, br`. I would expect that on-demand linker inserted thunks would outperform making all calls long for the majority of programs. I'm interested in any data that shows that long calls works better, and whether that could feed back into the lld thunk generation code. For example are the thunks too far away from the caller which causes page faults etc.
> > I note that with `-ffunction-sections` and certain linker options calls to static functions can go out of range too. These would get handled by linker thunks though.
> 
> This option is explicitly designed to ‌enable reliable patching workflows‌ when compiling object files. It is to guarantee call range safety in patches‌. When modifying/recompiling ‌individual object files‌ (e.g., during security patches),final memory layouts are ‌unknown at compile time‌, patched functions might end up >128MB away from callers. -mlong-calls forces all cross-object calls to use ‌64-bit absolute addressing‌.

If I've understood object patching, this would mean inserting a new function implementation, and binary patching all the call-sites to point to the new implementation.

As an aside to this patch.

I'd be tempted to see if I could indirect all the calls via the PLT. Then you'd be able add the new function and alter the dynamic symbol table entry to point to the new implementation and the dynamic linker would do the rest. That might need some fiddling in the linker or compiler driver to force it to create a PLT entry, --shared would do it, but for an executable we'd need a PT_INTERPRET section.

There was a Discourse thread on ROM Patching for embedded systems https://discourse.llvm.org/t/rfc-a-user-guided-rom-patching-mechanism-for-embedded-applications/78467 which had a similar idea.


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


More information about the llvm-commits mailing list