This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] sh: Update elf_machine_load_address for static PIE
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Date: Fri, 29 Sep 2017 14:33:19 -0700
- Subject: [PATCH] sh: Update elf_machine_load_address for static PIE
- Authentication-results: sourceware.org; auth=none
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/sh/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/sh/dl-machine.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/sysdeps/sh/dl-machine.h b/sysdeps/sh/dl-machine.h
index 7106afbdbd..627ef115a9 100644
--- a/sysdeps/sh/dl-machine.h
+++ b/sysdeps/sh/dl-machine.h
@@ -50,6 +50,7 @@ static inline Elf32_Addr __attribute__ ((unused))
elf_machine_load_address (void)
{
Elf32_Addr addr;
+#ifdef SHARED
asm ("mov.l 1f,r0\n\
mov.l 3f,r2\n\
add r12,r2\n\
@@ -61,6 +62,22 @@ elf_machine_load_address (void)
3: .long _dl_start@GOTOFF\n\
2: mov r2,%0"
: "=r" (addr) : : "r0", "r1", "r2");
+#else
+ extern Elf32_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+ if (!_DYNAMIC)
+ return 0;
+ asm ("mov.l 1f,r0\n\
+ mov.l 3f,r2\n\
+ add r12,r2\n\
+ mov.l @(r0,r12),r0\n\
+ bra 2f\n\
+ sub r0,r2\n\
+ .align 2\n\
+ 1: .long _dl_relocate_static_pie@GOT\n\
+ 3: .long _dl_relocate_static_pie@GOTOFF\n\
+ 2: mov r2,%0"
+ : "=r" (addr) : : "r0", "r1", "r2");
+#endif
return addr;
}
--
2.13.6