LobstersTuesday · July 28, 2026FREE

Seriously, what is the large code-model even for?

gcclarge-code-modeltlsbinary-size

Farid Zakaria's blog post examines the practical shortcomings of the large code model (-mcmodel=large) in GCC. The large code model is intended to support binaries exceeding 2 GiB by making no assumptions about addresses and section sizes. However, Zakaria discovers that the instruction sequences the compiler emits for Thread Local Storage (TLS) are 32-bit by construction, and -mcmodel=large has no alternative sequences to swap them for. This means the large code model is incapable of building complex large binaries despite its stated goal. To produce a test subject, Zakaria describes using uninitialized globals in the .bss section, which occupies virtual address space but zero bytes on disk, allowing gigabytes of address space to be created synthetically with a simple script that generates many 1 MiB arrays and a function that touches each one. The post highlights that relocation overflow is about virtual-address distance between a reference and its target, not disk size. Zakaria previously documented performance bottlenecks that made the code model largely theoretical, and this TLS limitation is presented as a more fundamental failure mode.

// why it matters

Developers relying on -mcmodel=large for large binaries may encounter TLS-related failures.

Sources

Primary · Lobsters
▸ Read original at fzakaria.com

Like this? Get the next digest.