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

Florian Weimer fweimer@redhat.com
Mon Jan 13 14:46:07 GMT 2025


* Yangyu Chen:

> On 1/13/25 20:50, Florian Weimer wrote:
>> * Yangyu Chen:
>> 
>>> 2. There is no ABI grey area now.
>>>
>>>  From [3] we have: `__global_pointer$` must be exported in the dynamic
>>> symbol table of dynamically-linked executables if there are any
>>> GP-relative accesses present in the executable.
>> If you can link editors to follow this even with version scripts
>> that
>> use ”local: *”, it will work.  But that's a big If.
>> 
>
> Thanks for that pointing out. For this issue, I think we should modify
> the psABI to force the linker to export `__global_pointer$` even with
> the existing version script. At least, the linker should output a
> warning message. Whatever, it is still simpler than adding something
> like DT_RISCV_GP_VALUE.

I would strongly suggest to unconditionally create the symbol.

>> This lookup should not use the link map's scope anyway because that
>> could included preloaded objects with a conflicting definition of
>> __global_pointer$.  You can use _dl_lookup_direct, similar to what
>> _dl_call_libc_early_init does.  It wants the symbol in exactly this
>> particular object, too.
>
> If we have checked l->l_type == lt_executable before looking for the
> `__global_pointer$` symbol, I think some preloaded objects will not
> cause any conflicting definitions. Is it right? Or am I missing
> something?

No, the scope will typically contain more than just the object itself.
That's why I suggested to use _dl_lookup_direct.  But this can be a
separate change, and hopefully it does not matter in practice.

Thanks,
Florian



More information about the Libc-alpha mailing list