This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] s390: 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:37 -0700
- Subject: [PATCH] s390: 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/s390/s390-32/dl-machine.h (elf_machine_dynamic): 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/s390/s390-64/dl-machine.h (elf_machine_dynamic):
Likewise.
---
sysdeps/s390/s390-32/dl-machine.h | 14 ++++++++++++++
sysdeps/s390/s390-64/dl-machine.h | 11 +++++++++++
2 files changed, 25 insertions(+)
diff --git a/sysdeps/s390/s390-32/dl-machine.h b/sysdeps/s390/s390-32/dl-machine.h
index c302c9d2ce..b5cdcb87cb 100644
--- a/sysdeps/s390/s390-32/dl-machine.h
+++ b/sysdeps/s390/s390-32/dl-machine.h
@@ -70,6 +70,7 @@ elf_machine_load_address (void)
{
Elf32_Addr addr;
+#ifdef SHARED
__asm__( " bras 1,2f\n"
"1: .long _GLOBAL_OFFSET_TABLE_ - 1b\n"
" .long (_dl_start - 1b - 0x80000000) & 0x00000000ffffffff\n"
@@ -78,6 +79,19 @@ elf_machine_load_address (void)
" al 1,0(1)\n"
" sl %0,_dl_start@GOT(1)"
: "=&d" (addr) : : "1" );
+#else
+ extern Elf32_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+ if (!_DYNAMIC)
+ return 0;
+ __asm__( " bras 1,2f\n"
+ "1: .long _GLOBAL_OFFSET_TABLE_ - 1b\n"
+ " .long (_dl_relocate_static_pie - 1b - 0x80000000) & 0x00000000ffffffff\n"
+ "2: l %0,4(1)\n"
+ " ar %0,1\n"
+ " al 1,0(1)\n"
+ " sl %0,_dl_relocate_static_pie@GOT(1)"
+ : "=&d" (addr) : : "1" );
+#endif
return addr;
}
diff --git a/sysdeps/s390/s390-64/dl-machine.h b/sysdeps/s390/s390-64/dl-machine.h
index 7513520417..724cc4f2e5 100644
--- a/sysdeps/s390/s390-64/dl-machine.h
+++ b/sysdeps/s390/s390-64/dl-machine.h
@@ -63,11 +63,22 @@ elf_machine_load_address (void)
{
Elf64_Addr addr;
+#ifdef SHARED
__asm__( " larl %0,_dl_start\n"
" larl 1,_GLOBAL_OFFSET_TABLE_\n"
" lghi 2,_dl_start@GOT\n"
" slg %0,0(2,1)"
: "=&d" (addr) : : "1", "2" );
+#else
+ extern Elf64_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
+ if (!_DYNAMIC)
+ return 0;
+ __asm__( " larl %0,_dl_relocate_static_pie\n"
+ " larl 1,_GLOBAL_OFFSET_TABLE_\n"
+ " lghi 2,_dl_relocate_static_pie@GOT\n"
+ " slg %0,0(2,1)"
+ : "=&d" (addr) : : "1", "2" );
+#endif
return addr;
}
--
2.13.6