]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
RISC-V: Fix the static-PIE non-relocated object check
authorPalmer Dabbelt <palmer@rivosinc.com>
Thu, 22 Feb 2024 23:24:00 +0000 (15:24 -0800)
committerAndreas Schwab <schwab@suse.de>
Mon, 25 Mar 2024 14:17:13 +0000 (15:17 +0100)
The value of l_scope is only valid post relocation, so this original
check was triggering undefined behavior.  Instead just directly check to
see if the object has been relocated, at which point using l_scope is
safe.

Reported-by: Andreas Schwab <schwab@suse.de>
Closes: BZ #31317
Fixes: e0590f41fe ("RISC-V: Enable static-pie.")
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
sysdeps/riscv/dl-machine.h

index 0cbb476c0583f1fc6adc3e5052aff076b7c67f3b..b2f28697f78a4241274a0e0aeab0125a5c9595d3 100644 (file)
@@ -348,7 +348,7 @@ 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_scope != NULL)
+  if (l->l_type == lt_executable && l->l_relocated)
     {
       /* The __global_pointer$ may not be defined by the linker if the
         $gp register does not be used to access the global variable