A question about 64 bit kernel linking
A question about 64 bit kernel linking
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?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: A question about 64 bit kernel linking
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.
Beyond that, there's no fundamental reason why PIC shouldn't work that I can think of.