@@ -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;
}
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(-)