[PATCH v3] RISC-V: Fix IFUNC resolver cannot access gp pointer

Yangyu Chen cyy@cyyself.name
Tue Jan 7 16:22:27 GMT 2025



> On Jan 8, 2025, at 00:04, Palmer Dabbelt <palmer@rivosinc.com> wrote:
> 
> On Mon, 06 Jan 2025 18:32:54 PST (-0800), cyy@cyyself.name wrote:
>> Ping again. It has already been 1 month after v3 patch was submitted.
>> 
>> I think this patch is critical for RISC-V GCC Function multi-versioning
>> to work correctly, as GCC 15, which has this feature, is going to be
>> released.
> 
> IIUC the conclusion here was to avoid global symbol resolution in IFUNCs and instead use the pre-resolved function hwprobe VDSO function pointer passed in via a register.  

I think this approach should be considered a workaround for GCC FMV support rather than a bug fix.

> There was a long discussion on this during the hwprobe/IFUNC support patches, and IIRC one during the FMV patches -- though I remember accepting those and now I'm not sure why, so maybe I'm just forgetting something here?


After a long discussion about the norelax attribute [1], I think the underlying cause of this issue lies in the GLIBC. In my opinion, this patch should be a suitable solution to address the problem.

To maintain backward compatibility with older versions of GLIBC, I can also modify GCC to avoid using any global symbol for FMV IFUNC. However, we have documented extension bitmask in RISC-V C-API that the use of global symbols is inevitable for its design [2], and we have already implemented this in libgcc and the llvm compiler-rt. Thus, we should care about its users and fix the GLIBC.

[1] https://github.com/riscv-non-isa/riscv-c-api-doc/pull/94
[2] https://github.com/riscv-non-isa/riscv-c-api-doc/blob/main/src/c-api.adoc#function-multi-version

Thanks,
Yangyu Chen

> 
>> On 12/10/24 15:57, Yangyu Chen wrote:
>>> I also provide a POC to explain the bug existed in the past:
>>> 
>>> https://github.com/cyyself/glibc/
>>> commit/5525b4fcb7d62d6a9b4dbd44cbc5400f8b08698b



More information about the Libc-alpha mailing list