sh: Update elf_machine_load_address for static PIE
diff mbox series

Message ID 20170929213319.GJ2482@gmail.com
State New
Headers show
Series
  • sh: Update elf_machine_load_address for static PIE
Related show

Commit Message

H.J. Lu Sept. 29, 2017, 9:33 p.m. UTC
When --enable-static-pie is used to configure glibc, we need to use
_dl_relocate_static_pie to compute load address in static PIE.

OK for master?

	* sysdeps/sh/dl-machine.h (elf_machine_load_address): Use
	_dl_relocate_static_pie instead of _dl_start to compute load
	address in static PIE.  Return 0 if _DYNAMIC is undefined for
	static executable.
---
 sysdeps/sh/dl-machine.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Patch
diff mbox series

diff --git a/sysdeps/sh/dl-machine.h b/sysdeps/sh/dl-machine.h
index 7106afbdbd..627ef115a9 100644
--- a/sysdeps/sh/dl-machine.h
+++ b/sysdeps/sh/dl-machine.h
@@ -50,6 +50,7 @@  static inline Elf32_Addr __attribute__ ((unused))
 elf_machine_load_address (void)
 {
   Elf32_Addr addr;
+#ifdef SHARED
   asm ("mov.l 1f,r0\n\
 	mov.l 3f,r2\n\
 	add r12,r2\n\
@@ -61,6 +62,22 @@  elf_machine_load_address (void)
 	3: .long _dl_start@GOTOFF\n\
 	2: mov r2,%0"
        : "=r" (addr) : : "r0", "r1", "r2");
+#else
+  extern Elf32_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+  if (!_DYNAMIC)
+    return 0;
+  asm ("mov.l 1f,r0\n\
+	mov.l 3f,r2\n\
+	add r12,r2\n\
+	mov.l @(r0,r12),r0\n\
+	bra 2f\n\
+	 sub r0,r2\n\
+	.align 2\n\
+	1: .long _dl_relocate_static_pie@GOT\n\
+	3: .long _dl_relocate_static_pie@GOTOFF\n\
+	2: mov r2,%0"
+       : "=r" (addr) : : "r0", "r1", "r2");
+#endif
   return addr;
 }