Patchwork aarch64: Update elf_machine_load_address for static PIE

login
register
mail settings
Submitter H.J. Lu
Date Sept. 29, 2017, 9:37 p.m.
Message ID <20170929213701.GT2482@gmail.com>
Download mbox | patch
Permalink /patch/23256/
State New
Headers show

Comments

H.J. Lu - Sept. 29, 2017, 9:37 p.m.
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/aarch64/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/aarch64/dl-machine.h | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Patch

diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h
index 60472036f5..6f259f1ef7 100644
--- a/sysdeps/aarch64/dl-machine.h
+++ b/sysdeps/aarch64/dl-machine.h
@@ -61,6 +61,7 @@  elf_machine_load_address (void)
   ElfW(Addr) static_addr;
   ElfW(Addr) dynamic_addr;
 
+#ifdef SHARED
   asm ("					\n"
 "	adrp	%1, _dl_start;			\n"
 #ifdef __LP64__
@@ -84,6 +85,34 @@  elf_machine_load_address (void)
 #endif
 "2:						\n"
     : "=r" (static_addr),  "=r" (dynamic_addr));
+#else
+  extern ElfW(Dyn) _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+  if (!_DYNAMIC)
+    return 0;
+  asm ("						\n"
+"	adrp	%1, _dl_relocate_static_pie;		\n"
+#ifdef __LP64__
+"	add	%1, %1, #:lo12:_dl_relocate_static_pie	\n"
+#else
+"	add	%w1, %w1, #:lo12:_dl_relocate_static_pie\n"
+#endif
+"	ldr	%w0, 1f					\n"
+"	b	2f					\n"
+"1:							\n"
+#ifdef __LP64__
+"	.word	_dl_relocate_static_pie			\n"
+#else
+# ifdef __AARCH64EB__
+"	.short  0                               	\n"
+# endif
+"	.short  _dl_relocate_static_pie                 \n"
+# ifndef __AARCH64EB__
+"	.short  0                               	\n"
+# endif
+#endif
+"2:						\n"
+    : "=r" (static_addr),  "=r" (dynamic_addr));
+#endif
   return dynamic_addr - static_addr;
 }