1 /* vi: set sw=4 ts=4: */
2 /* yoinked from glibc/sysdeps/x86_64/dl-machine.h */
3 /* Machine-dependent ELF dynamic relocation inline functions. x86-64 version.
4 Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
6 Contributed by Andreas Jaeger <aj@suse.de>.
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, see
20 <http://www.gnu.org/licenses/>. */
22 /* Define this if the system uses RELOCA. */
23 #define ELF_USES_RELOCA
26 /* Initialization sequence for the GOT. */
27 #define INIT_GOT(GOT_BASE,MODULE) \
29 GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
30 GOT_BASE[1] = (unsigned long) MODULE; \
33 /* Here we define the magic numbers that this dynamic loader should accept */
34 #define MAGIC1 EM_X86_64
37 /* Used for error messages */
38 #define ELF_TARGET "x86_64"
41 extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
43 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
44 TLS variable, so undefined references should not be allowed to
46 ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
47 of the main executable's symbols, as for a COPY reloc. */
48 #define elf_machine_type_class(type) \
49 ((((type) == R_X86_64_JUMP_SLOT \
50 || (type) == R_X86_64_DTPMOD64 \
51 || (type) == R_X86_64_DTPOFF64 \
52 || (type) == R_X86_64_TPOFF64) \
53 * ELF_RTYPE_CLASS_PLT) \
54 | (((type) == R_X86_64_COPY) * ELF_RTYPE_CLASS_COPY))
56 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
57 first element of the GOT. This must be inlined in a function which
59 static __always_inline Elf64_Addr __attribute__ ((unused))
60 elf_machine_dynamic (void)
64 /* This works because we have our GOT address available in the small PIC
66 addr = (Elf64_Addr) &_DYNAMIC;
72 /* Return the run-time load address of the shared object. */
73 static __always_inline Elf64_Addr __attribute__ ((unused))
74 elf_machine_load_address (void)
76 register Elf64_Addr addr, tmp;
78 /* The easy way is just the same as on x86:
80 leaq _dl_start(%%rip), %1
82 but this does not work with binutils since we then have
83 a R_X86_64_32S relocation in a shared lib.
85 Instead we store the address of _dl_start in the data section
86 and compare it with the current value that we can get via
87 an RIP relative addressing mode. */
89 __asm__ ("movq 1f(%%rip), %1\n"
90 "0:\tleaq _dl_start(%%rip), %0\n\t"
93 "1:\t.quad _dl_start\n\t"
95 : "=r" (addr), "=r" (tmp) : : "cc");
100 static __always_inline void
101 elf_machine_relative(Elf64_Addr load_off, const Elf64_Addr rel_addr,
102 Elf64_Word relative_count)
104 Elf64_Rela *rpnt = (Elf64_Rela*)rel_addr;
107 Elf64_Addr *const reloc_addr = (Elf64_Addr*)(load_off + (++rpnt)->r_offset);
109 *reloc_addr = load_off + rpnt->r_addend;
110 } while (--relative_count);