Re: [PATCH v7 0/5] LoongArch: Support toolchain with new relocation types

From: Xi Ruoyao
Date: Wed Aug 31 2022 - 04:09:12 EST


On Wed, 2022-08-31 at 14:58 +0800, Jinyang He wrote:
> That's right. Also I am wondering why new toolchain produce .got* in
> kernel. It's unneeded. In the past, gcc create la.global and parsed
> to la.pcrel by gas, and kernel works well. Now it seems we lost this
> feature in gcc. I checked the x86 asm code just now. And some info
> follows,
>
> LoongArch64, ./net/ipv4/udp_diag.s, *have reloc hint*
>          pcalau12i       $r4,%got_pc_hi20(udplite_table)
>          ld.d    $r4,$r4,%got_pc_lo12(udplite_table)
>          b       udp_dump
>
> x86_64, ./net/ipv4/udp_diag.s
>          movq    $udplite_table, %rdi
>          jmp     udp_dump
>
> It seems related to -fno-PIE and -cmodel=kernel on x86_64.
> Hope new gcc with this feature now.

On x86_64 -mcmodel=kernel means "all code and data are located in [-
2GiB, 0) range. We actually don't strictly require a "high" range as
we're mostly a PIC-friendly architecture: note that we use a
pcalau12i/addi.d pair for PIC addressing in [PC-2GiB, PC+2GiB, and a
lu12i.w/addi.d pair for "non-PIC" addressing in [-2GiB, 2GiB), both are
2-insn sequence.

If we can put the main kernel image and the modules in one 2GiB VA
range, we can avoid GOT completely. But it's not possible for now
because main kernel image is loaded in XKPRANGE but the modules are in
XKVRANGE. So the best we can achieve before implementing
CONFIG_RELOCATION is using GOT in modules, and avoid GOT in the main
kernel image (with a new code model in GCC, which will benefit both the
kernel and statically linked executables).

--
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University