[PATCH v3] RISC-V: Fix IFUNC resolver cannot access gp pointer
Yangyu Chen
cyy@cyyself.name
Wed Jan 8 02:01:19 GMT 2025
On 1/8/25 00:38, Florian Weimer wrote:
> * Palmer Dabbelt:
>
>> 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. 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?
>
> As far as I understand it, at least in some cases, the gp register needs
> to be set up for the main program even for local static/hidden symbol
> access. Unfortunately, the ABI does not provide a completely reliable
> way for the dynamic linker to discover the gp value the main program
> requires, which leads to the code we have now. I think we should have
> something that is more declarative than running a piece of assembler
> code at the right time (the existing code runs too late, after IFUNC
> resolver), and which does not depend on dynamic symbol resolution.
>
Can we move the IFUNC invocation function to somewhere after the
relocation? Thus, we have l->l_relocated == 1, then the original
condition meets. I didn't understand why GLIBC chose to invoke IFUNC
during relocation. In this case, the gp setup might safely work. We also
need to fix the global_pointer relocation in this case, which should not
directly use the st_value of the symbol, at least should add l->l_addr
to it.
As for "running a piece of assemble code at the right time" I guess what
you want is load_up [1]. I think that's technically correct, but how
could we provide an ABI change to support this?
[1]
https://github.com/bminor/glibc/blob/glibc-2.40.9000/sysdeps/riscv/start.S#L82
Thanks,
Yangyu Chen
> Thanks,
> Florian
More information about the Libc-alpha
mailing list