sparc: Update elf_machine_load_address for static PIE

Message ID 20170929213254.GI2482@gmail.com
State New, archived
Headers

Commit Message

H.J. Lu Sept. 29, 2017, 9:32 p.m. UTC
  sparc uses a local label 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/sparc/sparc32/dl-machine.h (elf_machine_dynamic): Return
	0 if _DYNAMIC is undefined for static executable.
	* sysdeps/sparc/sparc64/dl-machine.h (elf_machine_dynamic):
	Likewise.
---
 sysdeps/sparc/sparc32/dl-machine.h | 5 +++++
 sysdeps/sparc/sparc64/dl-machine.h | 5 +++++
 2 files changed, 10 insertions(+)
  

Patch

diff --git a/sysdeps/sparc/sparc32/dl-machine.h b/sysdeps/sparc/sparc32/dl-machine.h
index 436e4e6cc3..30ae1b56ee 100644
--- a/sysdeps/sparc/sparc32/dl-machine.h
+++ b/sysdeps/sparc/sparc32/dl-machine.h
@@ -77,6 +77,11 @@  elf_machine_dynamic (void)
 static inline Elf32_Addr
 elf_machine_load_address (void)
 {
+#ifndef SHARED
+  extern Elf32_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+  if (!_DYNAMIC)
+    return 0;
+#endif
   register Elf32_Addr *pc __asm ("%o7"), *got __asm ("%l7");
 
   __asm ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t"
diff --git a/sysdeps/sparc/sparc64/dl-machine.h b/sysdeps/sparc/sparc64/dl-machine.h
index c2871dca3a..22e6dcced3 100644
--- a/sysdeps/sparc/sparc64/dl-machine.h
+++ b/sysdeps/sparc/sparc64/dl-machine.h
@@ -66,6 +66,11 @@  elf_machine_dynamic (void)
 static inline Elf64_Addr
 elf_machine_load_address (void)
 {
+#ifndef SHARED
+  extern Elf64_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+  if (!_DYNAMIC)
+    return 0;
+#endif
   register Elf32_Addr *pc __asm ("%o7");
   register Elf64_Addr *got __asm ("%l7");