What is builtin.code_model?

Pretty much what it says in the title. I came across it Here and am now wondering what it does as I cant find any docs on it.
https://ziglang.org/documentation/master/std/#builtin.code_model

AMD64 instructions cannot encode 64-bit addresses as immediate operands.
Code models define constraints for code size, data size, address range and addressing (absolute vs position independent) that allow the compiler to generate better code.

It is defined in AMD64 System V ABI (link to PDF)
see Architectural Constraints page 39-41

4 Likes

Does this mean that choosing the wrong code model may break compilation / lead to a compile error?

Also thanks for the answer!

As a setting it is useful for embedded (small that means known address space), os (kernel that means loaded on the upper address space) and other special cases.

It might break compilation. It affects linking and loading.

But if there is no compile error then it should work flawlessly shouldn’t it?