]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/ldso/ldso/x86_64/dl-sysdep.h
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / ldso / ldso / x86_64 / dl-sysdep.h
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>.
7
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.
12
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.
17
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/>.  */
21
22 /* Define this if the system uses RELOCA.  */
23 #define ELF_USES_RELOCA
24 #include <elf.h>
25 #include <link.h>
26 /* Initialization sequence for the GOT.  */
27 #define INIT_GOT(GOT_BASE,MODULE)                                                       \
28 do {                                                                                                            \
29         GOT_BASE[2] = (unsigned long) _dl_linux_resolve;                \
30         GOT_BASE[1] = (unsigned long) MODULE;                                   \
31 } while(0)
32
33 /* Here we define the magic numbers that this dynamic loader should accept */
34 #define MAGIC1 EM_X86_64
35 #undef  MAGIC2
36
37 /* Used for error messages */
38 #define ELF_TARGET "x86_64"
39
40 struct elf_resolve;
41 extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
42
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
45    define the value.
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))
55
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
58    uses global data.  */
59 static __always_inline Elf64_Addr __attribute__ ((unused))
60 elf_machine_dynamic (void)
61 {
62   Elf64_Addr addr;
63
64   /* This works because we have our GOT address available in the small PIC
65      model.  */
66   addr = (Elf64_Addr) &_DYNAMIC;
67
68   return addr;
69 }
70
71
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)
75 {
76   register Elf64_Addr addr, tmp;
77
78   /* The easy way is just the same as on x86:
79        leaq _dl_start, %0
80        leaq _dl_start(%%rip), %1
81        subq %0, %1
82      but this does not work with binutils since we then have
83      a R_X86_64_32S relocation in a shared lib.
84
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.  */
88
89   __asm__ ("movq 1f(%%rip), %1\n"
90        "0:\tleaq _dl_start(%%rip), %0\n\t"
91        "subq %1, %0\n\t"
92        ".section\t.data\n"
93        "1:\t.quad _dl_start\n\t"
94        ".previous\n\t"
95        : "=r" (addr), "=r" (tmp) : : "cc");
96
97   return addr;
98 }
99
100 static __always_inline void
101 elf_machine_relative(Elf64_Addr load_off, const Elf64_Addr rel_addr,
102                      Elf64_Word relative_count)
103 {
104         Elf64_Rela *rpnt = (Elf64_Rela*)rel_addr;
105         --rpnt;
106         do {
107                 Elf64_Addr *const reloc_addr = (Elf64_Addr*)(load_off + (++rpnt)->r_offset);
108
109                 *reloc_addr = load_off + rpnt->r_addend;
110         } while (--relative_count);
111 }