[RFC] Add thunk support for x86

15 views
Skip to first unread message

Farid Zakaria

unread,
Feb 9, 2026, 2:36:54 PM (13 days ago) Feb 9
to X86-64 System V Application Binary Interface
Hi!

This is a more specific discussion of the general "Making medium code-model handle large binaries" discussion [1].

I had begun trying to upstream thunk support for x86-64 in lld via [2]

I am hoping to see if we can get consensus on a basic agreement on what thunks for x86 may look like so that we can implement it.  I think the main point of discussion is which register to reserve for use in the thunk, spacing discussions and how to handle thunks that may still not reach their final target (thunk to a thunk?).

Fangrui had already give me some good feedback on the PR, I plan on addressing as well in the interim.


Florian Weimer

unread,
Feb 9, 2026, 4:20:35 PM (13 days ago) Feb 9
to Farid Zakaria, X86-64 System V Application Binary Interface
* Farid Zakaria:
A couple of random comments:

The long thunk sequences may need a NOTRACK prefix on the JMP
instruction if we ever turn on IBT. Hopefully it won't need
an ENDBR64 marker, so the whole sequence stays below 16 bytes
for alignment purposes.

We should enable optional rewriting of long thunks to JMPABS at run
time, by some suitable markup.

Using r11 as temporary register appears to be the right choice. It's
desirable to define STO_X86_64_VARIANT_CC, so that the toolchain can
detect calling convention mismatches (if r11 is not usable for
procedure linkage, STO_X86_64_VARIANT_CC must be set on the function
symbol).
Reply all
Reply to author
Forward
0 new messages