Browse Source

ld.so: Rewrite elf_machine_load_address using _DYNAMIC symbol

Sync with GNU C library commit:
commit a68ba2f3cd3cbe32c1f31e13c20ed13487727b32
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Oct 18 17:26:23 2017 +0100

Fixes issues with binutils version > 2.29.1.
Waldemar Brodkorb 6 years ago
parent
commit
e87dec4f00
1 changed files with 7 additions and 22 deletions
  1. 7 22
      ldso/ldso/aarch64/dl-sysdep.h

+ 7 - 22
ldso/ldso/aarch64/dl-sysdep.h

@@ -2,12 +2,12 @@
  * Various assembly language/system dependent hacks that are required
  * so that we can minimize the amount of platform specific code.
  * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
- * Copyright (C) 2017 by Waldemar Brodkorb <wbx@uclibc-ng.org>
+ * Copyright (C) 2017-2018 by Waldemar Brodkorb <wbx@uclibc-ng.org>
  * Ported from GNU C Library
  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  */
 
-/* Copyright (C) 1995-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2017 Free Software Foundation, Inc.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public License as
@@ -71,26 +71,11 @@ 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 32/16bit relocations being resolved at link time
-     and that the static address fits in the 32/16 bits.  */
-
-  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;
+    _DYNAMIC sysmbol is used here as its link-time address stored in
+    the special unrelocated first GOT entry.  */
+
+    extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
+    return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
 }
 
 static __always_inline void