Page 1 of 1

A question about 64 bit kernel linking

Posted: Sun Nov 17, 2013 7:04 am
by nbdd0121
Currently I am coding a 64 bit kernel, so I added "-mcmodel-large" to the cflags, and it works fine. Because in assembly, every 64 bit immediate number should be stored in general registers first because the only command taking imm64 is "mov GPR, imm64". As a result, my kernel became very big. When I only added a printf function to the kernel, the kernel became 3KB larger. I came up an idea that to use -fPIC instead of -mcmodel-large to compile the kernel. It works fine, but I wondered if the usage will cause any potential problem, because it seems that every solution given by the Internet said "use mcmodel option". What's your opinion?

Re: A question about 64 bit kernel linking

Posted: Sun Nov 17, 2013 7:23 am
by Combuster
If you can use either the regular or kernel memory model, you don't lose bytes and cycles to indirect address calculations typical of PIC, even though it is still more efficient compared to the large memory model. Efficiency and practicality is basically the reason why you'll find all of the examples using -mcmodel=kernel. Consider why you actually need arbitrary kernel placement, and perhaps related, what paging doesn't solve for you already.

Beyond that, there's no fundamental reason why PIC shouldn't work that I can think of.