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

--- Comment #12 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Andy Lutomirski from comment #8)

> I would like to see something along these lines but even stronger: a way to
> instruct GCC to use a particular type of access and relocation.  For
> example, I think I should be able to ask GCC to reference symbol "foo" using
> a PC-relative relocation or using an absolute relocation at my option.

Please note that the reason to use RIP relative address is one byte shorter
insn sequence:

        addl    $1, %gs:a(%rip)
        addl    $2, %gs:a

assembles to:

   0:   65 83 05 00 00 00 00    addl   $0x1,%gs:0x0(%rip)        # 0x8
   7:   01 
                        3: R_X86_64_PC32        a-0x5
   8:   65 83 04 25 00 00 00    addl   $0x2,%gs:0x0
   f:   00 02 
                        c: R_X86_64_32S a

I'm not familiar with kernel code model assumptions, the doc says that 

'-mcmodel=kernel'
     Generate code for the kernel code model.  The kernel runs in the
     negative 2 GB of the address space.  This model has to be used for
     Linux kernel code.

so assuming that code and data fits in 2 GB of address space, all symbols
should be reachable with either relocation.

OTOH, we can avoid RIP relative addresses for non-default address spaces, when
-mcmodel=kernel compile flag is in effect.

Reply via email to