powerpc: Update elf_machine_load_address for static PIE

Message ID 20170929213400.GL2482@gmail.com
State Superseded
Headers

Commit Message

H.J. Lu Sept. 29, 2017, 9:34 p.m. UTC
  powerpc uses _DYNAMIC to compute load address, which works with static
PIE.  We just need to return 0 if _DYNAMIC is undefined for static
executable.

OK for master?

	* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_load_address):
	Return 0 if _DYNAMIC is undefined for static executable.
	* sysdeps/powerpc/powerpc64/dl-machine.h (elf_machine_load_address):
	Likewise.
---
 sysdeps/powerpc/powerpc32/dl-machine.h | 5 +++++
 sysdeps/powerpc/powerpc64/dl-machine.h | 5 +++++
 2 files changed, 10 insertions(+)
  

Comments

Alan Modra Sept. 29, 2017, 11:17 p.m. UTC | #1
On Fri, Sep 29, 2017 at 02:34:00PM -0700, H.J. Lu wrote:
> powerpc uses _DYNAMIC to compute load address, which works with static
> PIE.  We just need to return 0 if _DYNAMIC is undefined for static
> executable.

powerpc does, but powerpc64 does not.  So why is the test necessary on
powerpc64?

> 
> OK for master?
> 
> 	* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_load_address):
> 	Return 0 if _DYNAMIC is undefined for static executable.
> 	* sysdeps/powerpc/powerpc64/dl-machine.h (elf_machine_load_address):
> 	Likewise.
  

Patch

diff --git a/sysdeps/powerpc/powerpc32/dl-machine.h b/sysdeps/powerpc/powerpc32/dl-machine.h
index 1f8437ed9c..9cf876e136 100644
--- a/sysdeps/powerpc/powerpc32/dl-machine.h
+++ b/sysdeps/powerpc/powerpc32/dl-machine.h
@@ -64,6 +64,11 @@  elf_machine_dynamic (void)
 static inline Elf32_Addr __attribute__ ((const))
 elf_machine_load_address (void)
 {
+#ifndef SHARED
+  extern Elf32_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+  if (!_DYNAMIC)
+    return 0;
+#endif
   Elf32_Addr *branchaddr;
   Elf32_Addr runtime_dynamic;
 
diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h
index aeb91b8f69..3c67f831f3 100644
--- a/sysdeps/powerpc/powerpc64/dl-machine.h
+++ b/sysdeps/powerpc/powerpc64/dl-machine.h
@@ -90,6 +90,11 @@  elf_machine_load_address (void) __attribute__ ((const));
 static inline Elf64_Addr
 elf_machine_load_address (void)
 {
+#ifndef SHARED
+  extern Elf64_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+  if (!_DYNAMIC)
+    return 0;
+#endif
   Elf64_Addr ret;
 
   /* The first entry in .got (and thus the first entry in .toc) is the