[PATCH 2/2] RISC-V: Don't generate R_RISCV_RELATIVE if symbol referenced section is SH_ABS

Fangrui Song i@maskray.me
Fri Aug 22 17:07:44 GMT 2025


On Fri, Aug 22, 2025 at 6:11 AM Xi Ruoyao <xry111@xry111.site> wrote:
>
> On Fri, 2025-08-22 at 06:00 -0700, H.J. Lu wrote:
>
> /* snip */
>
> > > All ports of lld/ELF use this logic and Linux kernels linked with lld
> > > are working well:
> > > https://github.com/llvm/llvm-project/commit/ba2de8f22d0cac86d89c1806fb54ed3463349342
> > >
> >
> > How does it work with x86-64 kernel compiled as PIE?
>
> https://lore.kernel.org/lkml/20240925150059.3955569-30-ardb+git@google.com/
> has not made into the kernel yet, so the current kernel is not compiled
> as PIE, but got relocated with some custom logic on boot.
>
> --
> Xi Ruoyao <xry111@xry111.site>

Ard has certainly ensured the changes work with lld/ELF, so we don't
need to worry about that.

With the proposed PIE x86-64 kernel changes, most references will use
RIP-relative addressing. Most defined symbols will be relative to a
section, and PC-relative relocations referencing them can be resolved
at link time.
SHN_ABS symbol (typically a label difference or a ABSOLUTE(sym))
cannot be referenced by PC-relative relocation.


More information about the Binutils mailing list