Damn mcmodel=medium….

I have wasted my whole weekend on hunting for a not existing bug. A x86-64 kernel was not going to boot, hanging somewhere around the initialization of few classes. After a long and stressful investigation I have found out, that the code compiled with -mcmodel=medium flag was totally wrong (I have to use this memory model, since the kernel is located at address 0x0f8000000000). The gcc documentation said:

Generate code for the medium model: The program is linked in the

lower 2 GB of the address space but symbols can be located
anywhere in the address space.

According to this information, my code has to work! But it didn’t. And then, suddenly, after considering two other possibilities (kernel placed either in lowest 2GB or the highest 2GB of address space) I have found the solution:

When `-mcmodel=medium’ is specified, the data greater than

THRESHOLD are placed in large data section. This value must be the
same across all object linked into the binary and defaults to

Adding the “-mmlarge-data-threshold=1″ solved all my issues caused by change from gcc 4.0 to 4.1… Oh well… 😉