[0/2] riscv: add support for GNU indirect function

Message ID 1606818180-17436-1-git-send-email-vincent.chen@sifive.com
Headers
Series riscv: add support for GNU indirect function |

Message

Vincent Chen Dec. 1, 2020, 10:22 a.m. UTC
  The riscv Binutils supported GNU indirect function in the commit
02dd9d25. In order to make the whole mechanism work properly, the
first patch adds the required ports to enable Glibc to address the
riscv IRELATIVE relocation. 
In addition, since the dynamic linker resolves the IRELATIVE relocation
before jumping into the executable program, the $gp register has not
been initialized when the IFUNC resolver function is executed. It cause
that some unexpected error may occur when the dynamic loader resolves the
IREALTIVE relocation of the position-dependent executable program. To
solve this problem, a new RISCV specific dynamic entry, DT_RISCV_GP,
created by Binutils is used to record the gp address. The dynamic
linker can use it to initialize $gp register before resolving the
IREALTIVE relocation of the PDE program.
 
The related patch of DT_RISCV_GP in Binutils could be found in
https://sourceware.org/pipermail/binutils/2020-December/114346.html

Vincent Chen (2):
  riscv: Add support for GNU indirect function
  riscv: Initialize $gp before resolving the IRELATIVE relocation

 elf/elf.h                    |  4 +++
 libc-abis                    |  1 +
 sysdeps/riscv/dl-dtprocnum.h | 22 +++++++++++++++
 sysdeps/riscv/dl-irel.h      | 53 ++++++++++++++++++++++++++++++++++++
 sysdeps/riscv/dl-machine.h   | 31 +++++++++++++++++++++
 5 files changed, 111 insertions(+)
 create mode 100644 sysdeps/riscv/dl-dtprocnum.h
 create mode 100644 sysdeps/riscv/dl-irel.h
  

Comments

Jim Wilson Dec. 2, 2020, 2:52 a.m. UTC | #1
On Tue, Dec 1, 2020 at 2:23 AM Vincent Chen <vincent.chen@sifive.com> wrote:

> In addition, since the dynamic linker resolves the IRELATIVE relocation
> before jumping into the executable program, the $gp register has not
> been initialized when the IFUNC resolver function is executed. It cause
> that some unexpected error may occur when the dynamic loader resolves the
> IREALTIVE relocation of the position-dependent executable program. To
> solve this problem, a new RISCV specific dynamic entry, DT_RISCV_GP,
> created by Binutils is used to record the gp address. The dynamic
> linker can use it to initialize $gp register before resolving the
> IREALTIVE relocation of the PDE program.
>

We should discuss DT_RISCV_GP with RISC-V International since we don't own
the ISA.  I opened a psabi issue.
    https://github.com/riscv/riscv-elf-psabi-doc/issues/165
The llvm/lld and FreeBSD developers also care about this stuff.

Jim
  
Jim Wilson Dec. 7, 2020, 9:36 p.m. UTC | #2
On Tue, Dec 1, 2020 at 6:52 PM Jim Wilson <jimw@sifive.com> wrote:

> On Tue, Dec 1, 2020 at 2:23 AM Vincent Chen <vincent.chen@sifive.com>
> wrote:
>
>> IREALTIVE relocation of the position-dependent executable program. To
>> solve this problem, a new RISCV specific dynamic entry, DT_RISCV_GP,
>> created by Binutils is used to record the gp address. The dynamic
>> linker can use it to initialize $gp register before resolving the
>> IREALTIVE relocation of the PDE program.
>>
>
> We should discuss DT_RISCV_GP with RISC-V International since we don't own
> the ISA.  I opened a psabi issue.
>     https://github.com/riscv/riscv-elf-psabi-doc/issues/165
> The llvm/lld and FreeBSD developers also care about this stuff.
>

Just to follow up on this, in the psabi discussion, the lld and FreeBSD
linker experts asked for a DT_SYMTAB solution to get the gp value, instead
of adding a new dynamic tag which is an ABI change.

Jim