Hi,
I am working on RISC-V UEFI port recently. I found two RISC-V GNU linker issues which cause platform hangs when UEFI driver is launched.
In elfnn-riscv.c,
1. When handle R_RISCV_LO12_S in riscv_elf_relocate_section () ,
It uses X0 register as base address if the relative address is < 800h. This causes we lost high 20-bit of relocation.
2. In _bfd_riscv_relax_lui (),
This removes AUIPC when the relative address is < (RISCV_IMM_REACH/2), this causes relocation failed when launch UEFI image.
I also found there is some update of these two functions on Github. Just want to make sure are those update intended to fix the issues I mentioned above?
Thanks and happy new year!
Abner
R_RISCV_LO12_S should only be used for absolute relocations, so
dropping the high part is correct. R_RISCV_PCREL_LO12_S should be
used for pc-relative addressing.
Either use the la macro, use absolute addressing, or hand-write the
auipc sequence as
1: auipc t0, %pcrel_hi(sym)
...
addi t0, t0 %pcrel_lo(1b)
>
> 2. In _bfd_riscv_relax_lui (),
>
> This removes AUIPC when the relative address is < (RISCV_IMM_REACH/2), this
> causes relocation failed when launch UEFI image.
This sounds like the same issue as above (using R_RISCV_HI20 instead
of R_RISCV_PCREL_HI20).
Hi Tommy,
Thanks to your reply. I met this issue 1.5 month ago and fixed this by comment out some code in RISC-V GNU linker.
I will try to roll back my code and provide the sample files. However, I think I have to check the latest RISC-V tool chain on Github (mine is pretty old, it was Aug 2015). This issue probably was already fixed.
Thanks
Abner
VOID
EFIAPI
FvbNotificationEvent (
IN EFI_EVENT Event,
IN VOID *Context
)
{
.....
.....
}
EFI_STATUS
EFIAPI
FaultTolerantWriteInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
....
....
EfiCreateProtocolNotifyEvent (
&gEfiFirmwareVolumeBlockProtocolGuid,
TPL_CALLBACK,
FvbNotificationEvent, <--- **** Require relocation.
(VOID *)FtwDevice,
&mFvbRegistration
);
....
....
}
However, the relocation entry is deleted by "_bfd_riscv_relax_lui ()" function during the link process. See below ELF reloc dump.
00000000099c 000000000000 R_RISCV_NONE 0
00000000099c 03170000001b R_RISCV_LO12_I 00000000000007b0 FvbNotificationEvent + 0
This causes the relocation problem and results in system hang. I saw some change on this function in "elfnn-riscv.c" on Github. Not sure if the change fixed this issue or not. Will try the latest GNU tool chain later.
Thanks
Abner
-----Original Message-----
From: Andrew Waterman [mailto:and...@sifive.com]
Sent: Friday, January 01, 2016 7:36 AM
To: Chang, Abner
Cc: isa...@lists.riscv.org
Subject: Re: [riscv-sw] Relocation problem in RISC-V GNU Linker