diff mbox series

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

Message ID tencent_71D182FBDA6E8E57B80731DD218D8D5C7C08@qq.com
State New
Headers show
Series [v2] RISC-V: Fix IFUNC resolver cannot access gp pointer | expand

Commit Message

Yangyu Chen Oct. 15, 2024, 5:01 p.m. UTC
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 mbox series

Patch

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;
 }