Add Changelog ...
[jlayton/glibc.git] / sysdeps / tile / dl-runtime.c
1 /* Copyright (C) 2011 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library.  If not, see
17    <http://www.gnu.org/licenses/>.  */
18
19 /* Like x86_64, we pass the index of the relocation and not its offset.
20    In _dl_profile_fixup and _dl_call_pltexit we also use the index.
21    Therefore it is wasteful to compute the offset in the trampoline
22    just to reverse the operation immediately afterwards.  */
23 #define reloc_offset reloc_arg * sizeof (PLTREL)
24 #define reloc_index  reloc_arg
25
26 #include <elf/dl-runtime.c>
27
28 #include <sys/mman.h>
29 #include <arch/sim.h>
30
31 /* Support notifying the simulator about new objects. */
32 void internal_function
33 _dl_arch_map_object (struct link_map *l)
34 {
35   int shift;
36
37 #define DLPUTC(c) __insn_mtspr(SPR_SIM_CONTROL,                         \
38                                (SIM_CONTROL_DLOPEN                      \
39                                 | ((c) << _SIM_CONTROL_OPERATOR_BITS)))
40
41   /* Write the library address in hex. */
42   DLPUTC ('0');
43   DLPUTC ('x');
44   for (shift = (int) sizeof (unsigned long) * 8 - 4; shift >= 0; shift -= 4)
45     DLPUTC ("0123456789abcdef"[(l->l_map_start >> shift) & 0xF]);
46   DLPUTC (':');
47
48   /* Write the library path, including the terminating '\0'. */
49   for (size_t i = 0;; i++)
50     {
51       DLPUTC (l->l_name[i]);
52       if (l->l_name[i] == '\0')
53         break;
54     }
55 #undef DLPUTC
56 }
57
58 /* Support notifying the simulator about removed objects prior to munmap(). */
59 void internal_function
60 _dl_unmap (struct link_map *l)
61 {
62   int shift;
63
64 #define DLPUTC(c) __insn_mtspr(SPR_SIM_CONTROL,                         \
65                                (SIM_CONTROL_DLCLOSE                     \
66                                 | ((c) << _SIM_CONTROL_OPERATOR_BITS)))
67
68   /* Write the library address in hex. */
69   DLPUTC ('0');
70   DLPUTC ('x');
71   for (shift = (int) sizeof (unsigned long) * 8 - 4; shift >= 0; shift -= 4)
72     DLPUTC ("0123456789abcdef"[(l->l_map_start >> shift) & 0xF]);
73   DLPUTC ('\0');
74 #undef DLPUTC
75
76   __munmap ((void *) l->l_map_start, l->l_map_end - l->l_map_start);
77 }
78
79 #define DL_UNMAP(map) _dl_unmap (map)