add experimental aarch64 support
[uclibc-ng.git] / ldso / ldso / aarch64 / dl-sysdep.h
blob4e8cdd90611372589d23de61862dbd52db5a6cb6
1 /*
2 * Various assembly language/system dependent hacks that are required
3 * so that we can minimize the amount of platform specific code.
4 * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
5 * Copyright (C) 2017 by Waldemar Brodkorb <wbx@uclibc-ng.org>
6 * Ported from GNU C Library
7 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8 */
10 /* Copyright (C) 1995-2016 Free Software Foundation, Inc.
12 The GNU C Library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Lesser General Public License as
14 published by the Free Software Foundation; either version 2.1 of the
15 License, or (at your option) any later version.
17 The GNU C Library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public
23 License along with the GNU C Library; if not, see
24 <http://www.gnu.org/licenses/>. */
26 /* Define this if the system uses RELOCA. */
27 #define ELF_USES_RELOCA
29 #include <elf.h>
30 #include <link.h>
32 /* Initialization sequence for the GOT. */
33 #define INIT_GOT(GOT_BASE,MODULE) \
34 { \
35 GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
36 GOT_BASE[1] = (unsigned long) MODULE; \
39 /* Here we define the magic numbers that this dynamic loader should accept */
40 #define MAGIC1 EM_AARCH64
41 #undef MAGIC2
43 /* Used for error messages */
44 #define ELF_TARGET "aarch64"
46 struct elf_resolve;
47 unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
49 #define elf_machine_type_class(type) \
50 ((((type) == R_AARCH64_JUMP_SLOT \
51 || (type) == R_AARCH64_TLS_DTPMOD \
52 || (type) == R_AARCH64_TLS_DTPREL \
53 || (type) == R_AARCH64_TLS_TPREL \
54 || (type) == R_AARCH64_TLSDESC) * ELF_RTYPE_CLASS_PLT) \
55 | (((type) == R_AARCH64_COPY) * ELF_RTYPE_CLASS_COPY))
57 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
58 first element of the GOT. */
59 extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
60 static __always_inline ElfW(Addr) __attribute__ ((unused))
61 elf_machine_dynamic (void)
63 return _GLOBAL_OFFSET_TABLE_[0];
66 /* Return the run-time load address of the shared object. */
68 static __always_inline ElfW(Addr) __attribute__ ((unused))
69 elf_machine_load_address (void)
71 /* To figure out the load address we use the definition that for any symbol:
72 dynamic_addr(symbol) = static_addr(symbol) + load_addr
74 The choice of symbol is arbitrary. The static address we obtain
75 by constructing a non GOT reference to the symbol, the dynamic
76 address of the symbol we compute using adrp/add to compute the
77 symbol's address relative to the PC.
78 This depends on 32/16bit relocations being resolved at link time
79 and that the static address fits in the 32/16 bits. */
81 ElfW(Addr) static_addr;
82 ElfW(Addr) dynamic_addr;
84 __asm__(" \n"
85 " adrp %1, _dl_start; \n"
86 " add %1, %1, #:lo12:_dl_start \n"
87 " ldr %w0, 1f \n"
88 " b 2f \n"
89 "1: \n"
90 " .word _dl_start \n"
91 "2: \n"
92 : "=r" (static_addr), "=r" (dynamic_addr));
93 return dynamic_addr - static_addr;
96 static __always_inline void
97 elf_machine_relative(Elf64_Addr load_off, const Elf64_Addr rel_addr,
98 Elf64_Word relative_count)
100 Elf64_Rela *rpnt = (Elf64_Rela*)rel_addr;
101 --rpnt;
102 do {
103 Elf64_Addr *const reloc_addr = (Elf64_Addr*)(load_off + (++rpnt)->r_offset);
105 *reloc_addr = load_off + rpnt->r_addend;
106 } while (--relative_count);