[PATCH v2] RISC-V: Fix IFUNC resolver cannot access gp pointer
Yangyu Chen
cyy@cyyself.name
Wed Oct 30 02:58:14 GMT 2024
Friendly ping.
FYI, this bug can be reproduced through the steps outlined in the BZ #32269.
Link: https://sourceware.org/bugzilla/show_bug.cgi?id=32269
On 10/16/24 01:01, Yangyu Chen wrote:
> In some cases, an IFUNC resolver may need to access the gp pointer to
> resolve the function address. Such an object may have l_relocated == 0.
> In this case, the GP register will not be set up. Thus, the IFUNC
> resolver cannot access the gp pointer. This patch fixes this issue by
> relaxing the check of l_relocated in elf_machine_runtime_setup.
>
> As for the original Bug 31317, since the static-linked executable has
> already set up the gp pointer, we don't need to execute the code to set
> up the gp pointer again. I have also reproduced and checked Bug 31317,
> this patch can fix the issue.
>
> Closes: BZ #32269
> Fixes: 96d1b9ac23 ("RISC-V: Fix the static-PIE non-relocated object check")
> Signed-off-by: Yangyu Chen <cyy@cyyself.name>
> ---
> sysdeps/riscv/dl-machine.h | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
> index b2f28697f7..10a36d6701 100644
> --- a/sysdeps/riscv/dl-machine.h
> +++ b/sysdeps/riscv/dl-machine.h
> @@ -348,7 +348,8 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
> gotplt[1] = (ElfW(Addr)) l;
> }
>
> - if (l->l_type == lt_executable && l->l_relocated)
> +#ifdef SHARED
> + if (l->l_type == lt_executable)
> {
> /* The __global_pointer$ may not be defined by the linker if the
> $gp register does not be used to access the global variable
> @@ -368,6 +369,7 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
> : "r" (ref->st_value)
> );
> }
> +#endif
> #endif
> return lazy;
> }
More information about the Libc-alpha
mailing list