arm: Update elf_machine_load_address for static PIE

Message ID 20170929213634.GS2482@gmail.com
State Committed
Commit 8172aad937f52fe4ae891a206492150815791f2a
Headers

Commit Message

H.J. Lu Sept. 29, 2017, 9:36 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?

H.J.
--
	* sysdeps/arm/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/arm/dl-machine.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
  

Comments

Joseph Myers Sept. 29, 2017, 10:17 p.m. UTC | #1
On Fri, 29 Sep 2017, H.J. Lu wrote:

> 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?
> 
> H.J.
> --
> 	* sysdeps/arm/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.

OK.
  

Patch

diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
index 7d733f2b1c..efe2e1b3a3 100644
--- a/sysdeps/arm/dl-machine.h
+++ b/sysdeps/arm/dl-machine.h
@@ -53,10 +53,20 @@  elf_machine_dynamic (void)
 static inline Elf32_Addr __attribute__ ((unused))
 elf_machine_load_address (void)
 {
+  Elf32_Addr pcrel_addr;
+#ifdef SHARED
   extern Elf32_Addr __dl_start (void *) asm ("_dl_start");
   Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
-  Elf32_Addr pcrel_addr;
   asm ("adr %0, _dl_start" : "=r" (pcrel_addr));
+#else
+  extern Elf32_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+  if (!_DYNAMIC)
+    return 0;
+  extern Elf32_Addr __dl_relocate_static_pie (void *)
+    asm ("_dl_relocate_static_pie") attribute_hidden;
+  Elf32_Addr got_addr = (Elf32_Addr) &__dl_relocate_static_pie;
+  asm ("adr %0, _dl_relocate_static_pie" : "=r" (pcrel_addr));
+#endif
 #ifdef __thumb__
   /* Clear the low bit of the function address.