[PATCH] RISC-V: Add DT_RISCV_GP dynamic tag to fix the uninitialized gp for ifunc.

Jim Wilson jimw@sifive.com
Wed Dec 2 02:50:41 GMT 2020


On Tue, Dec 1, 2020 at 12:17 AM Nelson Chu <nelson.chu@sifive.com> wrote:

> When the ifunc resolver is in the executable, we may relax the variables
> to gp-relative access instruction in the ifunc resolver, or in other
> functions
> that called by the ifunc resolver.  But this will cause the uninitialized
> gp problem since the ifunc need to be resolved at the early runtime, that
> is at the pre-load stage, but we set the gp until the startup code.
>
> Therefore, we add a new dynamic tag, DT_RISCV_GP, to stroe the gp value and
> let ld.so can init the gp register early, before the pre-load stage.
> However, we only add the dynamic DT_RISCV_GP tag for the position
> dependence
> executable (not pic and pie), since we only do the relaxation for it.
>

There probably should be some discussion with RISC-V International before
adding a new dynamic tag, seeing as how SiFive doesn't actually own the
RISC-V architecture.  I created an abi issue for this
    https://github.com/riscv/riscv-elf-psabi-doc/issues/165
This will require an equivalent llvm/lld change.  And the FreeBSD toolchain
developers are affected too.

Jim


More information about the Binutils mailing list