June 24, 2007

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:

`-mcmodel=medium' 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:

`-mmlarge-data-threshold=NUMBER'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 65535.

6 Comments:

Man! I'm sorry about your weekend.What a drag! Sometimes another developer is a good sounding board or reality checker - it's hard to spot stuff, sometimes, when you're on you're own.Maybe you will fly through progress now!Thanks for sticking with it!