Skip to content

Segments, stack and far data

A source file's code over 64 KiB, in the models with far code, goes on in more code segments, <file>_TEXT_1 and so on. A function is in one segment, so it is at most 64 KiB.

The stack of an .EXE program is 4 KiB. The linker's option stack makes it larger: -Wl,option,stack=16384. The heap starts after it.

In compact, large, huge and huge16, a global or static variable larger than 32767 bytes is far data: it gets a segment of its own outside DGROUP, as in Open Watcom, so DGROUP keeps its 64 KiB for everything else. In huge such a variable can be over 64 KiB; it is split into consecutive 64 KiB segments. -mlarge-data-threshold=N moves the limit, and 0 keeps every variable in DGROUP. A variable declared extern with no size (extern char buf[];) may be far data in another file, so it is reached with far pointers, which work for near variables too. Far zero-initialized variables come after DGROUP and the stack, so they take no room in the .EXE file; the startup code clears them.