I am such a Nix zealot, I have not written much about the ongoing work on huge binaries I am pursuing through my employment at Meta. Dear Nix fans, please excuse this digression, I am multi-faceted beyond my love for reproducible builds.
The day before my fourth child was born, I had just given a talk at the 2026 LLVM Developers’ Meeting about building massive binaries, alongside Arthur Eubanks. We’ve made significant progress in understanding and addressing the challenges posed by extremely large binaries that exceed the limits of traditional code-models.
Here is a brief overview of the problem and our proposed solution.
Aside For more posts on huge binaries or the challenges of large code-models, check out my previous writings : what a relocation overflow is, why linker thunks are appealing, how much of the toolchain breaks past 2GiB, why thread-local storage is broken under the large code-model
We have designed a new code-model specifically for handling massive binaries, which we call the progressive large code-model.1
The design was done with my colleague Grigory Pastukhov and co-designed with Arthur at Google.
Aside The design was done in the open on public mailing lists and in collaboration with the wider community via a working group.
Personally, I like to call it the “Tolkien code-model”.
Most developers never think about code-models, or know by default they use the small code-model, until they hit a confusing relocation overflow. With this new code-model, the option to choose between small, medium, or large disappears.
§Why do code-models exist?
Even though x86-64 has 64-bit pointers, most instructions that reference a function or global variable (call, lea, mov) offer a variant that embeds a signed 32-bit offset relative to the instruction pointer (%rip), keeping machine code compact and fast.
The signed 32-bit offset variants are fast and allow the instruction to reach targets within ±2GiB of its own location, which is sufficient for most programs.
What happens when a target is more than 2GiB away from the instruction that references it? 💥
Who actually has >2GiB of code?
Hyperscalars! These companies all tend to use a large monorepo with extensive static linking, resulting in massive binaries that can easily exceed 2GiB of code (.text).
Tip For scale,
clangwith assertions is ~90MB of.textfrom about 4 million lines of source, so 2GiB is roughly 90 million lines.
.text takes roughly 22 Clangs.The standard answer for handling large binaries in the x86-64 world is changing the code model, which tells the compiler how to generate addresses and offsets for your program.
- small
- Everything fits within 2GiB, so 32-bit
%rip-relative offsets work everywhere. This is the default. - medium
- Code still fits within 2GiB, while large data objects move into separate large sections (
.ldata,.lbss,.lrodata) addressed with 64-bit offsets. - large
- No size assumptions at all. Every reference to another symbol is built from a 64-bit address.
Google rolled out medium and it bought them some runway by pushing big data tables out of the way. That doesn’t help when your .text itself is what’s blowing past 2GiB.
Great, problem solved? Why not just use -mcmodel=large? 🤔
§The trap of -mcmodel=large
The large code-model is not the panacea that it seems. It has some serious drawbacks and in practice we found it doesn’t even work.
The most obvious drawback is the sheer complexity of the generated code.
extern int counter;
extern void callee(void);
static int hits;
int read_global(void) { return counter; }
int read_static(void) { return hits; }
void call(void) { callee(); callee(); }
; -mcmodel=small -fpie
read_global:
movq counter@GOTPCREL(%rip), %rax
movl (%rax), %eax
retq
read_static:
movl hits(%rip), %eax
retq
call:
pushq %rax
callq callee@PLT
popq %rax
jmp callee@PLT
; -mcmodel=large -fpie
read_global:
leaq -0x7(%rip), %rax movabsq $_GLOBAL_OFFSET_TABLE_, %rcx addq %rax, %rcx movabsq $counter@GOT, %rax
movq (%rcx,%rax), %rax
movl (%rax), %eax
retq
read_static:
leaq -0x7(%rip), %rax movabsq $_GLOBAL_OFFSET_TABLE_, %rcx addq %rax, %rcx movabsq $hits@GOTOFF, %rax
movl (%rcx,%rax), %eax
retq
call:
pushq %rbx
leaq -0x7(%rip), %rax movabsq $_GLOBAL_OFFSET_TABLE_, %rcx addq %rax, %rcx movabsq $callee@GOT, %rax
movq (%rcx,%rax), %rbx
callq *%rbx
movq %rbx, %rax
popq %rbx
jmpq *%rax
What was only a few instructions in the small code-model becomes a complex sequence of instructions in the large code-model. Although we found CPUs to handle it reasonably well when executing real workloads, we found microbenchmarks to suffer significantly (>20%) in performance.
Looking past the performance regressions, the large code-model has fundamental limitations that make it impractical for real-world use, which to be honest was a big surprise to us.
The two issues that were immediately apparent to us: thread-local storage has no 64-bit form (deeper writeup) and mixing code-models in real binaries is fraught with pitfalls (any real binary will inevitably link prebuilt small objects).
lld gives a mixed binary today. Once .ltext grows past 2 GiB, every arrow crossing between the shaded middle and the outside overflows its 32-bit field.§Progressive large code-model
We set out to solve these problems either by improving the existing large code-model or by designing a new one from scratch.
Turns out that the existing large code-model is so unused that we decided to throw it away and start fresh. We put forward a new design to the psABI community, a very diffuse group that somehow dictates the rules for the ABI, that fixes all of the shortcomings we identified with the current model.
The core idea is to stop making the compiler assume the worst up front. We want our cake and eat it too: generate efficient small-code style instructions for the common case without sacrificing the ability to handle large binaries when necessary.
The design comes down to three mechanisms: multiple GOTs, linker thunks, and section demotion.
§Multiple GOTs
One of the advantages of the small code-model is that it can use compact, %rip-relative addressing for most symbol references via the Global Offset Table (GOT). The linker often relaxes these references when it can determine that the target is within reach, eliminating the need for a GOT slot entirely.
; far: a load from the GOT
movq counter@GOTPCREL(%rip), %rax
movl (%rax), %eax
; near: relaxed by the linker
leaq counter(%rip), %rax
movl (%rax), %eax
This works well as long as all the code and data are within ±2GiB.
The challenge arises when binaries grow beyond this limit, which is where multiple GOTs come into play.
We can have the linker create additional GOTs as needed partitioned by the code sections. As it lays out .ltext, roughly every 1.5GiB it splits the section and drops in a fresh GOT (.got.ltext.0, .got.ltext.1, and so on).
Each chunk of code uses the GOT sitting right beside it, so a GOT is always within 2GiB.
.ltext loads addresses from the GOT beside it; a symbol referenced from two chunks simply gets a slot in both.This solves our threshold problem for GOT reachability and the Thread Local Storage (TLS) R_X86_64_GOTTPOFF lack of reach simultaneously.2
Aside Dynamic linkers set each GOT as read-only after startup, respecting the
PT_GNU_RELROsegments. We have had to update dynamic linkers, such as glibc, to handle multiplePT_GNU_RELROsegments correctly.
§Zero-register linker thunks
Other architecutres have already faced the issue of limited branch reach and have implemented trampoline (a thunk) mechanisms to bridge distant calls. Aarch64, for example, has a 128MiB branch reach limit and relies on thunks for calls beyond that range.
We’ve adopted a similar approach for x86-64, introducing zero-register linker thunks to handle calls that exceed the 2GiB reach limit. The beauty of this approach is it pairs well with the multi-GOT layout, ensuring that a nearby GOT slot is always available for the thunk to use.
__X86_64Thunk_far_function:
jmpq *far_function@GOTPCREL(%rip) # ff 25 <rel32>, 6 bytes
Crucially, this touches zero registers. It turns out that on x86-64, even clobbering “scratch registers” like %r10 or %r11 isn’t safe everywhere (%r10 carries the static chain for nested functions, and split functions under -fbasic-block-sections expect every register to survive a jump). Going through the GOT avoids that problem completely.
Why not just compile with -fno-plt so every call goes through the GOT? Indirect calls are 1 byte longer than direct calls, leaving a wasted padding byte at every relaxed call site.
§Mixing code-models
In real binaries, prebuilt small objects still end up holding direct 32-bit references (R_X86_64_PC32) to symbols defined inside large sections. This happens constantly, whether from third-party libraries and hand-written assembly, ThinLTO marking declarations dso_local, or COMDAT inline functions where the linker picks the large copy over the small one.
Grigory had noticed that we could safely mix small and large code models by demoting large sections that are referenced from small code. This way, the small code can continue using direct 32-bit references, and the large code can still reach the demoted sections through its GOT.3
Effectively, whenever the linker sees a 32-bit relocation touching a large section, it demotes that section: it clears SHF_X86_64_LARGE and moves it into the small region (.ltext → .text, .ldata → .data), right next to the small code that needs it.
In practice, we found that the amount of demoted code and data is tiny, so it doesn’t threaten the 2GiB small budget. This was incredibly helpful since it allowed us to adopt the new code model much quicker without having to recompile all of our existing third-party code.
§To infinity and beyond
This work is happening in the open. You can check out the current prototype branch.
There is a long-tail, as with any large ambitious project, in ironing out all the remaining edge cases: linker scripts and all the userland tooling that interacts with the new code model. Everything expects there to only be one GOT or to help disassemble through the thunking layers correctly.
It’s been very rewarding to see different stakeholders engage in the problem via the LLVM Massive Binaries working group. What started as a discussion betwen two companies has grown into a broader community effort with members from Meta, Google, ByteDance, Arm, CHERI, and OxCaml, among others.
I have thought about maybe seeing what the largest real-world binaries we can build with this new code model are and submitting them to Guinness World Records.
Although we are removing the theoretical limit for linking large binaries, it remains to be seen how large in practice we can push real-world binaries before hitting other bottlenecks.
Engineering is always about removing one bottleneck and having it bubble up to the next one.

