diff mbox series

powerpc: Fix ld.so address determination for PCREL mode (bug 31640)

Message ID 87edb92vsi.fsf@oldenburg.str.redhat.com
State New
Headers show
Series powerpc: Fix ld.so address determination for PCREL mode (bug 31640) | expand

Commit Message

Florian Weimer April 13, 2024, 2:15 p.m. UTC
This seems to have stopped working with some GCC 14 versions,
which clobber r2.  With other compilers, the kernel-provided
r2 value is still available at this point.

---
 sysdeps/powerpc/powerpc64/dl-machine.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)


base-commit: ae7468a7b0bcf22e9cd5fcae42bb9e4f65de83ee

Comments

Peter Bergner April 13, 2024, 11:07 p.m. UTC | #1
On 4/13/24 9:15 AM, Florian Weimer wrote:
> This seems to have stopped working with some GCC 14 versions,
> which clobber r2.  With other compilers, the kernel-provided
> r2 value is still available at this point.

With PCREL, r2 is just another volatile/caller saved register.
That said, it wasn't until GCC commit 1bbb169fe6f9 where we
actually started using it.  Thanks for finding and fixing this!

LGTM

Reviewed-by: Peter Bergner <bergner@linux.ibm.com>


Peter
diff mbox series

Patch

diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h
index c6682f3445..2b6f5d2b08 100644
--- a/sysdeps/powerpc/powerpc64/dl-machine.h
+++ b/sysdeps/powerpc/powerpc64/dl-machine.h
@@ -78,6 +78,7 @@  elf_host_tolerates_class (const Elf64_Ehdr *ehdr)
 static inline Elf64_Addr
 elf_machine_load_address (void) __attribute__ ((const));
 
+#ifndef __PCREL__
 static inline Elf64_Addr
 elf_machine_load_address (void)
 {
@@ -105,6 +106,24 @@  elf_machine_dynamic (void)
   /* Then subtract off the load address offset.  */
   return runtime_dynamic - elf_machine_load_address() ;
 }
+#else /* __PCREL__ */
+/* In PCREL mode, r2 may have been clobbered.  Rely on relative
+   relocations instead.  */
+
+static inline ElfW(Addr)
+elf_machine_load_address (void)
+{
+  extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
+  return (ElfW(Addr)) &__ehdr_start;
+}
+
+static inline ElfW(Addr)
+elf_machine_dynamic (void)
+{
+  extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
+  return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address ();
+}
+#endif /* __PCREL__ */
 
 /* The PLT uses Elf64_Rela relocs.  */
 #define elf_machine_relplt elf_machine_rela