public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] aarch64: Update elf_machine_load_address for static PIE
@ 2017-09-29 21:37 H.J. Lu
  0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2017-09-29 21:37 UTC (permalink / raw)
  To: GNU C Library

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(+)

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-09-29 21:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-29 21:37 [PATCH] aarch64: Update elf_machine_load_address for static PIE H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).