Documentation

Last updated: 2026-09-27

The 2 GB wall — embedding a language model in a binary

Everlock ships as a self-contained binary.

The language model is inside it.

That constraint sounds like packaging.

Once the embedded model grows into multiple gigabytes, it turns into linker and address-space design.

The first surprising lesson was that "put a large file in the executable" stops being primarily a file-size problem long before the file itself becomes impossible to store.

At around two gigabytes, the architecture of the executable starts deciding whether the program can link at all.

The one-file rule

The requirement is intentionally strict:

cargo build
    |
    v
one runnable artifact

No model directory that has to be installed next to the executable.

No post-link packer.

No "download the binary, then fetch another payload."

The result should already be complete when the Rust build finishes.

That makes deployment pleasantly simple.

It also means the linker has to understand a binary containing a model that is larger than many complete applications by several orders of magnitude.

include_bytes! works until it really doesn't

Rust gives us an obvious tool:

include_bytes!("model.gguf")

For small assets, it is excellent.

The compiler turns the file into a constant and embeds it into the resulting artifact.

At hundreds of megabytes, that mechanism becomes expensive.

Embedding the roughly 266 MB SmolVLM weights this way drove compiler memory into multiple gigabytes and caused CI failures.

The compiler has to materialize and carry the constant through stages that were never intended to be a bulk-file transport mechanism.

At still larger sizes, another limit appears around rlib/archive handling.

So the first change was to stop asking rustc to own the payload.

Let the assembler stream the file

Everlock's build script generates a small assembly stub using .incbin.

Conceptually:

.section ...
model_start:
    .incbin "model.gguf"
model_end:

The assembler and linker can pull the model bytes directly into the final image.

Rust no longer has to represent the entire file as a compile-time constant.

That changes compiler memory behavior dramatically.

The payload size can grow without making rustc's peak memory scale in the same way.

This solves one problem.

Then the linker encounters the next one.

The linker error does not say "your model is too large"

On x86-64, ordinary code commonly uses RIP-relative addressing for nearby data.

The offset is encoded in a signed 32-bit relocation such as:

R_X86_64_PC32

That gives roughly a plus-or-minus 2 GB reach.

For normal programs, this is enormous.

For an executable containing several gigabytes of model data, it becomes a hard geometric constraint.

The issue is no longer:

does the file fit on disk?

It is:

what did the giant section push more than 2 GB away from something that references it?

The linker reports a relocation overflow.

The model may not even be mentioned in the error.

This is an address-layout problem

Imagine the executable as sections laid out in virtual address space:

.text
.rodata
.eh_frame
model blob
.gcc_except_table
.data
...

If the model blob is several gigabytes, placing it in the middle can separate normal sections that expect to remain close enough for 32-bit PC-relative references.

The code itself may be completely ordinary.

The relocation fails because the distance between two addresses is no longer ordinary.

That distinction matters.

Trying to optimize model size by a few megabytes is not the same as solving section placement.

The payload needs its own large-data region

On ELF x86-64, the working design puts the model into a section intended for large data:

.section .ldata,"awl",@progbits

The l flag marks it with SHF_X86_64_LARGE.

This gives the linker information that the section should not be treated like ordinary nearby data.

The large payload can be placed away from the cluster of normal code and metadata.

Conceptually:

normal executable sections
|-------------------------|

                     very large model section
                     |-----------------------|

The goal is to keep normal PC-relative relationships inside their expected range.

The model address itself is another trap

Putting the payload far away is only half the solution.

Rust code still needs to find it.

If generated Rust code directly takes the address of the far symbol, the compiler may create exactly the kind of PC-relative reference the layout is trying to avoid.

So the assembly adds an indirection.

A nearby section stores 64-bit absolute pointers using .quad.

Rust reads the pointer value from the nearby object.

Conceptually:

Rust code
   |
   v
near pointer object
   |
   v
64-bit absolute address
   |
   v
far model payload

The model can live far away.

The thing Rust references directly stays nearby.

Section names alone are not policy

Several approaches looked plausible and failed.

One was a custom read-only section named something like:

.lrodata

without the large-section flag.

That can appear to work with one linker version because the orphan section happens to be placed somewhere harmless.

Then the toolchain changes.

The linker chooses another position.

Previously nearby metadata sections become separated.

Relocations overflow.

Nothing in the source changed.

Only section placement did.

This is a useful reminder that relying on accidental linker layout is not a stable interface.

Large read-only placement caused another failure

Adding the large flag to read-only data did not automatically solve the problem either.

The linker could place large read-only data at the beginning of the image.

That pushed normal code several gigabytes upward.

Now PC-relative references from the code to low-address runtime symbols became the failing relationships.

The huge section had moved.

The geometry was still wrong.

There was even an lld option intended to place large read-only data after .bss, but the linker-driver path used by the Zig cross-build rejected the option before it reached lld.

The practical solution therefore used .ldata, which the relevant ELF linkers place in a workable region.

code-model=medium was not enough

Rust and LLVM provide larger code models for programs that need to address data farther away.

It is natural to try:

-C code-model=medium

But not every relocation in the final executable originates from Rust code compiled with that setting.

The failing references can live inside prebuilt runtime objects, libc++abi pieces, CRT objects, or other native components supplied by the cross-toolchain.

Changing rustc's code model cannot rewrite those already-built objects.

The whole link has to satisfy the assumptions of everything participating in the image.

Platform differences become model limits

The ELF solution is not automatically portable.

Different executable formats have different layout rules and ceilings.

On aarch64, the same 2 GB PC-relative constraint is not the central problem in this form, so the payload can use a simpler read-only arrangement.

macOS introduces another set of constraints.

The model cannot simply be moved into an arbitrary huge __DATA region without affecting the process's virtual layout.

For the Everlock build described here, that interacted badly with the dyld shared-cache mapping window on macOS 26.

Mach-O also has practical file-layout limits related to 32-bit section offsets.

The packaging rule is universal.

The implementation is not.

The tightest ceiling picks the model

There are two ways out of this.

Ship a different model size per target, and accept that the same version of Everlock answers differently depending on where it runs. Or pick one payload that fits under the strictest ceiling, and embed it everywhere.

Everlock took the second. The embedded pair — MiniCPM-V 4.6 Thinking at Q6_K, plus its vision sidecar — totals about 1.6 GB, which fits inside the Mach-O reach that macOS imposes. So every target embeds the same two files, and only the section placement differs:

TargetPayload lands inWhy
macOS__TEXT,__constKeeps the data at a low virtual address; __DATA pushes the layout past the dyld shared cache window on macOS 26+
Linux (x86-64).ldata, flagged awlSHF_X86_64_LARGE lifts the payload out of the ±2 GB reach
Linux (other).lrodataPlain read-only data; placement is uncritical within those architectures' reach
Windows.rdataPE has no large-data placement, so the image shares the macOS ceiling

This is still an unusual inversion.

Model choice is not determined only by inference speed, quality, or RAM.

The executable format itself becomes part of the model-selection policy — here it set an upper bound, and the model had to come in under it.

That is the broader lesson.

When people think about embedding a multi-gigabyte model, the first questions are usually:

how large will the binary be?
will the filesystem accept it?
how long will downloads take?

Those are valid.

But the more surprising failure happens before runtime.

The executable is a structured virtual-address-space layout.

Linkers, loaders, runtime objects, relocation types, and platform binary formats all have assumptions about where things can live relative to one another.

A giant payload changes those distances.

The error message points at the victim, not the cause

This is what makes the failure difficult to diagnose.

The relocation overflow may mention:

.eh_frame
.gcc_except_table
__dso_handle
_DYNAMIC
OPENSSL_memory_alloc

Those symbols are not necessarily broken.

They are simply the places where a distance assumption finally becomes impossible.

The model blob is the object that changed the geometry.

The linker reports the relationship that failed.

That is very different from reporting the design decision that caused it.

Build systems have memory ceilings too

The earlier include_bytes! failure belongs to the same family of problems.

A payload can be valid data and still be too large for the mechanism used to transport it through the build.

Rust constants are a poor bulk-file pipe at hundreds of megabytes.

Ordinary small-code-model section placement is a poor fit once a multi-gigabyte object changes address distances.

Mach-O has another set of constraints.

PE/COFF will have its own.

Embedding is therefore not one problem.

It is a sequence of boundaries:

source inclusion
compiler memory
object/archive format
linker relocation reach
section placement
loader layout
platform image limits

The payload has to survive all of them.

The one-file rule is still worth it

None of this means Everlock should abandon the self-contained binary.

That rule has a real operational benefit.

Deployment remains:

download one file
run one file

There is no synchronization problem between executable and model.

No missing model directory.

No version mismatch between two separately distributed artifacts.

No post-install assembly step.

The build complexity exists so the deployment complexity does not.

That is a reasonable trade if the build remains reproducible.

The useful question changes near 2 GB

For small embedded assets, ask:

Will this fit in the binary?

For very large assets, that question is incomplete.

The better question is:

What does this payload do to the executable's address layout?

At multi-gigabyte scale, the file is no longer passive cargo.

It participates in the geometry of the program.

That is why the 2 GB wall is so easy to misdiagnose.

Nothing about the source code says "distance."

The linker error rarely says "model."

But the real failure is exactly that:

Two things that used to be near one another are now too far apart.

Once you see the problem as address-space layout rather than file size, the fixes start to make sense.

updates ai build linker internals