https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119386

--- Comment #35 from Ard Biesheuvel <ardb at kernel dot org> ---
(In reply to Alexander Monakov from comment #34)
> We have -mcmodel=kernel already, which is incompatible with -fpic.
> 
> Ard, where is -fpic in the kernel context coming from? Kernel's top-level
> Makefile passes -fno-PIE, and arch/x86/Makefile passes -mcmodel=kernel. What
> is the scenario your r14-811 patch was dealing with?

These days, there is quite a lot of C code in Linux that executes before the
kernel virtual mapping is even up, and this code (and everything that may be
called by it) needs to be position independent. Currently, we rely on fragile
hacks (RIP_REL_REF() for example) to try and ensure that this works, but it
would be preferred if that code (or perhaps the entire kernel) could be built
with -fPIC. 

There is some pushback to this, given that RIP-relative LEA is sometimes more
expensive that a plain MOV (depending on the uarch) but not being able to use
both -fPIC and -pg in the kernel was an impediment. (The indirect call opcode
is longer, and does not honour -mnop-mcount, which is an issue for us)

Reply via email to