[1/1] aarch64/dl-machine.h: Fix load-address for prelink support

Message ID 1444987951-17277-1-git-send-email-maninder1.s@samsung.com
State New, archived
Headers

Commit Message

Maninder Singh Oct. 16, 2015, 9:32 a.m. UTC
  Fix load-address for prelink support in aarch64,
reference from x86_64.

Existing code always use compiled address, whereas it should
use compiled address for non-prelinked binaries and prelinked
address for prelinked binaries, which it can get from .GOT first entry.

Signed-off-by: Vaneet Narang <v.narang@samsung.com>
Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
---
 sysdeps/aarch64/dl-machine.h |   28 +++++-----------------------
 1 files changed, 5 insertions(+), 23 deletions(-)
  

Comments

Mike Frysinger Oct. 17, 2015, 2:35 a.m. UTC | #1
On 16 Oct 2015 15:02, Maninder Singh wrote:
> +  return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();

paren around ElfW(Addr) aren't really needed
-mike
  
Andreas Schwab Oct. 17, 2015, 7:37 a.m. UTC | #2
Mike Frysinger <vapier@gentoo.org> writes:

> On 16 Oct 2015 15:02, Maninder Singh wrote:
>> +  return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
>
> paren around ElfW(Addr) aren't really needed

It's a cast.

Andreas.
  

Patch

diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h
index 217e179..7bb737d 100644
--- a/sysdeps/aarch64/dl-machine.h
+++ b/sysdeps/aarch64/dl-machine.h
@@ -46,29 +46,11 @@  elf_machine_dynamic (void)
 static inline ElfW(Addr) __attribute__ ((unused))
 elf_machine_load_address (void)
 {
-  /* To figure out the load address we use the definition that for any symbol:
-     dynamic_addr(symbol) = static_addr(symbol) + load_addr
-
-     The choice of symbol is arbitrary. The static address we obtain
-     by constructing a non GOT reference to the symbol, the dynamic
-     address of the symbol we compute using adrp/add to compute the
-     symbol's address relative to the PC.
-     This depends on 32bit relocations being resolved at link time
-     and that the static address fits in the 32bits.  */
-
-  ElfW(Addr) static_addr;
-  ElfW(Addr) dynamic_addr;
-
-  asm ("					\n"
-"	adrp	%1, _dl_start;			\n"
-"	add	%1, %1, #:lo12:_dl_start	\n"
-"	ldr	%w0, 1f				\n"
-"	b	2f				\n"
-"1:						\n"
-"	.word	_dl_start			\n"
-"2:						\n"
-    : "=r" (static_addr),  "=r" (dynamic_addr));
-  return dynamic_addr - static_addr;
+  /* Compute the difference between the runtime address of _DYNAMIC as seen
+     by an IP-relative reference, and the link-time address found in the
+     special unrelocated first GOT entry.  */
+  extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
+  return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
 }
 
 /* Set up the loaded object described by L so its unrelocated PLT