HiOctocontrabass wrote: ↑Thu Oct 10, 2024 8:58 pmI wouldn't be surprised if those optimizations only work on ELF output. But why are you compiling position-independent code in the first place?
This code is a minimal extract from the kernel I'm playing with, that keeps the problem.
I completely understand I don't need PIC for this kernel, indeed, -fno-pic solves this problem (gcc -Q -v --help=common shows that -fPIC and -fPIE are enabled by default).
I think it's not an optimization: MOV 0xb(%rip), %rax does not store the address of the intended function, but the content of that address. It doesn't make any sense.
I know I'll die not being able to understand / know a 5% of what a linker does, but this looks like a bug to me... The linker resolves the reference to that function either by changing MOV to LEA and the offset to %rip, or by changing relative to absolute addressing. Which is ok. But keeping the MOV instruction with an offset of the %rip is not.